From: Frédéric Marchal Date: Thu, 4 Aug 2011 06:10:43 +0000 (+0000) Subject: Attempt to fix a FreeBSD IP address resolution X-Git-Tag: v2.3.2~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a50c63194f3ed7c380ad7449e9c9066c2cda1687;p=thirdparty%2Fsarg.git Attempt to fix a FreeBSD IP address resolution According to this post: http://lists.freebsd.org/pipermail/freebsd-standards/2005-July/000948.html Some old version of FreeBSD requires that the sa_len of the sockaddr_in structure be initialized with the exact length passed to getnameinfo. As Linux doesn't have the sa_len member, it is not initialized in sarg. Therefore the IP address resolution fails when sarg is compiled on FreeBSD. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index b646aa1..faacb75 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(sarg C) SET(sarg_VERSION 2) SET(sarg_REVISION "3.2-pre2") SET(sarg_BUILD "") -SET(sarg_BUILDDATE "Aug-01-2011") +SET(sarg_BUILDDATE "Aug-04-2011") INCLUDE(AddFileDependencies) INCLUDE(CheckIncludeFile) @@ -12,6 +12,7 @@ INCLUDE(CheckFunctionExists) INCLUDE(CheckTypeSize) INCLUDE(CheckSymbolExists) INCLUDE(CheckCCompilerFlag) +INCLUDE(CheckStructHasMember) DEFINE_PROPERTY(GLOBAL PROPERTY enable-htmldir BRIEF_DOCS "--enable-htmldir=htmldir" FULL_DOCS "Select htmldir as the root of your WWW documents") @@ -95,10 +96,10 @@ CHECK_INCLUDE_FILE(time.h HAVE_TIME_H) CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H) CHECK_INCLUDE_FILE(sys/dirent.h HAVE_SYS_DIRENT_H) CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H) +CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H) CHECK_INCLUDE_FILE(sys/socket.h HAVE_SYS_SOCKET_H) CHECK_INCLUDE_FILE(netdb.h HAVE_NETDB_H) CHECK_INCLUDE_FILE(arpa/inet.h HAVE_ARPA_INET_H) -CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H) CHECK_INCLUDE_FILE(netinet/in.h HAVE_NETINET_H) CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H) CHECK_INCLUDE_FILE(ctype.h HAVE_CTYPE_H) @@ -149,6 +150,8 @@ CHECK_FUNCTION_EXISTS(getnameinfo HAVE_GETNAMEINFO) CHECK_FUNCTION_EXISTS(getaddrinfo HAVE_GETADDRINFO) CHECK_FUNCTION_EXISTS(inet_aton HAVE_INET_ATON) +CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" ss_len sys/socket.h HAVE_SOCKADDR_SA_LEN) + # Find gd CHECK_INCLUDE_FILE(gd.h HAVE_GD_H) IF(HAVE_GD_H) diff --git a/configure.in b/configure.in index e72a60e..9b9a620 100644 --- a/configure.in +++ b/configure.in @@ -72,7 +72,7 @@ if test -n "$LIBICONV" ; then fi AC_CHECK_HEADERS(stdio.h stdlib.h string.h strings.h sys/time.h time.h unistd.h sys/dirent.h \ - dirent.h sys/socket.h netdb.h arpa/inet.h sys/types.h netinet/in.h sys/stat.h \ + dirent.h sys/types.h sys/socket.h netdb.h arpa/inet.h netinet/in.h sys/stat.h \ ctype.h gd.h gdfontl.h gdfontt.h gdfonts.h gdfontmb.h gdfontg.h iconv.h \ errno.h sys/resource.h sys/wait.h stdarg.h inttypes.h limits.h locale.h \ execinfo.h ldap.h math.h libintl.h libgen.h stdbool.h getopt.h) @@ -133,6 +133,9 @@ AC_CHECK_FUNCS(lstat) AC_CHECK_FUNCS(getnameinfo) AC_CHECK_FUNCS(getaddrinfo) +dnl check for structure members +AC_CHECK_MEMBER([struct sockaddr_storage.ss_len],[AC_DEFINE([HAVE_SOCKADDR_SA_LEN],1,[ss_len in sockaddr_storage])]) + dnl check for the rlim_t size AC_CHECK_SIZEOF(rlim_t,1,[#if HAVE_SYS_RESOURCE_H #include diff --git a/include/config.h.in b/include/config.h.in index ccfa37e..7563997 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -61,6 +61,8 @@ #cmakedefine HAVE_GETADDRINFO #cmakedefine HAVE_INET_ATON +#cmakedefine HAVE_SOCKADDR_SA_LEN + #define RLIM_STRING "@RLIM_STRING@" #define ICONV_CONST @ICONV_CONST@ diff --git a/include/info.h b/include/info.h index 9089e8e..5ba9e4e 100755 --- a/include/info.h +++ b/include/info.h @@ -1,3 +1,3 @@ -#define VERSION PACKAGE_VERSION" Aug-01-2011" +#define VERSION PACKAGE_VERSION" Aug-04-2011" #define PGM PACKAGE_NAME #define URL "http://sarg.sourceforge.net" diff --git a/ip2name.c b/ip2name.c index f2b96c0..4657a51 100644 --- a/ip2name.c +++ b/ip2name.c @@ -34,6 +34,7 @@ void ip2name(char *ip,int ip_len) { #ifdef HAVE_GETNAMEINFO struct sockaddr_storage sa; + int sockaddr_size; char host[NI_MAXHOST]; int n1,n2,n3,n4,next=0; int error; @@ -43,12 +44,17 @@ void ip2name(char *ip,int ip_len) struct sockaddr_in *s4=(struct sockaddr_in *)&sa; if (inet_pton(AF_INET,ip,&s4->sin_addr)!=1) return; sa.ss_family=AF_INET; + sockaddr_size=sizeof(*s4); } else { struct sockaddr_in6 *s6=(struct sockaddr_in6 *)&sa; if (inet_pton(AF_INET6,ip,&s6->sin6_addr)!=1) return; sa.ss_family=AF_INET6; + sockaddr_size=sizeof(*s6); } - error=getnameinfo((struct sockaddr *)&sa,sizeof(sa),host,sizeof(host),NULL,0,0); +#ifdef HAVE_SOCKADDR_SA_LEN + sa.ss_len=sockaddr_size; +#endif + error=getnameinfo((struct sockaddr *)&sa,sockaddr_size,host,sizeof(host),NULL,0,0); if (error==EAI_AGAIN) { /* This is a temporary failure. According to the man page we should try again but