PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/agent/address.h

https://gitlab.com/libnice/libnice
C Header | 307 lines | 62 code | 36 blank | 209 comment | 0 complexity | 2e837380b94e4112958fc7aeb1f1df38 MD5 | raw file
  1. /*
  2. * This file is part of the Nice GLib ICE library.
  3. *
  4. * (C) 2006-2009 Collabora Ltd.
  5. * Contact: Youness Alaoui
  6. * (C) 2006-2009 Nokia Corporation. All rights reserved.
  7. * Contact: Kai Vehmanen
  8. *
  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/
  13. *
  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
  17. * License.
  18. *
  19. * The Original Code is the Nice GLib ICE library.
  20. *
  21. * The Initial Developers of the Original Code are Collabora Ltd and Nokia
  22. * Corporation. All Rights Reserved.
  23. *
  24. * Contributors:
  25. * Youness Alaoui, Collabora Ltd.
  26. * Dafydd Harries, Collabora Ltd.
  27. * Kai Vehmanen
  28. *
  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.
  38. */
  39. #ifndef __LIBNICE_ADDRESS_H__
  40. #define __LIBNICE_ADDRESS_H__
  41. /**
  42. * SECTION:address
  43. * @short_description: IP address convenience library
  44. * @stability: Stable
  45. *
  46. * The #NiceAddress structure will allow you to easily set/get and modify an IPv4
  47. * or IPv6 address in order to communicate with the #NiceAgent.
  48. */
  49. #include <glib.h>
  50. #ifdef G_OS_WIN32
  51. #include <winsock2.h>
  52. #include <ws2tcpip.h>
  53. #else
  54. #include <sys/types.h>
  55. #include <sys/socket.h>
  56. #include <netinet/in.h>
  57. #include <arpa/inet.h>
  58. #endif
  59. G_BEGIN_DECLS
  60. /**
  61. * NiceAddress:
  62. *
  63. * The #NiceAddress structure that represents an IPv4 or IPv6 address.
  64. */
  65. struct _NiceAddress
  66. {
  67. union
  68. {
  69. struct sockaddr addr;
  70. struct sockaddr_in ip4;
  71. struct sockaddr_in6 ip6;
  72. } s;
  73. };
  74. /**
  75. * NICE_ADDRESS_STRING_LEN:
  76. *
  77. * The maximum string length representation of an address.
  78. * When using nice_address_to_string() make sure the string has a size of
  79. * at least %NICE_ADDRESS_STRING_LEN
  80. */
  81. #define NICE_ADDRESS_STRING_LEN INET6_ADDRSTRLEN
  82. typedef struct _NiceAddress NiceAddress;
  83. /**
  84. * nice_address_init:
  85. * @addr: The #NiceAddress to init
  86. *
  87. * Initialize a #NiceAddress into an undefined address
  88. */
  89. void
  90. nice_address_init (NiceAddress *addr);
  91. /**
  92. * nice_address_new:
  93. *
  94. * Create a new #NiceAddress with undefined address
  95. * You must free it with nice_address_free()
  96. *
  97. * Returns: The new #NiceAddress
  98. */
  99. NiceAddress *
  100. nice_address_new (void);
  101. /**
  102. * nice_address_free:
  103. * @addr: The #NiceAddress to free
  104. *
  105. * Frees a #NiceAddress created with nice_address_new() or nice_address_dup()
  106. */
  107. void
  108. nice_address_free (NiceAddress *addr);
  109. /**
  110. * nice_address_dup:
  111. * @addr: The #NiceAddress to dup
  112. *
  113. * Creates a new #NiceAddress with the same address as @addr
  114. *
  115. * Returns: The new #NiceAddress
  116. */
  117. NiceAddress *
  118. nice_address_dup (const NiceAddress *addr);
  119. /**
  120. * nice_address_set_ipv4:
  121. * @addr: The #NiceAddress to modify
  122. * @addr_ipv4: The IPv4 address
  123. *
  124. * Set @addr to an IPv4 address using the data from @addr_ipv4
  125. *
  126. <note>
  127. <para>
  128. This function will reset the port to 0, so make sure you call it before
  129. nice_address_set_port()
  130. </para>
  131. </note>
  132. */
  133. void
  134. nice_address_set_ipv4 (NiceAddress *addr, guint32 addr_ipv4);
  135. /**
  136. * nice_address_set_ipv6:
  137. * @addr: The #NiceAddress to modify
  138. * @addr_ipv6: The IPv6 address
  139. *
  140. * Set @addr to an IPv6 address using the data from @addr_ipv6
  141. *
  142. <note>
  143. <para>
  144. This function will reset the port to 0, so make sure you call it before
  145. nice_address_set_port()
  146. </para>
  147. </note>
  148. */
  149. void
  150. nice_address_set_ipv6 (NiceAddress *addr, const guchar *addr_ipv6);
  151. /**
  152. * nice_address_set_port:
  153. * @addr: The #NiceAddress to modify
  154. * @port: The port to set
  155. *
  156. * Set the port of @addr to @port
  157. */
  158. void
  159. nice_address_set_port (NiceAddress *addr, guint port);
  160. /**
  161. * nice_address_get_port:
  162. * @addr: The #NiceAddress to query
  163. *
  164. * Retreive the port of @addr
  165. *
  166. * Returns: The port of @addr
  167. */
  168. guint
  169. nice_address_get_port (const NiceAddress *addr);
  170. /**
  171. * nice_address_set_from_string:
  172. * @addr: The #NiceAddress to modify
  173. * @str: The string to set
  174. *
  175. * Sets an IPv4 or IPv6 address from the string @str
  176. *
  177. * Returns: %TRUE if success, %FALSE on error
  178. */
  179. gboolean
  180. nice_address_set_from_string (NiceAddress *addr, const gchar *str);
  181. /**
  182. * nice_address_set_from_sockaddr:
  183. * @addr: The #NiceAddress to modify
  184. * @sin: The sockaddr to set
  185. *
  186. * Sets an IPv4 or IPv6 address from the sockaddr structure @sin
  187. *
  188. */
  189. void
  190. nice_address_set_from_sockaddr (NiceAddress *addr, const struct sockaddr *sin);
  191. /**
  192. * nice_address_copy_to_sockaddr:
  193. * @addr: The #NiceAddress to query
  194. * @sin: The sockaddr to fill
  195. *
  196. * Fills the sockaddr structure @sin with the address contained in @addr
  197. *
  198. */
  199. void
  200. nice_address_copy_to_sockaddr (const NiceAddress *addr, struct sockaddr *sin);
  201. /**
  202. * nice_address_equal:
  203. * @a: First #NiceAddress to compare
  204. * @b: Second #NiceAddress to compare
  205. *
  206. * Compares two #NiceAddress structures to see if they contain the same address
  207. * and the same port.
  208. *
  209. * Returns: %TRUE if @a and @b are the same address, %FALSE if they are different
  210. */
  211. gboolean
  212. nice_address_equal (const NiceAddress *a, const NiceAddress *b);
  213. /**
  214. * nice_address_equal_no_port:
  215. * @a: First #NiceAddress to compare
  216. * @b: Second #NiceAddress to compare
  217. *
  218. * Compares two #NiceAddress structures to see if they contain the same address,
  219. * ignoring the port.
  220. *
  221. * Returns: %TRUE if @a and @b are the same address, %FALSE if they
  222. * are different
  223. *
  224. * Since: 0.1.8
  225. */
  226. gboolean
  227. nice_address_equal_no_port (const NiceAddress *a, const NiceAddress *b);
  228. /**
  229. * nice_address_to_string:
  230. * @addr: The #NiceAddress to query
  231. * @dst: The string to fill
  232. *
  233. * Transforms the address @addr into a human readable string
  234. *
  235. */
  236. void
  237. nice_address_to_string (const NiceAddress *addr, gchar *dst);
  238. /**
  239. * nice_address_is_private:
  240. * @addr: The #NiceAddress to query
  241. *
  242. * Verifies if the address in @addr is a private address or not
  243. *
  244. * Returns: %TRUE if @addr is a private address, %FALSE otherwise
  245. */
  246. gboolean
  247. nice_address_is_private (const NiceAddress *addr);
  248. /**
  249. * nice_address_is_valid:
  250. * @addr: The #NiceAddress to query
  251. *
  252. * Validate whether the #NiceAddress @addr is a valid IPv4 or IPv6 address
  253. *
  254. * Returns: %TRUE if @addr is valid, %FALSE otherwise
  255. */
  256. G_GNUC_WARN_UNUSED_RESULT
  257. gboolean
  258. nice_address_is_valid (const NiceAddress *addr);
  259. /**
  260. * nice_address_ip_version:
  261. * @addr: The #NiceAddress to query
  262. *
  263. * Returns the IP version of the address
  264. *
  265. * Returns: 4 for IPv4, 6 for IPv6 and 0 for undefined address
  266. */
  267. G_GNUC_WARN_UNUSED_RESULT
  268. int
  269. nice_address_ip_version (const NiceAddress *addr);
  270. G_END_DECLS
  271. #endif /* __LIBNICE_ADDRESS_H__ */