1.60 <GNetworkAddress>

Class: <GNetworkAddress>

It derives from <GObject>.

<GNetworkAddress> provides an easy way to resolve a hostname and then attempt to connect to that host, handling the possibility of multiple IP addresses and multiple address families.

The enumeration results of resolved addresses may be cached as long as this object is kept alive which may have unexpected results if alive for too long.

See <GSocketConnectable> for an example of using the connectable interface.

Fields

parent-instance

Properties

Property: network-address:hostname self

Hostname to resolve.

Its value is a string, or #f.

It can only be set when the object is made, with #:hostname.

Property: network-address:port self

Network port.

Its value is an unsigned 32-bit integer.

It can only be set when the object is made, with #:port.

Property: network-address:scheme self

URI scheme.

Its value is a string, or #f.

It can only be set when the object is made, with #:scheme.

Procedures

Method: network-address:get-hostname self ⇒ %return
Method: get-hostname self ⇒ %return

Gets self’s hostname. This might be either UTF-8 or ASCII-encoded, depending on what self was created with.

self

Passed: a <GNetworkAddress>.

a <GNetworkAddress>

%return

Returned: a string.

self’s hostname

Method: network-address:get-port self ⇒ %return
Method: get-port self ⇒ %return

Gets self’s port number

self

Passed: a <GNetworkAddress>.

a <GNetworkAddress>

%return

Returned: an unsigned 16-bit integer.

self’s port (which may be 0)

Method: network-address:get-scheme self ⇒ %return
Method: get-scheme self ⇒ %return

Gets self’s scheme

self

Passed: a <GNetworkAddress>.

a <GNetworkAddress>

%return

Returned: a string, or #f.

self’s scheme (#f if not built from URI)

Procedure: network-address:new hostname port ⇒ %return

Creates a new <GSocketConnectable> for connecting to the given hostname and port.

Note that depending on the configuration of the machine, a hostname of localhost may refer to the IPv4 loopback address only, or to both IPv4 and IPv6; use network-address:new-loopback to create a <GNetworkAddress> that is guaranteed to resolve to both addresses.

hostname

Passed: a string.

the hostname

port

Passed: an unsigned 16-bit integer.

the port

%return

Returned: a <GNetworkAddress>.

the new <GNetworkAddress>

Procedure: network-address:new-loopback port ⇒ %return

Creates a new <GSocketConnectable> for connecting to the local host over a loopback connection to the given port. This is intended for use in connecting to local services which may be running on IPv4 or IPv6.

The connectable will return IPv4 and IPv6 loopback addresses, regardless of how the host resolves localhost. By contrast, network-address:new will often only return an IPv4 address when resolving localhost, and an IPv6 address for localhost6.

network-address:get-hostname will always return localhost for a <GNetworkAddress> created with this constructor.

port

Passed: an unsigned 16-bit integer.

the port

%return

Returned: a <GNetworkAddress>.

the new <GNetworkAddress>

Procedure: network-address:parse host-and-port default-port ⇒ %return

Creates a new <GSocketConnectable> for connecting to the given hostname and port. May fail and return #f in case parsing host-and-port fails.

host-and-port may be in any of a number of recognised formats; an IPv6 address, an IPv4 address, or a domain name (in which case a DNS lookup is performed). Quoting with [] is supported for all address types. A port override may be specified in the usual way with a colon.

If no port is specified in host-and-port then default-port will be used as the port number to connect to.

In general, host-and-port is expected to be provided by the user (allowing them to give the hostname, and a port override if necessary) and default-port is expected to be provided by the application.

(The port component of host-and-port can also be specified as a service name rather than as a numeric port, but this functionality is deprecated, because it depends on the contents of /etc/services, which is generally quite sparse on platforms other than Linux.)

host-and-port

Passed: a string.

the hostname and optionally a port

default-port

Passed: an unsigned 16-bit integer.

the default port if not in host-and-port

%return

Returned: a <GNetworkAddress>.

the new <GNetworkAddress>, or #f on error

Procedure: network-address:parse-uri uri default-port ⇒ %return

Creates a new <GSocketConnectable> for connecting to the given uri. May fail and return #f in case parsing uri fails.

Using this rather than network-address:new or network-address:parse allows <GSocketClient> to determine when to use application-specific proxy protocols.

uri

Passed: a string.

the hostname and optionally a port

default-port

Passed: an unsigned 16-bit integer.

The default port if none is found in the URI

%return

Returned: a <GNetworkAddress>.

the new <GNetworkAddress>, or #f on error