Patch from Samuel Cormier-Iijima <sciyoshi@gmail.com>:
[cascardo/gnio.git] / gnio / ginet6address.c
1 /* GNIO - GLib Network Layer of GIO
2  * 
3  * Copyright (C) 2008 Christian Kellner 
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  * Author: Christian Kellner <gicmo@gnome.org>
21  */
22
23 #include <config.h>
24 #include <string.h>
25 #include <glib.h>
26
27 #include "ginet6address.h"
28
29 G_DEFINE_TYPE (GInet6Address, g_inet6_address, G_TYPE_INET_ADDRESS);
30
31 struct _GInet6AddressPrivate {
32   union {
33     guint8  u6_addr8[16];
34     guint16 u6_addr16[8];
35     guint32 u6_addr32[4];
36   } addr;
37 };
38
39 static void
40 g_inet6_address_finalize (GObject *object)
41 {
42   GInet6Address *address G_GNUC_UNUSED = G_INET6_ADDRESS (object);
43
44   if (G_OBJECT_CLASS (g_inet6_address_parent_class)->finalize)
45     (*G_OBJECT_CLASS (g_inet6_address_parent_class)->finalize) (object);
46 }
47
48 static void
49 g_inet6_address_dispose (GObject *object)
50 {
51   GInet6Address *address G_GNUC_UNUSED = G_INET6_ADDRESS (object);
52
53   if (G_OBJECT_CLASS (g_inet6_address_parent_class)->dispose)
54     (*G_OBJECT_CLASS (g_inet6_address_parent_class)->dispose) (object);
55 }
56
57 static void
58 g_inet6_address_class_init (GInet6AddressClass *klass)
59 {
60   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
61
62   g_type_class_add_private (klass, sizeof (GInet6AddressPrivate));
63
64   gobject_class->finalize = g_inet6_address_finalize;
65   gobject_class->dispose = g_inet6_address_dispose;
66 }
67
68 static void
69 g_inet6_address_init (GInet6Address *address)
70 {
71   address->priv = G_TYPE_INSTANCE_GET_PRIVATE (address,
72                                                G_TYPE_INET6_ADDRESS,
73                                                GInet6AddressPrivate);
74 }
75
76 /* ************************************************************************* */
77 /* Public Functions */
78
79 GInet6Address *
80 g_inet6_address_from_string (const char *string)
81 {
82   return NULL;
83 }
84
85 char *
86 g_inet6_address_to_string (GInet6Address *address)
87 {
88   return NULL;
89 }
90
91 GInet6Address *
92 g_inet6_address_from_bytes (guint8 bytes[])
93 {
94   GInet6Address *address = G_INET6_ADDRESS (g_object_new (G_TYPE_INET6_ADDRESS, NULL));
95
96   g_memmove (address->priv->addr.u6_addr8, bytes, 16);
97
98   return address;
99 }
100
101 const guint8 *
102 g_inet6_address_to_bytes (GInet6Address *address)
103 {
104   return NULL;
105 }
106
107 GInet6Address *
108 g_inet6_address_new_loopback (void)
109 {
110   guint8 bytes[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
111
112   return g_inet6_address_from_bytes (bytes);
113 }
114
115 GInet6Address *
116 g_inet6_address_new_any (void)
117 {
118   return NULL; 
119 }