Klaus Demo nginx / c5849a6
ngx_sock_ntop() takes family from sockaddr, remove duplicate field Igor Sysoev 13 years ago
7 changed file(s) with 12 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
4848 - ls->addr_text.data;
4949
5050 ls->fd = (ngx_socket_t) -1;
51 ls->family = AF_INET;
5251 ls->type = SOCK_STREAM;
5352 ls->sockaddr = (struct sockaddr *) sin;
5453 ls->socklen = sizeof(struct sockaddr_in);
112111 return NGX_ERROR;
113112 }
114113
115 ls[i].family = sin->sin_family;
116 len = ngx_sock_ntop(ls[i].family, ls[i].sockaddr,
117 ls[i].addr_text.data, NGX_INET_ADDRSTRLEN);
114 len = ngx_sock_ntop(ls[i].sockaddr, ls[i].addr_text.data,
115 NGX_INET_ADDRSTRLEN);
118116 if (len == 0) {
119117 return NGX_ERROR;
120118 }
254252 continue;
255253 }
256254
257 s = ngx_socket(ls[i].family, ls[i].type, 0);
255 s = ngx_socket(ls[i].sockaddr->sa_family, ls[i].type, 0);
258256
259257 if (s == -1) {
260258 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
2222 size_t addr_text_max_len;
2323 ngx_str_t addr_text;
2424
25 int family;
2625 int type;
2726
2827 int backlog;
5555 /* AF_INET only */
5656
5757 size_t
58 ngx_sock_ntop(int family, struct sockaddr *sa, u_char *text, size_t len)
58 ngx_sock_ntop(struct sockaddr *sa, u_char *text, size_t len)
5959 {
6060 u_char *p;
6161 struct sockaddr_in *sin;
6262
63 if (family == AF_INET) {
63 if (sa->sa_family == AF_INET) {
6464
6565 sin = (struct sockaddr_in *) sa;
6666 p = (u_char *) &sin->sin_addr;
456456 return NGX_ERROR;
457457 }
458458
459 len = ngx_sock_ntop(AF_INET, (struct sockaddr *) sin, p, len);
459 len = ngx_sock_ntop((struct sockaddr *) sin, p, len);
460460
461461 u->addrs[i].name.len = ngx_sprintf(&p[len], ":%d", u->port) - p;
462462 u->addrs[i].name.data = p;
6262
6363
6464 in_addr_t ngx_inet_addr(u_char *text, size_t len);
65 size_t ngx_sock_ntop(int family, struct sockaddr *sa, u_char *text, size_t len);
65 size_t ngx_sock_ntop(struct sockaddr *sa, u_char *text, size_t len);
6666 size_t ngx_inet_ntop(int family, void *addr, u_char *text, size_t len);
6767 ngx_int_t ngx_ptocidr(ngx_str_t *text, void *cidr);
6868 ngx_int_t ngx_parse_url(ngx_pool_t *pool, ngx_url_t *u);
206206 return;
207207 }
208208
209 c->addr_text.len = ngx_sock_ntop(ls->family, c->sockaddr,
210 c->addr_text.data,
209 c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->addr_text.data,
211210 ls->addr_text_max_len);
212211 if (c->addr_text.len == 0) {
213212 ngx_close_accepted_connection(c);
6464 return;
6565 }
6666
67 c->addr_text.len = ngx_sock_ntop(c->listening->family, c->sockaddr,
68 c->addr_text.data,
67 c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->addr_text.data,
6968 c->listening->addr_text_max_len);
7069 if (c->addr_text.len == 0) {
7170 /* TODO: close socket */
9998
10099 /* TODO: look up reused sockets */
101100
102 s = ngx_socket(ls->family, ls->type, 0);
101 s = ngx_socket(ls->sockaddr->sa_family, ls->type, 0);
103102
104103 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &ls->log, 0,
105104 ngx_socket_n " s:%d", s);
16241624 return NGX_OK;
16251625 }
16261626
1627 s->len = ngx_inet_ntop(c->listening->family, &r->in_addr,
1628 s->data, NGX_INET_ADDRSTRLEN);
1627 s->len = ngx_sock_ntop((struct sockaddr *) &sin, s->data,
1628 NGX_INET_ADDRSTRLEN);
16291629
16301630 return NGX_OK;
16311631 }