Mercurial > hg > nginx
comparison src/http/modules/ngx_http_realip_module.c @ 6593:b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Mon, 20 Jun 2016 11:50:39 +0300 |
parents | 3af0e65a461a |
children | 6b1b8c4b7a95 |
comparison
equal
deleted
inserted
replaced
6592:2c7b488a61fb | 6593:b3b7e33083ac |
---|---|
136 ngx_addr_t addr; | 136 ngx_addr_t addr; |
137 ngx_array_t *xfwd; | 137 ngx_array_t *xfwd; |
138 ngx_list_part_t *part; | 138 ngx_list_part_t *part; |
139 ngx_table_elt_t *header; | 139 ngx_table_elt_t *header; |
140 ngx_connection_t *c; | 140 ngx_connection_t *c; |
141 struct sockaddr_in *sin; | |
142 #if (NGX_HAVE_INET6) | |
143 struct sockaddr_in6 *sin6; | |
144 #endif | |
145 ngx_http_realip_ctx_t *ctx; | 141 ngx_http_realip_ctx_t *ctx; |
146 ngx_http_realip_loc_conf_t *rlcf; | 142 ngx_http_realip_loc_conf_t *rlcf; |
147 | 143 |
148 ctx = ngx_http_get_module_ctx(r, ngx_http_realip_module); | 144 ctx = ngx_http_get_module_ctx(r, ngx_http_realip_module); |
149 | 145 |
240 if (ngx_http_get_forwarded_addr(r, &addr, xfwd, value, rlcf->from, | 236 if (ngx_http_get_forwarded_addr(r, &addr, xfwd, value, rlcf->from, |
241 rlcf->recursive) | 237 rlcf->recursive) |
242 != NGX_DECLINED) | 238 != NGX_DECLINED) |
243 { | 239 { |
244 if (rlcf->type == NGX_HTTP_REALIP_PROXY) { | 240 if (rlcf->type == NGX_HTTP_REALIP_PROXY) { |
245 | 241 ngx_inet_set_port(addr.sockaddr, c->proxy_protocol_port); |
246 switch (addr.sockaddr->sa_family) { | |
247 | |
248 #if (NGX_HAVE_INET6) | |
249 case AF_INET6: | |
250 sin6 = (struct sockaddr_in6 *) addr.sockaddr; | |
251 sin6->sin6_port = htons(c->proxy_protocol_port); | |
252 break; | |
253 #endif | |
254 | |
255 default: /* AF_INET */ | |
256 sin = (struct sockaddr_in *) addr.sockaddr; | |
257 sin->sin_port = htons(c->proxy_protocol_port); | |
258 break; | |
259 } | |
260 } | 242 } |
261 | 243 |
262 return ngx_http_realip_set_addr(r, &addr); | 244 return ngx_http_realip_set_addr(r, &addr); |
263 } | 245 } |
264 | 246 |
576 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1); | 558 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1); |
577 if (v->data == NULL) { | 559 if (v->data == NULL) { |
578 return NGX_ERROR; | 560 return NGX_ERROR; |
579 } | 561 } |
580 | 562 |
581 switch (sa->sa_family) { | 563 port = ngx_inet_get_port(sa); |
582 | |
583 #if (NGX_HAVE_INET6) | |
584 case AF_INET6: | |
585 port = ntohs(((struct sockaddr_in6 *) sa)->sin6_port); | |
586 break; | |
587 #endif | |
588 | |
589 #if (NGX_HAVE_UNIX_DOMAIN) | |
590 case AF_UNIX: | |
591 port = 0; | |
592 break; | |
593 #endif | |
594 | |
595 default: /* AF_INET */ | |
596 port = ntohs(((struct sockaddr_in *) sa)->sin_port); | |
597 break; | |
598 } | |
599 | 564 |
600 if (port > 0 && port < 65536) { | 565 if (port > 0 && port < 65536) { |
601 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; | 566 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; |
602 } | 567 } |
603 | 568 |