[asterisk-commits] seanbright: branch seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_se...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 27 15:29:31 CST 2012


Author: seanbright
Date: Mon Feb 27 15:29:27 2012
New Revision: 357085

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=357085
Log:
Convert iax2_trunk_peer over to ast_sockaddr.

Modified:
    team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/channels/chan_iax2.c

Modified: team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/channels/chan_iax2.c?view=diff&rev=357085&r1=357084&r2=357085
==============================================================================
--- team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/channels/chan_iax2.c (original)
+++ team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/channels/chan_iax2.c Mon Feb 27 15:29:27 2012
@@ -548,7 +548,7 @@
 struct iax2_trunk_peer {
 	ast_mutex_t lock;
 	int sockfd;
-	struct sockaddr_in addr;
+	struct ast_sockaddr addr;
 	struct timeval txtrunktime;		/*!< Transmit trunktime */
 	struct timeval rxtrunktime;		/*!< Receive trunktime */
 	struct timeval lasttxtime;		/*!< Last transmitted trunktime */
@@ -3314,11 +3314,10 @@
 	return 0;
 }
 
-static int transmit_trunk(struct iax_frame *f, struct sockaddr_in *sin, int sockfd)
+static int transmit_trunk(struct iax_frame *f, struct ast_sockaddr *addr, int sockfd)
 {
 	int res;
-	res = sendto(sockfd, f->data, f->datalen, 0,(struct sockaddr *)sin,
-					sizeof(*sin));
+	res = ast_sendto(sockfd, f->data, f->datalen, 0, addr);
 	if (res < 0) {
 		ast_debug(1, "Received error: %s\n", strerror(errno));
 		handle_error();
@@ -6074,12 +6073,15 @@
 static struct iax2_trunk_peer *find_tpeer(struct sockaddr_in *sin, int fd)
 {
 	struct iax2_trunk_peer *tpeer = NULL;
+	struct ast_sockaddr addr = AST_SOCKADDR_INIT_VALUE;
+
+	ast_sockaddr_from_sin(&addr, sin);
 	
 	/* Finds and locks trunk peer */
 	AST_LIST_LOCK(&tpeers);
 
 	AST_LIST_TRAVERSE(&tpeers, tpeer, list) {
-		if (!inaddrcmp(&tpeer->addr, sin)) {
+		if (!ast_sockaddr_cmp_addr(&tpeer->addr, &addr)) {
 			ast_mutex_lock(&tpeer->lock);
 			break;
 		}
@@ -6089,14 +6091,14 @@
 		if ((tpeer = ast_calloc(1, sizeof(*tpeer)))) {
 			ast_mutex_init(&tpeer->lock);
 			tpeer->lastsent = 9999;
-			memcpy(&tpeer->addr, sin, sizeof(tpeer->addr));
+			ast_sockaddr_copy(&tpeer->addr, &addr);
 			tpeer->trunkact = ast_tvnow();
 			ast_mutex_lock(&tpeer->lock);
 			tpeer->sockfd = fd;
 #ifdef SO_NO_CHECK
 			setsockopt(tpeer->sockfd, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums));
 #endif
-			ast_debug(1, "Created trunk peer for '%s:%d'\n", ast_inet_ntoa(tpeer->addr.sin_addr), ntohs(tpeer->addr.sin_port));
+			ast_debug(1, "Created trunk peer for '%s'\n", ast_sockaddr_stringify(&tpeer->addr));
 			AST_LIST_INSERT_TAIL(&tpeers, tpeer, list);
 		}
 	}
@@ -6128,9 +6130,9 @@
 
 				tpeer->trunkdataalloc += DEFAULT_TRUNKDATA;
 				tpeer->trunkdata = tmp;
-				ast_debug(1, "Expanded trunk '%s:%d' to %d bytes\n", ast_inet_ntoa(tpeer->addr.sin_addr), ntohs(tpeer->addr.sin_port), tpeer->trunkdataalloc);
+				ast_debug(1, "Expanded trunk '%s' to %d bytes\n", ast_sockaddr_stringify(&tpeer->addr), tpeer->trunkdataalloc);
 			} else {
-				ast_log(LOG_WARNING, "Maximum trunk data space exceeded to %s:%d\n", ast_inet_ntoa(tpeer->addr.sin_addr), ntohs(tpeer->addr.sin_port));
+				ast_log(LOG_WARNING, "Maximum trunk data space exceeded to %s\n", ast_sockaddr_stringify(&tpeer->addr));
 				ast_mutex_unlock(&tpeer->lock);
 				return -1;
 			}
@@ -9191,7 +9193,14 @@
 			res = send_trunk(tpeer, &now);
 			trunk_timed++;
 			if (iaxtrunkdebug)
-				ast_verbose(" - Trunk peer (%s:%d) has %d call chunk%s in transit, %d bytes backloged and has hit a high water mark of %d bytes\n", ast_inet_ntoa(tpeer->addr.sin_addr), ntohs(tpeer->addr.sin_port), res, (res != 1) ? "s" : "", tpeer->trunkdatalen, tpeer->trunkdataalloc);
+				ast_verbose(
+					" - Trunk peer (%s) has %d call chunk%s in transit, %d bytes backlogged "
+					"and has hit a high water mark of %d bytes\n",
+					ast_sockaddr_stringify(&tpeer->addr),
+					res,
+					(res == 1) ? "" : "s",
+					tpeer->trunkdatalen,
+					tpeer->trunkdataalloc);
 		}
 		totalcalls += res;
 		res = 0;
@@ -9204,7 +9213,7 @@
 		ast_mutex_lock(&drop->lock);
 		/* Once we have this lock, we're sure nobody else is using it or could use it once we release it, 
 		   because by the time they could get tpeerlock, we've already grabbed it */
-		ast_debug(1, "Dropping unused iax2 trunk peer '%s:%d'\n", ast_inet_ntoa(drop->addr.sin_addr), ntohs(drop->addr.sin_port));
+		ast_debug(1, "Dropping unused iax2 trunk peer '%s'\n", ast_sockaddr_stringify(&drop->addr));
 		if (drop->trunkdata) {
 			ast_free(drop->trunkdata);
 			drop->trunkdata = NULL;




More information about the asterisk-commits mailing list