Module Eio_net_unix.InterfaceSource

Interface addresses and their changes.

The host's network interface addresses, and their changes.

Sourcemodule Address : sig ... end

Interface addresses.

Sourcemodule type S = sig ... end

The type for a host's interface addresses and their changes: this module's, or a stand-in's.

include S
Sourceval addresses : unit -> Address.t list

addresses () is every IPv4 and IPv6 address of the host's interfaces, up or down, in the order getifaddrs(3) lists them. An IPv6 link-local address is the one the interface's link sees, with no scope embedded in it as a KAME stack (macOS, the BSDs) embeds it.

Sourcetype watch

The type for subscriptions to the host's address changes.

Sourceval watch : sw:Eio.Switch.t -> watch

watch ~sw subscribes to the kernel's address-change notifications: rtnetlink's RTMGRP_IPV4_IFADDR and RTMGRP_IPV6_IFADDR groups on Linux, a PF_ROUTE socket elsewhere. Releasing sw closes it. A caller that reads addresses after opening the watch misses no change.

Sourceval changed : watch -> unit

changed w waits until an address has been added to or removed from an interface since the previous call returned, or since w opened. A notification the kernel dropped because the socket's buffer was full counts as a change. On Linux only the kernel's messages count: one a process with CAP_NET_ADMIN sends to the watch's port is ignored. A routing socket also carries messages of no address, a route learned for each new destination among them: each costs one read and returns nothing. A failed read raises the Eio.Io error Eio_unix.Err.v makes of it.