Crate cotton_netif

source ·
Expand description

Enumerating network interfaces and their IP addresses

The netif crate encapsulates the obtaining of the host’s network interfaces and IP addresses. It supports both static/synchronous listing (i.e., a snapshot of the current list of network interfaces) using get_interfaces and dynamic/asynchronous listing (i.e., getting events as network interfaces and addresses come and go) using get_interfaces_async.

At present this crate only works on Linux (and maybe BSD) but the structure is such that adding compatibility with other platforms in future, shouldn’t require changes to any client code.

Todo:

  • IPv6 in linux_netlink
  • Better test coverage
  • Does DelAddr need to include the address? yes
  • Can get_interfaces_async itself not be async?
  • Can we use just one netlink socket, perhaps with lower-level neli?
  • Turn async into a (cargo) Feature

Modules

Static listing using Linux/glibc’s getifaddrs(3)
Dynamic listing using Linux’s netlink socket

Structs

Flags describing a network interface’s features and state
Kernel network interface index (1-based)

Enums

Event when a new interface or address is detected, or when one disappears

Functions

Obtain the current list of network interfaces
Obtain the current list of network interfaces and a stream of future events