iPXE
in.h
Go to the documentation of this file.
00001 #ifndef _IPXE_IN_H
00002 #define _IPXE_IN_H
00003 
00004 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00005 
00006 #include <stdint.h>
00007 #include <byteswap.h>
00008 #include <ipxe/socket.h>
00009 
00010 /* Protocol numbers */
00011 
00012 #define IP_ICMP         1
00013 #define IP_TCP          6
00014 #define IP_UDP          17
00015 #define IP_ICMP6        58
00016 
00017 /* IP address constants */
00018 
00019 #define INADDR_NONE             htonl ( 0xffffffff )
00020 
00021 #define INADDR_BROADCAST        htonl ( 0xffffffff )
00022 
00023 #define INADDR_NET_CLASSA       htonl ( 0xff000000 )
00024 #define INADDR_NET_CLASSB       htonl ( 0xffff0000 )
00025 #define INADDR_NET_CLASSC       htonl ( 0xffffff00 )
00026 
00027 #define IN_IS_CLASSA( addr ) \
00028         ( ( (addr) & htonl ( 0x80000000 ) ) == htonl ( 0x00000000 ) )
00029 #define IN_IS_CLASSB( addr ) \
00030         ( ( (addr) & htonl ( 0xc0000000 ) ) == htonl ( 0x80000000 ) )
00031 #define IN_IS_CLASSC( addr ) \
00032         ( ( (addr) & htonl ( 0xe0000000 ) ) == htonl ( 0xc0000000 ) )
00033 #define IN_IS_MULTICAST( addr ) \
00034         ( ( (addr) & htonl ( 0xf0000000 ) ) == htonl ( 0xe0000000 ) )
00035 
00036 /**
00037  * IP address structure
00038  */
00039 struct in_addr {
00040         uint32_t        s_addr;
00041 };
00042 
00043 typedef struct in_addr in_addr;
00044 
00045 /**
00046  * IP6 address structure
00047  */
00048 struct in6_addr {
00049         union {
00050                 uint8_t u6_addr8[16];
00051                 uint16_t u6_addr16[8];
00052                 uint32_t u6_addr32[4];
00053         } in6_u;
00054 #define s6_addr         in6_u.u6_addr8
00055 #define s6_addr16       in6_u.u6_addr16
00056 #define s6_addr32       in6_u.u6_addr32
00057 };
00058 
00059 #define IN6_IS_ADDR_UNSPECIFIED( addr )                                 \
00060         ( ( ( ( ( const uint32_t * ) (addr) )[0] ) |                    \
00061             ( ( ( const uint32_t * ) (addr) )[1] ) |                    \
00062             ( ( ( const uint32_t * ) (addr) )[2] ) |                    \
00063             ( ( ( const uint32_t * ) (addr) )[3] ) ) == 0 )
00064 
00065 #define IN6_IS_ADDR_MULTICAST( addr )                                   \
00066         ( *( ( const uint8_t * ) (addr) ) == 0xff )
00067 
00068 #define IN6_IS_ADDR_LINKLOCAL( addr )                                   \
00069         ( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) ==    \
00070           htons ( 0xfe80 ) )
00071 
00072 #define IN6_IS_ADDR_SITELOCAL( addr )                                   \
00073         ( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) ==    \
00074           htons ( 0xfec0 ) )
00075 
00076 #define IN6_IS_ADDR_ULA( addr )                                         \
00077         ( ( *( ( const uint8_t * ) (addr) ) & 0xfe ) == 0xfc )
00078 
00079 /**
00080  * IPv4 socket address
00081  */
00082 struct sockaddr_in {
00083         /** Socket address family (part of struct @c sockaddr)
00084          *
00085          * Always set to @c AF_INET for IPv4 addresses
00086          */
00087         sa_family_t sin_family;
00088         /** Flags (part of struct @c sockaddr_tcpip) */
00089         uint16_t sin_flags;
00090         /** TCP/IP port (part of struct @c sockaddr_tcpip) */
00091         uint16_t sin_port;
00092         /** Scope ID (part of struct @c sockaddr_tcpip)
00093          *
00094          * For multicast addresses, this is the network device index.
00095          */
00096         uint16_t sin_scope_id;
00097         /** IPv4 address */
00098         struct in_addr sin_addr;
00099         /** Padding
00100          *
00101          * This ensures that a struct @c sockaddr_in is large enough
00102          * to hold a socket address for any TCP/IP address family.
00103          */
00104         char pad[ sizeof ( struct sockaddr ) -
00105                   ( sizeof ( sa_family_t ) /* sin_family */ +
00106                     sizeof ( uint16_t ) /* sin_flags */ +
00107                     sizeof ( uint16_t ) /* sin_port */ +
00108                     sizeof ( uint16_t ) /* sin_scope_id */ +
00109                     sizeof ( struct in_addr ) /* sin_addr */ ) ];
00110 } __attribute__ (( packed, may_alias ));
00111 
00112 /**
00113  * IPv6 socket address
00114  */
00115 struct sockaddr_in6 {
00116         /** Socket address family (part of struct @c sockaddr)
00117          *
00118          * Always set to @c AF_INET6 for IPv6 addresses
00119          */
00120         sa_family_t sin6_family;
00121         /** Flags (part of struct @c sockaddr_tcpip) */
00122         uint16_t sin6_flags;
00123         /** TCP/IP port (part of struct @c sockaddr_tcpip) */
00124         uint16_t sin6_port;
00125         /** Scope ID (part of struct @c sockaddr_tcpip)
00126          *
00127          * For link-local or multicast addresses, this is the network
00128          * device index.
00129          */
00130         uint16_t sin6_scope_id;
00131         /** IPv6 address */
00132         struct in6_addr sin6_addr;
00133         /** Padding
00134          *
00135          * This ensures that a struct @c sockaddr_in6 is large
00136          * enough to hold a socket address for any TCP/IP address
00137          * family.
00138          */
00139         char pad[ sizeof ( struct sockaddr ) -
00140                   ( sizeof ( sa_family_t ) /* sin6_family */ +
00141                     sizeof ( uint16_t ) /* sin6_flags */ +
00142                     sizeof ( uint16_t ) /* sin6_port */ +
00143                     sizeof ( uint16_t ) /* sin6_scope_id */ +
00144                     sizeof ( struct in6_addr ) /* sin6_addr */ ) ];
00145 } __attribute__ (( packed, may_alias ));
00146 
00147 extern int inet_aton ( const char *cp, struct in_addr *inp );
00148 extern char * inet_ntoa ( struct in_addr in );
00149 extern int inet6_aton ( const char *string, struct in6_addr *in );
00150 extern char * inet6_ntoa ( const struct in6_addr *in );
00151 
00152 #endif  /* _IPXE_IN_H */