[asterisk-commits] twilson: trunk r97653 - /trunk/res/res_phoneprov.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 9 18:22:51 CST 2008


Author: twilson
Date: Wed Jan  9 18:22:50 2008
New Revision: 97653

URL: http://svn.digium.com/view/asterisk?view=rev&rev=97653
Log:
Attempt at making lookup_iface work under FreeBSD.  Not yet tested, but it compiles under OS X.  And still works under linux.

Modified:
    trunk/res/res_phoneprov.c

Modified: trunk/res/res_phoneprov.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_phoneprov.c?view=diff&rev=97653&r1=97652&r2=97653
==============================================================================
--- trunk/res/res_phoneprov.c (original)
+++ trunk/res/res_phoneprov.c Wed Jan  9 18:22:50 2008
@@ -29,6 +29,8 @@
 #include "asterisk.h"
 
 #include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <net/if.h>
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 96773 $")
 
@@ -59,12 +61,6 @@
 #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, };
 
 /* \note This enum and the pp_variable_list must be in the same order or
@@ -183,10 +179,11 @@
 static int lookup_iface(const char *iface, struct in_addr *address)
 {
 	int mysock, res = 0;
-	struct my_ifreq ifreq;
-
-	memset(&ifreq, 0, sizeof(ifreq));
-	ast_copy_string(ifreq.ifrn_name, iface, sizeof(ifreq.ifrn_name));
+	struct ifreq ifr;
+	struct sockaddr_in *sin;
+
+	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 @@
 		return -1;
 	}
 
-	res = ioctl(mysock, SIOCGIFADDR, &ifreq);
+	res = ioctl(mysock, SIOCGIFADDR, &ifr);
 
 	close(mysock);
 
@@ -203,7 +200,8 @@
 		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;
 	}
 }




More information about the asterisk-commits mailing list