Fix the networking stuff on (current) OS X
[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 #ifdef G_OS_WIN32
311   struct sockaddr_storage sa;
312   struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
313   struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa;
314   gint len;
315 #else /* !G_OS_WIN32 */
316   struct in_addr in_addr;
317   struct in6_addr in6_addr;
318 #endif
319
320   /* Make sure _g_networking_init() has been called */
321   (void) g_inet_address_get_type ();
322
323 #ifdef G_OS_WIN32
324   memset (&sa, 0, sizeof (sa));
325   len = sizeof (sa);
326   if (WSAStringToAddress ((LPTSTR) string, AF_INET, NULL, (LPSOCKADDR) &sa, &len) == 0)
327     return g_inet_address_new_from_bytes ((guint8 *)&sin->sin_addr, AF_INET);
328   else if (WSAStringToAddress ((LPTSTR) string, AF_INET6, NULL, (LPSOCKADDR) &sa, &len) == 0)
329     return g_inet_address_new_from_bytes ((guint8 *)&sin6->sin6_addr, AF_INET6);
330
331 #else /* !G_OS_WIN32 */
332
333   if (inet_pton (AF_INET, string, &in_addr) > 0)
334     return g_inet_address_new_from_bytes ((guint8 *)&in_addr, AF_INET);
335   else if (inet_pton (AF_INET6, string, &in6_addr) > 0)
336     return g_inet_address_new_from_bytes ((guint8 *)&in6_addr, AF_INET6);
337 #endif
338
339   return NULL;
340 }
341
342 #define G_INET_ADDRESS_FAMILY_IS_VALID(family) ((family) == AF_INET || (family) == AF_INET6)
343
344 /**
345  * g_inet_address_new_from_bytes:
346  * @bytes: raw address data
347  * @family: the address family of @bytes
348  *
349  * Creates a new #GInetAddress from the given @family and @bytes.
350  * @bytes should be 4 bytes for %G_INET_ADDRESS_IPV4 and 16 bytes for
351  * %G_INET_ADDRESS_IPV6.
352  *
353  * Returns: a new #GInetAddress corresponding to @family and @bytes.
354  *
355  * Since: 2.22
356  */
357 GInetAddress *
358 g_inet_address_new_from_bytes (const guint8         *bytes,
359                                GSocketFamily  family)
360 {
361   g_return_val_if_fail (G_INET_ADDRESS_FAMILY_IS_VALID (family), NULL);
362
363   return g_object_new (G_TYPE_INET_ADDRESS,
364                        "family", family,
365                        "bytes", bytes,
366                        NULL);
367 }
368
369 /**
370  * g_inet_address_new_loopback:
371  * @family: the address family
372  *
373  * Creates a #GInetAddress for the loopback address for @family.
374  *
375  * Returns: a new #GInetAddress corresponding to the loopback address
376  * for @family.
377  *
378  * Since: 2.22
379  */
380 GInetAddress *
381 g_inet_address_new_loopback (GSocketFamily family)
382 {
383   g_return_val_if_fail (G_INET_ADDRESS_FAMILY_IS_VALID (family), NULL);
384
385   if (family == AF_INET)
386     {    
387       guint8 addr[4] = {127, 0, 0, 1};
388
389       return g_inet_address_new_from_bytes (addr, family);
390     }
391   else
392     return g_inet_address_new_from_bytes (in6addr_loopback.s6_addr, family);
393 }
394
395 /**
396  * g_inet_address_new_any:
397  * @family: the address family
398  *
399  * Creates a #GInetAddress for the "any" address (unassigned/"don't
400  * care") for @family.
401  *
402  * Returns: a new #GInetAddress corresponding to the "any" address
403  * for @family.
404  *
405  * Since: 2.22
406  */
407 GInetAddress *
408 g_inet_address_new_any (GSocketFamily family)
409 {
410   g_return_val_if_fail (G_INET_ADDRESS_FAMILY_IS_VALID (family), NULL);
411
412   if (family == AF_INET)
413     {    
414       guint8 addr[4] = {0, 0, 0, 0};
415
416       return g_inet_address_new_from_bytes (addr, family);
417     }
418   else
419     return g_inet_address_new_from_bytes (in6addr_any.s6_addr, family);
420 }
421
422
423 /**
424  * g_inet_address_to_string:
425  * @address: a #GInetAddress
426  *
427  * Converts @address to string form.
428  *
429  * Returns: a representation of @address as a string, which should be
430  * freed after use.
431  *
432  * Since: 2.22
433  */
434 gchar *
435 g_inet_address_to_string (GInetAddress *address)
436 {
437   gchar buffer[INET6_ADDRSTRLEN];
438 #ifdef G_OS_WIN32
439   DWORD buflen = sizeof (buffer), addrlen;
440   struct sockaddr_storage sa;
441   struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
442   struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa;
443 #endif
444
445   g_return_val_if_fail (G_IS_INET_ADDRESS (address), NULL);
446
447 #ifdef G_OS_WIN32
448   sa.ss_family = address->priv->family;
449   if (address->priv->family == AF_INET)
450     {
451       addrlen = sizeof (*sin);
452       memcpy (&sin->sin_addr, &address->priv->addr.ipv4,
453               sizeof (sin->sin_addr));
454       sin->sin_port = 0;
455     }
456   else
457     {
458       addrlen = sizeof (*sin6);
459       memcpy (&sin6->sin6_addr, &address->priv->addr.ipv6,
460               sizeof (sin6->sin6_addr));
461       sin6->sin6_port = 0;
462     }
463   if (WSAAddressToString ((LPSOCKADDR) &sa, addrlen, NULL, buffer, &buflen) != 0)
464     return NULL;
465
466 #else /* !G_OS_WIN32 */
467
468   if (address->priv->family == AF_INET)
469     inet_ntop (AF_INET, &address->priv->addr.ipv4, buffer, sizeof (buffer));
470   else
471     inet_ntop (AF_INET6, &address->priv->addr.ipv6, buffer, sizeof (buffer));
472 #endif
473
474   return g_strdup (buffer);
475 }
476
477 /**
478  * g_inet_address_to_bytes:
479  * @address: a #GInetAddress
480  *
481  * Gets the raw binary address data from @address.
482  *
483  * Returns: a pointer to an internal array of the bytes in @address,
484  * which should not be modified, stored, or freed.
485  *
486  * Since: 2.22
487  */
488 const guint8 *
489 g_inet_address_to_bytes (GInetAddress *address)
490 {
491   g_return_val_if_fail (G_IS_INET_ADDRESS (address), NULL);
492
493   return (guint8 *)&address->priv->addr;
494 }
495
496 /**
497  * g_inet_address_get_family:
498  * @address: a #GInetAddress
499  *
500  * Gets @address's family
501  *
502  * Returns: @address's family
503  *
504  * Since: 2.22
505  */
506 GSocketFamily
507 g_inet_address_get_family (GInetAddress *address)
508 {
509   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
510
511   return address->priv->family;
512 }
513
514 /**
515  * g_inet_address_get_is_any:
516  * @address: a #GInetAddress
517  *
518  * Tests whether @address is the "any" address for its family.
519  *
520  * Returns: %TRUE if @address is the "any" address for its family.
521  *
522  * Since: 2.22
523  */
524 gboolean
525 g_inet_address_get_is_any (GInetAddress *address)
526 {
527   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
528
529   if (address->priv->family == AF_INET)
530     {
531       guint32 addr4 = g_ntohl (address->priv->addr.ipv4.s_addr);
532
533       return addr4 == INADDR_ANY;
534     }
535   else
536     return IN6_IS_ADDR_UNSPECIFIED (&address->priv->addr.ipv6);
537 }
538
539 /**
540  * g_inet_address_get_is_loopback:
541  * @address: a #GInetAddress
542  *
543  * Tests whether @address is the loopback address for its family.
544  *
545  * Returns: %TRUE if @address is the loopback address for its family.
546  *
547  * Since: 2.22
548  */
549 gboolean
550 g_inet_address_get_is_loopback (GInetAddress *address)
551 {
552   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
553
554   if (address->priv->family == AF_INET)
555     {
556       guint32 addr4 = g_ntohl (address->priv->addr.ipv4.s_addr);
557
558       /* 127.0.0.0/8 */
559       return ((addr4 & 0xff000000) == 0x7f000000);
560     }
561   else
562     return IN6_IS_ADDR_LOOPBACK (&address->priv->addr.ipv6);
563 }
564
565 /**
566  * g_inet_address_get_is_link_local:
567  * @address: a #GInetAddress
568  *
569  * Tests whether @address is a link-local address (that is, if it
570  * identifies a host on a local network that is not connected to the
571  * Internet).
572  *
573  * Returns: %TRUE if @address is a link-local address.
574  *
575  * Since: 2.22
576  */
577 gboolean
578 g_inet_address_get_is_link_local (GInetAddress *address)
579 {
580   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
581
582   if (address->priv->family == AF_INET)
583     {
584       guint32 addr4 = g_ntohl (address->priv->addr.ipv4.s_addr);
585
586       /* 169.254.0.0/16 */
587       return ((addr4 & 0xffff0000) == 0xa9fe0000);
588     }
589   else
590     return IN6_IS_ADDR_LINKLOCAL (&address->priv->addr.ipv6);
591 }
592
593 /**
594  * g_inet_address_get_is_site_local:
595  * @address: a #GInetAddress
596  *
597  * Tests whether @address is a site-local address such as 10.0.0.1
598  * (that is, the address identifies a host on a local network that can
599  * not be reached directly from the Internet, but which may have
600  * outgoing Internet connectivity via a NAT or firewall).
601  *
602  * Returns: %TRUE if @address is a site-local address.
603  *
604  * Since: 2.22
605  */
606 gboolean
607 g_inet_address_get_is_site_local (GInetAddress *address)
608 {
609   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
610
611   if (address->priv->family == AF_INET)
612     {
613       guint32 addr4 = g_ntohl (address->priv->addr.ipv4.s_addr);
614
615       /* 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 */
616       return ((addr4 & 0xff000000) == 0x0a000000 ||
617               (addr4 & 0xfff00000) == 0xac100000 ||
618               (addr4 & 0xffff0000) == 0xc0a80000);
619     }
620   else
621     return IN6_IS_ADDR_SITELOCAL (&address->priv->addr.ipv6);
622 }
623
624 /**
625  * g_inet_address_get_is_multicast:
626  * @address: a #GInetAddress
627  *
628  * Tests whether @address is a multicast address.
629  *
630  * Returns: %TRUE if @address is a multicast address.
631  *
632  * Since: 2.22
633  */
634 gboolean
635 g_inet_address_get_is_multicast (GInetAddress *address)
636 {
637   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
638
639   if (address->priv->family == AF_INET)
640     {
641       guint32 addr4 = g_ntohl (address->priv->addr.ipv4.s_addr);
642
643       return IN_MULTICAST (addr4);
644     }
645   else
646     return IN6_IS_ADDR_MULTICAST (&address->priv->addr.ipv6);
647 }
648
649 /**
650  * g_inet_address_get_is_mc_global:
651  * @address: a #GInetAddress
652  *
653  * Tests whether @address is a global multicast address.
654  *
655  * Returns: %TRUE if @address is a global multicast address.
656  *
657  * Since: 2.22
658  */
659 gboolean
660 g_inet_address_get_is_mc_global (GInetAddress *address)
661 {
662   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
663
664   if (address->priv->family == AF_INET)
665     return FALSE;
666   else
667     return IN6_IS_ADDR_MC_GLOBAL (&address->priv->addr.ipv6);
668 }
669
670 /**
671  * g_inet_address_get_is_mc_link_local:
672  * @address: a #GInetAddress
673  *
674  * Tests whether @address is a link-local multicast address.
675  *
676  * Returns: %TRUE if @address is a link-local multicast address.
677  *
678  * Since: 2.22
679  */
680 gboolean
681 g_inet_address_get_is_mc_link_local (GInetAddress *address)
682 {
683   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
684
685   if (address->priv->family == AF_INET)
686     return FALSE;
687   else
688     return IN6_IS_ADDR_MC_LINKLOCAL (&address->priv->addr.ipv6);
689 }
690
691 /**
692  * g_inet_address_get_is_mc_node_local:
693  * @address: a #GInetAddress
694  *
695  * Tests whether @address is a node-local multicast address.
696  *
697  * Returns: %TRUE if @address is a node-local multicast address.
698  *
699  * Since: 2.22
700  */
701 gboolean
702 g_inet_address_get_is_mc_node_local (GInetAddress *address)
703 {
704   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
705
706   if (address->priv->family == AF_INET)
707     return FALSE;
708   else
709     return IN6_IS_ADDR_MC_NODELOCAL (&address->priv->addr.ipv6);
710 }
711
712 /**
713  * g_inet_address_get_is_mc_org_local:
714  * @address: a #GInetAddress
715  *
716  * Tests whether @address is an organization-local multicast address.
717  *
718  * Returns: %TRUE if @address is an organization-local multicast address.
719  *
720  * Since: 2.22
721  */
722 gboolean
723 g_inet_address_get_is_mc_org_local  (GInetAddress *address)
724 {
725   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
726
727   if (address->priv->family == AF_INET)
728     return FALSE;
729   else
730     return IN6_IS_ADDR_MC_ORGLOCAL (&address->priv->addr.ipv6);
731 }
732
733 /**
734  * g_inet_address_get_is_mc_site_local:
735  * @address: a #GInetAddress
736  *
737  * Tests whether @address is a site-local multicast address.
738  *
739  * Returns: %TRUE if @address is a site-local multicast address.
740  *
741  * Since: 2.22
742  */
743 gboolean
744 g_inet_address_get_is_mc_site_local (GInetAddress *address)
745 {
746   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
747
748   if (address->priv->family == AF_INET)
749     return FALSE;
750   else
751     return IN6_IS_ADDR_MC_SITELOCAL (&address->priv->addr.ipv6);
752 }
753
754 #define __G_INET_ADDRESS_C__
755 #include "gioaliasdef.c"