comparison src/http/ngx_http.c @ 6557:6f8254ae61b8

Use ngx_cmp_sockaddr() where appropriate.
author Ruslan Ermilov <ru@nginx.com>
date Fri, 20 May 2016 19:10:42 +0300
parents cf5e822cf470
children c90cf79d0e1d
comparison
equal deleted inserted replaced
6556:654d2dae97d3 6557:6f8254ae61b8
1213 1213
1214 static ngx_int_t 1214 static ngx_int_t
1215 ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, 1215 ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
1216 ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt) 1216 ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt)
1217 { 1217 {
1218 u_char *p;
1219 size_t len, off;
1220 ngx_uint_t i, default_server, proxy_protocol; 1218 ngx_uint_t i, default_server, proxy_protocol;
1221 struct sockaddr *sa;
1222 ngx_http_conf_addr_t *addr; 1219 ngx_http_conf_addr_t *addr;
1223 #if (NGX_HAVE_UNIX_DOMAIN)
1224 struct sockaddr_un *saun;
1225 #endif
1226 #if (NGX_HTTP_SSL) 1220 #if (NGX_HTTP_SSL)
1227 ngx_uint_t ssl; 1221 ngx_uint_t ssl;
1228 #endif 1222 #endif
1229 #if (NGX_HTTP_V2) 1223 #if (NGX_HTTP_V2)
1230 ngx_uint_t http2; 1224 ngx_uint_t http2;
1233 /* 1227 /*
1234 * we cannot compare whole sockaddr struct's as kernel 1228 * we cannot compare whole sockaddr struct's as kernel
1235 * may fill some fields in inherited sockaddr struct's 1229 * may fill some fields in inherited sockaddr struct's
1236 */ 1230 */
1237 1231
1238 sa = &lsopt->u.sockaddr;
1239
1240 switch (sa->sa_family) {
1241
1242 #if (NGX_HAVE_INET6)
1243 case AF_INET6:
1244 off = offsetof(struct sockaddr_in6, sin6_addr);
1245 len = 16;
1246 break;
1247 #endif
1248
1249 #if (NGX_HAVE_UNIX_DOMAIN)
1250 case AF_UNIX:
1251 off = offsetof(struct sockaddr_un, sun_path);
1252 len = sizeof(saun->sun_path);
1253 break;
1254 #endif
1255
1256 default: /* AF_INET */
1257 off = offsetof(struct sockaddr_in, sin_addr);
1258 len = 4;
1259 break;
1260 }
1261
1262 p = lsopt->u.sockaddr_data + off;
1263
1264 addr = port->addrs.elts; 1232 addr = port->addrs.elts;
1265 1233
1266 for (i = 0; i < port->addrs.nelts; i++) { 1234 for (i = 0; i < port->addrs.nelts; i++) {
1267 1235
1268 if (ngx_memcmp(p, addr[i].opt.u.sockaddr_data + off, len) != 0) { 1236 if (ngx_cmp_sockaddr(&lsopt->u.sockaddr, lsopt->socklen,
1237 &addr[i].opt.u.sockaddr, addr[i].opt.socklen, 0)
1238 != NGX_OK)
1239 {
1269 continue; 1240 continue;
1270 } 1241 }
1271 1242
1272 /* the address is already in the address list */ 1243 /* the address is already in the address list */
1273 1244