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
  • v4

    Undocumented

    Declaration

    Swift

    case v4(SocketAddress.IPv4Address)
  • v6

    Undocumented

    Declaration

    Swift

    case v6(SocketAddress.IPv6Address)
  • Undocumented

    Declaration

    Swift

    case unixDomainSocket(SocketAddress.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: UInt16? { 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)
  • Creates a new IPv6 SocketAddress.

    Declaration

    Swift

    public init(_ addr: sockaddr_in6, host: String)
  • Creates a new Unix Domain Socket SocketAddress.

    Declaration

    Swift

    public init(_ addr: sockaddr_un)
  • 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: UInt16) 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 newAddressResolving(host: String, port: Int) throws -> SocketAddress

    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 }