C++ IP2定位模块,用于获取HTTP_X_转发,而不是远程地址
我使用的是ip2location,对于不在负载平衡器后面的站点,它工作正常 任何位于F5或AWS ELB后面的内容,都将返回空字符串 我开始查看模块的IP2位置,并试图对其进行更改,以使其能够转发X_ 这是mod_ip2location.cC++ IP2定位模块,用于获取HTTP_X_转发,而不是远程地址,c++,c,apache,C++,C,Apache,我使用的是ip2location,对于不在负载平衡器后面的站点,它工作正常 任何位于F5或AWS ELB后面的内容,都将返回空字符串 我开始查看模块的IP2位置,并试图对其进行更改,以使其能够转发X_ 这是mod_ip2location.c #include "httpd.h" #include "http_config.h" #include "http_protocol.h" #include "http_log.h" #include "ap_config.h" #include "ap
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "http_log.h"
#include "ap_config.h"
#include "apr_strings.h"
#include "IP2Location.h"
static const int ENV_SET_MODE = 0x0001;
static const int NOTES_SET_MODE = 0x0002;
static const int ALL_SET_MODE = 0x0003;
typedef struct {
int enableFlag;
int setMode;
char* dbFile;
IP2Location* ip2locObj;
} ip2location_server_config;
module AP_MODULE_DECLARE_DATA IP2Location_module;
static apr_status_t ip2location_cleanup(void *cfgdata) {
// cleanup code here, if needed
return APR_SUCCESS;
}
static void ip2location_child_init(apr_pool_t *p, server_rec *s) {
apr_pool_cleanup_register(p, NULL, ip2location_cleanup, ip2location_cleanup);
}
static int ip2location_post_read_request(request_rec *r) {
char* ipaddr;
ip2location_server_config* config;
IP2LocationRecord* record;
char buff[20];
config = (ip2location_server_config*)
ap_get_module_config(r->server->module_config, &IP2Location_module);
if(!config->enableFlag)
return OK;
ipaddr = r->connection->remote_ip;
record = IP2Location_get_all(config->ip2locObj, ipaddr);
if(record) {
if(config->setMode & ENV_SET_MODE) {
apr_table_set(r->subprocess_env,
我试图改变这一行:
ipaddr = r->connection->remote_ip;
到
它不会编译并抛出
在函数“IP2位置后读取请求”中:
错误:“request\u rec”中没有名为“header\u in”的成员
警告字符常量对于其类型太长
我不确定是否有一个简单的修复我忽略了?谢谢 那么它在中是否有一个名为
header\u的成员?无论如何,字符串文字是用双引号写的,比如“X-Forwarded-For”
。我敢打赌代码是C,因此request\u rec
根本没有方法。感谢提示,我访问了httpd.h,因为我认为这就是ipaddr lines正在调用的内容,而没有看到它:***@用于存储每个连接的内容的简短结构*/struct conn\u rec{/**与此连接关联的池*/apr\u Pool\u t*Pool;/**此连接的物理主机*/server\u rec*base\u server;/**由http\u vhost.c使用*/void*vhost\u lookup\u data;/*有关连接本身的信息*/**客户端的IP地址*/char*remote\u IP;
我确实看到了以下内容httpd.h中的ng:struct request\u rec{/**MIME header environment from the request*/apr_table_t*headers_in;
这是我看到headers_in的唯一一行。另外,如果我在更改为双引号和headers_in后尝试编译,我现在会遇到以下错误mod_ip2location.c:在函数“ip2location_post_read_request”中:mod_ip2location.c:61:错误:调用obobject'r->headers\u in'不是函数
ipaddr = r->header_in('X-Forwarded-For');