Commit fc1ce1ab authored by Dafydd Harries's avatar Dafydd Harries

store address data in native endianness; use inet_ntop instead of inet_ntoa

darcs-hash:20070122043415-c9803-eef14fc5437db099eb27f1c0d96f8f0baaeb1941.gz
parent 8472d54e
...@@ -34,7 +34,7 @@ address_new_ipv4_from_string (gchar *str) ...@@ -34,7 +34,7 @@ address_new_ipv4_from_string (gchar *str)
struct in_addr iaddr; struct in_addr iaddr;
if (inet_aton (str, &iaddr) != 0) if (inet_aton (str, &iaddr) != 0)
return address_new_ipv4 (iaddr.s_addr); return address_new_ipv4 (ntohl (iaddr.s_addr));
else else
/* invalid address */ /* invalid address */
return NULL; return NULL;
...@@ -45,10 +45,14 @@ gchar * ...@@ -45,10 +45,14 @@ gchar *
address_to_string (Address *addr) address_to_string (Address *addr)
{ {
struct in_addr iaddr; struct in_addr iaddr;
gchar ip_str[INET_ADDRSTRLEN];
const gchar *ret;
g_assert (addr->type == ADDRESS_TYPE_IPV4); g_assert (addr->type == ADDRESS_TYPE_IPV4);
iaddr.s_addr = addr->addr_ipv4; iaddr.s_addr = htonl (addr->addr_ipv4);
return g_strdup (inet_ntoa (iaddr)); ret = inet_ntop (AF_INET, &iaddr, ip_str, INET_ADDRSTRLEN);
g_assert (ret);
return g_strdup (ip_str);
} }
......
...@@ -71,7 +71,7 @@ candidate_from_string (const gchar *s) ...@@ -71,7 +71,7 @@ candidate_from_string (const gchar *s)
port = strtol (last_slash + 1, NULL, 10); port = strtol (last_slash + 1, NULL, 10);
candidate = candidate_new (type); candidate = candidate_new (type);
addr = address_new_ipv4 (ip); addr = address_new_ipv4 (ntohl (ip));
candidate->addr = addr; candidate->addr = addr;
candidate->port = port; candidate->port = port;
......
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