mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
Add some debugging to the routines that finds our local IP address.
Related to bug #9225 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89405 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -313,9 +313,10 @@ int ast_ouraddrfor(struct in_addr *them, struct in_addr *us)
|
|||||||
int s;
|
int s;
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
socklen_t slen;
|
socklen_t slen;
|
||||||
|
|
||||||
s = socket(PF_INET, SOCK_DGRAM, 0);
|
s = socket(PF_INET, SOCK_DGRAM, 0);
|
||||||
if (s < 0) {
|
if (s < 0) {
|
||||||
ast_log(LOG_WARNING, "Cannot create socket\n");
|
ast_log(LOG_ERROR, "Cannot create socket\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sin.sin_family = AF_INET;
|
sin.sin_family = AF_INET;
|
||||||
@@ -333,6 +334,7 @@ int ast_ouraddrfor(struct in_addr *them, struct in_addr *us)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
close(s);
|
close(s);
|
||||||
|
ast_debug(3, "Found IP address for this socket\n");
|
||||||
*us = sin.sin_addr;
|
*us = sin.sin_addr;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -347,6 +349,7 @@ int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr)
|
|||||||
/* just use the bind address if it is nonzero */
|
/* just use the bind address if it is nonzero */
|
||||||
if (ntohl(bindaddr.sin_addr.s_addr)) {
|
if (ntohl(bindaddr.sin_addr.s_addr)) {
|
||||||
memcpy(ourip, &bindaddr.sin_addr, sizeof(*ourip));
|
memcpy(ourip, &bindaddr.sin_addr, sizeof(*ourip));
|
||||||
|
ast_debug(3, "Attached to given IP address\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* try to use our hostname */
|
/* try to use our hostname */
|
||||||
@@ -356,12 +359,15 @@ int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr)
|
|||||||
hp = ast_gethostbyname(ourhost, &ahp);
|
hp = ast_gethostbyname(ourhost, &ahp);
|
||||||
if (hp) {
|
if (hp) {
|
||||||
memcpy(ourip, hp->h_addr, sizeof(*ourip));
|
memcpy(ourip, hp->h_addr, sizeof(*ourip));
|
||||||
|
ast_debug(3, "Found one IP address based on local hostname %s.\n", ourhost);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ast_debug(3, "Trying to check A.ROOT-SERVERS.NET and get our IP address for that connection\n");
|
||||||
/* A.ROOT-SERVERS.NET. */
|
/* A.ROOT-SERVERS.NET. */
|
||||||
if (inet_aton("198.41.0.4", &saddr) && !ast_ouraddrfor(&saddr, ourip))
|
if (inet_aton("198.41.0.4", &saddr) && !ast_ouraddrfor(&saddr, ourip))
|
||||||
return 0;
|
return 0;
|
||||||
|
ast_debug(3, "Failed to find any IP address for us\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user