arpa_inet.odin 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // arpa/inet.h - definitions for internet operations
  9. foreign lib {
  10. // Use Odin's native big endian types `u32be` and `u16be` instead.
  11. // htonl :: proc(c.uint32_t) -> c.uint32_t ---
  12. // htons :: proc(c.uint16_t) -> c.uint16_t ---
  13. // ntohl :: proc(c.uint32_t) -> c.uint32_t ---
  14. // ntohs :: proc(c.uint16_t) -> c.uint16_t ---
  15. // Use of this function is problematic because -1 is a valid address (255.255.255.255).
  16. // Avoid its use in favor of inet_aton(), inet_pton(3), or getaddrinfo(3) which provide a cleaner way to indicate error return.
  17. // inet_addr :: proc(cstring) -> in_addr_t ---
  18. // Convert the Internet host address specified by in to a string in the Internet standard dot notation.
  19. //
  20. // NOTE: returns a static string overwritten by further calls.
  21. //
  22. // [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_ntoa.html ]]
  23. inet_ntoa :: proc(in_addr) -> cstring ---
  24. // Convert a numeric address into a text string suitable for presentation.
  25. //
  26. // Returns `nil` and sets `errno` on failure.
  27. //
  28. // [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_ntop.html ]]
  29. inet_ntop :: proc(
  30. af: AF, // INET or INET6
  31. src: rawptr, // either ^in_addr or ^in_addr6
  32. dst: [^]byte, // use `INET_ADDRSTRLEN` or `INET6_ADDRSTRLEN` for minimum lengths
  33. size: socklen_t,
  34. ) -> cstring ---
  35. // Convert an address in its standard text presentation form into its numeric binary form.
  36. //
  37. // [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_ntop.html ]]
  38. inet_pton :: proc(
  39. af: AF, // INET or INET6
  40. src: cstring,
  41. dst: rawptr, // either ^in_addr or ^in_addr6
  42. size: socklen_t, // size_of(dst^)
  43. ) -> pton_result ---
  44. }
  45. pton_result :: enum c.int {
  46. AFNOSUPPORT = -1,
  47. INVALID = 0,
  48. SUCCESS = 1,
  49. }