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.InetSocketAddress; 26 27 private import gio.InetAddress; 28 private import gio.SocketAddress; 29 private import glib.ConstructionException; 30 private import glib.Str; 31 private import gobject.ObjectG; 32 private import gtkc.gio; 33 public import gtkc.giotypes; 34 35 36 /** 37 * An IPv4 or IPv6 socket address; that is, the combination of a 38 * #GInetAddress and a port number. 39 */ 40 public class InetSocketAddress : SocketAddress 41 { 42 /** the main Gtk struct */ 43 protected GInetSocketAddress* gInetSocketAddress; 44 45 /** Get the main Gtk struct */ 46 public GInetSocketAddress* getInetSocketAddressStruct(bool transferOwnership = false) 47 { 48 if (transferOwnership) 49 ownedRef = false; 50 return gInetSocketAddress; 51 } 52 53 /** the main Gtk struct as a void* */ 54 protected override void* getStruct() 55 { 56 return cast(void*)gInetSocketAddress; 57 } 58 59 protected override void setStruct(GObject* obj) 60 { 61 gInetSocketAddress = cast(GInetSocketAddress*)obj; 62 super.setStruct(obj); 63 } 64 65 /** 66 * Sets our main struct and passes it to the parent class. 67 */ 68 public this (GInetSocketAddress* gInetSocketAddress, bool ownedRef = false) 69 { 70 this.gInetSocketAddress = gInetSocketAddress; 71 super(cast(GSocketAddress*)gInetSocketAddress, ownedRef); 72 } 73 74 75 /** */ 76 public static GType getType() 77 { 78 return g_inet_socket_address_get_type(); 79 } 80 81 /** 82 * Creates a new #GInetSocketAddress for @address and @port. 83 * 84 * Params: 85 * address = a #GInetAddress 86 * port = a port number 87 * 88 * Returns: a new #GInetSocketAddress 89 * 90 * Since: 2.22 91 * 92 * Throws: ConstructionException GTK+ fails to create the object. 93 */ 94 public this(InetAddress address, ushort port) 95 { 96 auto p = g_inet_socket_address_new((address is null) ? null : address.getInetAddressStruct(), port); 97 98 if(p is null) 99 { 100 throw new ConstructionException("null returned by new"); 101 } 102 103 this(cast(GInetSocketAddress*) p, true); 104 } 105 106 /** 107 * Creates a new #GInetSocketAddress for @address and @port. 108 * 109 * If @address is an IPv6 address, it can also contain a scope ID 110 * (separated from the address by a `%`). 111 * 112 * Params: 113 * address = the string form of an IP address 114 * port = a port number 115 * 116 * Returns: a new #GInetSocketAddress, or %NULL if @address cannot be 117 * parsed. 118 * 119 * Since: 2.40 120 * 121 * Throws: ConstructionException GTK+ fails to create the object. 122 */ 123 public this(string address, uint port) 124 { 125 auto p = g_inet_socket_address_new_from_string(Str.toStringz(address), port); 126 127 if(p is null) 128 { 129 throw new ConstructionException("null returned by new_from_string"); 130 } 131 132 this(cast(GInetSocketAddress*) p, true); 133 } 134 135 /** 136 * Gets @address's #GInetAddress. 137 * 138 * Returns: the #GInetAddress for @address, which must be 139 * g_object_ref()'d if it will be stored 140 * 141 * Since: 2.22 142 */ 143 public InetAddress getAddress() 144 { 145 auto p = g_inet_socket_address_get_address(gInetSocketAddress); 146 147 if(p is null) 148 { 149 return null; 150 } 151 152 return ObjectG.getDObject!(InetAddress)(cast(GInetAddress*) p); 153 } 154 155 /** 156 * Gets the `sin6_flowinfo` field from @address, 157 * which must be an IPv6 address. 158 * 159 * Returns: the flowinfo field 160 * 161 * Since: 2.32 162 */ 163 public uint getFlowinfo() 164 { 165 return g_inet_socket_address_get_flowinfo(gInetSocketAddress); 166 } 167 168 /** 169 * Gets @address's port. 170 * 171 * Returns: the port for @address 172 * 173 * Since: 2.22 174 */ 175 public ushort getPort() 176 { 177 return g_inet_socket_address_get_port(gInetSocketAddress); 178 } 179 180 /** 181 * Gets the `sin6_scope_id` field from @address, 182 * which must be an IPv6 address. 183 * 184 * Returns: the scope id field 185 * 186 * Since: 2.32 187 */ 188 public uint getScopeId() 189 { 190 return g_inet_socket_address_get_scope_id(gInetSocketAddress); 191 } 192 }