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 * Free the returned object with g_object_unref(). 130 * 131 * Since: 2.22 132 * 133 * Throws: ConstructionException GTK+ fails to create the object. 134 */ 135 public this(ubyte[] bytes, GSocketFamily family) 136 { 137 auto p = g_inet_address_new_from_bytes(bytes.ptr, family); 138 139 if(p is null) 140 { 141 throw new ConstructionException("null returned by new_from_bytes"); 142 } 143 144 this(cast(GInetAddress*) p, true); 145 } 146 147 /** 148 * Parses @string as an IP address and creates a new #GInetAddress. 149 * 150 * Params: 151 * str = a string representation of an IP address 152 * 153 * Return: a new #GInetAddress corresponding to @string, or %NULL if 154 * @string could not be parsed. 155 * Free the returned object with g_object_unref(). 156 * 157 * Since: 2.22 158 * 159 * Throws: ConstructionException GTK+ fails to create the object. 160 */ 161 public this(string str) 162 { 163 auto p = g_inet_address_new_from_string(Str.toStringz(str)); 164 165 if(p is null) 166 { 167 throw new ConstructionException("null returned by new_from_string"); 168 } 169 170 this(cast(GInetAddress*) p, true); 171 } 172 173 /** 174 * Checks if two #GInetAddress instances are equal, e.g. the same address. 175 * 176 * Params: 177 * otherAddress = Another #GInetAddress. 178 * 179 * Return: %TRUE if @address and @other_address are equal, %FALSE otherwise. 180 * 181 * Since: 2.30 182 */ 183 public bool equal(InetAddress otherAddress) 184 { 185 return g_inet_address_equal(gInetAddress, (otherAddress is null) ? null : otherAddress.getInetAddressStruct()) != 0; 186 } 187 188 /** 189 * Gets @address's family 190 * 191 * Return: @address's family 192 * 193 * Since: 2.22 194 */ 195 public GSocketFamily getFamily() 196 { 197 return g_inet_address_get_family(gInetAddress); 198 } 199 200 /** 201 * Tests whether @address is the "any" address for its family. 202 * 203 * Return: %TRUE if @address is the "any" address for its family. 204 * 205 * Since: 2.22 206 */ 207 public bool getIsAny() 208 { 209 return g_inet_address_get_is_any(gInetAddress) != 0; 210 } 211 212 /** 213 * Tests whether @address is a link-local address (that is, if it 214 * identifies a host on a local network that is not connected to the 215 * Internet). 216 * 217 * Return: %TRUE if @address is a link-local address. 218 * 219 * Since: 2.22 220 */ 221 public bool getIsLinkLocal() 222 { 223 return g_inet_address_get_is_link_local(gInetAddress) != 0; 224 } 225 226 /** 227 * Tests whether @address is the loopback address for its family. 228 * 229 * Return: %TRUE if @address is the loopback address for its family. 230 * 231 * Since: 2.22 232 */ 233 public bool getIsLoopback() 234 { 235 return g_inet_address_get_is_loopback(gInetAddress) != 0; 236 } 237 238 /** 239 * Tests whether @address is a global multicast address. 240 * 241 * Return: %TRUE if @address is a global multicast address. 242 * 243 * Since: 2.22 244 */ 245 public bool getIsMcGlobal() 246 { 247 return g_inet_address_get_is_mc_global(gInetAddress) != 0; 248 } 249 250 /** 251 * Tests whether @address is a link-local multicast address. 252 * 253 * Return: %TRUE if @address is a link-local multicast address. 254 * 255 * Since: 2.22 256 */ 257 public bool getIsMcLinkLocal() 258 { 259 return g_inet_address_get_is_mc_link_local(gInetAddress) != 0; 260 } 261 262 /** 263 * Tests whether @address is a node-local multicast address. 264 * 265 * Return: %TRUE if @address is a node-local multicast address. 266 * 267 * Since: 2.22 268 */ 269 public bool getIsMcNodeLocal() 270 { 271 return g_inet_address_get_is_mc_node_local(gInetAddress) != 0; 272 } 273 274 /** 275 * Tests whether @address is an organization-local multicast address. 276 * 277 * Return: %TRUE if @address is an organization-local multicast address. 278 * 279 * Since: 2.22 280 */ 281 public bool getIsMcOrgLocal() 282 { 283 return g_inet_address_get_is_mc_org_local(gInetAddress) != 0; 284 } 285 286 /** 287 * Tests whether @address is a site-local multicast address. 288 * 289 * Return: %TRUE if @address is a site-local multicast address. 290 * 291 * Since: 2.22 292 */ 293 public bool getIsMcSiteLocal() 294 { 295 return g_inet_address_get_is_mc_site_local(gInetAddress) != 0; 296 } 297 298 /** 299 * Tests whether @address is a multicast address. 300 * 301 * Return: %TRUE if @address is a multicast address. 302 * 303 * Since: 2.22 304 */ 305 public bool getIsMulticast() 306 { 307 return g_inet_address_get_is_multicast(gInetAddress) != 0; 308 } 309 310 /** 311 * Tests whether @address is a site-local address such as 10.0.0.1 312 * (that is, the address identifies a host on a local network that can 313 * not be reached directly from the Internet, but which may have 314 * outgoing Internet connectivity via a NAT or firewall). 315 * 316 * Return: %TRUE if @address is a site-local address. 317 * 318 * Since: 2.22 319 */ 320 public bool getIsSiteLocal() 321 { 322 return g_inet_address_get_is_site_local(gInetAddress) != 0; 323 } 324 325 /** 326 * Gets the size of the native raw binary address for @address. This 327 * is the size of the data that you get from g_inet_address_to_bytes(). 328 * 329 * Return: the number of bytes used for the native version of @address. 330 * 331 * Since: 2.22 332 */ 333 public size_t getNativeSize() 334 { 335 return g_inet_address_get_native_size(gInetAddress); 336 } 337 338 /** 339 * Gets the raw binary address data from @address. 340 * 341 * Return: a pointer to an internal array of the bytes in @address, 342 * which should not be modified, stored, or freed. The size of this 343 * array can be gotten with g_inet_address_get_native_size(). 344 * 345 * Since: 2.22 346 */ 347 public ubyte* toBytes() 348 { 349 return g_inet_address_to_bytes(gInetAddress); 350 } 351 352 /** 353 * Converts @address to string form. 354 * 355 * Return: a representation of @address as a string, which should be 356 * freed after use. 357 * 358 * Since: 2.22 359 */ 360 public override string toString() 361 { 362 auto retStr = g_inet_address_to_string(gInetAddress); 363 364 scope(exit) Str.freeString(retStr); 365 return Str.toString(retStr); 366 } 367 }