gethostbyname_r: Fix test of return value from inet_pton(). Zero does not mean success

This commit is contained in:
Gregory Nutt 2015-07-17 08:24:21 -06:00
parent 0aefd55383
commit 2a2e9fa56a
2 changed files with 26 additions and 13 deletions

View file

@ -88,10 +88,8 @@
* address (32 bits for AF_INET, 128 bits for AF_INET6).
*
* Returned Value:
* The inet_pton() function returns 1 if the conversion succeeds, with the
* address pointed to by dest in network byte order. It will return 0 if the
* input is not a valid IPv4 dotted-decimal string or a valid IPv6 address
* string, or -1 with errno set to EAFNOSUPPOR] if the af argument is unknown.
* inet_ipv4_pton() will returns 1 if the conversion succeeds. It will
* return 0 if the input is not a valid IPv4 dotted-decimal string string.
*
****************************************************************************/
@ -200,10 +198,8 @@ static int inet_ipv4_pton(FAR const char *src, FAR void *dest)
* address (32 bits for AF_INET, 128 bits for AF_INET6).
*
* Returned Value:
* The inet_pton() function returns 1 if the conversion succeeds, with the
* address pointed to by dest in network byte order. It will return 0 if the
* input is not a valid IPv4 dotted-decimal string or a valid IPv6 address
* string, or -1 with errno set to EAFNOSUPPOR] if the af argument is unknown.
* inet_ipv6_pton() will returns 1 if the conversion succeeds. It will
* return 0 if the input is not a valid IPv6 address string.
*
****************************************************************************/
@ -384,7 +380,7 @@ static int inet_ipv6_pton(FAR const char *src, FAR void *dest)
* The inet_pton() function returns 1 if the conversion succeeds, with the
* address pointed to by dest in network byte order. It will return 0 if the
* input is not a valid IPv4 dotted-decimal string or a valid IPv6 address
* string, or -1 with errno set to EAFNOSUPPORT] if the af argument is
* string, or -1 with errno set to EAFNOSUPPORT if the af argument is
* unknown.
*
****************************************************************************/

View file

@ -123,7 +123,9 @@ static int lib_numeric_address(FAR const char *name, FAR struct hostent *host,
memset(host, 0, sizeof(struct hostent));
memset(info, 0, sizeof(struct hostent_info_s));
/* If the address contains a colon, then it might be a numeric IPv6 */
/* If the address contains a colon, then it might be a numeric IPv6
* address
*/
if (strchr(name, ':') != NULL)
{
@ -136,7 +138,13 @@ static int lib_numeric_address(FAR const char *name, FAR struct hostent *host,
}
ret = inet_pton(AF_INET6, name, ptr);
if (ret < 0)
/* The inet_pton() function returns 1 if the conversion succeeds. It
* will return 0 if the input is not a valid IP address string, or -1
* if the address family argument is unsupported.
*/
if (ret < 1)
{
/* Conversion failed. Must not be a IPv6 address */
@ -145,7 +153,10 @@ static int lib_numeric_address(FAR const char *name, FAR struct hostent *host,
host->h_addrtype = AF_INET6;
}
/* If the address contains a colon, then it might be a numeric IPv6 */
/* If the address contains a colon, then it might be a numeric IPv6
* address.
*/
else if (strchr(name, '.') != NULL)
{
@ -158,7 +169,13 @@ static int lib_numeric_address(FAR const char *name, FAR struct hostent *host,
}
ret = inet_pton(AF_INET, name, ptr);
if (ret < 0)
/* The inet_pton() function returns 1 if the conversion succeeds. It
* will return 0 if the input is not a valid IP address string, or -1
* if the address family argument is unsupported.
*/
if (ret < 1)
{
/* Conversion failed. Must not be an IPv4 address */