]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Retry if getnameinfo returns EAI_AGAIN
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sat, 23 Apr 2011 14:58:09 +0000 (14:58 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sat, 23 Apr 2011 14:58:09 +0000 (14:58 +0000)
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.

ip2name.c

index f9d78c7bb29bf7948c046aabd847ca22edcfb6e4..f2b96c03d95a2198553a9e69b5503a4fce3b0dfb 100644 (file)
--- 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 {