Commit 839f9e3f authored by Philip Withnall's avatar Philip Withnall Committed by Olivier Crête
Browse files

agent: Use getaddrinfo() to parse addresses from strings

Rather than using inet_pton(), which doesn’t support IPv6 link-local
scope IDs, use getaddrinfo(). This is supported on all platforms
(POSIX.1-2001, and Windows winsock).
parent 9a622300
...@@ -44,6 +44,10 @@ ...@@ -44,6 +44,10 @@
#include <string.h> #include <string.h>
#ifndef G_OS_WIN32
#include <netdb.h>
#endif
#include "address.h" #include "address.h"
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
...@@ -197,18 +201,21 @@ nice_address_get_port (const NiceAddress *addr) ...@@ -197,18 +201,21 @@ nice_address_get_port (const NiceAddress *addr)
NICEAPI_EXPORT gboolean NICEAPI_EXPORT gboolean
nice_address_set_from_string (NiceAddress *addr, const gchar *str) nice_address_set_from_string (NiceAddress *addr, const gchar *str)
{ {
union struct addrinfo hints;
{ struct addrinfo *res;
struct in_addr ipv4;
struct in6_addr ipv6; memset (&hints, 0, sizeof (hints));
} a;
/* AI_NUMERICHOST prevents getaddrinfo() from doing DNS resolution. */
if (inet_pton (AF_INET, str, &a.ipv4) > 0) hints.ai_family = AF_UNSPEC;
nice_address_set_ipv4 (addr, ntohl (a.ipv4.s_addr)); hints.ai_flags = AI_NUMERICHOST;
else if (inet_pton (AF_INET6, str, &a.ipv6) > 0)
nice_address_set_ipv6 (addr, a.ipv6.s6_addr); if (getaddrinfo (str, NULL, &hints, &res) != 0)
else return FALSE; /* invalid address */
return FALSE; /* Invalid address */
nice_address_set_from_sockaddr (addr, res->ai_addr);
freeaddrinfo (res);
return TRUE; return TRUE;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment