From: Stefan Metzmacher Date: Thu, 3 Apr 2025 12:42:44 +0000 (+0200) Subject: s3:smbd: simplify binding to wildcard addresses X-Git-Tag: tevent-0.17.0~300 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f35aa7ecc00c833bb34dfac0ff9e477b1be13b2b;p=thirdparty%2Fsamba.git s3:smbd: simplify binding to wildcard addresses Signed-off-by: Stefan Metzmacher Reviewed-by: Volker Lendecke --- diff --git a/source3/smbd/server.c b/source3/smbd/server.c index b966739cff6..17862eb82a0 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -1219,29 +1219,26 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent, } else { /* Just bind to 0.0.0.0 - accept connections from anywhere. */ - - const char *sock_addr; - char *sock_tok; - const char *sock_ptr; - + const char * const sock_addrs[] = { #ifdef HAVE_IPV6 - sock_addr = "::,0.0.0.0"; -#else - sock_addr = "0.0.0.0"; + "::", #endif + "0.0.0.0", + }; + + for (i = 0; i < ARRAY_SIZE(sock_addrs); i++) { + const char *sock_tok = sock_addrs[i]; + struct sockaddr_storage ss; + + /* open an incoming socket */ + if (!interpret_string_addr(&ss, sock_tok, + AI_NUMERICHOST|AI_PASSIVE)) { + continue; + } - for (sock_ptr=sock_addr; - next_token_talloc(talloc_tos(), &sock_ptr, &sock_tok, " \t,"); ) { for (j = 0; ports && ports[j]; j++) { - struct sockaddr_storage ss; unsigned port = atoi(ports[j]); - /* open an incoming socket */ - if (!interpret_string_addr(&ss, sock_tok, - AI_NUMERICHOST|AI_PASSIVE)) { - continue; - } - /* * If we fail to open any sockets * in this loop the parent-sockets == NULL