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