Commit ac45c52a authored by Kai Vehmanen's avatar Kai Vehmanen

Properly initialize the address structs.

darcs-hash:20070918151422-77cd4-826dcabbd2161b390b5e42e4bd5bd4a8c805d851.gz
parent 18dacc48
......@@ -52,11 +52,7 @@ NICEAPI_EXPORT NiceAddress *
nice_address_new (void)
{
NiceAddress *addr = g_slice_new0 (NiceAddress);
memset (addr, 0, sizeof (addr));
addr->s.addr.sa_family = AF_UNSPEC;
#ifdef HAVE_SA_LEN
addr->s.addr.sa_len = sizeof (addr->s.addr);
#endif
nice_address_init (addr);
return addr;
}
......@@ -69,6 +65,7 @@ nice_address_set_ipv4 (NiceAddress *addr, guint32 addr_ipv4)
addr->s.ip4.sin_len = sizeof (addr->sa.ip4);
#endif
addr->s.ip4.sin_addr.s_addr = addr_ipv4 ? htonl (addr_ipv4) : INADDR_ANY;
addr->s.ip4.sin_port = 0;
}
......@@ -80,6 +77,7 @@ nice_address_set_ipv6 (NiceAddress *addr, const guchar *addr_ipv6)
addr->s.ip6.sin6_len = sizeof (addr->sa.ip6);
#endif
memcpy (addr->s.ip6.sin6_addr.s6_addr, addr_ipv6, 16);
addr->s.ip6.sin6_port = addr->s.ip6.sin6_scope_id = 0;
}
......
......@@ -61,6 +61,12 @@ struct _NiceAddress
} s;
};
static inline void
nice_address_init (NiceAddress *addr)
{
addr->s.addr.sa_family = AF_UNSPEC;
}
NiceAddress *
nice_address_new (void);
......
......@@ -59,8 +59,8 @@ test_ipv4 (void)
sin.sin_port = htons (9876);
g_assert (inet_pton (AF_INET, "1.2.3.4", &sin.sin_addr) > 0);
memset (&addr, 0, sizeof (addr));
memset (&other, 0, sizeof (other));
nice_address_init (&addr);
nice_address_init (&other);
nice_address_set_ipv4 (&addr, 0x01020304);
g_assert (addr.s.ip4.sin_family == AF_INET);
......@@ -116,7 +116,7 @@ test_ipv6 (void)
sin.sin6_port = htons (9876);
g_assert (inet_pton (AF_INET6, "11:2233:4455:6677:8899:aabb:ccdd:eeff", &sin.sin6_addr) > 0);
memset (&addr, 0, sizeof (addr));
nice_address_init (&addr);
nice_address_set_ipv6 (&addr, (guchar *)
"\x00\x11\x22\x33"
"\x44\x55\x66\x77"
......
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