mirror of
https://github.com/morgan9e/UxPlay
synced 2026-04-14 00:04:13 +09:00
add port information when accepting clients
This commit is contained in:
@@ -268,6 +268,7 @@ httpd_accept_connection(httpd_t *httpd, int server_fd, int is_ipv6)
|
|||||||
struct sockaddr_storage local_saddr;
|
struct sockaddr_storage local_saddr;
|
||||||
socklen_t local_saddrlen;
|
socklen_t local_saddrlen;
|
||||||
unsigned char *local, *remote;
|
unsigned char *local, *remote;
|
||||||
|
unsigned short port;
|
||||||
unsigned int local_zone_id, remote_zone_id;
|
unsigned int local_zone_id, remote_zone_id;
|
||||||
int local_len, remote_len;
|
int local_len, remote_len;
|
||||||
int ret, fd;
|
int ret, fd;
|
||||||
@@ -287,10 +288,10 @@ httpd_accept_connection(httpd_t *httpd, int server_fd, int is_ipv6)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger_log(httpd->logger, LOGGER_INFO, "Accepted %s client on socket %d",
|
local = netutils_get_address(&local_saddr, &local_len, &local_zone_id, &port);
|
||||||
(is_ipv6 ? "IPv6" : "IPv4"), fd);
|
logger_log(httpd->logger, LOGGER_INFO, "Accepted %s client on socket %d, port %u",
|
||||||
local = netutils_get_address(&local_saddr, &local_len, &local_zone_id);
|
(is_ipv6 ? "IPv6" : "IPv4"), fd, port);
|
||||||
remote = netutils_get_address(&remote_saddr, &remote_len, &remote_zone_id);
|
remote = netutils_get_address(&remote_saddr, &remote_len, &remote_zone_id, NULL);
|
||||||
assert (local_zone_id == remote_zone_id);
|
assert (local_zone_id == remote_zone_id);
|
||||||
|
|
||||||
ret = httpd_add_connection(httpd, fd, local, local_len, remote, remote_len, local_zone_id);
|
ret = httpd_add_connection(httpd, fd, local, local_len, remote, remote_len, local_zone_id);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ netutils_cleanup()
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *
|
unsigned char *
|
||||||
netutils_get_address(void *sockaddr, int *length, unsigned int *zone_id)
|
netutils_get_address(void *sockaddr, int *length, unsigned int *zone_id, unsigned short *port)
|
||||||
{
|
{
|
||||||
unsigned char ipv4_prefix[] = { 0,0,0,0,0,0,0,0,0,0,255,255 };
|
unsigned char ipv4_prefix[] = { 0,0,0,0,0,0,0,0,0,0,255,255 };
|
||||||
struct sockaddr *address = sockaddr;
|
struct sockaddr *address = sockaddr;
|
||||||
@@ -66,11 +66,17 @@ netutils_get_address(void *sockaddr, int *length, unsigned int *zone_id)
|
|||||||
*zone_id = 0;
|
*zone_id = 0;
|
||||||
sin = (struct sockaddr_in *)address;
|
sin = (struct sockaddr_in *)address;
|
||||||
*length = sizeof(sin->sin_addr.s_addr);
|
*length = sizeof(sin->sin_addr.s_addr);
|
||||||
|
if (port) {
|
||||||
|
*port = ntohs(sin->sin_port);
|
||||||
|
}
|
||||||
return (unsigned char *)&sin->sin_addr.s_addr;
|
return (unsigned char *)&sin->sin_addr.s_addr;
|
||||||
} else if (address->sa_family == AF_INET6) {
|
} else if (address->sa_family == AF_INET6) {
|
||||||
struct sockaddr_in6 *sin6;
|
struct sockaddr_in6 *sin6;
|
||||||
|
|
||||||
sin6 = (struct sockaddr_in6 *)address;
|
sin6 = (struct sockaddr_in6 *)address;
|
||||||
|
if (port) {
|
||||||
|
*port = ntohs(sin6->sin6_port);
|
||||||
|
}
|
||||||
if (!memcmp(sin6->sin6_addr.s6_addr, ipv4_prefix, 12)) {
|
if (!memcmp(sin6->sin6_addr.s6_addr, ipv4_prefix, 12)) {
|
||||||
/* Actually an embedded IPv4 address */
|
/* Actually an embedded IPv4 address */
|
||||||
*zone_id = 0;
|
*zone_id = 0;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ int netutils_init();
|
|||||||
void netutils_cleanup();
|
void netutils_cleanup();
|
||||||
|
|
||||||
int netutils_init_socket(unsigned short *port, int use_ipv6, int use_udp);
|
int netutils_init_socket(unsigned short *port, int use_ipv6, int use_udp);
|
||||||
unsigned char *netutils_get_address(void *sockaddr, int *length, unsigned int *zone_id);
|
unsigned char *netutils_get_address(void *sockaddr, int *length, unsigned int *zone_id, unsigned short *port);
|
||||||
int netutils_parse_address(int family, const char *src, void *dst, int dstlen);
|
int netutils_parse_address(int family, const char *src, void *dst, int dstlen);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user