Make to_string virtual, fix some warnings
[cascardo/gnio.git] / gnio / ginet6address.c
1 /* GNIO - GLib Network Layer of GIO
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 #include <string.h>
26 #include <glib.h>
27
28 #include <netinet/in.h>
29 #include <arpa/inet.h>
30
31 #include "ginet6address.h"
32
33 G_DEFINE_TYPE (GInet6Address, g_inet6_address, G_TYPE_INET_ADDRESS);
34
35 struct _GInet6AddressPrivate {
36   union {
37     guint8  u6_addr8[16];
38     guint16 u6_addr16[8];
39     guint32 u6_addr32[4];
40   } addr;
41 };
42
43 static gchar *
44 g_inet6_address_to_string (GInetAddress *address)
45 {
46   gchar *addr = g_malloc (48);
47
48   g_return_val_if_fail (G_IS_INET6_ADDRESS (address), NULL);
49
50   inet_ntop (AF_INET6, G_INET6_ADDRESS (address)->priv->addr.u6_addr8, addr, 48);
51
52   return addr;
53 }
54
55 static void
56 g_inet6_address_finalize (GObject *object)
57 {
58   GInet6Address *address G_GNUC_UNUSED = G_INET6_ADDRESS (object);
59
60   if (G_OBJECT_CLASS (g_inet6_address_parent_class)->finalize)
61     (*G_OBJECT_CLASS (g_inet6_address_parent_class)->finalize) (object);
62 }
63
64 static void
65 g_inet6_address_dispose (GObject *object)
66 {
67   GInet6Address *address G_GNUC_UNUSED = G_INET6_ADDRESS (object);
68
69   if (G_OBJECT_CLASS (g_inet6_address_parent_class)->dispose)
70     (*G_OBJECT_CLASS (g_inet6_address_parent_class)->dispose) (object);
71 }
72
73 static void
74 g_inet6_address_class_init (GInet6AddressClass *klass)
75 {
76   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
77   GInetAddressClass *ginetaddress_class = G_INET_ADDRESS_CLASS (klass);
78
79   g_type_class_add_private (klass, sizeof (GInet6AddressPrivate));
80
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;*/
94 }
95
96 static void
97 g_inet6_address_init (GInet6Address *address)
98 {
99   address->priv = G_TYPE_INSTANCE_GET_PRIVATE (address,
100                                                G_TYPE_INET6_ADDRESS,
101                                                GInet6AddressPrivate);
102 }
103
104 /* ************************************************************************* */
105 /* Public Functions */
106
107 GInet6Address *
108 g_inet6_address_from_string (const char *string)
109 {
110   return NULL;
111 }
112
113 GInet6Address *
114 g_inet6_address_from_bytes (guint8 bytes[])
115 {
116   GInet6Address *address = G_INET6_ADDRESS (g_object_new (G_TYPE_INET6_ADDRESS, NULL));
117
118   g_memmove (address->priv->addr.u6_addr8, bytes, 16);
119
120   return address;
121 }
122
123 const guint8 *
124 g_inet6_address_to_bytes (GInet6Address *address)
125 {
126   return NULL;
127 }
128
129 GInet6Address *
130 g_inet6_address_new_loopback (void)
131 {
132   guint8 bytes[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
133
134   return g_inet6_address_from_bytes (bytes);
135 }
136
137 GInet6Address *
138 g_inet6_address_new_any (void)
139 {
140   return NULL; 
141 }