1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD 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
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gio.InetAddress;
26 
27 private import gio.c.functions;
28 public  import gio.c.types;
29 private import glib.ConstructionException;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 public  import gtkc.giotypes;
33 
34 
35 /**
36  * #GInetAddress represents an IPv4 or IPv6 internet address. Use
37  * g_resolver_lookup_by_name() or g_resolver_lookup_by_name_async() to
38  * look up the #GInetAddress for a hostname. Use
39  * g_resolver_lookup_by_address() or
40  * g_resolver_lookup_by_address_async() to look up the hostname for a
41  * #GInetAddress.
42  * 
43  * To actually connect to a remote host, you will need a
44  * #GInetSocketAddress (which includes a #GInetAddress as well as a
45  * port number).
46  */
47 public class InetAddress : ObjectG
48 {
49 	/** the main Gtk struct */
50 	protected GInetAddress* gInetAddress;
51 
52 	/** Get the main Gtk struct */
53 	public GInetAddress* getInetAddressStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return gInetAddress;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected override void* getStruct()
62 	{
63 		return cast(void*)gInetAddress;
64 	}
65 
66 	/**
67 	 * Sets our main struct and passes it to the parent class.
68 	 */
69 	public this (GInetAddress* gInetAddress, bool ownedRef = false)
70 	{
71 		this.gInetAddress = gInetAddress;
72 		super(cast(GObject*)gInetAddress, ownedRef);
73 	}
74 
75 	/**
76 	 * Creates a InetAddress for the "any" address (unassigned/"don't
77 	 * care") for family.
78 	 *
79 	 * Params:
80 	 *     family = the address family
81 	 *     loopback = If true create an InetAddress for the loopback address.
82 	 *
83 	 * Throws: ConstructionException GTK+ fails to create the object.
84 	 *
85 	 * Since: 2.22
86 	 */
87 	public this (GSocketFamily family, bool loopback = false)
88 	{
89 		GInetAddress* p;
90 
91 		if ( loopback )
92 		{
93 			p = g_inet_address_new_loopback(family);
94 		}
95 		else
96 		{
97 			p = g_inet_address_new_any(family);
98 		}
99 
100 		if(p is null)
101 		{
102 			throw new ConstructionException("null returned by g_inet_address_new_any(family)");
103 		}
104 		this(p, true);
105 	}
106 
107 	/**
108 	 */
109 
110 	/** */
111 	public static GType getType()
112 	{
113 		return g_inet_address_get_type();
114 	}
115 
116 	/**
117 	 * Creates a new #GInetAddress from the given @family and @bytes.
118 	 * @bytes should be 4 bytes for %G_SOCKET_FAMILY_IPV4 and 16 bytes for
119 	 * %G_SOCKET_FAMILY_IPV6.
120 	 *
121 	 * Params:
122 	 *     bytes = raw address data
123 	 *     family = the address family of @bytes
124 	 *
125 	 * Returns: a new #GInetAddress corresponding to @family and @bytes.
126 	 *     Free the returned object with g_object_unref().
127 	 *
128 	 * Since: 2.22
129 	 *
130 	 * Throws: ConstructionException GTK+ fails to create the object.
131 	 */
132 	public this(ubyte[] bytes, GSocketFamily family)
133 	{
134 		auto __p = g_inet_address_new_from_bytes(bytes.ptr, family);
135 
136 		if(__p is null)
137 		{
138 			throw new ConstructionException("null returned by new_from_bytes");
139 		}
140 
141 		this(cast(GInetAddress*) __p, true);
142 	}
143 
144 	/**
145 	 * Parses @string as an IP address and creates a new #GInetAddress.
146 	 *
147 	 * Params:
148 	 *     string_ = a string representation of an IP address
149 	 *
150 	 * Returns: a new #GInetAddress corresponding to @string, or %NULL if
151 	 *     @string could not be parsed.
152 	 *     Free the returned object with g_object_unref().
153 	 *
154 	 * Since: 2.22
155 	 *
156 	 * Throws: ConstructionException GTK+ fails to create the object.
157 	 */
158 	public this(string string_)
159 	{
160 		auto __p = g_inet_address_new_from_string(Str.toStringz(string_));
161 
162 		if(__p is null)
163 		{
164 			throw new ConstructionException("null returned by new_from_string");
165 		}
166 
167 		this(cast(GInetAddress*) __p, true);
168 	}
169 
170 	/**
171 	 * Checks if two #GInetAddress instances are equal, e.g. the same address.
172 	 *
173 	 * Params:
174 	 *     otherAddress = Another #GInetAddress.
175 	 *
176 	 * Returns: %TRUE if @address and @other_address are equal, %FALSE otherwise.
177 	 *
178 	 * Since: 2.30
179 	 */
180 	public bool equal(InetAddress otherAddress)
181 	{
182 		return g_inet_address_equal(gInetAddress, (otherAddress is null) ? null : otherAddress.getInetAddressStruct()) != 0;
183 	}
184 
185 	/**
186 	 * Gets @address's family
187 	 *
188 	 * Returns: @address's family
189 	 *
190 	 * Since: 2.22
191 	 */
192 	public GSocketFamily getFamily()
193 	{
194 		return g_inet_address_get_family(gInetAddress);
195 	}
196 
197 	/**
198 	 * Tests whether @address is the "any" address for its family.
199 	 *
200 	 * Returns: %TRUE if @address is the "any" address for its family.
201 	 *
202 	 * Since: 2.22
203 	 */
204 	public bool getIsAny()
205 	{
206 		return g_inet_address_get_is_any(gInetAddress) != 0;
207 	}
208 
209 	/**
210 	 * Tests whether @address is a link-local address (that is, if it
211 	 * identifies a host on a local network that is not connected to the
212 	 * Internet).
213 	 *
214 	 * Returns: %TRUE if @address is a link-local address.
215 	 *
216 	 * Since: 2.22
217 	 */
218 	public bool getIsLinkLocal()
219 	{
220 		return g_inet_address_get_is_link_local(gInetAddress) != 0;
221 	}
222 
223 	/**
224 	 * Tests whether @address is the loopback address for its family.
225 	 *
226 	 * Returns: %TRUE if @address is the loopback address for its family.
227 	 *
228 	 * Since: 2.22
229 	 */
230 	public bool getIsLoopback()
231 	{
232 		return g_inet_address_get_is_loopback(gInetAddress) != 0;
233 	}
234 
235 	/**
236 	 * Tests whether @address is a global multicast address.
237 	 *
238 	 * Returns: %TRUE if @address is a global multicast address.
239 	 *
240 	 * Since: 2.22
241 	 */
242 	public bool getIsMcGlobal()
243 	{
244 		return g_inet_address_get_is_mc_global(gInetAddress) != 0;
245 	}
246 
247 	/**
248 	 * Tests whether @address is a link-local multicast address.
249 	 *
250 	 * Returns: %TRUE if @address is a link-local multicast address.
251 	 *
252 	 * Since: 2.22
253 	 */
254 	public bool getIsMcLinkLocal()
255 	{
256 		return g_inet_address_get_is_mc_link_local(gInetAddress) != 0;
257 	}
258 
259 	/**
260 	 * Tests whether @address is a node-local multicast address.
261 	 *
262 	 * Returns: %TRUE if @address is a node-local multicast address.
263 	 *
264 	 * Since: 2.22
265 	 */
266 	public bool getIsMcNodeLocal()
267 	{
268 		return g_inet_address_get_is_mc_node_local(gInetAddress) != 0;
269 	}
270 
271 	/**
272 	 * Tests whether @address is an organization-local multicast address.
273 	 *
274 	 * Returns: %TRUE if @address is an organization-local multicast address.
275 	 *
276 	 * Since: 2.22
277 	 */
278 	public bool getIsMcOrgLocal()
279 	{
280 		return g_inet_address_get_is_mc_org_local(gInetAddress) != 0;
281 	}
282 
283 	/**
284 	 * Tests whether @address is a site-local multicast address.
285 	 *
286 	 * Returns: %TRUE if @address is a site-local multicast address.
287 	 *
288 	 * Since: 2.22
289 	 */
290 	public bool getIsMcSiteLocal()
291 	{
292 		return g_inet_address_get_is_mc_site_local(gInetAddress) != 0;
293 	}
294 
295 	/**
296 	 * Tests whether @address is a multicast address.
297 	 *
298 	 * Returns: %TRUE if @address is a multicast address.
299 	 *
300 	 * Since: 2.22
301 	 */
302 	public bool getIsMulticast()
303 	{
304 		return g_inet_address_get_is_multicast(gInetAddress) != 0;
305 	}
306 
307 	/**
308 	 * Tests whether @address is a site-local address such as 10.0.0.1
309 	 * (that is, the address identifies a host on a local network that can
310 	 * not be reached directly from the Internet, but which may have
311 	 * outgoing Internet connectivity via a NAT or firewall).
312 	 *
313 	 * Returns: %TRUE if @address is a site-local address.
314 	 *
315 	 * Since: 2.22
316 	 */
317 	public bool getIsSiteLocal()
318 	{
319 		return g_inet_address_get_is_site_local(gInetAddress) != 0;
320 	}
321 
322 	/**
323 	 * Gets the size of the native raw binary address for @address. This
324 	 * is the size of the data that you get from g_inet_address_to_bytes().
325 	 *
326 	 * Returns: the number of bytes used for the native version of @address.
327 	 *
328 	 * Since: 2.22
329 	 */
330 	public size_t getNativeSize()
331 	{
332 		return g_inet_address_get_native_size(gInetAddress);
333 	}
334 
335 	/**
336 	 * Gets the raw binary address data from @address.
337 	 *
338 	 * Returns: a pointer to an internal array of the bytes in @address,
339 	 *     which should not be modified, stored, or freed. The size of this
340 	 *     array can be gotten with g_inet_address_get_native_size().
341 	 *
342 	 * Since: 2.22
343 	 */
344 	public ubyte* toBytes()
345 	{
346 		return g_inet_address_to_bytes(gInetAddress);
347 	}
348 
349 	/**
350 	 * Converts @address to string form.
351 	 *
352 	 * Returns: a representation of @address as a string, which should be
353 	 *     freed after use.
354 	 *
355 	 * Since: 2.22
356 	 */
357 	public override string toString()
358 	{
359 		auto retStr = g_inet_address_to_string(gInetAddress);
360 
361 		scope(exit) Str.freeString(retStr);
362 		return Str.toString(retStr);
363 	}
364 }