Fix ginetaddress.c compile on Linux
[platform/upstream/glib.git] / gio / ginetaddress.c
1 /* GIO - GLib Input, Output and Streaming Library
2  *
3  * Copyright (C) 2008 Christian Kellner, Samuel Cormier-Iijima
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Authors: Christian Kellner <gicmo@gnome.org>
21  *          Samuel Cormier-Iijima <sciyoshi@gmail.com>
22  */
23
24 #include <config.h>
25
26 #include <string.h>
27
28 #include <glib.h>
29
30 #include "ginetaddress.h"
31 #include "gioenums.h"
32 #include "gioenumtypes.h"
33 #include "glibintl.h"
34 #include "gnetworkingprivate.h"
35
36 #include "gioalias.h"
37
38 /**
39  * SECTION:ginetaddress
40  * @short_description: An IPv4/IPv6 address
41  *
42  * #GInetAddress represents an IPv4 or IPv6 internet address. Use
43  * g_resolver_lookup_by_name() or g_resolver_lookup_by_name_async() to
44  * look up the #GInetAddress for a hostname. Use
45  * g_resolver_lookup_by_address() or
46  * g_resolver_lookup_by_address_async() to look up the hostname for a
47  * #GInetAddress.
48  *
49  * To actually connect to a remote host, you will need a
50  * #GInetSocketAddress (which includes a #GInetAddress as well as a
51  * port number).
52  **/
53
54 /**
55  * GInetAddress:
56  *
57  * An IPv4 or IPv6 internet address.
58  **/
59
60 /* Networking initialization function, called from inside the g_once of
61  * g_inet_address_get_type()
62  */
63 static void
64 _g_networking_init (void)
65 {
66 #ifdef G_OS_WIN32
67   WSADATA wsadata;
68   if (WSAStartup (MAKEWORD (2, 0), &wsadata) != 0)
69     g_error ("Windows Sockets could not be initialized");
70 #endif
71 }
72
73 G_DEFINE_TYPE_WITH_CODE (GInetAddress, g_inet_address, G_TYPE_OBJECT,
74                          _g_networking_init ();)
75
76 struct _GInetAddressPrivate
77 {
78   GSocketFamily family;
79   union {
80     struct in_addr ipv4;
81     struct in6_addr ipv6;
82   } addr;
83 };
84
85 enum
86 {
87   PROP_0,
88   PROP_FAMILY,
89   PROP_BYTES,
90   PROP_IS_ANY,
91   PROP_IS_LOOPBACK,
92   PROP_IS_LINK_LOCAL,
93   PROP_IS_SITE_LOCAL,
94   PROP_IS_MULTICAST,
95   PROP_IS_MC_GLOBAL,
96   PROP_IS_MC_LINK_LOCAL,
97   PROP_IS_MC_NODE_LOCAL,
98   PROP_IS_MC_ORG_LOCAL,
99   PROP_IS_MC_SITE_LOCAL,
100 };
101
102 static void
103 g_inet_address_set_property (GObject      *object,
104                              guint         prop_id,
105                              const GValue *value,
106                              GParamSpec   *pspec)
107 {
108   GInetAddress *address = G_INET_ADDRESS (object);
109
110   switch (prop_id) 
111     {
112     case PROP_FAMILY:
113       address->priv->family = g_value_get_enum (value);
114       break;
115
116     case PROP_BYTES:
117       memcpy (&address->priv->addr, g_value_get_pointer (value),
118               address->priv->family == AF_INET ?
119               sizeof (address->priv->addr.ipv4) :
120               sizeof (address->priv->addr.ipv6));
121       break;
122
123     default:
124       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
125       break;
126     }
127
128 }
129
130 static void
131 g_inet_address_get_property (GObject    *object,
132                              guint       prop_id,
133                              GValue     *value,
134                              GParamSpec *pspec)
135 {
136   GInetAddress *address = G_INET_ADDRESS (object);
137
138   switch (prop_id)
139     {
140     case PROP_FAMILY:
141       g_value_set_enum (value, address->priv->family);
142       break;
143
144     case PROP_BYTES:
145       g_value_set_pointer (value, &address->priv->addr);
146       break;
147
148     case PROP_IS_ANY:
149       g_value_set_boolean (value, g_inet_address_get_is_any (address));
150       break;
151
152     case PROP_IS_LOOPBACK:
153       g_value_set_boolean (value, g_inet_address_get_is_loopback (address));
154       break;
155
156     case PROP_IS_LINK_LOCAL:
157       g_value_set_boolean (value, g_inet_address_get_is_link_local (address));
158       break;
159
160     case PROP_IS_SITE_LOCAL:
161       g_value_set_boolean (value, g_inet_address_get_is_site_local (address));
162       break;
163
164     case PROP_IS_MULTICAST:
165       g_value_set_boolean (value, g_inet_address_get_is_multicast (address));
166       break;
167
168     case PROP_IS_MC_GLOBAL:
169       g_value_set_boolean (value, g_inet_address_get_is_mc_global (address));
170       break;
171
172     case PROP_IS_MC_LINK_LOCAL:
173       g_value_set_boolean (value, g_inet_address_get_is_mc_link_local (address));
174       break;
175
176     case PROP_IS_MC_NODE_LOCAL:
177       g_value_set_boolean (value, g_inet_address_get_is_mc_node_local (address));
178       break;
179
180     case PROP_IS_MC_ORG_LOCAL:
181       g_value_set_boolean (value, g_inet_address_get_is_mc_org_local (address));
182       break;
183
184     case PROP_IS_MC_SITE_LOCAL:
185       g_value_set_boolean (value, g_inet_address_get_is_mc_site_local (address));
186       break;
187
188     default:
189       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
190     }
191 }
192
193 static void
194 g_inet_address_class_init (GInetAddressClass *klass)
195 {
196   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
197
198   g_type_class_add_private (klass, sizeof (GInetAddressPrivate));
199
200   gobject_class->set_property = g_inet_address_set_property;
201   gobject_class->get_property = g_inet_address_get_property;
202
203   g_object_class_install_property (gobject_class, PROP_FAMILY,
204                                    g_param_spec_enum ("family",
205                                                       P_("Address family"),
206                                                       P_("The address family (IPv4 or IPv6)"),
207                                                       G_TYPE_SOCKET_FAMILY,
208                                                       G_SOCKET_FAMILY_INVALID,
209                                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
210
211   g_object_class_install_property (gobject_class, PROP_BYTES,
212                                    g_param_spec_pointer ("bytes",
213                                                          P_("Bytes"),
214                                                          P_("The raw address data"),
215                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
216
217   g_object_class_install_property (gobject_class, PROP_IS_ANY,
218                                    g_param_spec_boolean ("is-any",
219                                                          P_("Is any"),
220                                                          P_("See g_inet_address_get_is_any()"),
221                                                          FALSE,
222                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
223
224   g_object_class_install_property (gobject_class, PROP_IS_LINK_LOCAL,
225                                    g_param_spec_boolean ("is-link-local",
226                                                          P_("Is link-local"),
227                                                          P_("See g_inet_address_get_is_link_local()"),
228                                                          FALSE,
229                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
230
231   g_object_class_install_property (gobject_class, PROP_IS_LOOPBACK,
232                                    g_param_spec_boolean ("is-loopback",
233                                                          P_("Is loopback"),
234                                                          P_("See g_inet_address_get_is_loopback()"),
235                                                          FALSE,
236                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
237
238   g_object_class_install_property (gobject_class, PROP_IS_SITE_LOCAL,
239                                    g_param_spec_boolean ("is-site-local",
240                                                          P_("Is site-local"),
241                                                          P_("See g_inet_address_get_is_site_local()"),
242                                                          FALSE,
243                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
244
245   g_object_class_install_property (gobject_class, PROP_IS_MULTICAST,
246                                    g_param_spec_boolean ("is-multicast",
247                                                          P_("Is multicast"),
248                                                          P_("See g_inet_address_get_is_multicast()"),
249                                                          FALSE,
250                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
251
252   g_object_class_install_property (gobject_class, PROP_IS_MC_GLOBAL,
253                                    g_param_spec_boolean ("is-mc-global",
254                                                          P_("Is multicast global"),
255                                                          P_("See g_inet_address_get_is_mc_global()"),
256                                                          FALSE,
257                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
258
259   g_object_class_install_property (gobject_class, PROP_IS_MC_LINK_LOCAL,
260                                    g_param_spec_boolean ("is-mc-link-local",
261                                                          P_("Is multicast link-local"),
262                                                          P_("See g_inet_address_get_is_mc_link_local()"),
263                                                          FALSE,
264                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
265
266   g_object_class_install_property (gobject_class, PROP_IS_MC_NODE_LOCAL,
267                                    g_param_spec_boolean ("is-mc-node-local",
268                                                          P_("Is multicast node-local"),
269                                                          P_("See g_inet_address_get_is_mc_node_local()"),
270                                                          FALSE,
271                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
272
273   g_object_class_install_property (gobject_class, PROP_IS_MC_ORG_LOCAL,
274                                    g_param_spec_boolean ("is-mc-org-local",
275                                                          P_("Is multicast org-local"),
276                                                          P_("See g_inet_address_get_is_mc_org_local()"),
277                                                          FALSE,
278                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
279
280   g_object_class_install_property (gobject_class, PROP_IS_MC_SITE_LOCAL,
281                                    g_param_spec_boolean ("is-mc-site-local",
282                                                          P_("Is multicast site-local"),
283                                                          P_("See g_inet_address_get_is_mc_site_local()"),
284                                                          FALSE,
285                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
286 }
287
288 static void
289 g_inet_address_init (GInetAddress *address)
290 {
291   address->priv = G_TYPE_INSTANCE_GET_PRIVATE (address,
292                                                G_TYPE_INET_ADDRESS,
293                                                GInetAddressPrivate);
294 }
295
296 /**
297  * g_inet_address_new_from_string:
298  * @string: a string representation of an IP address
299  *
300  * Parses @string as an IP address and creates a new #GInetAddress.
301  *
302  * Returns: a new #GInetAddress corresponding to @string, or %NULL if
303  * @string could not be parsed.
304  *
305  * Since: 2.22
306  */
307 GInetAddress *
308 g_inet_address_new_from_string (const gchar *string)
309 {
310   volatile GType type;
311 #ifdef G_OS_WIN32
312   struct sockaddr_storage sa;
313   struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
314   struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa;
315   gint len;
316 #else /* !G_OS_WIN32 */
317   struct in_addr in_addr;
318   struct in6_addr in6_addr;
319 #endif
320
321   /* Make sure _g_networking_init() has been called */
322   type = g_inet_address_get_type ();
323
324 #ifdef G_OS_WIN32
325   memset (&sa, 0, sizeof (sa));
326   len = sizeof (sa);
327   if (WSAStringToAddress ((LPTSTR) string, AF_INET, NULL, (LPSOCKADDR) &sa, &len) == 0)
328     return g_inet_address_new_from_bytes ((guint8 *)&sin->sin_addr, AF_INET);
329   else if (WSAStringToAddress ((LPTSTR) string, AF_INET6, NULL, (LPSOCKADDR) &sa, &len) == 0)
330     return g_inet_address_new_from_bytes ((guint8 *)&sin6->sin6_addr, AF_INET6);
331
332 #else /* !G_OS_WIN32 */
333
334   if (inet_pton (AF_INET, string, &in_addr) > 0)
335     return g_inet_address_new_from_bytes ((guint8 *)&in_addr, AF_INET);
336   else if (inet_pton (AF_INET6, string, &in6_addr) > 0)
337     return g_inet_address_new_from_bytes ((guint8 *)&in6_addr, AF_INET6);
338 #endif
339
340   return NULL;
341 }
342
343 #define G_INET_ADDRESS_FAMILY_IS_VALID(family) ((family) == AF_INET || (family) == AF_INET6)
344
345 /**
346  * g_inet_address_new_from_bytes:
347  * @bytes: raw address data
348  * @family: the address family of @bytes
349  *
350  * Creates a new #GInetAddress from the given @family and @bytes.
351  * @bytes should be 4 bytes for %G_INET_ADDRESS_IPV4 and 16 bytes for
352  * %G_INET_ADDRESS_IPV6.
353  *
354  * Returns: a new #GInetAddress corresponding to @family and @bytes.
355  *
356  * Since: 2.22
357  */
358 GInetAddress *
359 g_inet_address_new_from_bytes (const guint8         *bytes,
360                                GSocketFamily  family)
361 {
362   g_return_val_if_fail (G_INET_ADDRESS_FAMILY_IS_VALID (family), NULL);
363
364   return g_object_new (G_TYPE_INET_ADDRESS,
365                        "family", family,
366                        "bytes", bytes,
367                        NULL);
368 }
369
370 /**
371  * g_inet_address_new_loopback:
372  * @family: the address family
373  *
374  * Creates a #GInetAddress for the loopback address for @family.
375  *
376  * Returns: a new #GInetAddress corresponding to the loopback address
377  * for @family.
378  *
379  * Since: 2.22
380  */
381 GInetAddress *
382 g_inet_address_new_loopback (GSocketFamily family)
383 {
384   g_return_val_if_fail (G_INET_ADDRESS_FAMILY_IS_VALID (family), NULL);
385
386   if (family == AF_INET)
387     {    
388       guint8 addr[4] = {127, 0, 0, 1};
389
390       return g_inet_address_new_from_bytes (addr, family);
391     }
392   else
393     return g_inet_address_new_from_bytes (in6addr_loopback.s6_addr, family);
394 }
395
396 /**
397  * g_inet_address_new_any:
398  * @family: the address family
399  *
400  * Creates a #GInetAddress for the "any" address (unassigned/"don't
401  * care") for @family.
402  *
403  * Returns: a new #GInetAddress corresponding to the "any" address
404  * for @family.
405  *
406  * Since: 2.22
407  */
408 GInetAddress *
409 g_inet_address_new_any (GSocketFamily family)
410 {
411   g_return_val_if_fail (G_INET_ADDRESS_FAMILY_IS_VALID (family), NULL);
412
413   if (family == AF_INET)
414     {    
415       guint8 addr[4] = {0, 0, 0, 0};
416
417       return g_inet_address_new_from_bytes (addr, family);
418     }
419   else
420     return g_inet_address_new_from_bytes (in6addr_any.s6_addr, family);
421 }
422
423
424 /**
425  * g_inet_address_to_string:
426  * @address: a #GInetAddress
427  *
428  * Converts @address to string form.
429  *
430  * Returns: a representation of @address as a string, which should be
431  * freed after use.
432  *
433  * Since: 2.22
434  */
435 gchar *
436 g_inet_address_to_string (GInetAddress *address)
437 {
438   gchar buffer[INET6_ADDRSTRLEN];
439 #ifdef G_OS_WIN32
440   DWORD buflen = sizeof (buffer), addrlen;
441   struct sockaddr_storage sa;
442   struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
443   struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa;
444 #endif
445
446   g_return_val_if_fail (G_IS_INET_ADDRESS (address), NULL);
447
448 #ifdef G_OS_WIN32
449   sa.ss_family = address->priv->family;
450   if (address->priv->family == AF_INET)
451     {
452       addrlen = sizeof (*sin);
453       memcpy (&sin->sin_addr, &address->priv->addr.ipv4,
454               sizeof (sin->sin_addr));
455       sin->sin_port = 0;
456     }
457   else
458     {
459       addrlen = sizeof (*sin6);
460       memcpy (&sin6->sin6_addr, &address->priv->addr.ipv6,
461               sizeof (sin6->sin6_addr));
462       sin6->sin6_port = 0;
463     }
464   if (WSAAddressToString ((LPSOCKADDR) &sa, addrlen, NULL, buffer, &buflen) != 0)
465     return NULL;
466
467 #else /* !G_OS_WIN32 */
468
469   if (address->priv->family == AF_INET)
470     inet_ntop (AF_INET, &address->priv->addr.ipv4, buffer, sizeof (buffer));
471   else
472     inet_ntop (AF_INET6, &address->priv->addr.ipv6, buffer, sizeof (buffer));
473 #endif
474
475   return g_strdup (buffer);
476 }
477
478 /**
479  * g_inet_address_to_bytes:
480  * @address: a #GInetAddress
481  *
482  * Gets the raw binary address data from @address.
483  *
484  * Returns: a pointer to an internal array of the bytes in @address,
485  * which should not be modified, stored, or freed.
486  *
487  * Since: 2.22
488  */
489 const guint8 *
490 g_inet_address_to_bytes (GInetAddress *address)
491 {
492   g_return_val_if_fail (G_IS_INET_ADDRESS (address), NULL);
493
494   return (guint8 *)&address->priv->addr;
495 }
496
497 /**
498  * g_inet_address_get_family:
499  * @address: a #GInetAddress
500  *
501  * Gets @address's family
502  *
503  * Returns: @address's family
504  *
505  * Since: 2.22
506  */
507 GSocketFamily
508 g_inet_address_get_family (GInetAddress *address)
509 {
510   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
511
512   return address->priv->family;
513 }
514
515 /**
516  * g_inet_address_get_is_any:
517  * @address: a #GInetAddress
518  *
519  * Tests whether @address is the "any" address for its family.
520  *
521  * Returns: %TRUE if @address is the "any" address for its family.
522  *
523  * Since: 2.22
524  */
525 gboolean
526 g_inet_address_get_is_any (GInetAddress *address)
527 {
528   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
529
530   if (address->priv->family == AF_INET)
531     {
532       guint32 addr4 = g_ntohl (address->priv->addr.ipv4.s_addr);
533
534       return addr4 == INADDR_ANY;
535     }
536   else
537     return IN6_IS_ADDR_UNSPECIFIED (&address->priv->addr.ipv6);
538 }
539
540 /**
541  * g_inet_address_get_is_loopback:
542  * @address: a #GInetAddress
543  *
544  * Tests whether @address is the loopback address for its family.
545  *
546  * Returns: %TRUE if @address is the loopback address for its family.
547  *
548  * Since: 2.22
549  */
550 gboolean
551 g_inet_address_get_is_loopback (GInetAddress *address)
552 {
553   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
554
555   if (address->priv->family == AF_INET)
556     {
557       guint32 addr4 = g_ntohl (address->priv->addr.ipv4.s_addr);
558
559       /* 127.0.0.0/8 */
560       return ((addr4 & 0xff000000) == 0x7f000000);
561     }
562   else
563     return IN6_IS_ADDR_LOOPBACK (&address->priv->addr.ipv6);
564 }
565
566 /**
567  * g_inet_address_get_is_link_local:
568  * @address: a #GInetAddress
569  *
570  * Tests whether @address is a link-local address (that is, if it
571  * identifies a host on a local network that is not connected to the
572  * Internet).
573  *
574  * Returns: %TRUE if @address is a link-local address.
575  *
576  * Since: 2.22
577  */
578 gboolean
579 g_inet_address_get_is_link_local (GInetAddress *address)
580 {
581   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
582
583   if (address->priv->family == AF_INET)
584     {
585       guint32 addr4 = g_ntohl (address->priv->addr.ipv4.s_addr);
586
587       /* 169.254.0.0/16 */
588       return ((addr4 & 0xffff0000) == 0xa9fe0000);
589     }
590   else
591     return IN6_IS_ADDR_LINKLOCAL (&address->priv->addr.ipv6);
592 }
593
594 /**
595  * g_inet_address_get_is_site_local:
596  * @address: a #GInetAddress
597  *
598  * Tests whether @address is a site-local address such as 10.0.0.1
599  * (that is, the address identifies a host on a local network that can
600  * not be reached directly from the Internet, but which may have
601  * outgoing Internet connectivity via a NAT or firewall).
602  *
603  * Returns: %TRUE if @address is a site-local address.
604  *
605  * Since: 2.22
606  */
607 gboolean
608 g_inet_address_get_is_site_local (GInetAddress *address)
609 {
610   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
611
612   if (address->priv->family == AF_INET)
613     {
614       guint32 addr4 = g_ntohl (address->priv->addr.ipv4.s_addr);
615
616       /* 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 */
617       return ((addr4 & 0xff000000) == 0x0a000000 ||
618               (addr4 & 0xfff00000) == 0xac100000 ||
619               (addr4 & 0xffff0000) == 0xc0a80000);
620     }
621   else
622     return IN6_IS_ADDR_SITELOCAL (&address->priv->addr.ipv6);
623 }
624
625 /**
626  * g_inet_address_get_is_multicast:
627  * @address: a #GInetAddress
628  *
629  * Tests whether @address is a multicast address.
630  *
631  * Returns: %TRUE if @address is a multicast address.
632  *
633  * Since: 2.22
634  */
635 gboolean
636 g_inet_address_get_is_multicast (GInetAddress *address)
637 {
638   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
639
640   if (address->priv->family == AF_INET)
641     {
642       guint32 addr4 = g_ntohl (address->priv->addr.ipv4.s_addr);
643
644       return IN_MULTICAST (addr4);
645     }
646   else
647     return IN6_IS_ADDR_MULTICAST (&address->priv->addr.ipv6);
648 }
649
650 /**
651  * g_inet_address_get_is_mc_global:
652  * @address: a #GInetAddress
653  *
654  * Tests whether @address is a global multicast address.
655  *
656  * Returns: %TRUE if @address is a global multicast address.
657  *
658  * Since: 2.22
659  */
660 gboolean
661 g_inet_address_get_is_mc_global (GInetAddress *address)
662 {
663   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
664
665   if (address->priv->family == AF_INET)
666     return FALSE;
667   else
668     return IN6_IS_ADDR_MC_GLOBAL (&address->priv->addr.ipv6);
669 }
670
671 /**
672  * g_inet_address_get_is_mc_link_local:
673  * @address: a #GInetAddress
674  *
675  * Tests whether @address is a link-local multicast address.
676  *
677  * Returns: %TRUE if @address is a link-local multicast address.
678  *
679  * Since: 2.22
680  */
681 gboolean
682 g_inet_address_get_is_mc_link_local (GInetAddress *address)
683 {
684   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
685
686   if (address->priv->family == AF_INET)
687     return FALSE;
688   else
689     return IN6_IS_ADDR_MC_LINKLOCAL (&address->priv->addr.ipv6);
690 }
691
692 /**
693  * g_inet_address_get_is_mc_node_local:
694  * @address: a #GInetAddress
695  *
696  * Tests whether @address is a node-local multicast address.
697  *
698  * Returns: %TRUE if @address is a node-local multicast address.
699  *
700  * Since: 2.22
701  */
702 gboolean
703 g_inet_address_get_is_mc_node_local (GInetAddress *address)
704 {
705   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
706
707   if (address->priv->family == AF_INET)
708     return FALSE;
709   else
710     return IN6_IS_ADDR_MC_NODELOCAL (&address->priv->addr.ipv6);
711 }
712
713 /**
714  * g_inet_address_get_is_mc_org_local:
715  * @address: a #GInetAddress
716  *
717  * Tests whether @address is an organization-local multicast address.
718  *
719  * Returns: %TRUE if @address is an organization-local multicast address.
720  *
721  * Since: 2.22
722  */
723 gboolean
724 g_inet_address_get_is_mc_org_local  (GInetAddress *address)
725 {
726   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
727
728   if (address->priv->family == AF_INET)
729     return FALSE;
730   else
731     return IN6_IS_ADDR_MC_ORGLOCAL (&address->priv->addr.ipv6);
732 }
733
734 /**
735  * g_inet_address_get_is_mc_site_local:
736  * @address: a #GInetAddress
737  *
738  * Tests whether @address is a site-local multicast address.
739  *
740  * Returns: %TRUE if @address is a site-local multicast address.
741  *
742  * Since: 2.22
743  */
744 gboolean
745 g_inet_address_get_is_mc_site_local (GInetAddress *address)
746 {
747   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
748
749   if (address->priv->family == AF_INET)
750     return FALSE;
751   else
752     return IN6_IS_ADDR_MC_SITELOCAL (&address->priv->addr.ipv6);
753 }
754
755 #define __G_INET_ADDRESS_C__
756 #include "gioaliasdef.c"