net_if.odin 1.6 KB

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