• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef	_GPXE_IN_H
2 #define	_GPXE_IN_H
3 
4 FILE_LICENCE ( GPL2_OR_LATER );
5 
6 #include <stdint.h>
7 #include <gpxe/socket.h>
8 
9 /* Protocol numbers */
10 
11 #define IP_ICMP		1
12 #define IP_TCP		6
13 #define IP_UDP		17
14 #define IP_ICMP6	58
15 
16 /* IP address constants */
17 
18 #define INADDR_NONE 0xffffffff
19 
20 #define INADDR_BROADCAST 0xffffffff
21 
22 #define	IN_CLASSA(addr)		( ( (addr) & 0x80000000 ) == 0x00000000 )
23 #define	IN_CLASSA_NET		0xff000000
24 #define	IN_CLASSB(addr)		( ( (addr) & 0xc0000000 ) == 0x80000000 )
25 #define	IN_CLASSB_NET		0xffff0000
26 #define	IN_CLASSC(addr)		( ( (addr) & 0xe0000000 ) == 0xc0000000 )
27 #define	IN_CLASSC_NET		0xffffff00
28 #define IN_MULTICAST(addr)	( ( (addr) & 0xf0000000 ) == 0xe0000000 )
29 
30 /**
31  * IP address structure
32  */
33 struct in_addr {
34 	uint32_t	s_addr;
35 };
36 
37 typedef struct in_addr in_addr;
38 
39 /**
40  * IP6 address structure
41  */
42 struct in6_addr {
43         union {
44                 uint8_t u6_addr8[16];
45                 uint16_t u6_addr16[8];
46                 uint32_t u6_addr32[4];
47         } in6_u;
48 #define s6_addr         in6_u.u6_addr8
49 #define s6_addr16       in6_u.u6_addr16
50 #define s6_addr32       in6_u.u6_addr32
51 };
52 
53 /**
54  * IPv4 socket address
55  */
56 struct sockaddr_in {
57 	/** Socket address family (part of struct @c sockaddr)
58 	 *
59 	 * Always set to @c AF_INET for IPv4 addresses
60 	 */
61 	sa_family_t sin_family;
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_tcpip is large
69 	 * enough to hold a socket address for any TCP/IP address
70 	 * family.
71 	 */
72 	char pad[ sizeof ( struct sockaddr ) - sizeof ( sa_family_t )
73 					     - sizeof ( uint16_t )
74 					     - sizeof ( struct in_addr ) ];
75 } __attribute__ (( may_alias ));
76 
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 sin_family;
86 	/** TCP/IP port (part of struct @c sockaddr_tcpip) */
87 	uint16_t 	sin_port;
88         uint32_t        sin6_flowinfo;  /* Flow number */
89         struct in6_addr sin6_addr;      /* 128-bit destination address */
90         uint32_t        sin6_scope_id;  /* Scope ID */
91 } __attribute__ (( may_alias ));
92 
93 extern int inet_aton ( const char *cp, struct in_addr *inp );
94 extern char * inet_ntoa ( struct in_addr in );
95 
96 /* Adding the following for IP6 support
97  *
98 
99 extern int inet6_aton ( const char *cp, struct in6_addr *inp );
100 extern char * inet6_ntoa ( struct in_addr in );
101 
102  */
103 
104 #endif	/* _GPXE_IN_H */
105