1 /* GNIO - GLib Network Layer of GIO
3 * Copyright (C) 2008 Christian Kellner, Samuel Cormier-Iijima
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.
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.
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.
20 * Authors: Christian Kellner <gicmo@gnome.org>
21 * Samuel Cormier-Iijima <sciyoshi@gmail.com>
28 #include <netinet/in.h>
29 #include <arpa/inet.h>
31 #include "ginet6address.h"
33 G_DEFINE_TYPE (GInet6Address, g_inet6_address, G_TYPE_INET_ADDRESS);
35 struct _GInet6AddressPrivate {
44 g_inet6_address_to_string (GInetAddress *address)
46 gchar *addr = g_malloc (48);
48 g_return_val_if_fail (G_IS_INET6_ADDRESS (address), NULL);
50 inet_ntop (AF_INET6, G_INET6_ADDRESS (address)->priv->addr.u6_addr8, addr, 48);
56 g_inet6_address_finalize (GObject *object)
58 GInet6Address *address G_GNUC_UNUSED = G_INET6_ADDRESS (object);
60 if (G_OBJECT_CLASS (g_inet6_address_parent_class)->finalize)
61 (*G_OBJECT_CLASS (g_inet6_address_parent_class)->finalize) (object);
65 g_inet6_address_dispose (GObject *object)
67 GInet6Address *address G_GNUC_UNUSED = G_INET6_ADDRESS (object);
69 if (G_OBJECT_CLASS (g_inet6_address_parent_class)->dispose)
70 (*G_OBJECT_CLASS (g_inet6_address_parent_class)->dispose) (object);
74 g_inet6_address_class_init (GInet6AddressClass *klass)
76 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
77 GInetAddressClass *ginetaddress_class = G_INET_ADDRESS_CLASS (klass);
79 g_type_class_add_private (klass, sizeof (GInet6AddressPrivate));
81 gobject_class->finalize = g_inet6_address_finalize;
82 gobject_class->dispose = g_inet6_address_dispose;
83 ginetaddress_class->to_string = g_inet6_address_to_string;
84 /* ginetaddress_class->is_any = g_inet6_address_is_any;
85 ginetaddress_class->is_linklocal = g_inet6_address_is_linklocal;
86 ginetaddress_class->is_loopback = g_inet6_address_is_loopback;
87 ginetaddress_class->is_sitelocal = g_inet6_address_is_sitelocal;
88 ginetaddress_class->is_multicast = g_inet6_address_is_multicast;
89 ginetaddress_class->is_mc_global = g_inet6_address_is_mc_global;
90 ginetaddress_class->is_mc_linklocal = g_inet6_address_is_mc_linklocal;
91 ginetaddress_class->is_mc_nodelocal = g_inet6_address_is_mc_nodelocal;
92 ginetaddress_class->is_mc_orglocal = g_inet6_address_is_mc_orglocal;
93 ginetaddress_class->is_mc_sitelocal = g_inet6_address_is_mc_sitelocal;*/
97 g_inet6_address_init (GInet6Address *address)
99 address->priv = G_TYPE_INSTANCE_GET_PRIVATE (address,
100 G_TYPE_INET6_ADDRESS,
101 GInet6AddressPrivate);
104 /* ************************************************************************* */
105 /* Public Functions */
108 g_inet6_address_from_string (const char *string)
114 g_inet6_address_from_bytes (guint8 bytes[])
116 GInet6Address *address = G_INET6_ADDRESS (g_object_new (G_TYPE_INET6_ADDRESS, NULL));
118 g_memmove (address->priv->addr.u6_addr8, bytes, 16);
124 g_inet6_address_to_bytes (GInet6Address *address)
130 g_inet6_address_new_loopback (void)
132 guint8 bytes[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
134 return g_inet6_address_from_bytes (bytes);
138 g_inet6_address_new_any (void)