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>
27 #include "ginetaddress.h"
30 * SECTION:ginetaddress
31 * @short_description: Base class for implementing IPv4/IPv6 classes
37 G_DEFINE_ABSTRACT_TYPE (GInetAddress, g_inet_address, G_TYPE_INITIALLY_UNOWNED);
55 g_inet_address_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
57 GInetAddress *address = G_INET_ADDRESS (object);
62 g_value_set_boolean (value, G_INET_ADDRESS_GET_CLASS (address)->is_any (address));
65 case PROP_IS_LINKLOCAL:
66 g_value_set_boolean (value, G_INET_ADDRESS_GET_CLASS (address)->is_linklocal (address));
69 case PROP_IS_LOOPBACK:
70 g_value_set_boolean (value, G_INET_ADDRESS_GET_CLASS (address)->is_loopback (address));
74 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
79 g_inet_address_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
81 GInetAddress *address G_GNUC_UNUSED = G_INET_ADDRESS (object);
86 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
91 g_inet_address_class_init (GInetAddressClass *klass)
93 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
95 gobject_class->get_property = g_inet_address_get_property;
96 gobject_class->set_property = g_inet_address_set_property;
98 g_object_class_install_property (gobject_class, PROP_IS_ANY,
99 g_param_spec_boolean ("is-any",
103 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
105 g_object_class_install_property (gobject_class, PROP_IS_LINKLOCAL,
106 g_param_spec_boolean ("is-link-local",
110 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
112 g_object_class_install_property (gobject_class, PROP_IS_LOOPBACK,
113 g_param_spec_boolean ("is-loopback",
117 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
119 g_object_class_install_property (gobject_class, PROP_IS_SITELOCAL,
120 g_param_spec_boolean ("is-site-local",
124 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
126 g_object_class_install_property (gobject_class, PROP_IS_MULTICAST,
127 g_param_spec_boolean ("is-multicast",
131 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
133 g_object_class_install_property (gobject_class, PROP_IS_MC_GLOBAL,
134 g_param_spec_boolean ("is-mc-global",
138 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
140 g_object_class_install_property (gobject_class, PROP_IS_MC_LINKLOCAL,
141 g_param_spec_boolean ("is-mc-link-local",
145 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
147 g_object_class_install_property (gobject_class, PROP_IS_MC_NODELOCAL,
148 g_param_spec_boolean ("is-mc-node-local",
152 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
154 g_object_class_install_property (gobject_class, PROP_IS_MC_ORGLOCAL,
155 g_param_spec_boolean ("is-mc-org-local",
159 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
161 g_object_class_install_property (gobject_class, PROP_IS_MC_SITELOCAL,
162 g_param_spec_boolean ("is-mc-site-local",
166 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
170 g_inet_address_init (GInetAddress *address)
176 g_inet_address_to_string (GInetAddress *address)
178 g_return_val_if_fail (G_IS_INET_ADDRESS (address), NULL);
180 return G_INET_ADDRESS_GET_CLASS (address)->to_string (address);
183 /* ******************************************* */
184 /* Getters for properties */
187 get_boolean_property (GInetAddress *address, const gchar *property)
191 g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
193 g_object_get (address, property, &value, NULL);
199 g_inet_address_is_any (GInetAddress *address)
201 return get_boolean_property (address, "is-any");
205 g_inet_address_is_linklocal (GInetAddress *address)
207 return get_boolean_property (address, "is-link-local");
211 g_inet_address_is_loopback (GInetAddress *address)
213 return get_boolean_property (address, "is-loopback");
217 g_inet_address_is_sitelocal (GInetAddress *address)
219 return get_boolean_property (address, "is-site-local");
223 g_inet_address_is_multicast (GInetAddress *address)
225 return get_boolean_property (address, "is-multicast");
229 g_inet_address_is_mc_global (GInetAddress *address)
231 return get_boolean_property (address, "is-mc-global");
235 g_inet_address_is_mc_linklocal (GInetAddress *address)
237 return get_boolean_property (address, "is-mc-link-local");
241 g_inet_address_is_mc_nodelocal (GInetAddress *address)
243 return get_boolean_property (address, "is-mc-node-local");
247 g_inet_address_is_mc_orglocal (GInetAddress *address)
249 return get_boolean_property (address, "is-mc-org-local");
253 g_inet_address_is_mc_sitelocal (GInetAddress *address)
255 return get_boolean_property (address, "is-mc-site-local");