net_if.odin 1.6 KB

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