apache取得客户端ip

本文介绍了Apache中的request_rec结构体,并详细列举了其成员变量。通过分析该结构体,可以了解到HTTP请求处理过程中涉及的关键信息,如客户端IP地址等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天修改下so,搞ip,找了半天,发现了request_rec结构体里面有,记录下。

struct request_rec { 
    pool *pool; 
    conn_rec *connection; 
    server_rec *server; 
    request_rec *next; 
    request_rec *prev; 
    request_rec *main; 
    char *the_request; 
    int assbackwards; 
    enum proxyreqtype proxyreq; 
    int header_only; 
    char *protocol; 
    int proto_num; 
    char *hostname; 
    time_t request_time; 
    const char *status_line; 
    int status; 
    const char *method; 
    int method_number; 
    int allowed; 
    int sent_bodyct; 
    long bytes_sent; 
    time_t mtime; 
    int chunked; 
    int byterange; 
    char *boundary; 
    const char *range; 
    long clength; 
    long remaining; 
    long read_length; 
    int read_body; 
    int read_chunked; 
    unsigned expecting_100; 
    table *headers_in; 
    table *headers_out; 
    table *err_headers_out; 
    table *subprocess_env; 
    table *notes; 
    const char *content_type; 
    const char *handler; 
    const char *content_encoding; 
    const char *content_language; 
    array_header *content_languages; 
    char *vlist_validator; 
    int no_cache; 
    int no_local_copy; 
    char *unparsed_uri; 
    char *uri; 
    char *filename; 
    char *path_info; 
    char *args; 
    struct stat finfo; 
    uri_components parsed_uri; 
    void *per_dir_config; 
    void *request_config; 
    const struct htaccess_result *htaccess; 
    char *case_preserved_filename; 
};
typedef struct conn_rec conn_rec; 
struct conn_rec { 
    pool *pool; 
    server_rec *server; 
    server_rec *base_server; 
    void *vhost_lookup_data; 
    int child_num; 
    BUFF *client; 
    struct sockaddr_in local_addr; 
    struct sockaddr_in remote_addr; 
    char *remote_ip; 
    char *remote_host; 
    char *remote_logname; 
    char *user; 
    char *ap_auth_type; 
    unsigned aborted:1; 
    signed int keepalive:2; 
    unsigned keptalive:1; 
    signed int double_reverse:2; 
    int keepalives; 
    char *local_ip; 
    char *local_host; 
};
想打印出来看下,直接用
fprintf(stderr,"%s/n",r->connection->remote_ip);
打印到apache的日志中,日志中竟然没有记录,只好单独打印到一个文件中看下了。尴尬
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值