From: Volker Lendecke Date: Fri, 17 Jul 2020 20:29:10 +0000 (+0200) Subject: lib: Move get_socket_port() to its only consumer X-Git-Tag: talloc-2.3.2~858 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=753b6cc572e4de46f9d1d74bce70f943a9b27d8e;p=thirdparty%2Fsamba.git lib: Move get_socket_port() to its only consumer This is only used in netbios_session_retarget() Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/lib/util/util_net.c b/lib/util/util_net.c index 8f47eb88ab5..daaf9808b8f 100644 --- a/lib/util/util_net.c +++ b/lib/util/util_net.c @@ -894,39 +894,6 @@ char *print_canonical_sockaddr(TALLOC_CTX *ctx, return dest; } -/**************************************************************************** - Return the port number we've bound to on a socket. -****************************************************************************/ - -int get_socket_port(int fd) -{ - struct sockaddr_storage sa; - socklen_t length = sizeof(sa); - - if (fd == -1) { - return -1; - } - - if (getsockname(fd, (struct sockaddr *)&sa, &length) < 0) { - int level = (errno == ENOTCONN) ? 2 : 0; - DEBUG(level, ("getsockname failed. Error was %s\n", - strerror(errno))); - return -1; - } - -#if defined(HAVE_IPV6) - if (sa.ss_family == AF_INET6) { - struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)&sa; - return ntohs(sa_in6->sin6_port); - } -#endif - if (sa.ss_family == AF_INET) { - struct sockaddr_in *sa_in = (struct sockaddr_in *)&sa; - return ntohs(sa_in->sin_port); - } - return -1; -} - enum SOCK_OPT_TYPES {OPT_BOOL,OPT_INT,OPT_ON}; typedef struct smb_socket_option { diff --git a/lib/util/util_net.h b/lib/util/util_net.h index 6e991b8f904..80a7e08b7e8 100644 --- a/lib/util/util_net.h +++ b/lib/util/util_net.h @@ -120,7 +120,6 @@ char *print_sockaddr(char *dest, const struct sockaddr_storage *psa); char *print_canonical_sockaddr(TALLOC_CTX *ctx, const struct sockaddr_storage *pss); -int get_socket_port(int fd); void set_socket_options(int fd, const char *options); diff --git a/source3/include/proto.h b/source3/include/proto.h index ff58bc7e52e..506e2e80fa1 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -519,7 +519,6 @@ char *print_sockaddr(char *dest, const struct sockaddr_storage *psa); char *print_canonical_sockaddr(TALLOC_CTX *ctx, const struct sockaddr_storage *pss); -int get_socket_port(int fd); bool is_a_socket(int fd); void set_socket_options(int fd, const char *options); NTSTATUS read_fd_with_timeout(int fd, char *buf, diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 252b9556c3f..63d62a88a46 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -543,6 +543,39 @@ bool check_fsp_ntquota_handle(connection_struct *conn, struct smb_request *req, return true; } +/**************************************************************************** + Return the port number we've bound to on a socket. +****************************************************************************/ + +static int get_socket_port(int fd) +{ + struct sockaddr_storage sa; + socklen_t length = sizeof(sa); + + if (fd == -1) { + return -1; + } + + if (getsockname(fd, (struct sockaddr *)&sa, &length) < 0) { + int level = (errno == ENOTCONN) ? 2 : 0; + DEBUG(level, ("getsockname failed. Error was %s\n", + strerror(errno))); + return -1; + } + +#if defined(HAVE_IPV6) + if (sa.ss_family == AF_INET6) { + struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)&sa; + return ntohs(sa_in6->sin6_port); + } +#endif + if (sa.ss_family == AF_INET) { + struct sockaddr_in *sa_in = (struct sockaddr_in *)&sa; + return ntohs(sa_in->sin_port); + } + return -1; +} + static bool netbios_session_retarget(struct smbXsrv_connection *xconn, const char *name, int name_type) {