in.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef _BITS_NETINET_IN_H
  2. #define _BITS_NETINET_IN_H
  3. extern const struct in6_addr in6addr_any;
  4. extern const struct in6_addr in6addr_loopback;
  5. #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
  6. #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
  7. // from musl {
  8. #define IN6_IS_ADDR_UNSPECIFIED(a) \
  9. (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \
  10. ((uint32_t *) (a))[2] == 0 && ((uint32_t *) (a))[3] == 0)
  11. #define IN6_IS_ADDR_LOOPBACK(a) \
  12. (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \
  13. ((uint32_t *) (a))[2] == 0 && \
  14. ((uint8_t *) (a))[12] == 0 && ((uint8_t *) (a))[13] == 0 && \
  15. ((uint8_t *) (a))[14] == 0 && ((uint8_t *) (a))[15] == 1 )
  16. #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
  17. #define IN6_IS_ADDR_LINKLOCAL(a) \
  18. ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0x80)
  19. #define IN6_IS_ADDR_SITELOCAL(a) \
  20. ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0xc0)
  21. #define IN6_IS_ADDR_V4MAPPED(a) \
  22. (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \
  23. ((uint8_t *) (a))[8] == 0 && ((uint8_t *) (a))[9] == 0 && \
  24. ((uint8_t *) (a))[10] == 0xff && ((uint8_t *) (a))[11] == 0xff)
  25. #define IN6_IS_ADDR_V4COMPAT(a) \
  26. (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \
  27. ((uint32_t *) (a))[2] == 0 && ((uint8_t *) (a))[15] > 1)
  28. #define IN6_IS_ADDR_MC_NODELOCAL(a) \
  29. (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1))
  30. #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
  31. (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x2))
  32. #define IN6_IS_ADDR_MC_SITELOCAL(a) \
  33. (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x5))
  34. #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
  35. (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x8))
  36. #define IN6_IS_ADDR_MC_GLOBAL(a) \
  37. (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe))
  38. #define __ARE_4_EQUAL(a,b) \
  39. (!( (0[a]-0[b]) | (1[a]-1[b]) | (2[a]-2[b]) | (3[a]-3[b]) ))
  40. #define IN6_ARE_ADDR_EQUAL(a,b) \
  41. __ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b))
  42. #define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0)
  43. #define IN_CLASSA_NET 0xff000000
  44. #define IN_CLASSA_NSHIFT 24
  45. #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
  46. #define IN_CLASSA_MAX 128
  47. #define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
  48. #define IN_CLASSB_NET 0xffff0000
  49. #define IN_CLASSB_NSHIFT 16
  50. #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
  51. #define IN_CLASSB_MAX 65536
  52. #define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
  53. #define IN_CLASSC_NET 0xffffff00
  54. #define IN_CLASSC_NSHIFT 8
  55. #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
  56. #define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
  57. #define IN_MULTICAST(a) IN_CLASSD(a)
  58. #define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
  59. #define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)
  60. // } from musl
  61. #endif // _BITS_NETINET_IN_H