Skip to content

Use real IP if available #13

Description

@vldzhk

The header X-Forwarded-For may contain an ipv4 address for an ipv6 connection, and vice versa

more details https://blog.steve.fi/ipv6_and_thttpd.html

--- src/libhttpd.c
+++ src/libhttpd.c.new
@@ -2207,7 +2204,10 @@
 		{ // Use real IP if available 
 		cp = &buf[16];
 		cp += strspn( cp, " \t" );
-		inet_aton( cp, &(hc->client_addr.sa_in.sin_addr) );
+		if (inet_pton(AF_INET, cp, &(hc->client_addr.sa_in.sin_addr)))
+			hc->client_addr.sa.sa_family = AF_INET;
+		else if (inet_pton(AF_INET6, cp, &(hc->client_addr.sa_in6.sin6_addr)))
+			hc->client_addr.sa.sa_family = AF_INET6;
 		}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions