Skip to content

Commit

Permalink
consistent setting of sin_len
Browse files Browse the repository at this point in the history
  • Loading branch information
vlm committed Mar 24, 2017
1 parent fe184d6 commit 2c532da
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ipaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ static int ipaddr_ipany(struct ipaddr *addr, int port, int mode)
ipv4->sin_family = AF_INET;
ipv4->sin_addr.s_addr = htonl(INADDR_ANY);
ipv4->sin_port = htons((uint16_t)port);
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
ipv4->sin_len = sizeof(struct sockaddr_in);
#endif
return 0;
}
else {
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6*)addr;
ipv6->sin6_family = AF_INET6;
memcpy(&ipv6->sin6_addr, &in6addr_any, sizeof(in6addr_any));
ipv6->sin6_port = htons((uint16_t)port);
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
ipv6->sin6_len = sizeof(struct sockaddr_in6);
#endif
return 0;
}
}
Expand All @@ -82,6 +88,9 @@ static int ipaddr_ipv4_literal(struct ipaddr *addr, const char *name,
if(dill_slow(rc != 1)) {errno = EINVAL; return -1;}
ipv4->sin_family = AF_INET;
ipv4->sin_port = htons((uint16_t)port);
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
ipv4->sin_len = sizeof(struct sockaddr_in);
#endif
return 0;
}

Expand All @@ -94,6 +103,9 @@ static int ipaddr_ipv6_literal(struct ipaddr *addr, const char *name,
if(dill_slow(rc != 1)) {errno = EINVAL; return -1;}
ipv6->sin6_family = AF_INET6;
ipv6->sin6_port = htons((uint16_t)port);
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
ipv6->sin6_len = sizeof(struct sockaddr_in6);
#endif
return 0;
}

Expand Down

0 comments on commit 2c532da

Please sign in to comment.