You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

in.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifndef _IPXE_IN_H
  2. #define _IPXE_IN_H
  3. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  4. #include <stdint.h>
  5. #include <ipxe/socket.h>
  6. /* Protocol numbers */
  7. #define IP_ICMP 1
  8. #define IP_TCP 6
  9. #define IP_UDP 17
  10. #define IP_ICMP6 58
  11. /* IP address constants */
  12. #define INADDR_NONE 0xffffffff
  13. #define INADDR_BROADCAST 0xffffffff
  14. #define IN_CLASSA(addr) ( ( (addr) & 0x80000000 ) == 0x00000000 )
  15. #define IN_CLASSA_NET 0xff000000
  16. #define IN_CLASSB(addr) ( ( (addr) & 0xc0000000 ) == 0x80000000 )
  17. #define IN_CLASSB_NET 0xffff0000
  18. #define IN_CLASSC(addr) ( ( (addr) & 0xe0000000 ) == 0xc0000000 )
  19. #define IN_CLASSC_NET 0xffffff00
  20. #define IN_MULTICAST(addr) ( ( (addr) & 0xf0000000 ) == 0xe0000000 )
  21. /**
  22. * IP address structure
  23. */
  24. struct in_addr {
  25. uint32_t s_addr;
  26. };
  27. typedef struct in_addr in_addr;
  28. /**
  29. * IP6 address structure
  30. */
  31. struct in6_addr {
  32. union {
  33. uint8_t u6_addr8[16];
  34. uint16_t u6_addr16[8];
  35. uint32_t u6_addr32[4];
  36. } in6_u;
  37. #define s6_addr in6_u.u6_addr8
  38. #define s6_addr16 in6_u.u6_addr16
  39. #define s6_addr32 in6_u.u6_addr32
  40. };
  41. #define IN6_IS_ADDR_UNSPECIFIED( addr ) \
  42. ( ( ( ( ( const uint32_t * ) (addr) )[0] ) | \
  43. ( ( ( const uint32_t * ) (addr) )[1] ) | \
  44. ( ( ( const uint32_t * ) (addr) )[2] ) | \
  45. ( ( ( const uint32_t * ) (addr) )[3] ) ) == 0 )
  46. #define IN6_IS_ADDR_MULTICAST( addr ) \
  47. ( *( ( const uint8_t * ) (addr) ) == 0xff )
  48. #define IN6_IS_ADDR_LINKLOCAL( addr ) \
  49. ( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) == \
  50. htons ( 0xfe80 ) )
  51. /**
  52. * IPv4 socket address
  53. */
  54. struct sockaddr_in {
  55. /** Socket address family (part of struct @c sockaddr)
  56. *
  57. * Always set to @c AF_INET for IPv4 addresses
  58. */
  59. sa_family_t sin_family;
  60. /** Flags (part of struct @c sockaddr_tcpip) */
  61. uint16_t sin_flags;
  62. /** TCP/IP port (part of struct @c sockaddr_tcpip) */
  63. uint16_t sin_port;
  64. /** IPv4 address */
  65. struct in_addr sin_addr;
  66. /** Padding
  67. *
  68. * This ensures that a struct @c sockaddr_in is large enough
  69. * to hold a socket address for any TCP/IP address family.
  70. */
  71. char pad[ sizeof ( struct sockaddr ) -
  72. ( sizeof ( sa_family_t ) /* sin_family */ +
  73. sizeof ( uint16_t ) /* sin_flags */ +
  74. sizeof ( uint16_t ) /* sin_port */ +
  75. sizeof ( struct in_addr ) /* sin_addr */ ) ];
  76. } __attribute__ (( packed, may_alias ));
  77. /**
  78. * IPv6 socket address
  79. */
  80. struct sockaddr_in6 {
  81. /** Socket address family (part of struct @c sockaddr)
  82. *
  83. * Always set to @c AF_INET6 for IPv6 addresses
  84. */
  85. sa_family_t sin6_family;
  86. /** Flags (part of struct @c sockaddr_tcpip) */
  87. uint16_t sin6_flags;
  88. /** TCP/IP port (part of struct @c sockaddr_tcpip) */
  89. uint16_t sin6_port;
  90. /** Scope ID
  91. *
  92. * For link-local addresses, this is the network device index.
  93. */
  94. uint16_t sin6_scope_id;
  95. /** IPv6 address */
  96. struct in6_addr sin6_addr;
  97. /** Padding
  98. *
  99. * This ensures that a struct @c sockaddr_in6 is large
  100. * enough to hold a socket address for any TCP/IP address
  101. * family.
  102. */
  103. char pad[ sizeof ( struct sockaddr ) -
  104. ( sizeof ( sa_family_t ) /* sin6_family */ +
  105. sizeof ( uint16_t ) /* sin6_flags */ +
  106. sizeof ( uint16_t ) /* sin6_port */ +
  107. sizeof ( uint16_t ) /* sin6_scope_id */ +
  108. sizeof ( struct in6_addr ) /* sin6_addr */ ) ];
  109. } __attribute__ (( packed, may_alias ));
  110. extern int inet_aton ( const char *cp, struct in_addr *inp );
  111. extern char * inet_ntoa ( struct in_addr in );
  112. extern int inet6_aton ( const char *string, struct in6_addr *in );
  113. extern char * inet6_ntoa ( const struct in6_addr *in );
  114. #endif /* _IPXE_IN_H */