[Asterisk-Dev] PATCH: Fix code to find peer in check_user

Stephen Davies steve at daviesfam.org
Tue Apr 8 15:28:34 MST 2003


Hi,

Code compares two sock_addr_in's for sizeof(sock_addr_in) - but there are
slack bytes in this struct so the compare fails to work right - on my box
at least.

Patch also adds some more debug messages in the function.

Steve
-------------- next part --------------
Index: channels/chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.55
diff -u -r1.55 chan_sip.c
--- channels/chan_sip.c	8 Apr 2003 15:00:57 -0000	1.55
+++ channels/chan_sip.c	8 Apr 2003 22:29:47 -0000
@@ -568,6 +568,8 @@
 	p = peerl.peers;
 	while(p) {
 		if (!strcasecmp(p->name, peer)) {
+			if (sipdebug)
+				ast_verbose("Found peer for \"%s\"\n", peer);
 			found++;
 			r->capability = p->capability;
 			r->nat = p->nat;
@@ -608,6 +610,8 @@
 	}
 	ast_pthread_mutex_unlock(&peerl.lock);
 	if (!p && !found) {
+		if (sipdebug)
+			ast_verbose("No peer for \"%s\", looking up in DNS\n", peer);
 		hp = gethostbyname(peer);
 		if (hp) {
 			memcpy(&r->sa.sin_addr, hp->h_addr, sizeof(r->sa.sin_addr));
@@ -3167,10 +3171,14 @@
 	strncpy(p->callerid, of, sizeof(p->callerid) - 1);
 	if (!strlen(of))
 			return 0;
+	if (sipdebug)
+		ast_verbose("Looking for known user \"%s\"\n", of);
 	ast_pthread_mutex_lock(&userl.lock);
 	user = userl.users;
 	while(user) {
 		if (!strcasecmp(user->name, of)) {
+			if (sipdebug)
+				ast_verbose("Found matching user\n");
 			p->nat = user->nat;
 			if (p->rtp) {
 				ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", p->nat);
@@ -3200,10 +3208,15 @@
 	ast_pthread_mutex_unlock(&userl.lock);
 	if (!user) {
 	/* If we didn't find a user match, check for peers */
+		if (sipdebug)
+			ast_verbose("Couldn't find known user - instead looking for peer at %s:%d\n", inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port));
 		ast_pthread_mutex_lock(&peerl.lock);
 		peer = peerl.peers;
 		while(peer) {
-			if (!memcmp(&peer->addr, &p->recv, sizeof(peer->addr))) {
+			/*if (sipdebug) ast_verbose("...comparing against %s:%d\n", inet_ntoa(peer->addr.sin_addr), ntohs(peer->addr.sin_port));*/
+			if (p->recv.sin_addr.s_addr == peer->addr.sin_addr.s_addr && p->recv.sin_port == peer->addr.sin_port) {
+				if (sipdebug)
+					ast_verbose("Found peer \"%s\"\n", peer->name);
 				/* Take the peer */
 				p->nat = peer->nat;
 				if (p->rtp) {


More information about the asterisk-dev mailing list