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