[asterisk-commits] mmichelson: branch mmichelson/udptl-v6 r278019 - in /team/mmichelson/udptl-v6...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 19 17:32:14 CDT 2010


Author: mmichelson
Date: Mon Jul 19 17:32:10 2010
New Revision: 278019

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=278019
Log:
Stuff compiles now.

Next up, I'll need to write a test for this to be sure
stuff still works. But that'll have to wait until tomorrow.


Modified:
    team/mmichelson/udptl-v6/channels/chan_sip.c
    team/mmichelson/udptl-v6/include/asterisk/udptl.h
    team/mmichelson/udptl-v6/main/udptl.c

Modified: team/mmichelson/udptl-v6/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/udptl-v6/channels/chan_sip.c?view=diff&rev=278019&r1=278018&r2=278019
==============================================================================
--- team/mmichelson/udptl-v6/channels/chan_sip.c (original)
+++ team/mmichelson/udptl-v6/channels/chan_sip.c Mon Jul 19 17:32:10 2010
@@ -7792,7 +7792,6 @@
  	int vportno = -1;		/*!< RTP Video port number */
 	int tportno = -1;		/*!< RTP Text port number */
 	int udptlportno = -1;		/*!< UDPTL Image port number */
-	struct sockaddr_in isin;	/*!< image socket address */
 
 	/* Peer capability is the capability in the SDP, non codec is RFC2833 DTMF (101) */	
 	format_t peercapability = 0, vpeercapability = 0, tpeercapability = 0;
@@ -8265,13 +8264,13 @@
 								    isa);
 				if (!ast_sockaddr_isnull(isa)) {
 					if (debug) {
-						ast_log(LOG_DEBUG, "Peer T.38 UDPTL is set behind NAT and with destination, destination address now %s\n", ast_inet_ntoa(isin.sin_addr));
+						ast_log(LOG_DEBUG, "Peer T.38 UDPTL is set behind NAT and with destination, destination address now %s\n", ast_sockaddr_stringify(isa));
 					}
 				}
 			}
 			ast_udptl_set_peer(p->udptl, isa);
 			if (debug)
-				ast_debug(1,"Peer T.38 UDPTL is at port %s:%d\n", ast_inet_ntoa(isin.sin_addr), ntohs(isin.sin_port));
+				ast_debug(1,"Peer T.38 UDPTL is at port %s\n", ast_sockaddr_stringify(isa));
 
 			/* verify the far max ifp can be calculated. this requires far max datagram to be set. */
 			if (!ast_udptl_get_far_max_datagram(p->udptl)) {

Modified: team/mmichelson/udptl-v6/include/asterisk/udptl.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/udptl-v6/include/asterisk/udptl.h?view=diff&rev=278019&r1=278018&r2=278019
==============================================================================
--- team/mmichelson/udptl-v6/include/asterisk/udptl.h (original)
+++ team/mmichelson/udptl-v6/include/asterisk/udptl.h Mon Jul 19 17:32:10 2010
@@ -31,6 +31,7 @@
 #include "asterisk/io.h"
 #include "asterisk/sched.h"
 #include "asterisk/channel.h"
+#include "asterisk/netsock2.h"
 
 
 enum ast_t38_ec_modes {

Modified: team/mmichelson/udptl-v6/main/udptl.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/udptl-v6/main/udptl.c?view=diff&rev=278019&r1=278018&r2=278019
==============================================================================
--- team/mmichelson/udptl-v6/main/udptl.c (original)
+++ team/mmichelson/udptl-v6/main/udptl.c Mon Jul 19 17:32:10 2010
@@ -82,7 +82,7 @@
 static int udptlstart = 4500;
 static int udptlend = 4599;
 static int udptldebug;	                    /*!< Are we debugging? */
-static struct sockaddr_in udptldebugaddr;   /*!< Debug packets to/from this host */
+static struct ast_sockaddr udptldebugaddr;   /*!< Debug packets to/from this host */
 #ifdef SO_NO_CHECK
 static int nochecksums;
 #endif
@@ -184,17 +184,20 @@
 
 static AST_RWLIST_HEAD_STATIC(protos, ast_udptl_protocol);
 
-static inline int udptl_debug_test_addr(const struct sockaddr_in *addr)
+static inline int udptl_debug_test_addr(const struct ast_sockaddr *addr)
 {
 	if (udptldebug == 0)
 		return 0;
-	if (udptldebugaddr.sin_addr.s_addr) {
-		if (((ntohs(udptldebugaddr.sin_port) != 0) &&
-		     (udptldebugaddr.sin_port != addr->sin_port)) ||
-		    (udptldebugaddr.sin_addr.s_addr != addr->sin_addr.s_addr))
-			return 0;
-	}
-	return 1;
+
+	if (ast_sockaddr_isnull(&udptldebugaddr)) {
+		return 1;
+	}
+
+	if (ast_sockaddr_port(&udptldebugaddr)) {
+		return !ast_sockaddr_cmp(&udptldebugaddr, addr);
+	} else {
+		return !ast_sockaddr_cmp_addr(&udptldebugaddr, addr);
+	}
 }
 
 static int decode_length(uint8_t *buf, unsigned int limit, unsigned int *len, unsigned int *pvalue)
@@ -692,7 +695,7 @@
 	}
 
 	/* Ignore if the other side hasn't been given an address yet. */
-	if (ast_sockaddr_is_null(&udptl->them)) {
+	if (ast_sockaddr_isnull(&udptl->them)) {
 		return &ast_null_frame;
 	}
 
@@ -700,8 +703,8 @@
 		/* Send to whoever sent to us */
 		if (ast_sockaddr_cmp(&udptl->them, &addr)) {
 			ast_sockaddr_copy(&udptl->them, &addr);
-			ast_debug(1, "UDPTL NAT (%s): Using address %s:%d\n",
-				  LOG_TAG(udptl), ast_inet_ntoa(udptl->them.sin_addr), ntohs(udptl->them.sin_port));
+			ast_debug(1, "UDPTL NAT (%s): Using address %s\n",
+				  LOG_TAG(udptl), ast_sockaddr_stringify(&udptl->them));
 		}
 	}
 
@@ -956,7 +959,7 @@
 	startplace = x;
 	for (;;) {
 		ast_sockaddr_copy(&udptl->us, addr);
-		ast_sockaddr_set_port(&udptl, x);
+		ast_sockaddr_set_port(&udptl->us, x);
 		if (ast_bind(udptl->fd, &udptl->us)) {
 			break;
 		}
@@ -991,9 +994,8 @@
 
 struct ast_udptl *ast_udptl_new(struct sched_context *sched, struct io_context *io, int callbackmode)
 {
-	struct in_addr ia;
-	memset(&ia, 0, sizeof(ia));
-	return ast_udptl_new_with_bindaddr(sched, io, callbackmode, ia);
+	struct ast_sockaddr ia = { { 0,}, };
+	return ast_udptl_new_with_bindaddr(sched, io, callbackmode, &ia);
 }
 
 void ast_udptl_set_tag(struct ast_udptl *udptl, const char *format, ...)
@@ -1148,10 +1150,10 @@
 	struct ast_udptl *p1;
 	struct ast_udptl_protocol *pr0;
 	struct ast_udptl_protocol *pr1;
-	struct sockaddr_in ac0;
-	struct sockaddr_in ac1;
-	struct sockaddr_in t0;
-	struct sockaddr_in t1;
+	struct ast_sockaddr ac0;
+	struct ast_sockaddr ac1;
+	struct ast_sockaddr t0;
+	struct ast_sockaddr t1;
 	void *pvt0;
 	void *pvt1;
 	int to;
@@ -1216,19 +1218,19 @@
 		to = -1;
 		ast_udptl_get_peer(p1, &t1);
 		ast_udptl_get_peer(p0, &t0);
-		if (inaddrcmp(&t1, &ac1)) {
-			ast_debug(1, "Oooh, '%s' changed end address to %s:%d\n", 
-				c1->name, ast_inet_ntoa(t1.sin_addr), ntohs(t1.sin_port));
-			ast_debug(1, "Oooh, '%s' was %s:%d\n", 
-				c1->name, ast_inet_ntoa(ac1.sin_addr), ntohs(ac1.sin_port));
-			memcpy(&ac1, &t1, sizeof(ac1));
-		}
-		if (inaddrcmp(&t0, &ac0)) {
-			ast_debug(1, "Oooh, '%s' changed end address to %s:%d\n", 
-				c0->name, ast_inet_ntoa(t0.sin_addr), ntohs(t0.sin_port));
-			ast_debug(1, "Oooh, '%s' was %s:%d\n", 
-				c0->name, ast_inet_ntoa(ac0.sin_addr), ntohs(ac0.sin_port));
-			memcpy(&ac0, &t0, sizeof(ac0));
+		if (ast_sockaddr_cmp(&t1, &ac1)) {
+			ast_debug(1, "Oooh, '%s' changed end address to %s\n", 
+				c1->name, ast_sockaddr_stringify(&t1));
+			ast_debug(1, "Oooh, '%s' was %s\n", 
+				c1->name, ast_sockaddr_stringify(&ac1));
+			ast_sockaddr_copy(&ac1, &t1);
+		}
+		if (ast_sockaddr_cmp(&t0, &ac0)) {
+			ast_debug(1, "Oooh, '%s' changed end address to %s\n", 
+				c0->name, ast_sockaddr_stringify(&t0));
+			ast_debug(1, "Oooh, '%s' was %s\n", 
+				c0->name, ast_sockaddr_stringify(&ac0));
+			ast_sockaddr_copy(&ac0, &t0);
 		}
 		who = ast_waitfor_n(cs, 2, &to);
 		if (!who) {
@@ -1266,12 +1268,6 @@
 
 static char *handle_cli_udptl_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-	struct hostent *hp;
-	struct ast_hostent ahp;
-	int port;
-	char *p;
-	char *arg;
-
 	switch (cmd) {
 	case CLI_INIT:
 		e->command = "udptl set debug {on|off|ip}";
@@ -1300,27 +1296,16 @@
 			return CLI_SHOWUSAGE;
 		}
 	} else {
+		struct ast_sockaddr *addrs;
 		if (strncasecmp(a->argv[3], "ip", 2))
 			return CLI_SHOWUSAGE;
-		port = 0;
-		arg = ast_strdupa(a->argv[4]);
-		p = strstr(arg, ":");
-		if (p) {
-			*p = '\0';
-			p++;
-			port = atoi(p);
-		}
-		hp = ast_gethostbyname(arg, &ahp);
-		if (hp == NULL)
+		if (!ast_sockaddr_resolve(&addrs, a->argv[4], 0, 0)) {
 			return CLI_SHOWUSAGE;
-		udptldebugaddr.sin_family = AF_INET;
-		memcpy(&udptldebugaddr.sin_addr, hp->h_addr, sizeof(udptldebugaddr.sin_addr));
-		udptldebugaddr.sin_port = htons(port);
-		if (port == 0)
-			ast_cli(a->fd, "UDPTL Debugging Enabled for IP: %s\n", ast_inet_ntoa(udptldebugaddr.sin_addr));
-		else
-			ast_cli(a->fd, "UDPTL Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(udptldebugaddr.sin_addr), port);
+		}
+		ast_sockaddr_copy(&udptldebugaddr, &addrs[0]);
+			ast_cli(a->fd, "UDPTL Debugging Enabled for IP: %s\n", ast_sockaddr_stringify(&udptldebugaddr));
 		udptldebug = 1;
+		ast_free(addrs);
 	}
 
 	return CLI_SUCCESS;




More information about the asterisk-commits mailing list