[svn-commits] russell: branch russell/ais r78348 - /team/russell/ais/main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Aug 7 11:17:44 CDT 2007


Author: russell
Date: Tue Aug  7 11:17:43 2007
New Revision: 78348

URL: http://svn.digium.com/view/asterisk?view=rev&rev=78348
Log:
Make ast_set_eid() actually work and don't erroneously print the error message when it really did work

Modified:
    team/russell/ais/main/netsock.c
    team/russell/ais/main/utils.c

Modified: team/russell/ais/main/netsock.c
URL: http://svn.digium.com/view/asterisk/team/russell/ais/main/netsock.c?view=diff&rev=78348&r1=78347&r2=78348
==============================================================================
--- team/russell/ais/main/netsock.c (original)
+++ team/russell/ais/main/netsock.c Tue Aug  7 11:17:43 2007
@@ -45,6 +45,15 @@
 #include <netinet/ip.h>
 #include <sys/ioctl.h>
 
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(SOLARIS) || defined(__Darwin__)
+#include <sys/types.h>
+#endif
+
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__Darwin__)
+#include <net/if_dl.h>
+#include <ifaddrs.h>
+#endif
+
 #if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
 #include <fcntl.h>
 #include <net/route.h>
@@ -236,3 +245,74 @@
 {
 	ASTOBJ_UNREF(ns, ast_netsock_destroy);
 }
+
+char *ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
+{
+	int x;
+	char *os = s;
+	if (maxlen < 18) {
+		if (s && (maxlen > 0))
+			*s = '\0';
+	} else {
+		for (x=0;x<5;x++) {
+			sprintf(s, "%02x:", eid->eid[x]);
+			s += 3;
+		}
+		sprintf(s, "%02x", eid->eid[5]);
+	}
+	return os;
+}
+
+void ast_set_eid(struct ast_eid *eid)
+{
+	int success = 0;
+#if defined(SIOCGIFHWADDR)
+	int s, x = 0;
+	char eid_str[20];
+	struct ifreq ifr;
+
+	s = socket(AF_INET, SOCK_STREAM, 0);
+	if (s < 0)
+		return;
+	for (x = 0; x < 10; x++) {
+		memset(&ifr, 0, sizeof(ifr));
+		snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "eth%d", x);
+		if (ioctl(s, SIOCGIFHWADDR, &ifr))
+			continue;
+		memcpy(eid, ((unsigned char *)&ifr.ifr_hwaddr) + 2, sizeof(*eid));
+		if (option_debug) {
+			ast_log(LOG_DEBUG, "Seeding global EID '%s' from '%s'\n", 
+				ast_eid_to_str(eid_str, sizeof(eid_str), eid), ifr.ifr_name);
+		}
+		success = 1;
+		break;
+	}
+	close(s);
+#else
+#if defined(ifa_broadaddr) && !defined(SOLARIS)
+	char eid_str[20];
+	struct ifaddrs *ifap;
+	
+	if (getifaddrs(&ifap) == 0) {
+		struct ifaddrs *p;
+		for (p = ifap; p; p = p->ifa_next) {
+			if (p->ifa_addr->sa_family == AF_LINK) {
+				struct sockaddr_dl* sdp = (struct sockaddr_dl*) p->ifa_addr;
+				memcpy(
+					&(eid->eid),
+					sdp->sdl_data + sdp->sdl_nlen, 6);
+				if (option_debug)
+					ast_log(LOG_DEBUG, "Seeding global EID '%s' from '%s'\n", ast_eid_to_str(eid_str, sizeof(eid_str), eid), ifap->ifa_name);
+				freeifaddrs(ifap);
+				return;
+			}
+		}
+		freeifaddrs(ifap);
+	}
+#endif
+#endif
+	if (!success)
+		ast_log(LOG_ERROR, "No ethernet interface found for seeding default EID.  You will have to set it manually.\n");
+}
+
+

Modified: team/russell/ais/main/utils.c
URL: http://svn.digium.com/view/asterisk/team/russell/ais/main/utils.c?view=diff&rev=78348&r1=78347&r2=78348
==============================================================================
--- team/russell/ais/main/utils.c (original)
+++ team/russell/ais/main/utils.c Tue Aug  7 11:17:43 2007
@@ -1377,72 +1377,6 @@
 	return 0;
 }
 
-char *ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
-{
-	int x;
-	char *os = s;
-	if (maxlen < 18) {
-		if (s && (maxlen > 0))
-			*s = '\0';
-	} else {
-		for (x=0;x<5;x++) {
-			sprintf(s, "%02x:", eid->eid[x]);
-			s += 3;
-		}
-		sprintf(s, "%02x", eid->eid[5]);
-	}
-	return os;
-}
-
-void ast_set_eid(struct ast_eid *eid)
-{
-#if defined(SIOCGIFHWADDR)
-	int s, x = 0;
-	char eid_str[20];
-	struct ifreq ifr;
-
-	s = socket(AF_INET, SOCK_STREAM, 0);
-	if (s < 0)
-		return;
-	for (x = 0; x < 10; x++) {
-		memset(&ifr, 0, sizeof(ifr));
-		snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "eth%d", x);
-		if (ioctl(s, SIOCGIFHWADDR, &ifr))
-			continue;
-		memcpy(&global_eid, ((unsigned char *)&ifr.ifr_hwaddr) + 2, sizeof(*eid));
-		if (option_debug) {
-			ast_log(LOG_DEBUG, "Seeding global EID '%s' from '%s'\n", 
-				ast_eid_to_str(eid_str, sizeof(eid_str), eid), ifr.ifr_name);
-		}
-		break;
-	}
-	close(s);
-#else
-#if defined(ifa_broadaddr) && !defined(SOLARIS)
-	char eid_str[20];
-	struct ifaddrs *ifap;
-	
-	if (getifaddrs(&ifap) == 0) {
-		struct ifaddrs *p;
-		for (p = ifap; p; p = p->ifa_next) {
-			if (p->ifa_addr->sa_family == AF_LINK) {
-				struct sockaddr_dl* sdp = (struct sockaddr_dl*) p->ifa_addr;
-				memcpy(
-					&(eid->eid),
-					sdp->sdl_data + sdp->sdl_nlen, 6);
-				if (option_debug)
-					ast_log(LOG_DEBUG, "Seeding global EID '%s' from '%s'\n", ast_eid_to_str(eid_str, sizeof(eid_str), eid), ifap->ifa_name);
-				freeifaddrs(ifap);
-				return;
-			}
-		}
-		freeifaddrs(ifap);
-	}
-#endif
-#endif
-	ast_log(LOG_ERROR, "No ethernet interface found for seeding default EID.  You will have to set it manually.\n");
-}
-
 int ast_utils_init(void)
 {
 #ifdef HAVE_DEV_URANDOM




More information about the svn-commits mailing list