diff options
Diffstat (limited to 'acl.c')
-rwxr-xr-x | acl.c | 36 |
1 files changed, 32 insertions, 4 deletions
@@ -242,20 +242,19 @@ int ast_ouraddrfor(struct in_addr *them, struct in_addr *us) memset(&m_rtmsg, 0, sizeof(m_rtmsg)); m_rtmsg.m_rtm.rtm_type = RTM_GET; - m_rtmsg.m_rtm.rtm_flags = RTF_UP | RTF_HOST; m_rtmsg.m_rtm.rtm_version = RTM_VERSION; ast_mutex_lock(&routeseq_lock); seq = ++routeseq; ast_mutex_unlock(&routeseq_lock); m_rtmsg.m_rtm.rtm_seq = seq; - m_rtmsg.m_rtm.rtm_addrs = RTA_IFA | RTA_DST; + m_rtmsg.m_rtm.rtm_addrs = RTA_DST | RTA_IFA; m_rtmsg.m_rtm.rtm_msglen = sizeof(struct rt_msghdr) + sizeof(struct sockaddr_in); sin = (struct sockaddr_in *)m_rtmsg.m_space; sin->sin_family = AF_INET; sin->sin_len = sizeof(struct sockaddr_in); sin->sin_addr = *them; - if ((s = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) { + if ((s = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC)) < 0) { ast_log(LOG_ERROR, "Error opening routing socket\n"); return -1; } @@ -268,7 +267,7 @@ int ast_ouraddrfor(struct in_addr *them, struct in_addr *us) } do { l = read(s, (char *)&m_rtmsg, sizeof(m_rtmsg)); - } while (l > 0 && (m_rtmsg.m_rtm.rtm_seq != 1 || m_rtmsg.m_rtm.rtm_pid != pid)); + } while (l > 0 && (m_rtmsg.m_rtm.rtm_seq != seq || m_rtmsg.m_rtm.rtm_pid != pid)); if (l < 0) { if (errno != EAGAIN) ast_log(LOG_ERROR, "Error reading from routing socket\n"); @@ -379,3 +378,32 @@ int ast_ouraddrfor(struct in_addr *them, struct in_addr *us) return 0; #endif } + +int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr) +{ + char ourhost[MAXHOSTNAMELEN]=""; + struct ast_hostent ahp; + struct hostent *hp; + struct in_addr saddr; + + /* just use the bind address if it is nonzero */ + if (ntohl(bindaddr.sin_addr.s_addr)) { + memcpy(ourip, &bindaddr.sin_addr, sizeof(*ourip)); + return 0; + } + /* try to use our hostname */ + if (gethostname(ourhost, sizeof(ourhost)-1)) { + ast_log(LOG_WARNING, "Unable to get hostname\n"); + } else { + hp = ast_gethostbyname(ourhost, &ahp); + if (hp) { + memcpy(ourip, hp->h_addr, sizeof(*ourip)); + return 0; + } + } + /* A.ROOT-SERVERS.NET. */ + if (inet_aton("198.41.0.4", &saddr) && !ast_ouraddrfor(&saddr, ourip)) + return 0; + return -1; +} + |