This commit is contained in:
ge
2026-05-01 23:03:05 +03:00
parent 04a644869e
commit ed674e41e1
10 changed files with 430 additions and 412 deletions
+4 -3
View File
@@ -30,7 +30,7 @@ pub fn (e NetworkInterfaceNotFound) msg() string {
}
// name_to_index translates the network interface name to index.
// See also if_nametoindex(3).
// See also [if_nametoindex(3p)](https://man7.org/linux/man-pages/man3/if_nametoindex.3p.html).
pub fn name_to_index(name string) !u32 {
index := C.if_nametoindex(&char(name.str))
if index == 0 {
@@ -47,7 +47,7 @@ pub fn name_to_index(name string) !u32 {
}
// index_to_name translates the network interface index to name e.g. 'eth0'.
// See also if_indextoname(3).
// See also [if_indextoname(3p)](https://man7.org/linux/man-pages/man3/if_indextoname.3p.html).
pub fn index_to_name(index u32) !string {
name := []u8{len: C.IF_NAMESIZE}
ifname := C.if_indextoname(index, name.data)
@@ -92,7 +92,8 @@ pub fn find_network_interface(s string) !NetworkInterfaceId {
}
}
// network_interfaces returns an array with names and indexes of all network interfaces in system.
// network_interfaces returns an array with names and indexes of all network interfaces on system.
// See also [if_nameindex(3p)](https://man7.org/linux/man-pages/man3/if_nameindex.3p.html).
pub fn network_interfaces() ![]NetworkInterfaceId {
ifaces := C.if_nameindex()
if isnil(ifaces) {