SocketAddress

public enum SocketAddress : CustomStringConvertible

Represent a socket address to which we may want to connect or bind.

  • A single IPv4 address for SocketAddress.

    See more

    Declaration

    Swift

    public struct IPv4Address
  • A single IPv6 address for SocketAddress.

    See more

    Declaration

    Swift

    public struct IPv6Address
  • A single Unix socket address for SocketAddress.

    See more

    Declaration

    Swift

    public struct UnixSocketAddress
  • An IPv4 SocketAddress.

    Declaration

    Swift

    case v4(IPv4Address)
  • An IPv6 SocketAddress.

    Declaration

    Swift

    case v6(IPv6Address)
  • An UNIX Domain SocketAddress.

    Declaration

    Swift

    case unixDomainSocket(UnixSocketAddress)
  • A human-readable description of this SocketAddress. Mostly useful for logging.

    Declaration

    Swift

    public var description: String { get }
  • Returns the protocol family as defined in man 2 socket of this SocketAddress.

    Declaration

    Swift

    public var protocolFamily: Int32 { get }
  • Get the port associated with the address, if defined.

    Declaration

    Swift

    public var port: Int? { get }
  • Calls the given function with a pointer to a sockaddr structure and the associated size of that structure.

    Declaration

    Swift

    public func withSockAddr<T>(_ body: (UnsafePointer<sockaddr>, Int) throws -> T) rethrows -> T
  • Creates a new IPv4 SocketAddress.

    Declaration

    Swift

    public init(_ addr: sockaddr_in, host: String)

    Parameters

    addr

    the sockaddr_in that holds the ipaddress and port.

    host

    the hostname that resolved to the ipaddress.

  • Creates a new IPv6 SocketAddress.

    Declaration

    Swift

    public init(_ addr: sockaddr_in6, host: String)

    Parameters

    addr

    the sockaddr_in that holds the ipaddress and port.

    host

    the hostname that resolved to the ipaddress.

  • Creates a new Unix Domain Socket SocketAddress.

    Declaration

    Swift

    public init(_ addr: sockaddr_un)

    Parameters

    addr

    the sockaddr_un that holds the socket path.

  • Creates a new UDS SocketAddress.

    Throws

    may throw SocketAddressError.unixDomainSocketPathTooLong if the path is too long.

    Declaration

    Swift

    public init(unixDomainSocketPath: String) throws

    Parameters

    path

    the path to use for the SocketAddress.

    Return Value

    the SocketAddress for the given path.

  • Create a new SocketAddress for an IP address in string form.

    Throws

    may throw SocketAddressError.failedToParseIPString if the IP address cannot be parsed.

    Declaration

    Swift

    public init(ipAddress: String, port: Int) throws

    Parameters

    string

    The IP address, in string form.

    port

    The target port.

    Return Value

    the SocketAddress corresponding to this string and port combination.

  • Creates a new SocketAddress for the given host (which will be resolved) and port.

    Throws

    a SocketAddressError.unknown if we could not resolve the host, or SocketAddressError.unsupported if the address itself is not supported (yet).

    Declaration

    Swift

    public static func makeAddressResolvingHost(_ host: String, port: Int) throws -> SocketAddress

    Parameters

    host

    the hostname which should be resolved.

    port

    the port itself

    Return Value

    the SocketAddress for the host / port pair.

  • Declaration

    Swift

    public static func == (lhs: SocketAddress, rhs: SocketAddress) -> Bool
  • Whether this SocketAddress corresponds to a multicast address.

    Declaration

    Swift

    public var isMulticast: Bool { get }