source: appstream-generator/build/girepo/gio/InetAddress.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

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