]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Don't abort if a host name cannot be resolved into an IP address
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Thu, 5 Nov 2015 20:25:23 +0000 (21:25 +0100)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Thu, 5 Nov 2015 20:25:23 +0000 (21:25 +0100)
Finding the IP address of a host is not that critical. If it can't be
resolved, keep generating the report.

If the host name cannot be resolved into an IP address, an error message is
printed on stderr.

ip2name.c

index bd5da8ada7710b80fd00eb4c8fcb45ca7999ed2c..46e81210eb1e38ff47bb26755e32a79e4eeeb6b8 100644 (file)
--- a/ip2name.c
+++ b/ip2name.c
@@ -276,29 +276,29 @@ void name2ip(char *name,int name_size)
        error=getaddrinfo(addr,NULL,NULL,&res);
        if (error) {
                if (res) freeaddrinfo(res);
-               debuga(__FILE__,__LINE__,_("Cannot resolve host name %s: %s\n"),name,gai_strerror(error));
-               exit(EXIT_FAILURE);
-       }
-       if (res->ai_family==AF_INET) {
-               struct sockaddr_in *s4=(struct sockaddr_in *)res->ai_addr;
-               struct in_addr *sa=&s4->sin_addr;
-               if (res->ai_addrlen<sizeof(*s4)) {
-                       debuga(__FILE__,__LINE__,_("Short structure returned by getaddrinfo for an IPv4 address: %d bytes instead of %d\n"),res->ai_addrlen,(int)sizeof(*s4));
-                       exit(EXIT_FAILURE);
-               }
-               inet_ntop(res->ai_family,sa,name,name_size);
-       } else if (res->ai_family==AF_INET6) {
-               struct sockaddr_in6 *s6=(struct sockaddr_in6 *)res->ai_addr;
-               struct in6_addr *sa6=&s6->sin6_addr;
-               if (res->ai_addrlen<sizeof(*s6)) {
-                       debuga(__FILE__,__LINE__,_("Short structure returned by getaddrinfo for an IPv6 address: %d bytes instead of %d\n"),res->ai_addrlen,(int)sizeof(*s6));
-                       exit(EXIT_FAILURE);
-               }
-               inet_ntop(res->ai_family,sa6,name,name_size);
+               debuga(__FILE__,__LINE__,_("Cannot resolve host name \"%s\": %s\n"),name,gai_strerror(error));
        } else {
-               debuga(__FILE__,__LINE__,_("Invalid address type %d returned when resolving host name \"%s\"\n"),res->ai_family,name);
+               if (res->ai_family==AF_INET) {
+                       struct sockaddr_in *s4=(struct sockaddr_in *)res->ai_addr;
+                       struct in_addr *sa=&s4->sin_addr;
+                       if (res->ai_addrlen<sizeof(*s4)) {
+                               debuga(__FILE__,__LINE__,_("Short structure returned by getaddrinfo for an IPv4 address: %d bytes instead of %d\n"),res->ai_addrlen,(int)sizeof(*s4));
+                               exit(EXIT_FAILURE);
+                       }
+                       inet_ntop(res->ai_family,sa,name,name_size);
+               } else if (res->ai_family==AF_INET6) {
+                       struct sockaddr_in6 *s6=(struct sockaddr_in6 *)res->ai_addr;
+                       struct in6_addr *sa6=&s6->sin6_addr;
+                       if (res->ai_addrlen<sizeof(*s6)) {
+                               debuga(__FILE__,__LINE__,_("Short structure returned by getaddrinfo for an IPv6 address: %d bytes instead of %d\n"),res->ai_addrlen,(int)sizeof(*s6));
+                               exit(EXIT_FAILURE);
+                       }
+                       inet_ntop(res->ai_family,sa6,name,name_size);
+               } else {
+                       debuga(__FILE__,__LINE__,_("Invalid address type %d returned when resolving host name \"%s\"\n"),res->ai_family,name);
+               }
+               freeaddrinfo(res);
        }
-       freeaddrinfo(res);
 #else
        struct in_addr ia;
        struct hostent *hp;