[]Struct gio::NetworkAddress

pub struct NetworkAddress(_, _);

NetworkAddress 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 SocketConnectable for an example of using the connectable interface.

Implements

NetworkAddressExt, glib::object::ObjectExt, SocketConnectableExt

Methods

impl NetworkAddress[src]

pub fn new(hostname: &str, port: u16) -> NetworkAddress[src]

Creates a new SocketConnectable 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 NetworkAddress::new_loopback to create a NetworkAddress that is guaranteed to resolve to both addresses.

hostname

the hostname

port

the port

Returns

the new NetworkAddress

pub fn new_loopback(port: u16) -> NetworkAddress[src]

Creates a new SocketConnectable 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, NetworkAddress::new will often only return an IPv4 address when resolving localhost, and an IPv6 address for localhost6.

NetworkAddressExt::get_hostname will always return localhost for a NetworkAddress created with this constructor.

Feature: v2_44

port

the port

Returns

the new NetworkAddress

pub fn parse(
    host_and_port: &str,
    default_port: u16
) -> Result<NetworkAddress, Error>
[src]

Creates a new SocketConnectable for connecting to the given hostname and port. May fail and return None 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

the hostname and optionally a port

default_port

the default port if not in host_and_port

Returns

the new NetworkAddress, or None on error

pub fn parse_uri(uri: &str, default_port: u16) -> Result<NetworkAddress, Error>[src]

Creates a new SocketConnectable for connecting to the given uri. May fail and return None in case parsing uri fails.

Using this rather than NetworkAddress::new or NetworkAddress::parse allows SocketClient to determine when to use application-specific proxy protocols.

uri

the hostname and optionally a port

default_port

The default port if none is found in the URI

Returns

the new NetworkAddress, or None on error

Trait Implementations

impl Clone for NetworkAddress

impl Debug for NetworkAddress

impl Display for NetworkAddress[src]

impl Eq for NetworkAddress

impl Hash for NetworkAddress

impl IsA<SocketConnectable> for NetworkAddress

impl Ord for NetworkAddress

impl<T: ObjectType> PartialEq<T> for NetworkAddress

impl<T: ObjectType> PartialOrd<T> for NetworkAddress

impl Send for NetworkAddress[src]

impl StaticType for NetworkAddress

impl Sync for NetworkAddress[src]

Auto Trait Implementations

impl RefUnwindSafe for NetworkAddress

impl Unpin for NetworkAddress

impl UnwindSafe for NetworkAddress

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Super, Sub> CanDowncast<Sub> for Super where
    Sub: IsA<Super>,
    Super: IsA<Super>, 
[src]

impl<T> Cast for T where
    T: ObjectType
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ObjectExt for T where
    T: ObjectType
[src]

impl<'a, T> ToGlibContainerFromSlice<'a, *const GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 
[src]

impl<'a, T> ToGlibContainerFromSlice<'a, *const GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 
[src]

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 
[src]

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 
[src]

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToSendValue for T where
    T: ToValue + SetValue + Send + ?Sized
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> ToValue for T where
    T: SetValue + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.