diff options
author | Dafydd Harries <dafydd.harries@collabora.co.uk> | 2007-02-12 13:02:00 +0000 |
---|---|---|
committer | Dafydd Harries <dafydd.harries@collabora.co.uk> | 2007-02-12 13:02:00 +0000 |
commit | f1df61dc13a4fdc297a4bbfd369024a70f0cb624 (patch) | |
tree | d92797edb7958fb5c232183dcbd48316e095151e /address | |
parent | 1772be3b2f165eeac99f68f5b5b9bd8f4cb98535 (diff) | |
download | libnice-f1df61dc13a4fdc297a4bbfd369024a70f0cb624.tar.gz |
address/: support converting IPv6 addresses to strings
darcs-hash:20070212130249-c9803-5c79bc290b79171ffcf062bc59092f900e2c6603.gz
Diffstat (limited to 'address')
-rw-r--r-- | address/address.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/address/address.c b/address/address.c index 5bef7ee..7c55515 100644 --- a/address/address.c +++ b/address/address.c @@ -57,14 +57,22 @@ nice_address_set_ipv4_from_string (NiceAddress *addr, const gchar *str) gchar * nice_address_to_string (NiceAddress *addr) { - struct in_addr iaddr; - gchar ip_str[INET_ADDRSTRLEN]; - const gchar *ret; + struct in_addr iaddr = {0,}; + gchar ip_str[INET6_ADDRSTRLEN] = {0,}; + const gchar *ret = NULL; + + switch (addr->type) + { + case NICE_ADDRESS_TYPE_IPV4: + iaddr.s_addr = htonl (addr->addr_ipv4); + ret = inet_ntop (AF_INET, &iaddr, ip_str, INET_ADDRSTRLEN); + break; + case NICE_ADDRESS_TYPE_IPV6: + ret = inet_ntop (AF_INET6, &addr->addr_ipv6, ip_str, INET6_ADDRSTRLEN); + break; + } - g_assert (addr->type == NICE_ADDRESS_TYPE_IPV4); - iaddr.s_addr = htonl (addr->addr_ipv4); - ret = inet_ntop (AF_INET, &iaddr, ip_str, INET_ADDRSTRLEN); - g_assert (ret); + g_assert (ret == ip_str); return g_strdup (ip_str); } |