Author: rfm Date: Thu Jan 12 11:34:23 2017 New Revision: 40289 URL: http://svn.gna.org/viewcvs/gnustep?rev=40289&view=rev Log: fix for bug #50032
Modified: libs/base/trunk/ChangeLog libs/base/trunk/Source/NSHost.m libs/base/trunk/Tools/gdomap.c Modified: libs/base/trunk/ChangeLog URL: http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/ChangeLog?rev=40289&r1=40288&r2=40289&view=diff ============================================================================== --- libs/base/trunk/ChangeLog (original) +++ libs/base/trunk/ChangeLog Thu Jan 12 11:34:23 2017 @@ -1,3 +1,8 @@ +2017-01-06 Richard Frith-Macdonald <r...@gnu.org> + + * Tools/gdomap.c: Use getaddrinfo rather than gethostbyname if + available (bug #50032). + 2016-12-06 Richard Frith-Macdonald <r...@gnu.org> * Tools/AGSParser.m: Fix missing line preventing documentation of Modified: libs/base/trunk/Source/NSHost.m URL: http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSHost.m?rev=40289&r1=40288&r2=40289&view=diff ============================================================================== --- libs/base/trunk/Source/NSHost.m (original) +++ libs/base/trunk/Source/NSHost.m Thu Jan 12 11:34:23 2017 @@ -163,8 +163,7 @@ memset(&hints, '\0', sizeof(hints)); hints.ai_flags = AI_CANONNAME; - getaddrinfo([a UTF8String], 0, &hints, &entry); - if (0 == entry) + if (getaddrinfo([a UTF8String], 0, &hints, &entry) != 0) { /* * Can't find a database entry for this IP address, but since Modified: libs/base/trunk/Tools/gdomap.c URL: http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Tools/gdomap.c?rev=40289&r1=40288&r2=40289&view=diff ============================================================================== --- libs/base/trunk/Tools/gdomap.c (original) +++ libs/base/trunk/Tools/gdomap.c Thu Jan 12 11:34:23 2017 @@ -3975,7 +3975,6 @@ nameServer(const char* name, const char* host, int op, int ptype, struct sockaddr_in* addr, int pnum, int max) { struct sockaddr_in sin; - struct hostent* hp; unsigned short p; unsigned short port = 0; int len = strlen(name); @@ -3997,11 +3996,14 @@ return -1; } + memset((char*)&sin, '\0', sizeof(sin)); + sin.sin_family = AF_INET; + #if GDOMAP_PORT_OVERRIDE p = htons(GDOMAP_PORT_OVERRIDE); #else { - struct servent* sp; + struct servent *sp; /* * Ensure we have port number to connect to name server. * The TCP service name 'gdomap' overrides the default port. @@ -4016,6 +4018,7 @@ } } #endif + sin.sin_port = p; /* * The host name '*' matches any host on the local network. @@ -4037,30 +4040,56 @@ } host = local_hostname; } - if ((hp = gethostbyname(host)) == 0 && first_dot != 0) - { - *first_dot = '.'; - hp = gethostbyname(host); - } - if (hp == 0) - { - snprintf(ebuf, sizeof(ebuf), - "gethostbyname('%s') failed: %s", host, strerror(errno)); - gdomap_log(LOG_ERR); - return -1; - } - if (hp->h_addrtype != AF_INET) - { - snprintf(ebuf, sizeof(ebuf), - "non-internet network not supported for %s", host); - gdomap_log(LOG_ERR); - return -1; - } - - memset((char*)&sin, '\0', sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_port = p; - memcpy(&sin.sin_addr, hp->h_addr, hp->h_length); + +#if HAVE_GETADDRINFO + { + struct addrinfo hints; + struct addrinfo *info; + int err; + + memset(&hints, '\0', sizeof(hints)); + hints.ai_family = AF_INET; + + if (getaddrinfo(host, NULL, &hints, &info) != 0 && first_dot != 0) + { + *first_dot = '.'; + if ((err = getaddrinfo(host, NULL, &hints, &info)) != 0) + { + snprintf(ebuf, sizeof(ebuf), + "getaddrinfo('%s') failed: %s", host, gai_strerror(err)); + gdomap_log(LOG_ERR); + return -1; + } + } + memcpy(&sin.sin_addr, info->ai_addr, info->ai_addrlen); + freeaddrinfo(info); + } +#else + { + struct hostent *hp; + + if ((hp = gethostbyname(host)) == 0 && first_dot != 0) + { + *first_dot = '.'; + hp = gethostbyname(host); + } + if (hp == 0) + { + snprintf(ebuf, sizeof(ebuf), + "gethostbyname('%s') failed: %s", host, strerror(errno)); + gdomap_log(LOG_ERR); + return -1; + } + if (hp->h_addrtype != AF_INET) + { + snprintf(ebuf, sizeof(ebuf), + "non-internet network not supported for %s", host); + gdomap_log(LOG_ERR); + return -1; + } + memcpy(&sin.sin_addr, hp->h_addr, hp->h_length); + } +#endif if (multi) { @@ -4193,33 +4222,12 @@ donames(const char *host) { struct sockaddr_in sin; - struct hostent* hp; unsigned short p; unsigned short num = 0; int rval; uptr b; char *first_dot = 0; -#if GDOMAP_PORT_OVERRIDE - p = htons(GDOMAP_PORT_OVERRIDE); -#else -{ - struct servent* sp; - /* - * Ensure we have port number to connect to name server. - * The TCP service name 'gdomap' overrides the default port. - */ - if ((sp = getservbyname("gdomap", "tcp")) != 0) - { - p = sp->s_port; /* Network byte order. */ - } - else - { - p = htons(GDOMAP_PORT); - } -} -#endif - if (host == 0 || *host == '\0') { /* @@ -4232,30 +4240,82 @@ } host = local_hostname; } - if ((hp = gethostbyname(host)) == 0 && first_dot != 0) - { - *first_dot = '.'; - hp = gethostbyname(host); - } - if (hp == 0) - { - snprintf(ebuf, sizeof(ebuf), - "gethostbyname('%s') failed: %s", host, strerror(errno)); - gdomap_log(LOG_ERR); - return; - } - if (hp->h_addrtype != AF_INET) - { - snprintf(ebuf, sizeof(ebuf), - "non-internet network not supported for %s", host); - gdomap_log(LOG_ERR); - return; - } memset((char*)&sin, '\0', sizeof(sin)); sin.sin_family = AF_INET; + +#if GDOMAP_PORT_OVERRIDE + p = htons(GDOMAP_PORT_OVERRIDE); +#else + { + struct servent *sp; + /* + * Ensure we have port number to connect to name server. + * The TCP service name 'gdomap' overrides the default port. + */ + if ((sp = getservbyname("gdomap", "tcp")) != 0) + { + p = sp->s_port; /* Network byte order. */ + } + else + { + p = htons(GDOMAP_PORT); + } + } +#endif + sin.sin_port = p; - memcpy(&sin.sin_addr, hp->h_addr, hp->h_length); + +#if HAVE_GETADDRINFO + { + struct addrinfo hints; + struct addrinfo *info; + int err; + + memset(&hints, '\0', sizeof(hints)); + hints.ai_family = AF_INET; + + if (getaddrinfo(host, NULL, &hints, &info) != 0 && first_dot != 0) + { + *first_dot = '.'; + if ((err = getaddrinfo(host, NULL, &hints, &info)) != 0) + { + snprintf(ebuf, sizeof(ebuf), + "getaddrinfo('%s') failed: %s", host, gai_strerror(err)); + gdomap_log(LOG_ERR); + return; + } + } + memcpy(&sin.sin_addr, info->ai_addr, info->ai_addrlen); + freeaddrinfo(info); + } +#else + { + struct hostent *hp; + + if ((hp = gethostbyname(host)) == 0 && first_dot != 0) + { + *first_dot = '.'; + hp = gethostbyname(host); + } + if (hp == 0) + { + snprintf(ebuf, sizeof(ebuf), + "gethostbyname('%s') failed: %s", host, strerror(errno)); + gdomap_log(LOG_ERR); + return; + } + if (hp->h_addrtype != AF_INET) + { + snprintf(ebuf, sizeof(ebuf), + "non-internet network not supported for %s", host); + gdomap_log(LOG_ERR); + return; + } + + memcpy(&sin.sin_addr, hp->h_addr, hp->h_length); + } +#endif rval = tryHost(GDO_NAMES, 0, 0, 0, &sin, &num, (uptr*)&b); if (rval != 0) _______________________________________________ Gnustep-cvs mailing list Gnustep-cvs@gna.org https://mail.gna.org/listinfo/gnustep-cvs