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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #ifndef _GPXE_IN_H
  2. #define _GPXE_IN_H
  3. #include <stdint.h>
  4. #include <gpxe/socket.h>
  5. /* Protocol numbers */
  6. #define IP_ICMP 1
  7. #define IP_IGMP 2
  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. /**
  42. * IPv4 socket address
  43. */
  44. struct sockaddr_in {
  45. /** Socket address family (part of struct @c sockaddr)
  46. *
  47. * Always set to @c AF_INET for IPv4 addresses
  48. */
  49. sa_family_t sin_family;
  50. /** TCP/IP port (part of struct @c sockaddr_tcpip) */
  51. uint16_t sin_port;
  52. /** IPv4 address */
  53. struct in_addr sin_addr;
  54. /** Padding
  55. *
  56. * This ensures that a struct @c sockaddr_tcpip is large
  57. * enough to hold a socket address for any TCP/IP address
  58. * family.
  59. */
  60. char pad[ sizeof ( struct sockaddr ) - sizeof ( sa_family_t )
  61. - sizeof ( uint16_t )
  62. - sizeof ( struct in_addr ) ];
  63. } __attribute__ (( may_alias ));
  64. /**
  65. * IPv6 socket address
  66. */
  67. struct sockaddr_in6 {
  68. /** Socket address family (part of struct @c sockaddr)
  69. *
  70. * Always set to @c AF_INET6 for IPv6 addresses
  71. */
  72. sa_family_t sin_family;
  73. /** TCP/IP port (part of struct @c sockaddr_tcpip) */
  74. uint16_t sin_port;
  75. uint32_t sin6_flowinfo; /* Flow number */
  76. struct in6_addr sin6_addr; /* 128-bit destination address */
  77. uint32_t sin6_scope_id; /* Scope ID */
  78. } __attribute__ (( may_alias ));
  79. extern int inet_aton ( const char *cp, struct in_addr *inp );
  80. extern char * inet_ntoa ( struct in_addr in );
  81. /* Adding the following for IP6 support
  82. *
  83. extern int inet6_aton ( const char *cp, struct in6_addr *inp );
  84. extern char * inet6_ntoa ( struct in_addr in );
  85. */
  86. #endif /* _GPXE_IN_H */