comparison src/http/ngx_http_variables.c @ 2533:c843171d5dc2

axe r->port_text
author Igor Sysoev <igor@sysoev.ru>
date Tue, 24 Feb 2009 07:29:55 +0000
parents 2e91aecb9e57
children a6d6d762c554
comparison
equal deleted inserted replaced
2532:aa53ef3e36e9 2533:c843171d5dc2
954 954
955 static ngx_int_t 955 static ngx_int_t
956 ngx_http_variable_server_port(ngx_http_request_t *r, 956 ngx_http_variable_server_port(ngx_http_request_t *r,
957 ngx_http_variable_value_t *v, uintptr_t data) 957 ngx_http_variable_value_t *v, uintptr_t data)
958 { 958 {
959 v->len = r->port_text->len - 1; 959 ngx_uint_t port;
960 v->valid = 1; 960 struct sockaddr_in *sin;
961 v->no_cacheable = 0; 961 #if (NGX_HAVE_INET6)
962 v->not_found = 0; 962 struct sockaddr_in6 *sin6;
963 v->data = r->port_text->data + 1; 963 #endif
964
965 v->len = 0;
966 v->valid = 1;
967 v->no_cacheable = 0;
968 v->not_found = 0;
969
970 if (ngx_http_server_addr(r, NULL) != NGX_OK) {
971 return NGX_ERROR;
972 }
973
974 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);
975 if (v->data == NULL) {
976 return NGX_ERROR;
977 }
978
979 switch (r->connection->local_sockaddr->sa_family) {
980
981 #if (NGX_HAVE_INET6)
982 case AF_INET6:
983 sin6 = (struct sockaddr_in6 *) r->connection->local_sockaddr;
984 port = ntohs(sin6->sin6_port);
985 break;
986 #endif
987
988 default: /* AF_INET */
989 sin = (struct sockaddr_in *) r->connection->local_sockaddr;
990 port = ntohs(sin->sin_port);
991 break;
992 }
993
994 if (port > 0 && port < 65536) {
995 v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
996 }
964 997
965 return NGX_OK; 998 return NGX_OK;
966 } 999 }
967 1000
968 1001