From: Volker Lendecke Date: Fri, 17 Jul 2020 10:40:28 +0000 (+0200) Subject: lib: Move read_udp_v4_socket() to nmbd X-Git-Tag: talloc-2.3.2~864 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ccc9df4b313e8ff07a6c6ee34ab52c5c283c2c9;p=thirdparty%2Fsamba.git lib: Move read_udp_v4_socket() to nmbd This is the only consumer of it Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/include/proto.h b/source3/include/proto.h index fe3acde078e..1c505579b9d 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -525,10 +525,6 @@ const char *client_socket_addr(int fd, char *addr, size_t addr_len); int client_socket_port(int fd); bool is_a_socket(int fd); void set_socket_options(int fd, const char *options); -ssize_t read_udp_v4_socket(int fd, - char *buf, - size_t len, - struct sockaddr_storage *psa); NTSTATUS read_fd_with_timeout(int fd, char *buf, size_t mincnt, size_t maxcnt, unsigned int time_out, diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index fb64c0e61cd..590e8f4d55c 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -56,48 +56,6 @@ bool is_a_socket(int fd) return(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&v, &l) == 0); } -/**************************************************************************** - Read from a socket. -****************************************************************************/ - -ssize_t read_udp_v4_socket(int fd, - char *buf, - size_t len, - struct sockaddr_storage *psa) -{ - ssize_t ret; - socklen_t socklen = sizeof(*psa); - struct sockaddr_in *si = (struct sockaddr_in *)psa; - - memset((char *)psa,'\0',socklen); - - ret = (ssize_t)sys_recvfrom(fd,buf,len,0, - (struct sockaddr *)psa,&socklen); - if (ret <= 0) { - /* Don't print a low debug error for a non-blocking socket. */ - if (errno == EAGAIN) { - DEBUG(10,("read_udp_v4_socket: returned EAGAIN\n")); - } else { - DEBUG(2,("read_udp_v4_socket: failed. errno=%s\n", - strerror(errno))); - } - return 0; - } - - if (psa->ss_family != AF_INET) { - DEBUG(2,("read_udp_v4_socket: invalid address family %d " - "(not IPv4)\n", (int)psa->ss_family)); - return 0; - } - - DEBUG(10,("read_udp_v4_socket: ip %s port %d read: %lu\n", - inet_ntoa(si->sin_addr), - si->sin_port, - (unsigned long)ret)); - - return ret; -} - /**************************************************************************** Read data from a file descriptor with a timout in msec. mincount = if timeout, minimum to read before returning diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index bbcb9582ec5..be9e091f006 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1879,6 +1879,49 @@ static void nmbd_fd_handler(struct tevent_context *ev, attr->triggered = true; } +/**************************************************************************** + Read from a socket. +****************************************************************************/ + +static ssize_t read_udp_v4_socket( + int fd, + char *buf, + size_t len, + struct sockaddr_storage *psa) +{ + ssize_t ret; + socklen_t socklen = sizeof(*psa); + struct sockaddr_in *si = (struct sockaddr_in *)psa; + + memset((char *)psa,'\0',socklen); + + ret = (ssize_t)sys_recvfrom(fd,buf,len,0, + (struct sockaddr *)psa,&socklen); + if (ret <= 0) { + /* Don't print a low debug error for a non-blocking socket. */ + if (errno == EAGAIN) { + DEBUG(10,("read_udp_v4_socket: returned EAGAIN\n")); + } else { + DEBUG(2,("read_udp_v4_socket: failed. errno=%s\n", + strerror(errno))); + } + return 0; + } + + if (psa->ss_family != AF_INET) { + DEBUG(2,("read_udp_v4_socket: invalid address family %d " + "(not IPv4)\n", (int)psa->ss_family)); + return 0; + } + + DEBUG(10,("read_udp_v4_socket: ip %s port %d read: %lu\n", + inet_ntoa(si->sin_addr), + si->sin_port, + (unsigned long)ret)); + + return ret; +} + /******************************************************************* Read a packet from a socket and parse it, returning a packet ready to be used or put on the queue. This assumes a UDP socket.