2 * This file is part of the Nice GLib ICE library.
4 * (C) 2006, 2007 Collabora Ltd.
5 * Contact: Dafydd Harries
6 * (C) 2006, 2007 Nokia Corporation. All rights reserved.
7 * Contact: Kai Vehmanen
9 * The contents of this file are subject to the Mozilla Public License Version
10 * 1.1 (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 * http://www.mozilla.org/MPL/
14 * Software distributed under the License is distributed on an "AS IS" basis,
15 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16 * for the specific language governing rights and limitations under the
19 * The Original Code is the Nice GLib ICE library.
21 * The Initial Developers of the Original Code are Collabora Ltd and Nokia
22 * Corporation. All Rights Reserved.
25 * Dafydd Harries, Collabora Ltd.
28 * Alternatively, the contents of this file may be used under the terms of the
29 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
30 * case the provisions of LGPL are applicable instead of those above. If you
31 * wish to allow use of your version of this file only under the terms of the
32 * LGPL and not to allow others to use your version of this file under the
33 * MPL, indicate your decision by deleting the provisions above and replace
34 * them with the notice and other provisions required by the LGPL. If you do
35 * not delete the provisions above, a recipient may use your version of this
36 * file under either the MPL or the LGPL.
50 gchar str
[NICE_ADDRESS_STRING_LEN
];
52 nice_address_init (&addr
);
53 nice_address_init (&other
);
54 nice_address_set_ipv4 (&addr
, 0x01020304);
55 g_assert (addr
.s
.ip4
.sin_family
== AF_INET
);
57 nice_address_to_string (&addr
, str
);
58 g_assert (0 == strcmp (str
, "1.2.3.4"));
60 nice_address_to_string (&addr
, str
);
63 nice_address_set_ipv4 (&other
, 0x01020304);
64 g_assert (TRUE
== nice_address_equal (&addr
, &other
));
66 /* from sockaddr_in */
67 nice_address_set_port (&other
, 9876); /* in native byte order */
68 other
.s
.ip4
.sin_family
= AF_INET
;
69 nice_address_set_from_string (&addr
, "1.2.3.4");
70 nice_address_set_port (&addr
, 9876); /* in native byte order */
71 nice_address_to_string (&addr
, str
);
72 nice_address_to_string (&other
, str
);
73 g_assert (TRUE
== nice_address_equal (&addr
, &other
));
76 nice_address_set_ipv4 (&other
, 0x01020305);
77 g_assert (FALSE
== nice_address_equal (&addr
, &other
));
80 nice_address_set_ipv4 (&other
, 0x01020304);
81 nice_address_set_port (&addr
, 1);
82 g_assert (FALSE
== nice_address_equal (&addr
, &other
));
84 /* test private address check */
86 NiceAddress
*heap_addr
= nice_address_new ();
87 g_assert (nice_address_set_from_string (heap_addr
, "127.0.0.1") == TRUE
);
88 g_assert (nice_address_is_private (heap_addr
) == TRUE
);
89 g_assert (nice_address_set_from_string (heap_addr
, "127.0.0.1.1") != TRUE
);
90 nice_address_free (heap_addr
);
97 NiceAddress addr
, other
, v4addr
;
98 gchar str
[NICE_ADDRESS_STRING_LEN
];
99 struct sockaddr_in6 sin
, sin2
;
101 g_assert (nice_address_set_from_string (&v4addr
, "172.1.0.1") == TRUE
);
103 memset (&sin
, 0, sizeof (sin
));
104 memset (&sin2
, 0, sizeof (sin2
));
106 memset (&addr
, 0, sizeof (NiceAddress
));
107 memset (&other
, 0, sizeof (NiceAddress
));
108 nice_address_init (&addr
);
109 nice_address_init (&other
);
110 nice_address_set_ipv6 (&addr
, (guchar
*)
115 g_assert (addr
.s
.ip6
.sin6_family
== AF_INET6
);
117 nice_address_to_string (&addr
, str
);
118 g_assert (0 == strcmp (str
, "11:2233:4455:6677:8899:aabb:ccdd:eeff"));
120 nice_address_set_port (&addr
, 9876); /* in native byte order */
121 nice_address_set_from_string (&other
, "11:2233:4455:6677:8899:aabb:ccdd:eeff");
122 nice_address_set_port (&other
, 9876); /* in native byte order */
124 nice_address_copy_to_sockaddr (&other
, (struct sockaddr
*)&sin2
);
125 nice_address_copy_to_sockaddr (&addr
, (struct sockaddr
*)&sin
);
126 g_assert (nice_address_equal (&addr
, &other
) == TRUE
);
127 nice_address_to_string (&addr
, str
);
128 nice_address_to_string (&other
, str
);
130 g_assert (memcmp (&sin
, &sin2
, sizeof(sin
)) == 0);
132 /* private IPv6 address */
133 nice_address_set_ipv6 (&addr
, (guchar
*)
138 g_assert (nice_address_is_private (&addr
) == TRUE
);
139 nice_address_set_ipv6 (&addr
, (guchar
*)
144 g_assert (nice_address_is_private (&addr
) == TRUE
);
146 /* mismatching address families */
147 g_assert (nice_address_equal (&addr
, &v4addr
) != TRUE
);
149 /* mismatched type */
150 addr
.s
.addr
.sa_family
= AF_UNSPEC
;
151 /*g_assert (nice_address_equal (&addr, &v4addr) != TRUE);*/
162 WSAStartup(0x0202, &w
);