Skip to main content

Module net

Module net 

Source
Expand description

Network interfaces, download and upload, and connection counts.

sys-lib never sends a packet, never lists connections or their addresses, and never says which program owns a socket: it reports interfaces and counts.

use sys_lib as sys;

for i in sys::net::interfaces()? {
    println!("{} {:?} up={} speed={:?}", i.name, i.kind, i.running, i.speed_mbps);
}

Structs§

Connections
How many network connections the machine has open, as counts. A value an OS does not report is None.
Counters
One interface’s cumulative counters.
Dns
The DNS configuration, read from configuration only: sys-lib never sends a DNS query.
Interface
One network interface.
InterfaceOptions
Which interfaces interfaces_with returns, and in how much detail.
InterfaceTraffic
One interface’s traffic.
IpNet
An address with its prefix length.
Mac
A hardware (MAC) address. An identifier: for device identity use the device module (0.5), never a raw MAC.
Sampler
Measures download and upload between samples. Owned by the caller: two samplers never disturb each other. sample never blocks and allocates nothing.
Totals
Bytes and packets moved since boot, every interface but loopback.
Traffic
Download and upload over an interval.

Enums§

InterfaceKind
What kind of network interface.
MacKind
Whether a MAC address is the hardware’s own (E-54).

Constants§

DEFAULT_WINDOW
The interval traffic measures over: 1 s.

Functions§

addresses
The addresses of the interfaces that are up, without loopback and link-local addresses (E-57).
connections
How many network connections the machine has open: counts only, never addresses, ports, or owners. Inside a container they are the container’s network namespace.
counters
Each interface’s cumulative counters, loopback included (Tier 2).
dns
The DNS servers this machine is configured to use.
interfaces
Every network interface, sorted by index, then name.
interfaces_with
The interfaces options selects, sorted by index, then name. A Kubernetes node with thousands of veth interfaces lists them quickly with details: false (E-56).
primary
The interface holding the default route; None without one.
totals
Bytes and packets moved since boot, every interface but loopback: one read, no waiting. Counters are 64-bit on every platform. Inside a container they are the container’s network namespace.
traffic
Download and upload over the next second. Blocks for DEFAULT_WINDOW; a monitor keeps a Sampler.
traffic_over
Download and upload over window, clamped to 100 ms ..= 60 s. Blocks for the window.