From: Philip Homburg Date: Fri, 30 Sep 2005 12:49:10 +0000 (+0000) Subject: X expects an implicit bind to INADDR_ANY for UDP sockets. X-Git-Tag: v3.1.2a~689 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/cppcheck-error.log?a=commitdiff_plain;h=99fa9df34473a65c190cfb3128fb8f7391f078cf;p=minix.git X expects an implicit bind to INADDR_ANY for UDP sockets. --- diff --git a/lib/ip/socket.c b/lib/ip/socket.c index 7900ce341..c08ded1bc 100644 --- a/lib/ip/socket.c +++ b/lib/ip/socket.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -57,7 +58,8 @@ static int _tcp_socket(int protocol) static int _udp_socket(int protocol) { - int fd; + int r, fd, t_errno; + struct sockaddr_in sin; if (protocol != 0 && protocol != IPPROTO_UDP) { @@ -68,6 +70,21 @@ static int _udp_socket(int protocol) return -1; } fd= open(UDP_DEVICE, O_RDWR); + if (fd == -1) + return fd; + + /* Bind is implict for UDP sockets? */ + sin.sin_family= AF_INET; + sin.sin_addr.s_addr= INADDR_ANY; + sin.sin_port= 0; + r= bind(fd, (struct sockaddr *)&sin, sizeof(sin)); + if (r != 0) + { + t_errno= errno; + close(fd); + errno= t_errno; + return -1; + } return fd; }