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 	public static GType getType()
114 	{
115 		return g_inet_address_get_type();
116 	}
117 
118 	/**
119 	 * Creates a new #GInetAddress from the given @family and @bytes.
120 	 * @bytes should be 4 bytes for %G_SOCKET_FAMILY_IPV4 and 16 bytes for
121 	 * %G_SOCKET_FAMILY_IPV6.
122 	 *
123 	 * Params:
124 	 *     bytes = raw address data
125 	 *     family = the address family of @bytes
126 	 *
127 	 * Return: a new #GInetAddress corresponding to @family and @bytes.
128 	 *
129 	 * Since: 2.22
130 	 *
131 	 * Throws: ConstructionException GTK+ fails to create the object.
132 	 */
133 	public this(ubyte[] bytes, GSocketFamily family)
134 	{
135 		auto p = g_inet_address_new_from_bytes(bytes.ptr, family);
136 		
137 		if(p is null)
138 		{
139 			throw new ConstructionException("null returned by new_from_bytes");
140 		}
141 		
142 		this(cast(GInetAddress*) p, true);
143 	}
144 
145 	/**
146 	 * Parses @string as an IP address and creates a new #GInetAddress.
147 	 *
148 	 * Params:
149 	 *     str = a string representation of an IP address
150 	 *
151 	 * Return: a new #GInetAddress corresponding to @string, or %NULL if
152 	 *     @string could not be parsed.
153 	 *
154 	 * Since: 2.22
155 	 *
156 	 * Throws: ConstructionException GTK+ fails to create the object.
157 	 */
158 	public this(string str)
159 	{
160 		auto p = g_inet_address_new_from_string(Str.toStringz(str));
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 	 * Return: %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 	 * Return: @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 	 * Return: %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 	 * Return: %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 	 * Return: %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 	 * Return: %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 	 * Return: %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 	 * Return: %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 	 * Return: %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 	 * Return: %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 	 * Return: %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 	 * Return: %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 	 * Return: 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 	 * Return: 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 	 * Return: 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 		return Str.toString(g_inet_address_to_string(gInetAddress));
360 	}
361 }