getaddrinfo.c: Don't fail when SOCK_STREAM or SOCK_DGRAM are
authorSimon Josefsson <simon@josefsson.org>
Tue, 10 May 2005 12:34:54 +0000 (12:34 +0000)
committerSimon Josefsson <simon@josefsson.org>
Tue, 10 May 2005 12:34:54 +0000 (12:34 +0000)
specified in ai_socktype. Fix invalid ai_protocol
check. ai_protocol is usually set to 0 or depending on
ai_family/ai_socktype to IPPROTO_TCP / IPPROTO_UDP.  Checking for
SOCK_STREAM / SOCK_DGRAM in ai_protocol was invalid.  Set
ai_socktype / ai_protocol in the returned addrinfo structure.

lib/ChangeLog
lib/getaddrinfo.c

index db3bf18..b65a5e8 100644 (file)
@@ -1,3 +1,12 @@
+2005-05-10  Yoann Vandoorselaere <yoann.v@prelude-ids.com>
+
+       * getaddrinfo.c: Don't fail when SOCK_STREAM or SOCK_DGRAM are
+       specified in ai_socktype. Fix invalid ai_protocol
+       check. ai_protocol is usually set to 0 or depending on
+       ai_family/ai_socktype to IPPROTO_TCP / IPPROTO_UDP.  Checking for
+       SOCK_STREAM / SOCK_DGRAM in ai_protocol was invalid.  Set
+       ai_socktype / ai_protocol in the returned addrinfo structure.
+
 2005-05-09  Yoann Vandoorselaere <yoann.v@prelude-ids.com>
             Bruno Haible  <bruno@clisp.org>
 
index 145eac5..a71e616 100644 (file)
@@ -1,5 +1,5 @@
 /* Get address information (partial implementation).
-   Copyright (C) 1997, 2001, 2002, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1997, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
    Contributed by Simon Josefsson <simon@josefsson.org>.
 
    This program is free software; you can redistribute it and/or modify
@@ -74,14 +74,10 @@ getaddrinfo (const char *restrict nodename,
   if (hints && !validate_family (hints->ai_family))
     return EAI_FAMILY;
 
-  if (hints && hints->ai_socktype)
-    /* FIXME: Support more socket types. */
-    return EAI_SOCKTYPE;
-
   if (hints &&
-      hints->ai_protocol != SOCK_STREAM && hints->ai_protocol != SOCK_DGRAM)
-    /* FIXME: Support other protocols. */
-    return EAI_SERVICE;                /* FIXME: Better return code? */
+      hints->ai_socktype != SOCK_STREAM && hints->ai_socktype != SOCK_DGRAM)
+    /* FIXME: Support other socktype. */
+    return EAI_SOCKTYPE; /* FIXME: Better return code? */
 
   if (!nodename)
     /* FIXME: Support server bind mode. */
@@ -90,7 +86,7 @@ getaddrinfo (const char *restrict nodename,
   if (servname)
     {
       const char *proto =
-       (hints && hints->ai_protocol == SOCK_DGRAM) ? "udp" : "tcp";
+       (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp";
 
       /* FIXME: Use getservbyname_r if available. */
       se = getservbyname (servname, proto);
@@ -171,6 +167,8 @@ getaddrinfo (const char *restrict nodename,
       return EAI_NODATA;
     }
 
+  tmp->ai_protocol = (hints) ? hints->ai_protocol : 0;
+  tmp->ai_socktype = (hints) ? hints->ai_socktype : 0;
   tmp->ai_addr->sa_family = he->h_addrtype;
 
   /* FIXME: If more than one address, create linked list of addrinfo's. */