blob: 182a049d17e69efee4c1c45a3aec158fcaf13c06 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#+build linux, darwin, netbsd, openbsd, freebsd
package posix
import "core:c"
when ODIN_OS == .Darwin {
foreign import lib "system:System"
} else {
foreign import lib "system:c"
}
// net/if.h - sockets local interfaces
foreign lib {
/*
Retrieve an array of name indexes. Where the last one has an index of 0 and name of nil.
Returns: nil (setting errno) on failure, an array that should be freed with if_freenameindex otherwise
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/if_nameindex.html ]]
*/
if_nameindex :: proc() -> [^]if_nameindex_t ---
/*
Returns the interface index matching the name or zero.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/if_nametoindex.html ]]
*/
if_nametoindex :: proc(name: cstring) -> c.uint ---
/*
Returns the name corresponding to the index.
ifname should be at least IF_NAMESIZE bytes in size.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/if_indextoname.html ]]
*/
if_indextoname :: proc(ifindex: c.uint, ifname: [^]byte) -> cstring ---
/*
Frees memory allocated by if_nameindex.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/if_freenameindex.html ]]
*/
if_freenameindex :: proc(ptr: ^if_nameindex_t) ---
}
when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD || ODIN_OS == .Linux {
// NOTE: `_t` suffix added due to name conflict.
if_nameindex_t :: struct {
if_index: c.uint, /* [PSX] 1, 2, ... */
if_name: cstring, /* [PSX] null terminated name: "le0", ... */
}
IF_NAMESIZE :: 16
}
|