Mercurial > hg > nginx
comparison src/mail/ngx_mail_core_module.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 | adf25b8d0431 |
comparison
equal
deleted
inserted
replaced
6556:654d2dae97d3 | 6557:6f8254ae61b8 |
---|---|
286 static char * | 286 static char * |
287 ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 287 ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
288 { | 288 { |
289 ngx_mail_core_srv_conf_t *cscf = conf; | 289 ngx_mail_core_srv_conf_t *cscf = conf; |
290 | 290 |
291 size_t len, off; | |
292 in_port_t port; | |
293 ngx_str_t *value; | 291 ngx_str_t *value; |
294 ngx_url_t u; | 292 ngx_url_t u; |
295 ngx_uint_t i, m; | 293 ngx_uint_t i, m; |
296 struct sockaddr *sa; | |
297 ngx_mail_listen_t *ls; | 294 ngx_mail_listen_t *ls; |
298 ngx_mail_module_t *module; | 295 ngx_mail_module_t *module; |
299 struct sockaddr_in *sin; | |
300 ngx_mail_core_main_conf_t *cmcf; | 296 ngx_mail_core_main_conf_t *cmcf; |
301 #if (NGX_HAVE_INET6) | |
302 struct sockaddr_in6 *sin6; | |
303 #endif | |
304 | 297 |
305 value = cf->args->elts; | 298 value = cf->args->elts; |
306 | 299 |
307 ngx_memzero(&u, sizeof(ngx_url_t)); | 300 ngx_memzero(&u, sizeof(ngx_url_t)); |
308 | 301 |
323 | 316 |
324 ls = cmcf->listen.elts; | 317 ls = cmcf->listen.elts; |
325 | 318 |
326 for (i = 0; i < cmcf->listen.nelts; i++) { | 319 for (i = 0; i < cmcf->listen.nelts; i++) { |
327 | 320 |
328 sa = &ls[i].u.sockaddr; | 321 if (ngx_cmp_sockaddr(&ls[i].u.sockaddr, ls[i].socklen, |
329 | 322 (struct sockaddr *) &u.sockaddr, u.socklen, 1) |
330 if (sa->sa_family != u.family) { | 323 != NGX_OK) |
331 continue; | |
332 } | |
333 | |
334 switch (sa->sa_family) { | |
335 | |
336 #if (NGX_HAVE_INET6) | |
337 case AF_INET6: | |
338 off = offsetof(struct sockaddr_in6, sin6_addr); | |
339 len = 16; | |
340 sin6 = &ls[i].u.sockaddr_in6; | |
341 port = ntohs(sin6->sin6_port); | |
342 break; | |
343 #endif | |
344 | |
345 #if (NGX_HAVE_UNIX_DOMAIN) | |
346 case AF_UNIX: | |
347 off = offsetof(struct sockaddr_un, sun_path); | |
348 len = sizeof(((struct sockaddr_un *) sa)->sun_path); | |
349 port = 0; | |
350 break; | |
351 #endif | |
352 | |
353 default: /* AF_INET */ | |
354 off = offsetof(struct sockaddr_in, sin_addr); | |
355 len = 4; | |
356 sin = &ls[i].u.sockaddr_in; | |
357 port = ntohs(sin->sin_port); | |
358 break; | |
359 } | |
360 | |
361 if (ngx_memcmp(ls[i].u.sockaddr_data + off, u.sockaddr + off, len) | |
362 != 0) | |
363 { | 324 { |
364 continue; | |
365 } | |
366 | |
367 if (port != u.port) { | |
368 continue; | 325 continue; |
369 } | 326 } |
370 | 327 |
371 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 328 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
372 "duplicate \"%V\" address and port pair", &u.url); | 329 "duplicate \"%V\" address and port pair", &u.url); |
432 continue; | 389 continue; |
433 } | 390 } |
434 | 391 |
435 if (ngx_strncmp(value[i].data, "ipv6only=o", 10) == 0) { | 392 if (ngx_strncmp(value[i].data, "ipv6only=o", 10) == 0) { |
436 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) | 393 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) |
394 size_t len; | |
437 u_char buf[NGX_SOCKADDR_STRLEN]; | 395 u_char buf[NGX_SOCKADDR_STRLEN]; |
438 | 396 |
439 sa = &ls->u.sockaddr; | 397 if (ls->u.sockaddr.sa_family == AF_INET6) { |
440 | |
441 if (sa->sa_family == AF_INET6) { | |
442 | 398 |
443 if (ngx_strcmp(&value[i].data[10], "n") == 0) { | 399 if (ngx_strcmp(&value[i].data[10], "n") == 0) { |
444 ls->ipv6only = 1; | 400 ls->ipv6only = 1; |
445 | 401 |
446 } else if (ngx_strcmp(&value[i].data[10], "ff") == 0) { | 402 } else if (ngx_strcmp(&value[i].data[10], "ff") == 0) { |
454 } | 410 } |
455 | 411 |
456 ls->bind = 1; | 412 ls->bind = 1; |
457 | 413 |
458 } else { | 414 } else { |
459 len = ngx_sock_ntop(sa, ls->socklen, buf, | 415 len = ngx_sock_ntop(&ls->u.sockaddr, ls->socklen, buf, |
460 NGX_SOCKADDR_STRLEN, 1); | 416 NGX_SOCKADDR_STRLEN, 1); |
461 | 417 |
462 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 418 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
463 "ipv6only is not supported " | 419 "ipv6only is not supported " |
464 "on addr \"%*s\", ignored", len, buf); | 420 "on addr \"%*s\", ignored", len, buf); |