mirror of
https://github.com/nginx/nginx.git
synced 2025-01-19 01:42:58 +08:00
ngx_http_variable_binary_remote_addr()
This commit is contained in:
parent
e6bf2be77e
commit
d5ca16cdd4
@ -28,6 +28,8 @@ static ngx_int_t ngx_http_variable_unknown_header(ngx_http_variable_value_t *v,
|
||||
|
||||
static ngx_int_t ngx_http_variable_host(ngx_http_request_t *r,
|
||||
ngx_http_variable_value_t *v, uintptr_t data);
|
||||
static ngx_int_t ngx_http_variable_binary_remote_addr(ngx_http_request_t *r,
|
||||
ngx_http_variable_value_t *v, uintptr_t data);
|
||||
static ngx_int_t ngx_http_variable_remote_addr(ngx_http_request_t *r,
|
||||
ngx_http_variable_value_t *v, uintptr_t data);
|
||||
static ngx_int_t ngx_http_variable_remote_port(ngx_http_request_t *r,
|
||||
@ -116,7 +118,7 @@ static ngx_http_variable_t ngx_http_core_variables[] = {
|
||||
{ ngx_string("host"), NULL, ngx_http_variable_host, 0, 0, 0 },
|
||||
|
||||
{ ngx_string("binary_remote_addr"), NULL,
|
||||
ngx_http_variable_remote_addr, 1, 0, 0 },
|
||||
ngx_http_variable_binary_remote_addr, 0, 0, 0 },
|
||||
|
||||
{ ngx_string("remote_addr"), NULL, ngx_http_variable_remote_addr, 0, 0, 0 },
|
||||
|
||||
@ -699,30 +701,34 @@ ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_variable_remote_addr(ngx_http_request_t *r,
|
||||
ngx_http_variable_binary_remote_addr(ngx_http_request_t *r,
|
||||
ngx_http_variable_value_t *v, uintptr_t data)
|
||||
{
|
||||
struct sockaddr_in *sin;
|
||||
|
||||
if (data == 0) {
|
||||
v->len = r->connection->addr_text.len;
|
||||
v->valid = 1;
|
||||
v->no_cachable = 0;
|
||||
v->not_found = 0;
|
||||
v->data = r->connection->addr_text.data;
|
||||
/* AF_INET only */
|
||||
|
||||
} else {
|
||||
sin = (struct sockaddr_in *) r->connection->sockaddr;
|
||||
|
||||
/* AF_INET only */
|
||||
v->len = sizeof(in_addr_t);
|
||||
v->valid = 1;
|
||||
v->no_cachable = 0;
|
||||
v->not_found = 0;
|
||||
v->data = (u_char *) &sin->sin_addr.s_addr;
|
||||
|
||||
sin = (struct sockaddr_in *) r->connection->sockaddr;
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
v->len = sizeof(in_addr_t);
|
||||
v->valid = 1;
|
||||
v->no_cachable = 0;
|
||||
v->not_found = 0;
|
||||
v->data = (u_char *) &sin->sin_addr.s_addr;
|
||||
}
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_variable_remote_addr(ngx_http_request_t *r,
|
||||
ngx_http_variable_value_t *v, uintptr_t data)
|
||||
{
|
||||
v->len = r->connection->addr_text.len;
|
||||
v->valid = 1;
|
||||
v->no_cachable = 0;
|
||||
v->not_found = 0;
|
||||
v->data = r->connection->addr_text.data;
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user