summaryrefslogtreecommitdiff
path: root/src/network.c
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2017-01-14 16:19:54 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2017-01-31 14:36:15 -0500
commit8981ca0467316a5d046d5c257ceea57a49333c87 (patch)
tree04284137db21c2d3c387a1defacb4de0d3dbea18 /src/network.c
parent9c91af0cfddd1e80978e38700af035b7bdb6ca1b (diff)
downloadlighttpd1.4-8981ca0467316a5d046d5c257ceea57a49333c87.tar.gz
lighttpd1.4-8981ca0467316a5d046d5c257ceea57a49333c87.zip
[core] use getaddrinfo,inet_pton vs gethostbyname (fixes #2783)
when available, use getaddrinfo(),inet_pton() instead of gethostbyname() NOTE: behavior change: mod_scgi now listens to INADDR_LOOPBACK if "host" is not specified. (Prior behavior was INADDR_ANY.) Backends should not listen on potentially public IPs unless explicitly configured to do so. This change matches a change to mod_fastcgi made in 2008. x-ref "gethostbyname deprecated, should use getaddrinfo" https://redmine.lighttpd.net/issues/2783
Diffstat (limited to 'src/network.c')
-rw-r--r--src/network.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/network.c b/src/network.c
index 9afd5f88..2c787d0c 100644
--- a/src/network.c
+++ b/src/network.c
@@ -216,6 +216,24 @@ static int network_server_init(server *srv, buffer *host_token, size_t sidx) {
if (host == NULL) {
srv_socket->addr.ipv4.sin_addr.s_addr = htonl(INADDR_ANY);
} else {
+#ifdef HAVE_INET_PTON /*(reuse HAVE_INET_PTON for presence of getaddrinfo())*/
+ struct addrinfo hints, *res;
+ int r;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+
+ if (0 != (r = getaddrinfo(host, NULL, &hints, &res))) {
+ log_error_write(srv, __FILE__, __LINE__,
+ "sssss", "getaddrinfo failed: ",
+ gai_strerror(r), "'", host, "'");
+ goto error_free_socket;
+ }
+
+ memcpy(&(srv_socket->addr.ipv4), res->ai_addr, res->ai_addrlen);
+ freeaddrinfo(res);
+#else
struct hostent *he;
if (NULL == (he = gethostbyname(host))) {
log_error_write(srv, __FILE__, __LINE__,
@@ -235,6 +253,7 @@ static int network_server_init(server *srv, buffer *host_token, size_t sidx) {
}
memcpy(&(srv_socket->addr.ipv4.sin_addr.s_addr), he->h_addr_list[0], he->h_length);
+#endif
}
srv_socket->addr.ipv4.sin_port = htons(port);
addr_len = sizeof(struct sockaddr_in);