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.
59 #include <sys/types.h>
60 #include <sys/socket.h>
61 #include <netinet/in.h>
62 #include <arpa/inet.h>
70 * @addr: Generic sockaddr address
71 * @ip4: IPv4 sockaddr address
72 * @ip6: IPv6 sockaddr address
74 * The #NiceAddress structure that represents an IPv4 or IPv6 address.
81 struct sockaddr_in ip4
;
82 struct sockaddr_in6 ip6
;
88 * NICE_ADDRESS_STRING_LEN:
90 * The maximum string length representation of an address.
91 * When using nice_address_to_string() make sure the string has a size of
92 * at least %NICE_ADDRESS_STRING_LEN
94 #define NICE_ADDRESS_STRING_LEN INET6_ADDRSTRLEN
96 typedef struct _NiceAddress NiceAddress
;
101 * @addr: The #NiceAddress to init
103 * Initialize a #NiceAddress into an undefined address
106 nice_address_init (NiceAddress
*addr
);
111 * Create a new #NiceAddress with undefined address
112 * You must free it with nice_address_free()
114 * Returns: The new #NiceAddress
117 nice_address_new (void);
121 * @addr: The #NiceAddress to free
123 * Frees a #NiceAddress created with nice_address_new() or nice_address_dup()
126 nice_address_free (NiceAddress
*addr
);
130 * @addr: The #NiceAddress to dup
132 * Creates a new #NiceAddress with the same address as @addr
134 * Returns: The new #NiceAddress
137 nice_address_dup (const NiceAddress
*addr
);
141 * nice_address_set_ipv4:
142 * @addr: The #NiceAddress to modify
143 * @addr_ipv4: The IPv4 address
145 * Set @addr to an IPv4 address using the data from @addr_ipv4
149 This function will reset the port to 0, so make sure you call it before
150 nice_address_set_port()
155 nice_address_set_ipv4 (NiceAddress
*addr
, guint32 addr_ipv4
);
159 * nice_address_set_ipv6:
160 * @addr: The #NiceAddress to modify
161 * @addr_ipv6: The IPv6 address
163 * Set @addr to an IPv6 address using the data from @addr_ipv6
167 This function will reset the port to 0, so make sure you call it before
168 nice_address_set_port()
173 nice_address_set_ipv6 (NiceAddress
*addr
, const guchar
*addr_ipv6
);
177 * nice_address_set_port:
178 * @addr: The #NiceAddress to modify
179 * @port: The port to set
181 * Set the port of @addr to @port
184 nice_address_set_port (NiceAddress
*addr
, guint port
);
187 * nice_address_get_port:
188 * @addr: The #NiceAddress to query
190 * Retreive the port of @addr
192 * Returns: The port of @addr
195 nice_address_get_port (const NiceAddress
*addr
);
198 * nice_address_set_from_string:
199 * @addr: The #NiceAddress to modify
200 * @str: The string to set
202 * Sets an IPv4 or IPv6 address from the string @str
204 * Returns: %TRUE if success, %FALSE on error
207 nice_address_set_from_string (NiceAddress
*addr
, const gchar
*str
);
210 * nice_address_set_from_sockaddr:
211 * @addr: The #NiceAddress to modify
212 * @sin: The sockaddr to set
214 * Sets an IPv4 or IPv6 address from the sockaddr structure @sin
218 nice_address_set_from_sockaddr (NiceAddress
*addr
, const struct sockaddr
*sin
);
222 * nice_address_copy_to_sockaddr:
223 * @addr: The #NiceAddress to query
224 * @sin: The sockaddr to fill
226 * Fills the sockaddr structure @sin with the address contained in @addr
230 nice_address_copy_to_sockaddr (const NiceAddress
*addr
, struct sockaddr
*sin
);
233 * nice_address_equal:
234 * @a: First #NiceAddress to compare
235 * @b: Second #NiceAddress to compare
237 * Compares two #NiceAddress structures to see if they contain the same address
239 * Returns: %TRUE if @a and @b are the same address, %FALSE if they are different
242 nice_address_equal (const NiceAddress
*a
, const NiceAddress
*b
);
245 * nice_address_to_string:
246 * @addr: The #NiceAddress to query
247 * @dst: The string to fill
249 * Transforms the address @addr into a human readable string
253 nice_address_to_string (const NiceAddress
*addr
, gchar
*dst
);
256 * nice_address_is_private:
257 * @addr: The #NiceAddress to query
259 * Verifies if the address in @addr is a private address or not
261 * Returns: %TRUE if @addr is a private address, %FALSE otherwise
264 nice_address_is_private (const NiceAddress
*addr
);
267 * nice_address_is_valid:
268 * @addr: The #NiceAddress to query
270 * Validate whether the #NiceAddress @addr is a valid IPv4 or IPv6 address
272 * Returns: %TRUE if @addr is valid, %FALSE otherwise
274 G_GNUC_WARN_UNUSED_RESULT
276 nice_address_is_valid (const NiceAddress
*addr
);
280 #endif /* _ADDRESS_H */