inet.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <endian.h>
  8. #include <inttypes.h>
  9. #include <netinet/in.h>
  10. #include <sys/cdefs.h>
  11. #include <sys/socket.h>
  12. __BEGIN_DECLS
  13. #define INET_ADDRSTRLEN 16
  14. #define INET6_ADDRSTRLEN 46
  15. const char* inet_ntop(int af, const void* src, char* dst, socklen_t);
  16. int inet_pton(int af, const char* src, void* dst);
  17. static inline int inet_aton(const char* cp, struct in_addr* inp)
  18. {
  19. return inet_pton(AF_INET, cp, inp);
  20. }
  21. char* inet_ntoa(struct in_addr);
  22. static inline uint16_t htons(uint16_t value)
  23. {
  24. #if __BYTE_ORDER == __LITTLE_ENDIAN
  25. return __builtin_bswap16(value);
  26. #else
  27. return value;
  28. #endif
  29. }
  30. static inline uint16_t ntohs(uint16_t value)
  31. {
  32. return htons(value);
  33. }
  34. static inline uint32_t htonl(uint32_t value)
  35. {
  36. #if __BYTE_ORDER == __LITTLE_ENDIAN
  37. return __builtin_bswap32(value);
  38. #else
  39. return value;
  40. #endif
  41. }
  42. static inline uint32_t ntohl(uint32_t value)
  43. {
  44. return htonl(value);
  45. }
  46. __END_DECLS