Created
August 20, 2012 11:06
-
-
Save tmotyl/3403227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C{ | |
#include <netinet/in.h> | |
#include <string.h> | |
#include <sys/socket.h> | |
#include <arpa/inet.h> | |
}C | |
C{ | |
// | |
// This is a hack from Igor Gariev (gariev hotmail com): | |
// Copy IP address from "X-Forwarded-For" header | |
// into Varnish's client_ip structure. | |
// This works with Varnish 3.0.1; test with other versions | |
// | |
// Trusted "X-Forwarded-For" header is a must! | |
// No commas are allowed. If your load balancer something other | |
// than a single IP, then use a regsub() to fix it. | |
// | |
struct sockaddr *client_ip_ss = VRT_r_client_ip(sp); | |
struct sockaddr_in *client_ip_si = (struct sockaddr_in *) client_ip_ss; | |
struct in_addr *client_ip_ia = &(client_ip_si->sin_addr); | |
char *xff_ip = VRT_GetHdr(sp, HDR_REQ, "\020X-Forwarded-For:"); | |
if (xff_ip != NULL) { | |
// Copy the ip address into the struct's sin_addr. | |
inet_pton(AF_INET, xff_ip, client_ip_ia); | |
} | |
}C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment