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  * module aliases:
51  * local aliases:
52  * overrides:
53  * 	- toString
54  */
55 
56 module gio.InetAddress;
57 
58 public  import gtkc.giotypes;
59 
60 private import gtkc.gio;
61 private import glib.ConstructionException;
62 private import gobject.ObjectG;
63 
64 
65 private import glib.Str;
66 
67 
68 
69 private import gobject.ObjectG;
70 
71 /**
72  * Description
73  * GInetAddress represents an IPv4 or IPv6 internet address. Use
74  * g_resolver_lookup_by_name() or g_resolver_lookup_by_name_async() to
75  * look up the GInetAddress for a hostname. Use
76  * g_resolver_lookup_by_address() or
77  * g_resolver_lookup_by_address_async() to look up the hostname for a
78  * GInetAddress.
79  * To actually connect to a remote host, you will need a
80  * GInetSocketAddress (which includes a GInetAddress as well as a
81  * port number).
82  */
83 public class InetAddress : ObjectG
84 {
85 	
86 	/** the main Gtk struct */
87 	protected GInetAddress* gInetAddress;
88 	
89 	
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_INET_ADDRESS_IPV4 and 16 bytes for
170 	 * G_INET_ADDRESS_IPV6.
171 	 * Since 2.22
172 	 * Params:
173 	 * bytes = raw address data
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 	 * Gets the raw binary address data from address.
190 	 * Since 2.22
191 	 * 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().
192 	 */
193 	public ubyte[] toBytes()
194 	{
195 		// const guint8 * g_inet_address_to_bytes (GInetAddress *address);
196 		auto p = g_inet_address_to_bytes(gInetAddress);
197 		
198 		if(p is null)
199 		{
200 			return null;
201 		}
202 		
203 		return p[0 .. getNativeSize()];
204 	}
205 	
206 	/**
207 	 * Gets the size of the native raw binary address for address. This
208 	 * is the size of the data that you get from g_inet_address_to_bytes().
209 	 * Since 2.22
210 	 * Returns: the number of bytes used for the native version of address.
211 	 */
212 	public gsize getNativeSize()
213 	{
214 		// gsize g_inet_address_get_native_size (GInetAddress *address);
215 		return g_inet_address_get_native_size(gInetAddress);
216 	}
217 	
218 	/**
219 	 * Converts address to string form.
220 	 * Since 2.22
221 	 * Returns: a representation of address as a string, which should be freed after use.
222 	 */
223 	public override string toString()
224 	{
225 		// gchar * g_inet_address_to_string (GInetAddress *address);
226 		return Str.toString(g_inet_address_to_string(gInetAddress));
227 	}
228 	
229 	/**
230 	 * Gets address's family
231 	 * Since 2.22
232 	 * Returns: address's family
233 	 */
234 	public GSocketFamily getFamily()
235 	{
236 		// GSocketFamily g_inet_address_get_family (GInetAddress *address);
237 		return g_inet_address_get_family(gInetAddress);
238 	}
239 	
240 	/**
241 	 * Tests whether address is the "any" address for its family.
242 	 * Since 2.22
243 	 * Returns: TRUE if address is the "any" address for its family.
244 	 */
245 	public int getIsAny()
246 	{
247 		// gboolean g_inet_address_get_is_any (GInetAddress *address);
248 		return g_inet_address_get_is_any(gInetAddress);
249 	}
250 	
251 	/**
252 	 * Tests whether address is the loopback address for its family.
253 	 * Since 2.22
254 	 * Returns: TRUE if address is the loopback address for its family.
255 	 */
256 	public int getIsLoopback()
257 	{
258 		// gboolean g_inet_address_get_is_loopback (GInetAddress *address);
259 		return g_inet_address_get_is_loopback(gInetAddress);
260 	}
261 	
262 	/**
263 	 * Tests whether address is a link-local address (that is, if it
264 	 * identifies a host on a local network that is not connected to the
265 	 * Internet).
266 	 * Since 2.22
267 	 * Returns: TRUE if address is a link-local address.
268 	 */
269 	public int getIsLinkLocal()
270 	{
271 		// gboolean g_inet_address_get_is_link_local (GInetAddress *address);
272 		return g_inet_address_get_is_link_local(gInetAddress);
273 	}
274 	
275 	/**
276 	 * Tests whether address is a site-local address such as 10.0.0.1
277 	 * (that is, the address identifies a host on a local network that can
278 	 * not be reached directly from the Internet, but which may have
279 	 * outgoing Internet connectivity via a NAT or firewall).
280 	 * Since 2.22
281 	 * Returns: TRUE if address is a site-local address.
282 	 */
283 	public int getIsSiteLocal()
284 	{
285 		// gboolean g_inet_address_get_is_site_local (GInetAddress *address);
286 		return g_inet_address_get_is_site_local(gInetAddress);
287 	}
288 	
289 	/**
290 	 * Tests whether address is a multicast address.
291 	 * Since 2.22
292 	 * Returns: TRUE if address is a multicast address.
293 	 */
294 	public int getIsMulticast()
295 	{
296 		// gboolean g_inet_address_get_is_multicast (GInetAddress *address);
297 		return g_inet_address_get_is_multicast(gInetAddress);
298 	}
299 	
300 	/**
301 	 * Tests whether address is a link-local multicast address.
302 	 * Since 2.22
303 	 * Returns: TRUE if address is a link-local multicast address.
304 	 */
305 	public int getIsMcLinkLocal()
306 	{
307 		// gboolean g_inet_address_get_is_mc_link_local (GInetAddress *address);
308 		return g_inet_address_get_is_mc_link_local(gInetAddress);
309 	}
310 	
311 	/**
312 	 * Tests whether address is a node-local multicast address.
313 	 * Since 2.22
314 	 * Returns: TRUE if address is a node-local multicast address.
315 	 */
316 	public int getIsMcNodeLocal()
317 	{
318 		// gboolean g_inet_address_get_is_mc_node_local (GInetAddress *address);
319 		return g_inet_address_get_is_mc_node_local(gInetAddress);
320 	}
321 	
322 	/**
323 	 * Tests whether address is a site-local multicast address.
324 	 * Since 2.22
325 	 * Returns: TRUE if address is a site-local multicast address.
326 	 */
327 	public int getIsMcSiteLocal()
328 	{
329 		// gboolean g_inet_address_get_is_mc_site_local (GInetAddress *address);
330 		return g_inet_address_get_is_mc_site_local(gInetAddress);
331 	}
332 	
333 	/**
334 	 * Tests whether address is an organization-local multicast address.
335 	 * Since 2.22
336 	 * Returns: TRUE if address is an organization-local multicast address.
337 	 */
338 	public int getIsMcOrgLocal()
339 	{
340 		// gboolean g_inet_address_get_is_mc_org_local (GInetAddress *address);
341 		return g_inet_address_get_is_mc_org_local(gInetAddress);
342 	}
343 	
344 	/**
345 	 * Tests whether address is a global multicast address.
346 	 * Since 2.22
347 	 * Returns: TRUE if address is a global multicast address.
348 	 */
349 	public int getIsMcGlobal()
350 	{
351 		// gboolean g_inet_address_get_is_mc_global (GInetAddress *address);
352 		return g_inet_address_get_is_mc_global(gInetAddress);
353 	}
354 }