- use CFLAGS -Wall only with GCC compiler

- fixed a number of compiler warnings (by Norm Brandinger)
  [3086593,3086371,3086351]
- use getifaddrs() to get the IP address of local interfaces.
  This seems to be required with FreeeBSD jails.
This commit is contained in:
Thomas Ries 2011-01-09 13:10:27 +00:00
parent 7be49c4329
commit f2c98485f8
6 changed files with 92 additions and 17 deletions

View File

@ -1,5 +1,10 @@
0.8.1 0.8.1
===== =====
09-Jan-2011: - use CFLAGS -Wall only with GCC compiler
14-Oct-2010: - fixed a number of compiler warnings (by Norm Brandinger)
[3086593,3086371,3086351]
03-Oct-2010: - use getifaddrs() to get the IP address of local interfaces.
This seems to be required with FreeeBSD jails.
19-Jun-2010: - fix: include correct ltdl.h for system & convenience libltdl 19-Jun-2010: - fix: include correct ltdl.h for system & convenience libltdl
26-Apr-2010: - Clean building from distribuion TAR did fail if the host 26-Apr-2010: - Clean building from distribuion TAR did fail if the host
installed libltdl lib was used (and not the convenience lib) installed libltdl lib was used (and not the convenience lib)

View File

@ -45,6 +45,9 @@
/* Define to 1 if you have the `gethostbyname' function. */ /* Define to 1 if you have the `gethostbyname' function. */
#undef HAVE_GETHOSTBYNAME #undef HAVE_GETHOSTBYNAME
/* Define to 1 if you have the `getifaddrs' function. */
#undef HAVE_GETIFADDRS
/* Define to 1 if you have the <getopt.h> header file. */ /* Define to 1 if you have the <getopt.h> header file. */
#undef HAVE_GETOPT_H #undef HAVE_GETOPT_H

View File

@ -50,6 +50,7 @@ dnl and fall back using convenienve libltdl (WARN)
dnl 26-Apr-2010 tries Fresh building from distribuion TAR did fail if dnl 26-Apr-2010 tries Fresh building from distribuion TAR did fail if
dnl the host-installed libltdl lib is used (and not the dnl the host-installed libltdl lib is used (and not the
dnl convenience lib) dnl convenience lib)
dnl 09-Jan-2011 tries use CFLAGS -Wall only with GCC compiler
dnl dnl
dnl dnl
@ -234,6 +235,17 @@ dnl
fi fi
dnl
dnl Use -Wall if we have gcc.
dnl
if test "x$GCC" = "xyes"; then
case " $CFLAGS " in
*[\ ]-Wall[\ ]*) ;;
*) CFLAGS="$CFLAGS -Wall" ;;
esac
fi
dnl dnl
dnl target platform specific stuff dnl target platform specific stuff
dnl dnl
@ -471,6 +483,7 @@ ACX_WHICH_GETHOSTBYNAME_R()
AC_CHECK_FUNCS(getopt_long setsid syslog) AC_CHECK_FUNCS(getopt_long setsid syslog)
AC_CHECK_FUNCS(getuid setuid getgid setgid getpwnam chroot) AC_CHECK_FUNCS(getuid setuid getgid setgid getpwnam chroot)
AC_CHECK_FUNCS(socket bind select read send sendto fcntl) AC_CHECK_FUNCS(socket bind select read send sendto fcntl)
AC_CHECK_FUNCS(getifaddrs)
AC_CHECK_FUNCS(strcmp strcasecmp) AC_CHECK_FUNCS(strcmp strcasecmp)
AC_CHECK_FUNCS(strncpy strchr strstr sprintf vfprintf vsnprintf) AC_CHECK_FUNCS(strncpy strchr strstr sprintf vfprintf vsnprintf)
AC_CHECK_FUNCS(listen accept) AC_CHECK_FUNCS(listen accept)

View File

@ -23,7 +23,7 @@ if use_convenience_ltdl
LTDLDEF = -DLTDL_CONVLIB LTDLDEF = -DLTDL_CONVLIB
endif endif
AM_CFLAGS = -Wall -D_GNU_SOURCE $(LTDLDEF) \ AM_CFLAGS = -D_GNU_SOURCE $(LTDLDEF) \
-DBUILDSTR="\"`cat .buildno`\"" -DBUILDSTR="\"`cat .buildno`\""
# #

View File

@ -428,7 +428,7 @@ int is_sipuri_local (sip_ticket_t *ticket) {
/* need name resolution */ /* need name resolution */
sts=get_ip_by_host(sip->req_uri->host, &addr_uri); sts=get_ip_by_host(sip->req_uri->host, &addr_uri);
if (sts == STS_FAILURE) { if (sts == STS_FAILURE) {
DEBUGC(DBCLASS_PROXY, "sip_gen_response: cannot resolve via [%s]", DEBUGC(DBCLASS_PROXY, "sip_gen_response: cannot resolve request uri [%s]",
sip->req_uri->host); sip->req_uri->host);
return STS_FALSE; return STS_FALSE;
} }

View File

@ -34,6 +34,10 @@
#include <net/if.h> #include <net/if.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#ifdef HAVE_GETIFADDRS
# include <ifaddrs.h>
#endif
#ifdef _SOLARIS2 #ifdef _SOLARIS2
# include <sys/sockio.h> # include <sys/sockio.h>
#endif #endif
@ -401,11 +405,9 @@ int get_interface_real_ip(int interface, struct in_addr *retaddr) {
* STS_FAILURE if interface is DOWN or other problem * STS_FAILURE if interface is DOWN or other problem
*/ */
int get_ip_by_ifname(char *ifname, struct in_addr *retaddr) { int get_ip_by_ifname(char *ifname, struct in_addr *retaddr) {
struct ifreq ifr; struct in_addr ifaddr; /* resulting IP */
struct sockaddr_in *sin = (struct sockaddr_in *)&ifr.ifr_addr;
int sockfd;
int i, j; int i, j;
int ifflags, isup; int ifflags=0, isup=0;
time_t t; time_t t;
static struct { static struct {
time_t timestamp; time_t timestamp;
@ -414,6 +416,14 @@ int get_ip_by_ifname(char *ifname, struct in_addr *retaddr) {
char ifname[IFNAME_SIZE+1]; char ifname[IFNAME_SIZE+1];
} ifaddr_cache[IFADR_CACHE_SIZE]; } ifaddr_cache[IFADR_CACHE_SIZE];
static int cache_initialized=0; static int cache_initialized=0;
#ifdef HAVE_GETIFADDRS
struct ifaddrs *ifa;
struct ifaddrs *ifa_list;
#else
struct ifreq ifr;
struct sockaddr_in *sin = (struct sockaddr_in *)&ifr.ifr_addr;
int sockfd;
#endif
if (ifname == NULL) { if (ifname == NULL) {
WARN("get_ip_by_ifname: got NULL ifname passed - please check config" WARN("get_ip_by_ifname: got NULL ifname passed - please check config"
@ -457,38 +467,83 @@ int get_ip_by_ifname(char *ifname, struct in_addr *retaddr) {
} /* for i */ } /* for i */
/* not found in cache, go and get it */ /* not found in cache, go and get it */
memset(&ifr, 0, sizeof(ifr));
if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { #ifdef HAVE_GETIFADDRS
ERROR("Error in socket: %s\n",strerror(errno)); if (getifaddrs(&ifa_list)) {
ERROR("Error in getifaddrs: %s",strerror(errno));
return STS_FAILURE; return STS_FAILURE;
} }
i=0; /* use "found" marker */
for (ifa = ifa_list; ifa->ifa_next; ifa = ifa->ifa_next) {
DEBUGC(DBCLASS_BABBLE,"getifaddrs - %s / %s, ifa_addr=%p, addrfamily=%i",
ifname, ifa->ifa_name,ifa->ifa_addr,
(ifa->ifa_addr)?ifa->ifa_addr->sa_family:-1);
if (ifa && ifa->ifa_name && ifa->ifa_addr &&
ifa->ifa_addr->sa_family == AF_INET &&
strcmp(ifa->ifa_name, ifname) == 0) {
/* found the entry */
i=1;
/*&&&*/DEBUGC(DBCLASS_BABBLE,"&&&1 ifname=0x%p",ifname);
memcpy(&ifaddr, &((struct sockaddr_in*)ifa->ifa_addr)->sin_addr, sizeof(struct in_addr));
/*&&&*/DEBUGC(DBCLASS_BABBLE,"&&&2 ifname=0x%p",ifname);
ifflags=ifa->ifa_flags;
DEBUGC(DBCLASS_BABBLE,"getifaddrs - MATCH, sin_addr=%s",
utils_inet_ntoa(ifaddr));
break;
}
}
/*&&&*/DEBUGC(DBCLASS_BABBLE,"&&&4 ifname=0x%p",ifname);
freeifaddrs(ifa_list);
/*&&&*/DEBUGC(DBCLASS_BABBLE,"&&&5 ifname=0x%p",ifname);
if (i==0) {
DEBUGC(DBCLASS_DNS,"Interface %s not found.", ifname);
return STS_FAILURE;
}
#else
memset(&ifr, 0, sizeof(ifr));
if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
ERROR("Error in socket: %s",strerror(errno));
return STS_FAILURE;
}
/*&&&*/DEBUGC(DBCLASS_BABBLE,"&&&6 ifname=0x%p",ifname);
strcpy(ifr.ifr_name, ifname); strcpy(ifr.ifr_name, ifname);
sin->sin_family = AF_INET; sin->sin_family = AF_INET;
/* get interface flags */ /* get interface flags */
if(ioctl(sockfd, SIOCGIFFLAGS, &ifr) != 0) { if(ioctl(sockfd, SIOCGIFFLAGS, &ifr) != 0) {
ERROR("Error in ioctl SIOCGIFFLAGS: %s [%s]\n", ERROR("Error in ioctl SIOCGIFFLAGS: %s [%s]",
strerror(errno), ifname); strerror(errno), ifname);
close(sockfd); close(sockfd);
return STS_FAILURE; return STS_FAILURE;
} }
ifflags=ifr.ifr_flags; ifflags=ifr.ifr_flags;
/*&&&*/DEBUGC(DBCLASS_BABBLE,"&&&7 ifname=0x%p",ifname);
/* get address */ /* get address */
if(ioctl(sockfd, SIOCGIFADDR, &ifr) != 0) { if(ioctl(sockfd, SIOCGIFADDR, &ifr) != 0) {
ERROR("Error in ioctl SIOCGIFADDR: %s (interface %s)\n", ERROR("Error in ioctl SIOCGIFADDR: %s (interface %s)",
strerror(errno), ifname); strerror(errno), ifname);
close(sockfd); close(sockfd);
return STS_FAILURE; return STS_FAILURE;
} }
/*&&&*/DEBUGC(DBCLASS_BABBLE,"&&&8 ifname=0x%p",ifname);
memcpy(&ifaddr, &sin->sin_addr, sizeof(struct in_addr));
/*&&&*/DEBUGC(DBCLASS_BABBLE,"&&&9 ifname=0x%p",ifname);
close(sockfd);
#endif
if (ifflags & IFF_UP) isup=1; if (ifflags & IFF_UP) isup=1;
else isup=0; else isup=0;
DEBUGC(DBCLASS_DNS, "get_ip_by_ifname: if %s has IP:%s (flags=%x) %s", DEBUGC(DBCLASS_DNS, "get_ip_by_ifname: if %s has IP:%s (flags=%x) %s",
ifname, utils_inet_ntoa(sin->sin_addr), ifflags, ifname, utils_inet_ntoa(ifaddr), ifflags,
(isup)? "UP":"DOWN"); (isup)? "UP":"DOWN");
/* /*
@ -513,12 +568,11 @@ int get_ip_by_ifname(char *ifname, struct in_addr *retaddr) {
memset(&ifaddr_cache[i], 0, sizeof(ifaddr_cache[0])); memset(&ifaddr_cache[i], 0, sizeof(ifaddr_cache[0]));
strncpy(ifaddr_cache[i].ifname, ifname, IFNAME_SIZE); strncpy(ifaddr_cache[i].ifname, ifname, IFNAME_SIZE);
ifaddr_cache[i].timestamp=t; ifaddr_cache[i].timestamp=t;
memcpy(&ifaddr_cache[i].ifaddr, &sin->sin_addr, sizeof(sin->sin_addr)); memcpy(&ifaddr_cache[i].ifaddr, &ifaddr, sizeof(struct in_addr));
ifaddr_cache[i].isup=isup; ifaddr_cache[i].isup=isup;
if (retaddr) memcpy(retaddr, &sin->sin_addr, sizeof(sin->sin_addr)); if (retaddr) memcpy(retaddr, &ifaddr, sizeof(struct in_addr));
close(sockfd);
return (isup)? STS_SUCCESS : STS_FAILURE; return (isup)? STS_SUCCESS : STS_FAILURE;
} }
@ -540,7 +594,7 @@ char *utils_inet_ntoa(struct in_addr in) {
#if defined(HAVE_INET_NTOP) #if defined(HAVE_INET_NTOP)
static char string[INET_ADDRSTRLEN]; static char string[INET_ADDRSTRLEN];
if ((inet_ntop(AF_INET, &in, string, INET_ADDRSTRLEN)) == NULL) { if ((inet_ntop(AF_INET, &in, string, INET_ADDRSTRLEN)) == NULL) {
ERROR("inet_ntop() failed: %s\n",strerror(errno)); ERROR("inet_ntop() failed: %s",strerror(errno));
string[0]='\0'; string[0]='\0';
} }
return string; return string;