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