Commit 34d60446 authored by Olivier Crête's avatar Olivier Crête

stund: Pass sockaddr_storage size for both families

parent 3a9d9281
...@@ -100,15 +100,12 @@ int listen_socket (int fam, int type, int proto, unsigned int port) ...@@ -100,15 +100,12 @@ int listen_socket (int fam, int type, int proto, unsigned int port)
struct sockaddr_in6 in6; struct sockaddr_in6 in6;
struct sockaddr_storage storage; struct sockaddr_storage storage;
} addr; } addr;
int len;
if (fd == -1) if (fd == -1)
{ {
perror ("Error opening IP port"); perror ("Error opening IP port");
return -1; return -1;
} }
if (fd < 3)
goto error;
memset (&addr, 0, sizeof (addr)); memset (&addr, 0, sizeof (addr));
addr.storage.ss_family = fam; addr.storage.ss_family = fam;
...@@ -120,7 +117,6 @@ int listen_socket (int fam, int type, int proto, unsigned int port) ...@@ -120,7 +117,6 @@ int listen_socket (int fam, int type, int proto, unsigned int port)
{ {
case AF_INET: case AF_INET:
addr.in.sin_port = htons (port); addr.in.sin_port = htons (port);
len = sizeof (struct sockaddr_in);
break; break;
case AF_INET6: case AF_INET6:
...@@ -128,14 +124,13 @@ int listen_socket (int fam, int type, int proto, unsigned int port) ...@@ -128,14 +124,13 @@ int listen_socket (int fam, int type, int proto, unsigned int port)
setsockopt (fd, SOL_IPV6, IPV6_V6ONLY, &yes, sizeof (yes)); setsockopt (fd, SOL_IPV6, IPV6_V6ONLY, &yes, sizeof (yes));
#endif #endif
addr.in6.sin6_port = htons (port); addr.in6.sin6_port = htons (port);
len = sizeof (struct sockaddr_in6);
break; break;
default: default:
assert (0); /* should never be reached */ assert (0); /* should never be reached */
} }
if (bind (fd, &addr.addr, len)) if (bind (fd, &addr.addr, sizeof (struct sockaddr_storage)))
{ {
perror ("Error opening IP port"); perror ("Error opening IP port");
goto error; goto error;
...@@ -192,7 +187,7 @@ static int dgram_process (int sock, StunAgent *oldagent, StunAgent *newagent) ...@@ -192,7 +187,7 @@ static int dgram_process (int sock, StunAgent *oldagent, StunAgent *newagent)
StunValidationStatus validation; StunValidationStatus validation;
StunAgent *agent = NULL; StunAgent *agent = NULL;
addr_len = sizeof (struct sockaddr_in); addr_len = sizeof (struct sockaddr_storage);
len = recvfrom (sock, buf, sizeof(buf), 0, &addr.addr, &addr_len); len = recvfrom (sock, buf, sizeof(buf), 0, &addr.addr, &addr_len);
if (len == (size_t)-1) if (len == (size_t)-1)
return -1; return -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment