mirror of
https://github.com/nginx/nginx.git
synced 2025-08-05 22:26:15 +08:00
use ngx_http_server_addr()
This commit is contained in:
parent
3f24ae2be2
commit
c7a9b7a990
@ -300,12 +300,10 @@ static ngx_int_t
|
||||
ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
|
||||
ngx_http_userid_conf_t *conf)
|
||||
{
|
||||
u_char *cookie, *p;
|
||||
size_t len;
|
||||
socklen_t slen;
|
||||
struct sockaddr_in sin;
|
||||
ngx_str_t src, dst;
|
||||
ngx_table_elt_t *set_cookie, *p3p;
|
||||
u_char *cookie, *p;
|
||||
size_t len;
|
||||
ngx_str_t src, dst;
|
||||
ngx_table_elt_t *set_cookie, *p3p;
|
||||
|
||||
/*
|
||||
* TODO: in the threaded mode the sequencers should be in TLS and their
|
||||
@ -327,18 +325,8 @@ ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
|
||||
|
||||
} else {
|
||||
if (conf->service == NGX_CONF_UNSET) {
|
||||
if (r->in_addr == 0) {
|
||||
slen = sizeof(struct sockaddr_in);
|
||||
if (getsockname(r->connection->fd,
|
||||
(struct sockaddr *) &sin, &slen)
|
||||
== -1)
|
||||
{
|
||||
ngx_connection_error(r->connection, ngx_socket_errno,
|
||||
"getsockname() failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
r->in_addr = sin.sin_addr.s_addr;
|
||||
if (ngx_http_server_addr(r, NULL) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
ctx->uid_set[0] = htonl(r->in_addr);
|
||||
|
@ -220,9 +220,7 @@ static void
|
||||
ngx_http_init_request(ngx_event_t *rev)
|
||||
{
|
||||
ngx_time_t *tp;
|
||||
socklen_t len;
|
||||
ngx_uint_t i;
|
||||
struct sockaddr_in sin;
|
||||
ngx_connection_t *c;
|
||||
ngx_http_request_t *r;
|
||||
ngx_http_in_port_t *hip;
|
||||
@ -295,6 +293,8 @@ ngx_http_init_request(ngx_event_t *rev)
|
||||
|
||||
i = 0;
|
||||
|
||||
r->connection = c;
|
||||
|
||||
if (hip->naddrs > 1) {
|
||||
|
||||
/*
|
||||
@ -302,7 +302,7 @@ ngx_http_init_request(ngx_event_t *rev)
|
||||
* is the "*:port" wildcard so getsockname() is needed to determine
|
||||
* the server address.
|
||||
*
|
||||
* AcceptEx() already gave this address.
|
||||
* AcceptEx() already has given this address.
|
||||
*/
|
||||
|
||||
#if (NGX_WIN32)
|
||||
@ -313,15 +313,10 @@ ngx_http_init_request(ngx_event_t *rev)
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
len = sizeof(struct sockaddr_in);
|
||||
if (getsockname(c->fd, (struct sockaddr *) &sin, &len) == -1) {
|
||||
ngx_connection_error(c, ngx_socket_errno,
|
||||
"getsockname() failed");
|
||||
if (ngx_http_server_addr(r, NULL) != NGX_OK) {
|
||||
ngx_http_close_connection(c);
|
||||
return;
|
||||
}
|
||||
|
||||
r->in_addr = sin.sin_addr.s_addr;
|
||||
}
|
||||
|
||||
/* the last address is "*" */
|
||||
@ -426,8 +421,6 @@ ngx_http_init_request(ngx_event_t *rev)
|
||||
c->single_connection = 1;
|
||||
c->destroyed = 0;
|
||||
|
||||
r->connection = c;
|
||||
|
||||
r->main = r;
|
||||
|
||||
tp = ngx_timeofday();
|
||||
|
@ -808,32 +808,22 @@ static ngx_int_t
|
||||
ngx_http_variable_server_addr(ngx_http_request_t *r,
|
||||
ngx_http_variable_value_t *v, uintptr_t data)
|
||||
{
|
||||
socklen_t len;
|
||||
ngx_connection_t *c;
|
||||
struct sockaddr_in sin;
|
||||
ngx_str_t s;
|
||||
|
||||
v->data = ngx_palloc(r->pool, INET_ADDRSTRLEN);
|
||||
if (v->data == NULL) {
|
||||
s.data = ngx_palloc(r->pool, INET_ADDRSTRLEN);
|
||||
if (s.data == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
c = r->connection;
|
||||
|
||||
if (r->in_addr == 0) {
|
||||
len = sizeof(struct sockaddr_in);
|
||||
if (getsockname(c->fd, (struct sockaddr *) &sin, &len) == -1) {
|
||||
ngx_connection_error(c, ngx_socket_errno, "getsockname() failed");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
r->in_addr = sin.sin_addr.s_addr;
|
||||
if (ngx_http_server_addr(r, &s) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
v->len = ngx_inet_ntop(c->listening->family, &r->in_addr,
|
||||
v->data, INET_ADDRSTRLEN);
|
||||
v->len = s.len;
|
||||
v->valid = 1;
|
||||
v->no_cacheable = 0;
|
||||
v->not_found = 0;
|
||||
v->data = s.data;
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user