[asterisk-commits] coreyfarrell: trunk r417167 - in /trunk: include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 23 21:50:23 CDT 2014


Author: coreyfarrell
Date: Mon Jun 23 21:50:15 2014
New Revision: 417167

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=417167
Log:
Move eid functions to utils.c, mark netsock.h deprecated

Move eid functions from netsock.c to utils.c.  These functions were
already published by utils.h.  Flag netsock.h as deprecated and switch
res_pjsip_session.h to use netsock2.h.  The only code that still uses
netsock.h is chan_iax2.

ASTERISK-23920 #close
Reported by: Corey Farrell
Review: https://reviewboard.asterisk.org/r/3661/

Modified:
    trunk/include/asterisk/netsock.h
    trunk/include/asterisk/res_pjsip_session.h
    trunk/main/netsock.c
    trunk/main/utils.c

Modified: trunk/include/asterisk/netsock.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/netsock.h?view=diff&rev=417167&r1=417166&r2=417167
==============================================================================
--- trunk/include/asterisk/netsock.h (original)
+++ trunk/include/asterisk/netsock.h Mon Jun 23 21:50:15 2014
@@ -19,6 +19,8 @@
 
 /*! \file
  * \brief Network socket handling
+ *
+ * \deprecated Use netsock2.h instead
  */
 
 #ifndef _ASTERISK_NETSOCK_H

Modified: trunk/include/asterisk/res_pjsip_session.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/res_pjsip_session.h?view=diff&rev=417167&r1=417166&r2=417167
==============================================================================
--- trunk/include/asterisk/res_pjsip_session.h (original)
+++ trunk/include/asterisk/res_pjsip_session.h Mon Jun 23 21:50:15 2014
@@ -25,7 +25,7 @@
 /* Needed for AST_MAX_EXTENSION constant */
 #include "asterisk/channel.h"
 /* Needed for ast_sockaddr struct */
-#include "asterisk/netsock.h"
+#include "asterisk/netsock2.h"
 /* Needed for ast_sdp_srtp struct */
 #include "asterisk/sdp_srtp.h"
 

Modified: trunk/main/netsock.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/netsock.c?view=diff&rev=417167&r1=417166&r2=417167
==============================================================================
--- trunk/main/netsock.c (original)
+++ trunk/main/netsock.c Mon Jun 23 21:50:15 2014
@@ -201,106 +201,3 @@
 {
 	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:", (unsigned)eid->eid[x]);
-			s += 3;
-		}
-		sprintf(s, "%02x", (unsigned)eid->eid[5]);
-	}
-	return os;
-}
-
-void ast_set_default_eid(struct ast_eid *eid)
-{
-#if defined(SIOCGIFHWADDR) && defined(HAVE_STRUCT_IFREQ_IFR_IFRU_IFRU_HWADDR)
-	int s, x = 0;
-	char eid_str[20];
-	struct ifreq ifr;
-	static const unsigned int MAXIF = 10;
-
-	s = socket(AF_INET, SOCK_STREAM, 0);
-	if (s < 0)
-		return;
-	for (x = 0; x < MAXIF; x++) {
-		static const char *prefixes[] = { "eth", "em" };
-		unsigned int i;
-
-		for (i = 0; i < ARRAY_LEN(prefixes); i++) {
-			memset(&ifr, 0, sizeof(ifr));
-			snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s%d", prefixes[i], x);
-			if (!ioctl(s, SIOCGIFHWADDR, &ifr)) {
-				break;
-			}
-		}
-
-		if (i == ARRAY_LEN(prefixes)) {
-			/* Try pciX#[1..N] */
-			for (i = 0; i < MAXIF; i++) {
-				memset(&ifr, 0, sizeof(ifr));
-				snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "pci%d#%u", x, i);
-				if (!ioctl(s, SIOCGIFHWADDR, &ifr)) {
-					break;
-				}
-			}
-			if (i == MAXIF) {
-				continue;
-			}
-		}
-
-		memcpy(eid, ((unsigned char *)&ifr.ifr_hwaddr) + 2, sizeof(*eid));
-		ast_debug(1, "Seeding global EID '%s' from '%s' using 'siocgifhwaddr'\n", ast_eid_to_str(eid_str, sizeof(eid_str), eid), ifr.ifr_name);
-		close(s);
-		return;
-	}
-	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) && !(p->ifa_flags & IFF_LOOPBACK) && (p->ifa_flags & IFF_RUNNING)) {
-				struct sockaddr_dl* sdp = (struct sockaddr_dl*) p->ifa_addr;
-				memcpy(&(eid->eid), sdp->sdl_data + sdp->sdl_nlen, 6);
-				ast_debug(1, "Seeding global EID '%s' from '%s' using 'getifaddrs'\n", ast_eid_to_str(eid_str, sizeof(eid_str), eid), p->ifa_name);
-				freeifaddrs(ifap);
-				return;
-			}
-		}
-		freeifaddrs(ifap);
-	}
-#endif
-#endif
-	ast_debug(1, "No ethernet interface found for seeding global EID. You will have to set it manually.\n");
-}
-
-int ast_str_to_eid(struct ast_eid *eid, const char *s)
-{
-	unsigned int eid_int[6];
-	int x;
-
-	if (sscanf(s, "%2x:%2x:%2x:%2x:%2x:%2x", &eid_int[0], &eid_int[1], &eid_int[2],
-		 &eid_int[3], &eid_int[4], &eid_int[5]) != 6)
-			return -1;
-
-	for (x = 0; x < 6; x++)
-		eid->eid[x] = eid_int[x];
-
-	return 0;
-}
-
-int ast_eid_cmp(const struct ast_eid *eid1, const struct ast_eid *eid2)
-{
-	return memcmp(eid1, eid2, sizeof(*eid1));
-}

Modified: trunk/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/utils.c?view=diff&rev=417167&r1=417166&r2=417167
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Mon Jun 23 21:50:15 2014
@@ -2548,3 +2548,110 @@
 	ast_do_crash();
 }
 #endif	/* defined(AST_DEVMODE) */
+
+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:", (unsigned)eid->eid[x]);
+			s += 3;
+		}
+		sprintf(s, "%02x", (unsigned)eid->eid[5]);
+	}
+	return os;
+}
+
+void ast_set_default_eid(struct ast_eid *eid)
+{
+#if defined(SIOCGIFHWADDR) && defined(HAVE_STRUCT_IFREQ_IFR_IFRU_IFRU_HWADDR)
+	int s, x = 0;
+	char eid_str[20];
+	struct ifreq ifr;
+	static const unsigned int MAXIF = 10;
+
+	s = socket(AF_INET, SOCK_STREAM, 0);
+	if (s < 0) {
+		return;
+	}
+	for (x = 0; x < MAXIF; x++) {
+		static const char *prefixes[] = { "eth", "em" };
+		unsigned int i;
+
+		for (i = 0; i < ARRAY_LEN(prefixes); i++) {
+			memset(&ifr, 0, sizeof(ifr));
+			snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s%d", prefixes[i], x);
+			if (!ioctl(s, SIOCGIFHWADDR, &ifr)) {
+				break;
+			}
+		}
+
+		if (i == ARRAY_LEN(prefixes)) {
+			/* Try pciX#[1..N] */
+			for (i = 0; i < MAXIF; i++) {
+				memset(&ifr, 0, sizeof(ifr));
+				snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "pci%d#%u", x, i);
+				if (!ioctl(s, SIOCGIFHWADDR, &ifr)) {
+					break;
+				}
+			}
+			if (i == MAXIF) {
+				continue;
+			}
+		}
+
+		memcpy(eid, ((unsigned char *)&ifr.ifr_hwaddr) + 2, sizeof(*eid));
+		ast_debug(1, "Seeding global EID '%s' from '%s' using 'siocgifhwaddr'\n", ast_eid_to_str(eid_str, sizeof(eid_str), eid), ifr.ifr_name);
+		close(s);
+		return;
+	}
+	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) && !(p->ifa_flags & IFF_LOOPBACK) && (p->ifa_flags & IFF_RUNNING)) {
+				struct sockaddr_dl* sdp = (struct sockaddr_dl*) p->ifa_addr;
+				memcpy(&(eid->eid), sdp->sdl_data + sdp->sdl_nlen, 6);
+				ast_debug(1, "Seeding global EID '%s' from '%s' using 'getifaddrs'\n", ast_eid_to_str(eid_str, sizeof(eid_str), eid), p->ifa_name);
+				freeifaddrs(ifap);
+				return;
+			}
+		}
+		freeifaddrs(ifap);
+	}
+#endif
+#endif
+	ast_debug(1, "No ethernet interface found for seeding global EID. You will have to set it manually.\n");
+}
+
+int ast_str_to_eid(struct ast_eid *eid, const char *s)
+{
+	unsigned int eid_int[6];
+	int x;
+
+	if (sscanf(s, "%2x:%2x:%2x:%2x:%2x:%2x", &eid_int[0], &eid_int[1], &eid_int[2],
+		 &eid_int[3], &eid_int[4], &eid_int[5]) != 6) {
+			return -1;
+	}
+
+	for (x = 0; x < 6; x++) {
+		eid->eid[x] = eid_int[x];
+	}
+
+	return 0;
+}
+
+int ast_eid_cmp(const struct ast_eid *eid1, const struct ast_eid *eid2)
+{
+	return memcmp(eid1, eid2, sizeof(*eid1));
+}




More information about the asterisk-commits mailing list