Skip to content

Commit

Permalink
nwrap: move setting of ai_{flags|socktype|protocol} into nwrap_conver…
Browse files Browse the repository at this point in the history
…t_he_ai

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 <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
  • Loading branch information
obnoxxx committed Jan 11, 2016
1 parent a66606c commit 062c97b
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions lib/nss_wrapper/nss_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -5244,18 +5255,6 @@ static int nwrap_getaddrinfo(const char *node,
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;
Expand Down

0 comments on commit 062c97b

Please sign in to comment.