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