Initialize the socket address structure to zero.

It is safer and more correct to clear the addresses before use. The IPv6
fields flowinfo and scope_id in particular should not be set to random
values from the stack.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2012-11-25 17:45:37 +01:00
parent b8b96dd606
commit 87313fd05d
2 changed files with 4 additions and 0 deletions

2
udp.c
View File

@ -87,6 +87,7 @@ static int open_socket(char *name, struct in_addr mc_addr[2], short port)
struct sockaddr_in addr;
int fd, index, on = 1;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(port);
@ -184,6 +185,7 @@ static int udp_send(struct transport *t, struct fdarray *fda, int event, int pee
struct sockaddr_in addr;
unsigned char junk[1600];
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr = peer ? mcast_addr[MC_PDELAY] : mcast_addr[MC_PRIMARY];
addr.sin_port = htons(event ? EVENT_PORT : GENERAL_PORT);

2
udp6.c
View File

@ -86,6 +86,7 @@ static int open_socket_ipv6(char *name, struct in6_addr mc_addr[2], short port)
struct sockaddr_in6 addr;
int fd, index, on = 1;
memset(&addr, 0, sizeof(addr));
addr.sin6_family = AF_INET6;
addr.sin6_addr = in6addr_any;
addr.sin6_port = htons(port);
@ -183,6 +184,7 @@ static int udp6_send(struct transport *t, struct fdarray *fda, int event, int pe
struct sockaddr_in6 addr;
unsigned char junk[1600];
memset(&addr, 0, sizeof(addr));
addr.sin6_family = AF_INET6;
addr.sin6_addr = peer ? mc6_addr[MC_PDELAY] : mc6_addr[MC_PRIMARY];
addr.sin6_port = htons(event ? EVENT_PORT : GENERAL_PORT);