提交 f1430d52 authored 作者: Anthony Minessale's avatar Anthony Minessale 提交者: Brian West

fix switch_get_addr to work with v6 properly

上级 86fcc2c0
......@@ -197,6 +197,7 @@ SWITCH_DECLARE(switch_status_t) switch_find_local_ip(_Out_opt_bytecapcount_(len)
\return the ip adress string
*/
SWITCH_DECLARE(char *) get_addr(char *buf, switch_size_t len, struct sockaddr *sa, socklen_t salen);
SWITCH_DECLARE(char *) get_addr6(char *buf, switch_size_t len, struct sockaddr_in6 *sa, socklen_t salen);
SWITCH_DECLARE(int) get_addr_int(switch_sockaddr_t *sa);
SWITCH_DECLARE(int) switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2);
......
......@@ -778,9 +778,14 @@ SWITCH_DECLARE(switch_status_t) switch_mcast_loopback(switch_socket_t *sock, uin
SWITCH_DECLARE(const char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
{
if (!in) {
return "";
return SWITCH_BLANK_STRING;
}
return get_addr(buf, len, (struct sockaddr *) &in->sa, in->salen);
if (in->family == AF_INET) {
return get_addr(buf, len, (struct sockaddr *) &in->sa, in->salen);
}
return get_addr6(buf, len, (struct sockaddr_in6 *) &in->sa, in->salen);
}
SWITCH_DECLARE(uint16_t) switch_sockaddr_get_port(switch_sockaddr_t *sa)
......
......@@ -1482,6 +1482,17 @@ SWITCH_DECLARE(int) switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *s
return 0;
}
SWITCH_DECLARE(char *) get_addr6(char *buf, switch_size_t len, struct sockaddr_in6 *sa, socklen_t salen)
{
switch_assert(buf);
*buf = '\0';
if (sa) {
inet_ntop(AF_INET6, sa, buf, len);
}
return buf;
}
SWITCH_DECLARE(char *) get_addr(char *buf, switch_size_t len, struct sockaddr *sa, socklen_t salen)
{
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论