diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index 19344ab48..9fe6c19b8 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -12,52 +12,6 @@ ngx_os_io_t ngx_io; -ngx_listening_t * -ngx_listening_inet_stream_socket(ngx_conf_t *cf, in_addr_t addr, in_port_t port) -{ - size_t len; - ngx_listening_t *ls; - struct sockaddr_in *sin; - - ls = ngx_array_push(&cf->cycle->listening); - if (ls == NULL) { - return NULL; - } - - ngx_memzero(ls, sizeof(ngx_listening_t)); - - sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)); - if (sin == NULL) { - return NULL; - } - - sin->sin_family = AF_INET; - sin->sin_addr.s_addr = addr; - sin->sin_port = htons(port); - - - ls->addr_text.data = ngx_pnalloc(cf->pool, - NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1); - if (ls->addr_text.data == NULL) { - return NULL; - } - - len = ngx_inet_ntop(AF_INET, &addr, ls->addr_text.data, - NGX_INET_ADDRSTRLEN); - - ls->addr_text.len = ngx_sprintf(ls->addr_text.data + len, ":%d", port) - - ls->addr_text.data; - - ls->fd = (ngx_socket_t) -1; - ls->type = SOCK_STREAM; - ls->sockaddr = (struct sockaddr *) sin; - ls->socklen = sizeof(struct sockaddr_in); - ls->addr_text_max_len = NGX_INET_ADDRSTRLEN; - - return ls; -} - - ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle) { diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h index de0ef41be..33c7f5b92 100644 --- a/src/core/ngx_connection.h +++ b/src/core/ngx_connection.h @@ -168,8 +168,6 @@ struct ngx_connection_s { #endif -ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf, - in_addr_t addr, in_port_t port); ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle); ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle); void ngx_configure_listening_socket(ngx_cycle_t *cycle); diff --git a/src/mail/ngx_mail.c b/src/mail/ngx_mail.c index 53dc481ec..a06798958 100644 --- a/src/mail/ngx_mail.c +++ b/src/mail/ngx_mail.c @@ -72,12 +72,15 @@ ngx_mail_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ngx_listening_t *ls; ngx_mail_listen_t *mls; ngx_mail_module_t *module; + struct sockaddr *sa; + struct sockaddr_in *sin; ngx_mail_in_port_t *mip; ngx_mail_conf_ctx_t *ctx; ngx_mail_conf_in_port_t *in_port; ngx_mail_conf_in_addr_t *in_addr; ngx_mail_core_srv_conf_t **cscfp; ngx_mail_core_main_conf_t *cmcf; + u_char buf[NGX_SOCKADDR_STRLEN]; if (cmd->name.data[0] == 'i') { ngx_conf_log_error(NGX_LOG_WARN, cf, 0, @@ -299,10 +302,51 @@ ngx_mail_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) continue; } - ls = ngx_listening_inet_stream_socket(cf, in_addr[a].addr, - in_port[p].port); + ls = ngx_array_push(&cf->cycle->listening); if (ls == NULL) { - return NGX_CONF_ERROR; + return NULL; + } + + ngx_memzero(ls, sizeof(ngx_listening_t)); + + sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)); + if (sin == NULL) { + return NULL; + } + + sin->sin_family = AF_INET; + sin->sin_addr.s_addr = in_addr[a].addr; + sin->sin_port = htons(in_port[p].port); + + sa = (struct sockaddr *) sin; + + ls->sockaddr = sa; + ls->socklen = sizeof(struct sockaddr_in); + + ls->addr_text.len = ngx_sock_ntop(sa, buf, NGX_SOCKADDR_STRLEN, 1); + + ls->addr_text.data = ngx_pnalloc(cf->pool, ls->addr_text.len); + if (ls->addr_text.data == NULL) { + return NULL; + } + + ngx_memcpy(ls->addr_text.data, buf, ls->addr_text.len); + + ls->fd = (ngx_socket_t) -1; + ls->type = SOCK_STREAM; + + switch (ls->sockaddr->sa_family) { +#if (NGX_HAVE_INET6) + case AF_INET6: + ls->addr_text_max_len = NGX_INET6_ADDRSTRLEN; + break; +#endif + case AF_INET: + ls->addr_text_max_len = NGX_INET_ADDRSTRLEN; + break; + default: + ls->addr_text_max_len = NGX_SOCKADDR_STRLEN; + break; } ls->backlog = NGX_LISTEN_BACKLOG;