2 * This file is part of the Nice GLib ICE library.
4 * (C) 2006-2009 Collabora Ltd.
5 * Contact: Youness Alaoui
6 * (C) 2006-2009 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 * Youness Alaoui, Collabora Ltd.
26 * Dafydd Harries, Collabora Ltd.
29 * Alternatively, the contents of this file may be used under the terms of the
30 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
31 * case the provisions of LGPL are applicable instead of those above. If you
32 * wish to allow use of your version of this file only under the terms of the
33 * LGPL and not to allow others to use your version of this file under the
34 * MPL, indicate your decision by deleting the provisions above and replace
35 * them with the notice and other provisions required by the LGPL. If you do
36 * not delete the provisions above, a recipient may use your version of this
37 * file under either the MPL or the LGPL.
40 #ifndef __LIBNICE_ADDRESS_H__
41 #define __LIBNICE_ADDRESS_H__
45 * @short_description: IP address convenience library
48 * The #NiceAddress structure will allow you to easily set/get and modify an IPv4
49 * or IPv6 address in order to communicate with the #NiceAgent.
59 #include <sys/types.h>
60 #include <sys/socket.h>
61 #include <netinet/in.h>
62 #include <arpa/inet.h>
71 * The #NiceAddress structure that represents an IPv4 or IPv6 address.
78 struct sockaddr_in ip4;
79 struct sockaddr_in6 ip6;
85 * NICE_ADDRESS_STRING_LEN:
87 * The maximum string length representation of an address.
88 * When using nice_address_to_string() make sure the string has a size of
89 * at least %NICE_ADDRESS_STRING_LEN
91 #define NICE_ADDRESS_STRING_LEN INET6_ADDRSTRLEN
93 typedef struct _NiceAddress NiceAddress;
98 * @addr: The #NiceAddress to init
100 * Initialize a #NiceAddress into an undefined address
103 nice_address_init (NiceAddress *addr);
108 * Create a new #NiceAddress with undefined address
109 * You must free it with nice_address_free()
111 * Returns: The new #NiceAddress
114 nice_address_new (void);
118 * @addr: The #NiceAddress to free
120 * Frees a #NiceAddress created with nice_address_new() or nice_address_dup()
123 nice_address_free (NiceAddress *addr);
127 * @addr: The #NiceAddress to dup
129 * Creates a new #NiceAddress with the same address as @addr
131 * Returns: The new #NiceAddress
134 nice_address_dup (const NiceAddress *addr);
138 * nice_address_set_ipv4:
139 * @addr: The #NiceAddress to modify
140 * @addr_ipv4: The IPv4 address
142 * Set @addr to an IPv4 address using the data from @addr_ipv4
146 This function will reset the port to 0, so make sure you call it before
147 nice_address_set_port()
152 nice_address_set_ipv4 (NiceAddress *addr, guint32 addr_ipv4);
156 * nice_address_set_ipv6:
157 * @addr: The #NiceAddress to modify
158 * @addr_ipv6: The IPv6 address
160 * Set @addr to an IPv6 address using the data from @addr_ipv6
164 This function will reset the port to 0, so make sure you call it before
165 nice_address_set_port()
170 nice_address_set_ipv6 (NiceAddress *addr, const guchar *addr_ipv6);
174 * nice_address_set_port:
175 * @addr: The #NiceAddress to modify
176 * @port: The port to set
178 * Set the port of @addr to @port
181 nice_address_set_port (NiceAddress *addr, guint port);
184 * nice_address_get_port:
185 * @addr: The #NiceAddress to query
187 * Retreive the port of @addr
189 * Returns: The port of @addr
192 nice_address_get_port (const NiceAddress *addr);
195 * nice_address_set_from_string:
196 * @addr: The #NiceAddress to modify
197 * @str: The string to set
199 * Sets an IPv4 or IPv6 address from the string @str
201 * Returns: %TRUE if success, %FALSE on error
204 nice_address_set_from_string (NiceAddress *addr, const gchar *str);
207 * nice_address_set_from_sockaddr:
208 * @addr: The #NiceAddress to modify
209 * @sin: The sockaddr to set
211 * Sets an IPv4 or IPv6 address from the sockaddr structure @sin
215 nice_address_set_from_sockaddr (NiceAddress *addr, const struct sockaddr *sin);
219 * nice_address_copy_to_sockaddr:
220 * @addr: The #NiceAddress to query
221 * @sin: The sockaddr to fill
223 * Fills the sockaddr structure @sin with the address contained in @addr
227 nice_address_copy_to_sockaddr (const NiceAddress *addr, struct sockaddr *sin);
230 * nice_address_equal:
231 * @a: First #NiceAddress to compare
232 * @b: Second #NiceAddress to compare
234 * Compares two #NiceAddress structures to see if they contain the same address
237 * Returns: %TRUE if @a and @b are the same address, %FALSE if they are different
240 nice_address_equal (const NiceAddress *a, const NiceAddress *b);
243 * nice_address_equal_no_port:
244 * @a: First #NiceAddress to compare
245 * @b: Second #NiceAddress to compare
247 * Compares two #NiceAddress structures to see if they contain the same address,
250 * Returns: %TRUE if @a and @b are the same address, %FALSE if they
256 nice_address_equal_no_port (const NiceAddress *a, const NiceAddress *b);
259 * nice_address_to_string:
260 * @addr: The #NiceAddress to query
261 * @dst: The string to fill
263 * Transforms the address @addr into a human readable string
267 nice_address_to_string (const NiceAddress *addr, gchar *dst);
270 * nice_address_is_private:
271 * @addr: The #NiceAddress to query
273 * Verifies if the address in @addr is a private address or not
275 * Returns: %TRUE if @addr is a private address, %FALSE otherwise
278 nice_address_is_private (const NiceAddress *addr);
281 * nice_address_is_valid:
282 * @addr: The #NiceAddress to query
284 * Validate whether the #NiceAddress @addr is a valid IPv4 or IPv6 address
286 * Returns: %TRUE if @addr is valid, %FALSE otherwise
288 G_GNUC_WARN_UNUSED_RESULT
290 nice_address_is_valid (const NiceAddress *addr);
293 * nice_address_ip_version:
294 * @addr: The #NiceAddress to query
296 * Returns the IP version of the address
298 * Returns: 4 for IPv4, 6 for IPv6 and 0 for undefined address
300 G_GNUC_WARN_UNUSED_RESULT
302 nice_address_ip_version (const NiceAddress *addr);
306 #endif /* __LIBNICE_ADDRESS_H__ */