]> Zhao Yanbai Git Server - minix.git/commitdiff
X expects an implicit bind to INADDR_ANY for UDP sockets.
authorPhilip Homburg <philip@cs.vu.nl>
Fri, 30 Sep 2005 12:49:10 +0000 (12:49 +0000)
committerPhilip Homburg <philip@cs.vu.nl>
Fri, 30 Sep 2005 12:49:10 +0000 (12:49 +0000)
lib/ip/socket.c

index 7900ce341e84b24f1e915e6f2349a88e5ef04baf..c08ded1bc65f5b5d81d59ee072d78a3558317ad8 100644 (file)
@@ -2,6 +2,7 @@
 #include <fcntl.h>
 #include <signal.h>
 #include <stdio.h>
+#include <unistd.h>
 #include <sys/socket.h>
 
 #include <net/netlib.h>
@@ -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;
 }