InetAddress
Object Hierarchy:
GLib.InetAddress
GLib.InetAddress
GLib.InetAddress
GLib.Object
GLib.Object
GLib.Object->GLib.InetAddress
Description:
[ CCode ( type_id = "g_inet_address_get_type ()" ) ]public class InetAddress : Object
InetAddress represents an IPv4 or IPv6 internet address.
Use lookup_by_name or
lookup_by_name_async to look up the
InetAddress for a hostname. Use lookup_by_address or
lookup_by_address_async to look up the hostname for a
InetAddress .
To actually connect to a remote host, you will need a InetSocketAddress (which
includes a InetAddress as well as a port number).
Example: InetAddress:
public static int main (string [] args) { Resolver resolver = Resolver.get_default (); // Example 1: InetAddress address1 = new InetAddress.from_bytes ({208 , 80 , 152 , 201 }, SocketFamily.IPV4 ); try { // Output: ``wikipedia-lb.pmtpa.wikimedia.org`` (Wed Oct 24, 20012) string hostname = resolver.lookup_by_address (address1 , null ); print ("host: %s \n " , hostname); } catch (Error e) { print ("Error: %s \n " , e.message); } // Example 2: InetAddress address2 = new InetAddress.from_string ("208.80.152.201" ); try { // Output: ``wikipedia-lb.pmtpa.wikimedia.org`` (Wed Oct 24, 20012) string hostname = resolver.lookup_by_address (address2 , null ); print ("host: %s \n " , hostname); } catch (Error e) { print ("Error: %s \n " , e.message); } // Example 3: try { // Resolve hostname to IP address: string host = "www.valadoc.org" ; List<InetAddress> addresses = resolver.lookup_by_name (host, null ); InetAddress address4 = addresses.nth_data (0 ); // Connect: SocketClient client = new SocketClient (); SocketConnection conn = client.connect (new InetSocketAddress (address4 , 80 )); // Send HTTP GET request string message = @"GET / HTTP/1.1 \r \n Host: %s \r \n \r \n " .printf (host); conn.output_stream.write (message.data); // Receive response DataInputStream response = new DataInputStream (conn.input_stream); string status_line = response.read_line (null ).strip (); print ("Received status line: %s \n " , status_line); } catch (Error e) { print ("Error: %s \n " , e.message); } return 0 ; }
valac --pkg gio-2.0 GLib.InetAddress.vala
Content:
Properties:
public void * bytes { get ; construct ; }
public SocketFamily family { get ; construct ; }
public bool is_any { get ; }
Whether this is the "any" address for its family.
public bool is_link_local { get ; }
Whether this is a link-local address.
public bool is_loopback { get ; }
Whether this is the loopback address for its family.
public bool is_mc_global { get ; }
Whether this is a global multicast address.
public bool is_mc_link_local { get ; }
Whether this is a link-local multicast address.
public bool is_mc_node_local { get ; }
Whether this is a node-local multicast address.
public bool is_mc_org_local { get ; }
Whether this is an organization-local multicast address.
public bool is_mc_site_local { get ; }
Whether this is a site-local multicast address.
public bool is_multicast { get ; }
Whether this is a multicast address.
public bool is_site_local { get ; }
Whether this is a site-local address.
Creation methods:
Methods:
public bool equal (InetAddress other_address)
Checks if two InetAddress instances are
equal, e.
public SocketFamily get_family ()
Gets this 's family
public bool get_is_any ()
Tests whether this is the "any"
address for its family.
public bool get_is_link_local ()
Tests whether this is a link-local
address (that is, if it identifies a host on a local network that is not connected to the Internet).
public bool get_is_loopback ()
Tests whether this is the loopback
address for its family.
public bool get_is_mc_global ()
Tests whether this is a global
multicast address.
public bool get_is_mc_link_local ()
Tests whether this is a link-local
multicast address.
public bool get_is_mc_node_local ()
Tests whether this is a node-local
multicast address.
public bool get_is_mc_org_local ()
Tests whether this is an
organization-local multicast address.
public bool get_is_mc_site_local ()
Tests whether this is a site-local
multicast address.
public bool get_is_multicast ()
Tests whether this is a multicast
address.
public bool get_is_site_local ()
Tests whether this is a site-local
address such as 10.0.0.1 (that is, the address identifies a host on a local network that can not be reached directly from the
Internet, but which may have outgoing Internet connectivity via a NAT or firewall).
public size_t get_native_size ()
Gets the size of the native raw binary address for
this .
public virtual unowned uint8 [] to_bytes ()
Gets the raw binary address data from this
.
public virtual string to_string ()
Converts this to string form.
Inherited Members:
All known members inherited from class GLib.Object
@get
@new
@ref
@set
add_toggle_ref
add_weak_pointer
bind_property
connect
constructed
disconnect
dispose
dup_data
dup_qdata
force_floating
freeze_notify
get_class
get_data
get_property
get_qdata
get_type
getv
interface_find_property
interface_install_property
interface_list_properties
is_floating
new_valist
new_with_properties
newv
notify
notify_property
ref_count
ref_sink
remove_toggle_ref
remove_weak_pointer
replace_data
replace_qdata
set_data
set_data_full
set_property
set_qdata
set_qdata_full
set_valist
setv
steal_data
steal_qdata
thaw_notify
unref
watch_closure
weak_ref
weak_unref