From 878dd9be499a7d271d808fdf73f804f9df77e564 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Sat, 7 Oct 2017 13:05:25 -0400 Subject: [PATCH] [core] use sun_path for addr string for AF_UNIX (fixes #2826) (occurs when lighttpd is configured to listen on unix socket path) x-ref: "stale REMOTE_ADDR when using AF_UNIX socket" https://redmine.lighttpd.net/issues/2826 --- src/inet_ntop_cache.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/inet_ntop_cache.c b/src/inet_ntop_cache.c index 68a60cf7..8a1625b9 100644 --- a/src/inet_ntop_cache.c +++ b/src/inet_ntop_cache.c @@ -474,6 +474,9 @@ const char * inet_ntop_cache_get_ip(server *srv, sock_addr *addr) { int i; UNUSED(srv); + #ifdef HAVE_SYS_UN_H + if (addr->plain.sa_family == AF_UNIX) return addr->un.sun_path; + #endif for (i = 0; i < INET_NTOP_CACHE_MAX; i++) { if (inet_ntop_cache[i].family == addr->plain.sa_family) { if (inet_ntop_cache[i].family == AF_INET6 && @@ -515,6 +518,10 @@ const char * inet_ntop_cache_get_ip(server *srv, sock_addr *addr) { return inet_ntop_cache[i].b2; #else UNUSED(srv); - return inet_ntoa(addr->ipv4.sin_addr); + if (addr->plain.sa_family == AF_INET) return inet_ntoa(addr->ipv4.sin_addr); + #ifdef HAVE_SYS_UN_H + if (addr->plain.sa_family == AF_UNIX) return addr->un.sun_path; + #endif + return ""; #endif }