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 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef _GPXE_IN_H
  2. #define _GPXE_IN_H
  3. FILE_LICENCE ( GPL2_OR_LATER );
  4. #include <stdint.h>
  5. #include <gpxe/socket.h>
  6. /* Protocol numbers */
  7. #define IP_ICMP 1
  8. #define IP_IGMP 2
  9. #define IP_TCP 6
  10. #define IP_UDP 17
  11. #define IP_ICMP6 58
  12. /* IP address constants */
  13. #define INADDR_NONE 0xffffffff
  14. #define INADDR_BROADCAST 0xffffffff
  15. #define IN_CLASSA(addr) ( ( (addr) & 0x80000000 ) == 0x00000000 )
  16. #define IN_CLASSA_NET 0xff000000
  17. #define IN_CLASSB(addr) ( ( (addr) & 0xc0000000 ) == 0x80000000 )
  18. #define IN_CLASSB_NET 0xffff0000
  19. #define IN_CLASSC(addr) ( ( (addr) & 0xe0000000 ) == 0xc0000000 )
  20. #define IN_CLASSC_NET 0xffffff00
  21. #define IN_MULTICAST(addr) ( ( (addr) & 0xf0000000 ) == 0xe0000000 )
  22. /**
  23. * IP address structure
  24. */
  25. struct in_addr {
  26. uint32_t s_addr;
  27. };
  28. typedef struct in_addr in_addr;
  29. /**
  30. * IP6 address structure
  31. */
  32. struct in6_addr {
  33. union {
  34. uint8_t u6_addr8[16];
  35. uint16_t u6_addr16[8];
  36. uint32_t u6_addr32[4];
  37. } in6_u;
  38. #define s6_addr in6_u.u6_addr8
  39. #define s6_addr16 in6_u.u6_addr16
  40. #define s6_addr32 in6_u.u6_addr32
  41. };
  42. /**
  43. * IPv4 socket address
  44. */
  45. struct sockaddr_in {
  46. /** Socket address family (part of struct @c sockaddr)
  47. *
  48. * Always set to @c AF_INET for IPv4 addresses
  49. */
  50. sa_family_t sin_family;
  51. /** TCP/IP port (part of struct @c sockaddr_tcpip) */
  52. uint16_t sin_port;
  53. /** IPv4 address */
  54. struct in_addr sin_addr;
  55. /** Padding
  56. *
  57. * This ensures that a struct @c sockaddr_tcpip is large
  58. * enough to hold a socket address for any TCP/IP address
  59. * family.
  60. */
  61. char pad[ sizeof ( struct sockaddr ) - sizeof ( sa_family_t )
  62. - sizeof ( uint16_t )
  63. - sizeof ( struct in_addr ) ];
  64. } __attribute__ (( may_alias ));
  65. /**
  66. * IPv6 socket address
  67. */
  68. struct sockaddr_in6 {
  69. /** Socket address family (part of struct @c sockaddr)
  70. *
  71. * Always set to @c AF_INET6 for IPv6 addresses
  72. */
  73. sa_family_t sin_family;
  74. /** TCP/IP port (part of struct @c sockaddr_tcpip) */
  75. uint16_t sin_port;
  76. uint32_t sin6_flowinfo; /* Flow number */
  77. struct in6_addr sin6_addr; /* 128-bit destination address */
  78. uint32_t sin6_scope_id; /* Scope ID */
  79. } __attribute__ (( may_alias ));
  80. extern int inet_aton ( const char *cp, struct in_addr *inp );
  81. extern char * inet_ntoa ( struct in_addr in );
  82. /* Adding the following for IP6 support
  83. *
  84. extern int inet6_aton ( const char *cp, struct in6_addr *inp );
  85. extern char * inet6_ntoa ( struct in_addr in );
  86. */
  87. #endif /* _GPXE_IN_H */