<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Event",
  "identifier" : "/documentation/Event/SocketAddress/from(storage:length:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Event"
    ],
    "preciseIdentifier" : "s:5Event13SocketAddressV4from7storage6lengthACSgSo09sockaddr_E0V_s6UInt32VtFZ"
  },
  "title" : "from(storage:length:)"
}
-->

# from(storage:length:)

Wraps a kernel-supplied `sockaddr_storage` as a `SocketAddress`.

```
static func from(storage: sockaddr_storage, length: socklen_t) -> SocketAddress?
```

## Parameters

`storage`

A `sockaddr_storage` already populated by the kernel.

`length`

The `socklen_t` the kernel reported via `getsockname(2)` /
`getpeername(2)`. Stored as-is; not validated against `ss_family`.

## Discussion

Used by [`localAddress`](/documentation/Event/ServerSocket/localAddress), [`localAddress`](/documentation/Event/Socket/localAddress), and
[`remoteAddress`](/documentation/Event/Socket/remoteAddress) to convert the result of `getsockname(2)` /
`getpeername(2)` into the value type the rest of the API speaks.
Returns `nil` for any address family other than `AF_INET` or `AF_INET6`
— the only families this package supports.

Exposed as a `static` factory rather than a failable initializer so
the struct’s other initializers ([`ipv4(_:port:)`](/documentation/Event/SocketAddress/ipv4(_:port:)), [`ipv6(_:port:)`](/documentation/Event/SocketAddress/ipv6(_:port:)),
[`anyIPv4(port:)`](/documentation/Event/SocketAddress/anyIPv4(port:))) keep using the synthesised memberwise constructor.