Fix calls to ast_get_ip() not initializing the address family.

........

Merged revisions 346239 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 346240 from http://svn.asterisk.org/svn/asterisk/branches/10


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@346241 65c4cc65-6c06-0410-ace0-fbb531ad65f3
certified/11.2
Richard Mudgett 14 years ago
parent 2ee874178e
commit 7d9ba4875b

@ -1463,6 +1463,7 @@ static struct oh323_user *build_user(const char *name, struct ast_variable *v, s
} else { } else {
struct ast_sockaddr tmp; struct ast_sockaddr tmp;
tmp.ss.ss_family = AF_INET;
if (ast_get_ip(&tmp, v->value)) { if (ast_get_ip(&tmp, v->value)) {
ASTOBJ_UNREF(user, oh323_destroy_user); ASTOBJ_UNREF(user, oh323_destroy_user);
return NULL; return NULL;

@ -12367,7 +12367,8 @@ static int peer_set_srcaddr(struct iax2_peer *peer, const char *srcaddr)
if (port < 1) if (port < 1)
port = IAX_DEFAULT_PORTNO; port = IAX_DEFAULT_PORTNO;
} }
sin_tmp.ss.ss_family = AF_INET;
if (!ast_get_ip(&sin_tmp, addr)) { if (!ast_get_ip(&sin_tmp, addr)) {
struct ast_netsock *sock; struct ast_netsock *sock;
int res; int res;
@ -12583,6 +12584,7 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
} else if (!strcasecmp(v->name, "defaultip")) { } else if (!strcasecmp(v->name, "defaultip")) {
struct ast_sockaddr peer_defaddr_tmp; struct ast_sockaddr peer_defaddr_tmp;
peer_defaddr_tmp.ss.ss_family = AF_INET;
if (ast_get_ip(&peer_defaddr_tmp, v->value)) { if (ast_get_ip(&peer_defaddr_tmp, v->value)) {
return peer_unref(peer); return peer_unref(peer);
} }

@ -7385,6 +7385,7 @@ static struct ast_channel *skinny_request(const char *type, struct ast_format_ca
if (type & (TYPE_DEVICE)) { if (type & (TYPE_DEVICE)) {
struct ast_sockaddr CDEV_addr_tmp; struct ast_sockaddr CDEV_addr_tmp;
CDEV_addr_tmp.ss.ss_family = AF_INET;
if (ast_get_ip(&CDEV_addr_tmp, v->value)) { if (ast_get_ip(&CDEV_addr_tmp, v->value)) {
ast_log(LOG_WARNING, "Bad IP '%s' at line %d.\n", v->value, v->lineno); ast_log(LOG_WARNING, "Bad IP '%s' at line %d.\n", v->value, v->lineno);
} }

@ -123,36 +123,39 @@ int ast_apply_ha(const struct ast_ha *ha, const struct ast_sockaddr *addr);
* \details * \details
* Similar in nature to ast_gethostbyname, except that instead * Similar in nature to ast_gethostbyname, except that instead
* of getting an entire hostent structure, you instead are given * of getting an entire hostent structure, you instead are given
* only the IP address inserted into a sockaddr_in structure. * only the IP address inserted into a ast_sockaddr structure.
*
* \param addr The IP address found. The address family is used
* as an input parameter to filter the returned addresses. If
* it is 0, both IPv4 and IPv6 addresses can be returned.
* \param hostname The hostname to look up
* *
* \param[out] addr The IP address is written into sin->sin_addr
* \param value The hostname to look up
* \retval 0 Success * \retval 0 Success
* \retval -1 Failure * \retval -1 Failure
*/ */
int ast_get_ip(struct ast_sockaddr *addr, const char *value); int ast_get_ip(struct ast_sockaddr *addr, const char *hostname);
/*! /*!
* \brief Get the IP address given a hostname and optional service * \brief Get the IP address given a hostname and optional service
* *
* \details * \details
* If the service parameter is non-NULL, then an SRV lookup will be made by * If the service parameter is non-NULL, then an SRV lookup will be made by
* prepending the service to the value parameter, separated by a '.' * prepending the service to the hostname parameter, separated by a '.'
* For example, if value is "example.com" and service is "_sip._udp" then * For example, if hostname is "example.com" and service is "_sip._udp" then
* an SRV lookup will be done for "_sip._udp.example.com". If service is NULL, * an SRV lookup will be done for "_sip._udp.example.com". If service is NULL,
* then this function acts exactly like a call to ast_get_ip. * then this function acts exactly like a call to ast_get_ip.
* *
* \param addr The IP address found. The address family is used as an input parameter to * \param addr The IP address found. The address family is used
* filter the returned addresses. if it is 0, both IPv4 and IPv6 addresses * as an input parameter to filter the returned addresses. If
* can be returned. * it is 0, both IPv4 and IPv6 addresses can be returned.
* *
* \param value The hostname to look up * \param hostname The hostname to look up
* \param service A specific service provided by the host. A NULL service results * \param service A specific service provided by the host. A NULL service results
* in an A-record lookup instead of an SRV lookup * in an A-record lookup instead of an SRV lookup
* \retval 0 Success * \retval 0 Success
* \retval -1 Failure * \retval -1 Failure
*/ */
int ast_get_ip_or_srv(struct ast_sockaddr *addr, const char *value, const char *service); int ast_get_ip_or_srv(struct ast_sockaddr *addr, const char *hostname, const char *service);
/*! /*!
* \brief Get our local IP address when contacting a remote host * \brief Get our local IP address when contacting a remote host

@ -586,7 +586,7 @@ static int resolve_first(struct ast_sockaddr *addr, const char *name, int flag,
return 0; return 0;
} }
int ast_get_ip_or_srv(struct ast_sockaddr *addr, const char *value, const char *service) int ast_get_ip_or_srv(struct ast_sockaddr *addr, const char *hostname, const char *service)
{ {
char srv[256]; char srv[256];
char host[256]; char host[256];
@ -594,13 +594,13 @@ int ast_get_ip_or_srv(struct ast_sockaddr *addr, const char *value, const char *
int tportno; int tportno;
if (service) { if (service) {
snprintf(srv, sizeof(srv), "%s.%s", service, value); snprintf(srv, sizeof(srv), "%s.%s", service, hostname);
if ((srv_ret = ast_get_srv(NULL, host, sizeof(host), &tportno, srv)) > 0) { if ((srv_ret = ast_get_srv(NULL, host, sizeof(host), &tportno, srv)) > 0) {
value = host; hostname = host;
} }
} }
if (resolve_first(addr, value, PARSE_PORT_FORBID, addr->ss.ss_family) != 0) { if (resolve_first(addr, hostname, PARSE_PORT_FORBID, addr->ss.ss_family) != 0) {
return -1; return -1;
} }
@ -689,9 +689,9 @@ const char *ast_tos2str(unsigned int tos)
return "unknown"; return "unknown";
} }
int ast_get_ip(struct ast_sockaddr *addr, const char *value) int ast_get_ip(struct ast_sockaddr *addr, const char *hostname)
{ {
return ast_get_ip_or_srv(addr, value, NULL); return ast_get_ip_or_srv(addr, hostname, NULL);
} }
int ast_ouraddrfor(const struct ast_sockaddr *them, struct ast_sockaddr *us) int ast_ouraddrfor(const struct ast_sockaddr *them, struct ast_sockaddr *us)

Loading…
Cancel
Save