SocketAddress

public enum SocketAddress

A Swift wrapper for sockaddr.

This wrapper was described on the blog from Marco Masser

  • For IPv4 addresses.

    Declaration

    Swift

    case version4(address: sockaddr_in)
  • For IPv6 addresses.

    Declaration

    Swift

    case version6(address: sockaddr_in6)
  • Initialize a SocketAddress from the given addrinfo.

    Declaration

    Swift

    public init(addrInfo: addrinfo)

    Parameters

    addrinfo

    The addrinfo from which to build the SocketAddress

  • Initialize a SocketAddress from the result of the closure.

    Declaration

    Swift

    public init?(addressProvider: @escaping (UnsafeMutablePointer<sockaddr>, UnsafeMutablePointer<socklen_t>) throws -> Void) rethrows

    Parameters

    addressProvider

    A closure that returns either an IPv4 addrinfo structure or an IPv6 addrinfo structure, or nil.

  • Use the SocketAddress in the given closure.

    Declaration

    Swift

    public func doWithPtr<Result>(body: (UnsafePointer<sockaddr>, socklen_t) throws -> Result) rethrows -> Result

    Parameters

    body

    A closure that needs a sockaddr pointer.

    Return Value

    The rsult of the closure.