From: Frédéric Marchal Date: Sat, 23 Apr 2011 14:58:09 +0000 (+0000) Subject: Retry if getnameinfo returns EAI_AGAIN X-Git-Tag: v2.3.2~61 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8fa27cb02e3f46eb23d6785f0e0ebc4aa3d74e9c;p=thirdparty%2Fsarg.git Retry if getnameinfo returns EAI_AGAIN The man page tells that the program should try again when getnameinfo returns EAI_AGAIN but it doesn't say if the program should wait and how many attempts it should perform. Therefore, we assume the implementation just want us to call it again but we won't waste more time than that. The number of IP addresses to resolve is potentially very big and it doesn't matter much if a few addresses are not resolved. --- diff --git a/ip2name.c b/ip2name.c index f9d78c7..f2b96c0 100644 --- a/ip2name.c +++ b/ip2name.c @@ -49,8 +49,18 @@ void ip2name(char *ip,int ip_len) sa.ss_family=AF_INET6; } error=getnameinfo((struct sockaddr *)&sa,sizeof(sa),host,sizeof(host),NULL,0,0); - if (error==0) - { + if (error==EAI_AGAIN) { + /* + This is a temporary failure. According to the man page we should try again but + it doesn't say if the program should wait before trying again nor how many attempts + before it becomes a fatal error. I could find no clues on internet so I try once and + leave it at that. Considering the number of IP addresses to resolve and the absence + of serious consequences should some IP fail to be resolved properly, it is best + not waste too much time on this. + */ + error=getnameinfo((struct sockaddr *)&sa,sizeof(sa),host,sizeof(host),NULL,0,0); + } + if (error==0) { strncpy(ip,host,ip_len-1); ip[ip_len-1]='\0'; } else {