nwrap: move setting of ai_{flags|socktype|protocol} into nwrap_convert_he_ai
authorMichael Adam <obnox@samba.org>
Thu, 12 Nov 2015 10:15:03 +0000 (11:15 +0100)
committerMichael Adam <obnox@samba.org>
Mon, 11 Jan 2016 11:25:31 +0000 (12:25 +0100)
This makes the code in nwrap_getaddrinfo() more readable
and also treats all ai stuctures in the linked list, not
just the first one!

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/nss_wrapper/nss_wrapper.c

index 38866f19202e093171e91e9393c8c003e6934142..a97d19812f59a955a4abf545883d44640837d14b 100644 (file)
@@ -5055,12 +5055,23 @@ static int nwrap_convert_he_ai(const struct hostent *he,
                return EAI_MEMORY;
        }
 
-       ai->ai_flags = 0;
+       ai->ai_flags = hints->ai_flags;
        ai->ai_family = he->h_addrtype;
        ai->ai_socktype = hints->ai_socktype;
        ai->ai_protocol = hints->ai_protocol;
        ai->ai_canonname = NULL;
 
+       if (ai->ai_socktype == 0) {
+               ai->ai_socktype = SOCK_DGRAM;
+       }
+       if (ai->ai_protocol == 0) {
+               if (ai->ai_socktype == SOCK_DGRAM) {
+                       ai->ai_protocol = IPPROTO_UDP;
+               } else if (ai->ai_socktype == SOCK_STREAM) {
+                       ai->ai_protocol = IPPROTO_TCP;
+               }
+       }
+
        ai->ai_addrlen = socklen;
        ai->ai_addr = (void *)(ai + 1);
 
@@ -5244,18 +5255,6 @@ valid_port:
                return rc;
        }
 
-       if (ai->ai_flags == 0) {
-               ai->ai_flags = hints->ai_flags;
-       }
-       if (ai->ai_socktype == 0) {
-               ai->ai_socktype = SOCK_DGRAM;
-       }
-       if (ai->ai_protocol == 0 && ai->ai_socktype == SOCK_DGRAM) {
-               ai->ai_protocol = IPPROTO_UDP;
-       } else if (ai->ai_protocol == 0 && ai->ai_socktype == SOCK_STREAM) {
-               ai->ai_protocol = IPPROTO_TCP;
-       }
-
        if (hints->ai_socktype == 0) {
                /* Add second ai */
                struct addrinfo *ai_head = ai;