Make sure start_listening_socket does everything, this will lead the way to multiple listen ports.
This commit is contained in:
@@ -381,11 +381,11 @@ int net_accept(int fd, struct ip_addr_encap* ipaddr)
|
||||
{
|
||||
char address[INET6_ADDRSTRLEN+1] = { 0, };
|
||||
net_address_to_string(AF_INET6, (void*) &addr6->sin6_addr, address, INET6_ADDRSTRLEN+1);
|
||||
if (!strncmp(address, "::ffff:", 7))
|
||||
if (strchr(address, '.'))
|
||||
{
|
||||
/* Hack to convert IPv6 mapped IPv4 addresses to true IPv4 addresses */
|
||||
net_string_to_address(AF_INET, address + 7, (void*) &ipaddr->internal_ip_data.in);
|
||||
ipaddr->af = AF_INET;
|
||||
net_string_to_address(AF_INET, address, (void*) &ipaddr->internal_ip_data.in);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -526,7 +526,12 @@ const char* net_address_to_string(int af, const void* src, char* dst, socklen_t
|
||||
|
||||
return NULL;
|
||||
#else
|
||||
return inet_ntop(af, src, dst, cnt);
|
||||
const char* address = inet_ntop(af, src, dst, cnt);
|
||||
if (af == AF_INET6 && strncmp(address, "::ffff:", 7) == 0) /* IPv6 mapped IPv4 address. */
|
||||
{
|
||||
return &address[7];
|
||||
}
|
||||
return address;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -573,9 +578,6 @@ int net_string_to_address(int af, const char* src, void* dst)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const char* net_get_peer_address(int fd)
|
||||
{
|
||||
static char address[INET6_ADDRSTRLEN+1];
|
||||
@@ -598,17 +600,12 @@ const char* net_get_peer_address(int fd)
|
||||
if (af == AF_INET6)
|
||||
{
|
||||
net_address_to_string(af, (void*) &name6->sin6_addr, address, INET6_ADDRSTRLEN);
|
||||
if (strncmp(address, "::ffff:", 7) == 0) /* IPv6 mapped IPv4 address. */
|
||||
{
|
||||
return &address[7];
|
||||
}
|
||||
return address;
|
||||
}
|
||||
else
|
||||
{
|
||||
net_address_to_string(af, (void*) &name4->sin_addr, address, INET6_ADDRSTRLEN);
|
||||
return address;
|
||||
}
|
||||
return address;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -619,6 +616,45 @@ const char* net_get_peer_address(int fd)
|
||||
return "0.0.0.0";
|
||||
}
|
||||
|
||||
const char* net_get_local_address(int fd)
|
||||
{
|
||||
static char address[INET6_ADDRSTRLEN+1];
|
||||
struct sockaddr_storage storage;
|
||||
struct sockaddr_in6* name6;
|
||||
struct sockaddr_in* name4;
|
||||
struct sockaddr* name;
|
||||
|
||||
memset(address, 0, INET6_ADDRSTRLEN);
|
||||
socklen_t namelen = sizeof(struct sockaddr_storage);
|
||||
memset(&storage, 0, namelen);
|
||||
|
||||
name6 = (struct sockaddr_in6*) &storage;
|
||||
name4 = (struct sockaddr_in*) &storage;
|
||||
name = (struct sockaddr*) &storage;
|
||||
|
||||
if (getsockname(fd, (struct sockaddr*) name, &namelen) != -1)
|
||||
{
|
||||
int af = name4->sin_family;
|
||||
if (af == AF_INET6)
|
||||
{
|
||||
net_address_to_string(af, (void*) &name6->sin6_addr, address, INET6_ADDRSTRLEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
net_address_to_string(af, (void*) &name4->sin_addr, address, INET6_ADDRSTRLEN);
|
||||
}
|
||||
return address;
|
||||
}
|
||||
else
|
||||
{
|
||||
net_error_out(fd, "net_get_local_address");
|
||||
net_stats_add_error();
|
||||
}
|
||||
|
||||
return "0.0.0.0";
|
||||
}
|
||||
|
||||
|
||||
|
||||
ssize_t net_recv(int fd, void* buf, size_t len, int flags)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user