]> Zhao Yanbai Git Server - minix.git/commitdiff
Support for read/write on connected UDP sockets
authorDavid van Moolenbroek <david@minix3.org>
Thu, 19 Nov 2009 23:45:46 +0000 (23:45 +0000)
committerDavid van Moolenbroek <david@minix3.org>
Thu, 19 Nov 2009 23:45:46 +0000 (23:45 +0000)
lib/ip/connect.c
lib/ip/recvfrom.c

index f1ae13d588a5017d7fec199b05084f5d6b467701..614fee142a155a0eb515f5c45785fa22ca57bdc9 100644 (file)
@@ -110,7 +110,7 @@ static int _udp_connect(int socket, const struct sockaddr *address,
        if (address == NULL)
        {
                /* Unset remote address */
-               udpopt.nwuo_flags= NWUO_RP_ANY | NWUO_RA_ANY;
+               udpopt.nwuo_flags= NWUO_RP_ANY | NWUO_RA_ANY | NWUO_RWDATALL;
 
                r= ioctl(socket, NWIOSUDPOPT, &udpopt);
                return r;
@@ -127,7 +127,7 @@ static int _udp_connect(int socket, const struct sockaddr *address,
                errno= EINVAL;
                return -1;
        }
-       udpopt.nwuo_flags= NWUO_RP_SET | NWUO_RA_SET;
+       udpopt.nwuo_flags= NWUO_RP_SET | NWUO_RA_SET | NWUO_RWDATONLY;
        if ((udpoptp->nwuo_flags & NWUO_LOCPORT_MASK) == NWUO_LP_ANY)
                udpopt.nwuo_flags |= NWUO_LP_SEL;
        udpopt.nwuo_remaddr= sinp->sin_addr.s_addr;
index 9018c817a989492c0add7b7810ecfb123f6dd8a6..ce9656585c3475803441d50b22169574b26b5930 100644 (file)
@@ -120,12 +120,36 @@ static ssize_t _udp_recvfrom(int socket, void *_RESTRICT buffer, size_t length,
 
        if (udpoptp->nwuo_flags & NWUO_RWDATONLY)
        {
+               if (address != NULL &&
+                       (udpoptp->nwuo_flags & (NWUO_RA_SET | NWUO_RP_SET)) !=
+                       (NWUO_RA_SET | NWUO_RP_SET))
+               {
+
 #if DEBUG
-               fprintf(stderr,
-                       "recvfrom(udp): NWUO_RWDATONLY not implemented\n");
+                       fprintf(stderr,
+                       "recvfrom(udp): RWDATONLY on unconnected socket\n");
 #endif
-               errno= ENOSYS;
-               return -1;
+                       errno= ENOTCONN;
+                       return -1;
+               }
+
+               r= read(socket, buffer, length);
+               if (r == -1)
+                       return r;
+
+               if (address != NULL)
+               {
+                       sin.sin_family= AF_INET;
+                       sin.sin_addr.s_addr= udpoptp->nwuo_remaddr;
+                       sin.sin_port= udpoptp->nwuo_remport;
+                       len= *address_len;
+                       if (len > sizeof(sin))
+                               len= sizeof(sin);
+                       memcpy(address, &sin, len);
+                       *address_len= sizeof(sin);
+               }
+
+               return r;
        }
 
        buflen= sizeof(*io_hdrp) + length;