summaryrefslogtreecommitdiff
path: root/src/network.c
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2016-07-27 15:37:46 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2016-07-27 15:37:46 -0400
commita69a803e35500c2ec0ba900420452cd4db750502 (patch)
tree54e548832d344a96dd94aac53f50f1355bd322b8 /src/network.c
parenta95aaa9de984dc004dd1d4302147e8a0c23efb10 (diff)
downloadlighttpd1.4-a69a803e35500c2ec0ba900420452cd4db750502.tar.gz
lighttpd1.4-a69a803e35500c2ec0ba900420452cd4db750502.zip
[core] try AF_INET after AF_INET6 if use-ipv6
try AF_INET after AF_INET6 if server.use-ipv6 = "enable" and getaddrinfo() fails EAI_ADDRFAMILY when hints.ai_family is AF_INET6. (Prefer IPv6 instead of setting hinst.ai_family to AF_UNSPEC since lighttpd only uses the first address returned)
Diffstat (limited to 'src/network.c')
-rw-r--r--src/network.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/network.c b/src/network.c
index f5599294..61aeb395 100644
--- a/src/network.c
+++ b/src/network.c
@@ -281,6 +281,16 @@ static int network_server_init(server *srv, buffer *host_token, specific_config
hints.ai_protocol = IPPROTO_TCP;
if (0 != (r = getaddrinfo(host, NULL, &hints, &res))) {
+ hints.ai_family = AF_INET;
+ if (EAI_ADDRFAMILY == r && 0 == getaddrinfo(host, NULL, &hints, &res)) {
+ srv_socket->addr.ipv4.sin_family = AF_INET;
+ srv_socket->addr.ipv4.sin_port = htons(port);
+ memcpy(&(srv_socket->addr.ipv4.sin_addr.s_addr), res->ai_addr, res->ai_addrlen);
+ addr_len = sizeof(struct sockaddr_in);
+ freeaddrinfo(res);
+ break;
+ }
+
log_error_write(srv, __FILE__, __LINE__,
"sssss", "getaddrinfo failed: ",
gai_strerror(r), "'", host, "'");