The IPv6 form of accept: takes the next pending connection from s and returns it with the peer's IPv6 address.
Blocking, the INVALID_SOCKET result and ownership of the returned socket are as for accept. The listener must
be an AF_INET6 socket; a host without IPv6 fails at socket or bind before this is reached.
assert(socket_init());
listener := socket(AF_INET6, .SOCK_STREAM, .TCP);
// Hosts without IPv6 or without ::1 have nothing to show.
if listener != INVALID_SOCKET {
defer close_and_reset(*listener);
if bind(listener, "::1", 0, AF_INET6) == 0 {
assert(listen(listener, 4) == 0);
local: sockaddr_in6;
length: socklen_t = size_of(sockaddr_in6);
assert(getsockname(listener, cast(*sockaddr) *local, *length) == 0);
client := socket(AF_INET6, .SOCK_STREAM, .TCP);
defer close_and_reset(*client);
assert(connect(client, cast(*sockaddr) *local, length) == 0);
peer, from := accept_v6(listener);
defer close_and_reset(*peer);
assert(peer != INVALID_SOCKET);
assert(from.sin6_family == AF_INET6);
}
}Doesn't run in the browser (skipped on wasm).
accept_v6 :: (s: Socket) -> (Socket, sockaddr_in6)
The IPv6 form of accept: takes the next pending connection from s and returns it with the peer's IPv6 address.
Blocking, the INVALID_SOCKET result and ownership of the returned socket are as for accept. The listener must
be an AF_INET6 socket; a host without IPv6 fails at socket or bind before this is reached.
Parameters
- s: Socket
Returns
- Socket
- sockaddr_in6
assert(socket_init());
listener := socket(AF_INET6, .SOCK_STREAM, .TCP);
// Hosts without IPv6 or without ::1 have nothing to show.
if listener != INVALID_SOCKET {
defer close_and_reset(*listener);
if bind(listener, "::1", 0, AF_INET6) == 0 {
assert(listen(listener, 4) == 0);
local: sockaddr_in6;
length: socklen_t = size_of(sockaddr_in6);
assert(getsockname(listener, cast(*sockaddr) *local, *length) == 0);
client := socket(AF_INET6, .SOCK_STREAM, .TCP);
defer close_and_reset(*client);
assert(connect(client, cast(*sockaddr) *local, length) == 0);
peer, from := accept_v6(listener);
defer close_and_reset(*peer);
assert(peer != INVALID_SOCKET);
assert(from.sin6_family == AF_INET6);
}
}Doesn't run in the browser (skipped on wasm).