Merge pull request #599 from jow-/master
Expose `USE_GETIFADDRS` and tweak `getifaddr()` behaviour
This commit is contained in:
commit
9e042264fa
|
@ -47,6 +47,7 @@ case "$argv" in
|
|||
FW=$(echo $argv | cut -d= -f2) ;;
|
||||
--iptablespath=*)
|
||||
IPTABLESPATH=$(echo $argv | cut -d= -f2) ;;
|
||||
--getifaddrs) GETIFADDRS=1 ;;
|
||||
--help|-h)
|
||||
echo "Usage : $0 [options]"
|
||||
echo " --ipv6 enable IPv6"
|
||||
|
@ -62,6 +63,7 @@ case "$argv" in
|
|||
echo " --firewall=<name> force the firewall type (nftables, iptables, pf, ipf, ipfw)"
|
||||
echo " --iptablespath=/path/to/iptables use a specific version of iptables"
|
||||
echo " --disable-fork Do not go to background and do not write pid file"
|
||||
echo " --getifaddrs Force use getifaddrs() to obtain interface addresses"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
|
@ -387,6 +389,7 @@ case $OS_NAME in
|
|||
OpenWrt)
|
||||
OS_URL=http://www.openwrt.org/
|
||||
echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
|
||||
GETIFADDRS=1
|
||||
;;
|
||||
OpenEmbedded)
|
||||
OS_URL=http://www.openembedded.org/
|
||||
|
@ -850,6 +853,13 @@ else
|
|||
echo "/*#define NO_BACKGROUND_NO_PIDFILE*/" >> ${CONFIGFILE}
|
||||
fi
|
||||
|
||||
echo "/* Whether to use getifaddrs() to determine interface addresses */" >> ${CONFIGFILE}
|
||||
if [ -n "$GETIFADDRS" ] && [ $GETIFADDRS -eq 1 ] ; then
|
||||
echo "#define USE_GETIFADDRS" >> ${CONFIGFILE}
|
||||
else
|
||||
echo "/*#define USE_GETIFADDRS*/" >> ${CONFIGFILE}
|
||||
fi
|
||||
|
||||
echo "#endif /* ${CONFIGMACRO} */" >> ${CONFIGFILE}
|
||||
|
||||
${MV} ${CONFIGFILE} ${CONFIGFILE_FINAL}
|
||||
|
|
|
@ -101,6 +101,7 @@ getifaddr(const char * ifname, char * buf, int len,
|
|||
/* Works for all address families (both ip v4 and ip v6) */
|
||||
struct ifaddrs * ifap;
|
||||
struct ifaddrs * ife;
|
||||
struct ifaddrs * candidate = NULL;
|
||||
|
||||
if(!ifname || ifname[0]=='\0')
|
||||
return -1;
|
||||
|
@ -119,14 +120,10 @@ getifaddr(const char * ifname, char * buf, int len,
|
|||
switch(ife->ifa_addr->sa_family)
|
||||
{
|
||||
case AF_INET:
|
||||
if(buf)
|
||||
{
|
||||
inet_ntop(ife->ifa_addr->sa_family,
|
||||
&((struct sockaddr_in *)ife->ifa_addr)->sin_addr,
|
||||
buf, len);
|
||||
}
|
||||
if(addr) *addr = ((struct sockaddr_in *)ife->ifa_addr)->sin_addr;
|
||||
if(mask) *mask = ((struct sockaddr_in *)ife->ifa_netmask)->sin_addr;
|
||||
if(!candidate ||
|
||||
(addr_is_reserved(&((struct sockaddr_in *)candidate->ifa_addr)->sin_addr) &&
|
||||
!addr_is_reserved(&((struct sockaddr_in *)ife->ifa_addr)->sin_addr)))
|
||||
candidate = ife;
|
||||
break;
|
||||
/*
|
||||
case AF_INET6:
|
||||
|
@ -136,6 +133,17 @@ getifaddr(const char * ifname, char * buf, int len,
|
|||
*/
|
||||
}
|
||||
}
|
||||
if(candidate)
|
||||
{
|
||||
if(buf)
|
||||
{
|
||||
inet_ntop(candidate->ifa_addr->sa_family,
|
||||
&((struct sockaddr_in *)candidate->ifa_addr)->sin_addr,
|
||||
buf, len);
|
||||
}
|
||||
if(addr) *addr = ((struct sockaddr_in *)candidate->ifa_addr)->sin_addr;
|
||||
if(mask) *mask = ((struct sockaddr_in *)candidate->ifa_netmask)->sin_addr;
|
||||
}
|
||||
freeifaddrs(ifap);
|
||||
#endif
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue