From c46162bb4ce79beca38b36c48f25aa81b0735808 Mon Sep 17 00:00:00 2001 From: twilson Date: Thu, 10 Jan 2008 00:22:50 +0000 Subject: Attempt at making lookup_iface work under FreeBSD. Not yet tested, but it compiles under OS X. And still works under linux. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@97653 f38db490-d61c-443f-a65b-d21fe96a405b --- res/res_phoneprov.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/res/res_phoneprov.c b/res/res_phoneprov.c index f03c4919c..a8a8ec53c 100644 --- a/res/res_phoneprov.c +++ b/res/res_phoneprov.c @@ -29,6 +29,8 @@ #include "asterisk.h" #include +#include +#include ASTERISK_FILE_VERSION(__FILE__, "$Revision: 96773 $") @@ -58,12 +60,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision: 96773 $") #define VAR_BUF_SIZE 4096 -/*! \brief for use in lookup_iface */ -struct my_ifreq { - char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "eth0", "ppp0", etc. */ - struct sockaddr_in ifru_addr; -}; - /*! \brief for use in lookup_iface */ static struct in_addr __ourip = { .s_addr = 0x00000000, }; @@ -183,10 +179,11 @@ static char *ftype2mtype(const char *ftype) static int lookup_iface(const char *iface, struct in_addr *address) { int mysock, res = 0; - struct my_ifreq ifreq; + struct ifreq ifr; + struct sockaddr_in *sin; - memset(&ifreq, 0, sizeof(ifreq)); - ast_copy_string(ifreq.ifrn_name, iface, sizeof(ifreq.ifrn_name)); + memset(&ifr, 0, sizeof(ifr)); + ast_copy_string(ifr.ifr_name, iface, sizeof(ifr.ifr_name)); mysock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); if (mysock < 0) { @@ -194,7 +191,7 @@ static int lookup_iface(const char *iface, struct in_addr *address) return -1; } - res = ioctl(mysock, SIOCGIFADDR, &ifreq); + res = ioctl(mysock, SIOCGIFADDR, &ifr); close(mysock); @@ -203,7 +200,8 @@ static int lookup_iface(const char *iface, struct in_addr *address) memcpy(address, &__ourip, sizeof(__ourip)); return -1; } else { - memcpy(address, &ifreq.ifru_addr.sin_addr, sizeof(ifreq.ifru_addr.sin_addr)); + sin = (struct sockaddr_in *)&ifr.ifr_addr; + memcpy(address, &sin->sin_addr, sizeof(*address)); return 0; } } -- cgit v1.2.3