From: Marc Kleine-Budde Date: Sat, 29 Oct 2011 18:55:06 +0200 Subject: [PATCH] bing_1.1.3-2.diff From http://ftp.de.debian.org/debian/pool/main/b/bing/bing_1.1.3-2.diff.gz Signed-off-by: Marc Kleine-Budde --- bing.c | 63 ++++++++++++++++++++++++++++++--------------------------------- 1 files changed, 30 insertions(+), 33 deletions(-) diff --git a/bing.c b/bing.c index aa078f9..e1094e9 100644 --- a/bing.c +++ b/bing.c @@ -104,7 +104,9 @@ static char rcsid[] = "$Id: bing.c,v 1.17 1997/01/23 21:00:03 pb Exp $"; #include /* More specific includes/declarations */ +#ifndef __GNU__ #include +#endif /* __GNU__ */ #include #include #include @@ -152,7 +154,9 @@ char* __progname; * standard libraries. */ #include +#ifndef __GNU__ #include +#endif /* __GNU__ */ #include #include "mod_icmp.h" @@ -320,9 +324,7 @@ struct timestats { struct hoststats { /* Host info */ - char hnamebuf[MAXHOSTNAMELEN]; char *hostname; - struct sockaddr_in whereto; struct sockaddr_in *to; struct timestats *ts; }; @@ -365,28 +367,19 @@ void set_ip(hs, target) struct hoststats *hs; char *target; { - struct hostent *hp; + struct addrinfo hints, *ai; + int r; - hs->to = &hs->whereto; - - memset((char *)hs->to, 0, sizeof(struct sockaddr_in)); - hs->to->sin_family = AF_INET; - hs->to->sin_addr.s_addr = inet_addr(target); - if (hs->to->sin_addr.s_addr != (u_int)-1) - hs->hostname = target; - else { - hp = gethostbyname(target); - if (!hp) { - (void)fprintf(stderr, - "bing: unknown host %s\n", target); - exit(1); - } - hs->to->sin_family = hp->h_addrtype; - memcpy((caddr_t)&hs->to->sin_addr, hp->h_addr, hp->h_length); - strncpy(hs->hnamebuf, hp->h_name, sizeof(hs->hnamebuf) - 1); - hs->hnamebuf[sizeof(hs->hnamebuf)-1] = '\0'; - hs->hostname = hs->hnamebuf; + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_INET; + hints.ai_flags = AI_CANONNAME; + if((r = getaddrinfo(target, NULL, &hints, &ai))) { + fprintf(stderr, "bing: couldn't resolve %s: %s\n", + target, gai_strerror(r)); + exit(1); } + hs->to = (struct sockaddr_in *) ai->ai_addr; + hs->hostname = ai->ai_canonname; } void randomfill(bp, len, seed) @@ -677,18 +670,22 @@ char * pr_addr(l) u_long l; { - struct hostent *hp; - static char buf[80]; + static char buf[MAXHOSTNAMELEN+19]; + struct sockaddr_in sa; + int r; - if ((options & F_NUMERIC) || - !(hp = gethostbyaddr((char *)&l, 4, AF_INET))) - (void)snprintf(snfargs(buf, sizeof(buf), "%s"), - inet_ntoa(*(struct in_addr *)&l)); - else - (void)snprintf(snfargs(buf, sizeof(buf), "%s (%s)"), - hp->h_name, - inet_ntoa(*(struct in_addr *)&l)); - return(buf); + sa.sin_family = AF_INET; + sa.sin_port = 0; + memcpy(&sa.sin_addr, &l, sizeof l); + + r = getnameinfo((struct sockaddr *) &sa, sizeof sa, buf, sizeof buf, + NULL, 0, (options & F_NUMERIC) ? NI_NUMERICHOST : 0); + if(r) { + fprintf(stderr, "bing: getaddrinfo: %s\n", gai_strerror(r)); + exit(1); + } + + return buf; } /*