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