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
45 g_inet6_address_to_string (GInetAddress *address)
47 gchar *addr = g_malloc (48);
49 g_return_val_if_fail (G_IS_INET6_ADDRESS (address), NULL);
51 inet_ntop (AF_INET6, G_INET6_ADDRESS (address)->priv->addr.u6_addr8, addr, 48);
57 g_inet6_address_finalize (GObject *object)
59 GInet6Address *address G_GNUC_UNUSED = G_INET6_ADDRESS (object);
61 if (G_OBJECT_CLASS (g_inet6_address_parent_class)->finalize)
62 (*G_OBJECT_CLASS (g_inet6_address_parent_class)->finalize) (object);
66 g_inet6_address_dispose (GObject *object)
68 GInet6Address *address G_GNUC_UNUSED = G_INET6_ADDRESS (object);
70 if (G_OBJECT_CLASS (g_inet6_address_parent_class)->dispose)
71 (*G_OBJECT_CLASS (g_inet6_address_parent_class)->dispose) (object);
75 g_inet6_address_class_init (GInet6AddressClass *klass)
77 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
78 GInetAddressClass *ginetaddress_class = G_INET_ADDRESS_CLASS (klass);
80 g_type_class_add_private (klass, sizeof (GInet6AddressPrivate));
82 gobject_class->finalize = g_inet6_address_finalize;
83 gobject_class->dispose = g_inet6_address_dispose;
84 ginetaddress_class->to_string = g_inet6_address_to_string;
85 /* ginetaddress_class->is_any = g_inet6_address_is_any;
86 ginetaddress_class->is_linklocal = g_inet6_address_is_linklocal;
87 ginetaddress_class->is_loopback = g_inet6_address_is_loopback;
88 ginetaddress_class->is_sitelocal = g_inet6_address_is_sitelocal;
89 ginetaddress_class->is_multicast = g_inet6_address_is_multicast;
90 ginetaddress_class->is_mc_global = g_inet6_address_is_mc_global;
91 ginetaddress_class->is_mc_linklocal = g_inet6_address_is_mc_linklocal;
92 ginetaddress_class->is_mc_nodelocal = g_inet6_address_is_mc_nodelocal;
93 ginetaddress_class->is_mc_orglocal = g_inet6_address_is_mc_orglocal;
94 ginetaddress_class->is_mc_sitelocal = g_inet6_address_is_mc_sitelocal;*/
98 g_inet6_address_init (GInet6Address *address)
100 address->priv = G_TYPE_INSTANCE_GET_PRIVATE (address,
101 G_TYPE_INET6_ADDRESS,
102 GInet6AddressPrivate);
105 /* ************************************************************************* */
106 /* Public Functions */
109 g_inet6_address_from_string (const char *string)
115 g_inet6_address_from_bytes (guint8 bytes[])
117 GInet6Address *address = G_INET6_ADDRESS (g_object_new (G_TYPE_INET6_ADDRESS, NULL));
119 g_memmove (address->priv->addr.u6_addr8, bytes, 16);
125 g_inet6_address_to_bytes (GInet6Address *address)
131 g_inet6_address_new_loopback (void)
133 guint8 bytes[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
135 return g_inet6_address_from_bytes (bytes);
139 g_inet6_address_new_any (void)
141 guint8 bytes[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
143 return g_inet6_address_from_bytes (bytes);