Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improve socket creation error message
  • Loading branch information
Fabian Mauchle committed Jan 20, 2023
1 parent c62d06d commit 7b6c965
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions util.c
Expand Up @@ -152,28 +152,28 @@ int bindtoaddr(struct addrinfo *addrinfo, int family, int reuse) {
struct addrinfo *res;

for (res = addrinfo; res; res = res->ai_next) {
if (family != AF_UNSPEC && family != res->ai_family)
continue;
s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (s < 0) {
debug(DBG_WARN, "bindtoaddr: socket failed");
continue;
}

disable_DF_bit(s,res);

if (reuse)
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1)
if (family != AF_UNSPEC && family != res->ai_family)
continue;
s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (s < 0) {
debugerrno(errno, DBG_WARN, "bindtoaddr: socket creation failed");
continue;
}

disable_DF_bit(s,res);

if (reuse)
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1)
debugerrno(errno, DBG_WARN, "Failed to set SO_REUSEADDR");
#ifdef IPV6_V6ONLY
if (family == AF_INET6)
if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1)
if (family == AF_INET6)
if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1)
debugerrno(errno, DBG_WARN, "Failed to set IPV6_V6ONLY");
#endif
if (!bind(s, res->ai_addr, res->ai_addrlen))
return s;
debug(DBG_WARN, "bindtoaddr: bind failed");
close(s);
if (!bind(s, res->ai_addr, res->ai_addrlen))
return s;
debug(DBG_WARN, "bindtoaddr: bind failed");
close(s);
}
return -1;
}
Expand Down

0 comments on commit 7b6c965

Please sign in to comment.