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.
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.
60 #include <sys/types.h>
61 #include <sys/socket.h>
62 #include <netinet/in.h>
63 #include <arpa/inet.h>
71 * @addr: Generic sockaddr address
72 * @ip4: IPv4 sockaddr address
73 * @ip6: IPv6 sockaddr address
75 * The #NiceAddress structure that represents an IPv4 or IPv6 address.
82 struct sockaddr_in ip4
;
83 struct sockaddr_in6 ip6
;
89 * NICE_ADDRESS_STRING_LEN:
91 * The maximum string length representation of an address.
92 * When using nice_address_to_string() make sure the string has a size of
93 * at least %NICE_ADDRESS_STRING_LEN
95 #define NICE_ADDRESS_STRING_LEN INET6_ADDRSTRLEN
97 typedef struct _NiceAddress NiceAddress
;
102 * @addr: The #NiceAddress to init
104 * Initialize a #NiceAddress into an undefined address
107 nice_address_init (NiceAddress
*addr
);
112 * Create a new #NiceAddress with undefined address
113 * You must free it with nice_address_free()
115 * Returns: The new #NiceAddress
118 nice_address_new (void);
122 * @addr: The #NiceAddress to free
124 * Frees a #NiceAddress created with nice_address_new() or nice_address_dup()
127 nice_address_free (NiceAddress
*addr
);
131 * @addr: The #NiceAddress to dup
133 * Creates a new #NiceAddress with the same address as @addr
135 * Returns: The new #NiceAddress
138 nice_address_dup (const NiceAddress
*addr
);
142 * nice_address_set_ipv4:
143 * @addr: The #NiceAddress to modify
144 * @addr_ipv4: The IPv4 address
146 * Set @addr to an IPv4 address using the data from @addr_ipv4
150 This function will reset the port to 0, so make sure you call it before
151 nice_address_set_port()
156 nice_address_set_ipv4 (NiceAddress
*addr
, guint32 addr_ipv4
);
160 * nice_address_set_ipv6:
161 * @addr: The #NiceAddress to modify
162 * @addr_ipv6: The IPv6 address
164 * Set @addr to an IPv6 address using the data from @addr_ipv6
168 This function will reset the port to 0, so make sure you call it before
169 nice_address_set_port()
174 nice_address_set_ipv6 (NiceAddress
*addr
, const guchar
*addr_ipv6
);
178 * nice_address_set_port:
179 * @addr: The #NiceAddress to modify
180 * @port: The port to set
182 * Set the port of @addr to @port
185 nice_address_set_port (NiceAddress
*addr
, guint port
);
188 * nice_address_get_port:
189 * @addr: The #NiceAddress to query
191 * Retreive the port of @addr
193 * Returns: The port of @addr
196 nice_address_get_port (const NiceAddress
*addr
);
199 * nice_address_set_from_string:
200 * @addr: The #NiceAddress to modify
201 * @str: The string to set
203 * Sets an IPv4 or IPv6 address from the string @str
205 * Returns: %TRUE if success, %FALSE on error
208 nice_address_set_from_string (NiceAddress
*addr
, const gchar
*str
);
211 * nice_address_set_from_sockaddr:
212 * @addr: The #NiceAddress to modify
213 * @sin: The sockaddr to set
215 * Sets an IPv4 or IPv6 address from the sockaddr structure @sin
219 nice_address_set_from_sockaddr (NiceAddress
*addr
, const struct sockaddr
*sin
);
223 * nice_address_copy_to_sockaddr:
224 * @addr: The #NiceAddress to query
225 * @sin: The sockaddr to fill
227 * Fills the sockaddr structure @sin with the address contained in @addr
231 nice_address_copy_to_sockaddr (const NiceAddress
*addr
, struct sockaddr
*sin
);
234 * nice_address_equal:
235 * @a: First #NiceAddress to compare
236 * @b: Second #NiceAddress to compare
238 * Compares two #NiceAddress structures to see if they contain the same address
240 * Returns: %TRUE if @a and @b are the same address, %FALSE if they are different
243 nice_address_equal (const NiceAddress
*a
, const NiceAddress
*b
);
246 * nice_address_to_string:
247 * @addr: The #NiceAddress to query
248 * @dst: The string to fill
250 * Transforms the address @addr into a human readable string
254 nice_address_to_string (const NiceAddress
*addr
, gchar
*dst
);
257 * nice_address_is_private:
258 * @addr: The #NiceAddress to query
260 * Verifies if the address in @addr is a private address or not
262 * Returns: %TRUE if @addr is a private address, %FALSE otherwise
265 nice_address_is_private (const NiceAddress
*addr
);
268 * nice_address_is_valid:
269 * @addr: The #NiceAddress to query
271 * Validate whether the #NiceAddress @addr is a valid IPv4 or IPv6 address
273 * Returns: %TRUE if @addr is valid, %FALSE otherwise
275 G_GNUC_WARN_UNUSED_RESULT
277 nice_address_is_valid (const NiceAddress
*addr
);
281 #endif /* _ADDRESS_H */