Skip to content

Instantly share code, notes, and snippets.

@joshenders
Created February 8, 2015 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshenders/faac5b0478039b10f971 to your computer and use it in GitHub Desktop.
Save joshenders/faac5b0478039b10f971 to your computer and use it in GitHub Desktop.
X-Forwarded-For patch for thttpd-2.26
--- libhttpd.c 2014-12-10 12:53:07.000000000 -0800
+++ libhttpd.c.patched 2015-02-07 22:44:59.183663432 -0800
@@ -2231,6 +2231,12 @@
if ( strcasecmp( cp, "keep-alive" ) == 0 )
hc->keep_alive = 1;
}
+ else if ( strncasecmp( buf, "X-Forwarded-For:", 16 ) == 0 )
+ { // Use real IP if available
+ cp = &buf[16];
+ cp += strspn( cp, " \t" );
+ inet_aton( cp, &(hc->client_addr.sa_in.sin_addr) );
+ }
#ifdef LOG_UNKNOWN_HEADERS
else if ( strncasecmp( buf, "Accept-Charset:", 15 ) == 0 ||
strncasecmp( buf, "Accept-Language:", 16 ) == 0 ||
@troglobit
Copy link

Thanks! (FYI: This is included in both sthttpd and Merecat, both forks of thttpd.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment