From: Simon Josefsson Date: Tue, 10 May 2005 12:34:54 +0000 (+0000) Subject: getaddrinfo.c: Don't fail when SOCK_STREAM or SOCK_DGRAM are X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58ed6c0708242f4ee6432e083ebb8bb9b7217ac6;p=pspp 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. --- diff --git a/lib/ChangeLog b/lib/ChangeLog index db3bf18849..b65a5e8650 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,12 @@ +2005-05-10 Yoann Vandoorselaere + + * 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 Bruno Haible diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c index 145eac519b..a71e6168ab 100644 --- a/lib/getaddrinfo.c +++ b/lib/getaddrinfo.c @@ -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 . 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. */