iPXE
Data Structures | Defines | Typedefs | Functions
in.h File Reference
#include <stdint.h>
#include <byteswap.h>
#include <ipxe/socket.h>

Go to the source code of this file.

Data Structures

struct  in_addr
 IP address structure. More...
struct  in6_addr
 IP6 address structure. More...
struct  sockaddr_in
 IPv4 socket address. More...
struct  sockaddr_in6
 IPv6 socket address. More...

Defines

#define IP_ICMP   1
#define IP_TCP   6
#define IP_UDP   17
#define IP_ICMP6   58
#define INADDR_NONE   htonl ( 0xffffffff )
#define INADDR_BROADCAST   htonl ( 0xffffffff )
#define INADDR_NET_CLASSA   htonl ( 0xff000000 )
#define INADDR_NET_CLASSB   htonl ( 0xffff0000 )
#define INADDR_NET_CLASSC   htonl ( 0xffffff00 )
#define IN_IS_CLASSA(addr)   ( ( (addr) & htonl ( 0x80000000 ) ) == htonl ( 0x00000000 ) )
#define IN_IS_CLASSB(addr)   ( ( (addr) & htonl ( 0xc0000000 ) ) == htonl ( 0x80000000 ) )
#define IN_IS_CLASSC(addr)   ( ( (addr) & htonl ( 0xe0000000 ) ) == htonl ( 0xc0000000 ) )
#define IN_IS_MULTICAST(addr)   ( ( (addr) & htonl ( 0xf0000000 ) ) == htonl ( 0xe0000000 ) )
#define s6_addr   in6_u.u6_addr8
#define s6_addr16   in6_u.u6_addr16
#define s6_addr32   in6_u.u6_addr32
#define IN6_IS_ADDR_UNSPECIFIED(addr)
#define IN6_IS_ADDR_MULTICAST(addr)   ( *( ( const uint8_t * ) (addr) ) == 0xff )
#define IN6_IS_ADDR_LINKLOCAL(addr)
#define IN6_IS_ADDR_SITELOCAL(addr)
#define IN6_IS_ADDR_ULA(addr)   ( ( *( ( const uint8_t * ) (addr) ) & 0xfe ) == 0xfc )

Typedefs

typedef struct in_addr in_addr

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int inet_aton (const char *cp, struct in_addr *inp)
 Parse IPv4 address.
char * inet_ntoa (struct in_addr in)
 Convert IPv4 address to dotted-quad notation.
int inet6_aton (const char *string, struct in6_addr *in)
 Parse IPv6 address.
char * inet6_ntoa (const struct in6_addr *in)
 Convert IPv6 address to standard notation.

Define Documentation

#define IP_ICMP   1

Definition at line 12 of file in.h.

#define IP_TCP   6

Definition at line 13 of file in.h.

#define IP_UDP   17

Definition at line 14 of file in.h.

Referenced by gdbudp_recv(), and gdbudp_send().

#define IP_ICMP6   58

Definition at line 15 of file in.h.

#define INADDR_NONE   htonl ( 0xffffffff )

Definition at line 19 of file in.h.

#define INADDR_BROADCAST   htonl ( 0xffffffff )
#define INADDR_NET_CLASSA   htonl ( 0xff000000 )

Definition at line 23 of file in.h.

Referenced by ipv4_settings().

#define INADDR_NET_CLASSB   htonl ( 0xffff0000 )

Definition at line 24 of file in.h.

Referenced by ipv4_settings().

#define INADDR_NET_CLASSC   htonl ( 0xffffff00 )

Definition at line 25 of file in.h.

Referenced by ipv4_settings().

#define IN_IS_CLASSA (   addr)    ( ( (addr) & htonl ( 0x80000000 ) ) == htonl ( 0x00000000 ) )

Definition at line 27 of file in.h.

Referenced by ipv4_settings(), and ipv4_test_exec().

#define IN_IS_CLASSB (   addr)    ( ( (addr) & htonl ( 0xc0000000 ) ) == htonl ( 0x80000000 ) )

Definition at line 29 of file in.h.

Referenced by ipv4_settings(), and ipv4_test_exec().

#define IN_IS_CLASSC (   addr)    ( ( (addr) & htonl ( 0xe0000000 ) ) == htonl ( 0xc0000000 ) )

Definition at line 31 of file in.h.

Referenced by ipv4_settings(), and ipv4_test_exec().

#define IN_IS_MULTICAST (   addr)    ( ( (addr) & htonl ( 0xf0000000 ) ) == htonl ( 0xe0000000 ) )

Definition at line 33 of file in.h.

Referenced by efi_pxe_ip_filter(), ipv4_route(), ipv4_test_exec(), and ipv4_tx().

#define s6_addr   in6_u.u6_addr8

Definition at line 54 of file in.h.

#define s6_addr16   in6_u.u6_addr16

Definition at line 55 of file in.h.

#define s6_addr32   in6_u.u6_addr32

Definition at line 56 of file in.h.

Value:
( ( ( ( ( const uint32_t * ) (addr) )[0] ) |                    \
            ( ( ( const uint32_t * ) (addr) )[1] ) |                    \
            ( ( ( const uint32_t * ) (addr) )[2] ) |                    \
            ( ( ( const uint32_t * ) (addr) )[3] ) ) == 0 )

Definition at line 59 of file in.h.

Referenced by dhcpv6_fetch_lease(), ipv6_test_exec(), and ipv6_tx().

#define IN6_IS_ADDR_MULTICAST (   addr)    ( *( ( const uint8_t * ) (addr) ) == 0xff )
#define IN6_IS_ADDR_LINKLOCAL (   addr)
Value:
( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) ==    \
          htons ( 0xfe80 ) )

Definition at line 68 of file in.h.

Referenced by ipv6_scope(), ipv6_sock_aton(), ipv6_sock_ntoa(), and ipv6_test_exec().

#define IN6_IS_ADDR_SITELOCAL (   addr)
Value:
( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) ==    \
          htons ( 0xfec0 ) )

Definition at line 72 of file in.h.

Referenced by ipv6_scope(), and ipv6_test_exec().

#define IN6_IS_ADDR_ULA (   addr)    ( ( *( ( const uint8_t * ) (addr) ) & 0xfe ) == 0xfc )

Definition at line 76 of file in.h.

Referenced by ipv6_scope(), and ipv6_test_exec().


Typedef Documentation

typedef struct in_addr in_addr

Definition at line 43 of file in.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int inet_aton ( const char *  string,
struct in_addr in 
)

Parse IPv4 address.

Parameters:
stringIPv4 address string
Return values:
inIPv4 address to fill in
okIPv4 address is valid

Note that this function returns nonzero iff the address is valid, to match the standard BSD API function of the same name. Unlike most other iPXE functions, a zero therefore indicates failure.

Definition at line 631 of file ipv4.c.

References byte, strtoul(), and value.

Referenced by inet_aton_fail_okx(), inet_aton_okx(), ipv4_sock_aton(), parse_ipv4_setting(), slam_parse_multicast_address(), and tftp_process_multicast().

                                                         {
        const char *separator = "...";
        uint8_t *byte = ( ( uint8_t * ) in );
        char *endp;
        unsigned long value;

        while ( 1 ) {
                value = strtoul ( string, &endp, 0 );
                if ( string == endp )
                        return 0;
                if ( value > 0xff )
                        return 0;
                *(byte++) = value;
                if ( *endp != *separator )
                        return 0;
                if ( ! *(separator++) )
                        return 1;
                string = ( endp + 1 );
        }
}
char* inet_ntoa ( struct in_addr  in)

Convert IPv4 address to dotted-quad notation.

Parameters:
inIPv4 address
Return values:
stringIPv4 address in dotted-quad notation

Definition at line 658 of file ipv4.c.

References bytes, and sprintf.

Referenced by add_ipv4_miniroute(), del_ipv4_miniroute(), dhcp_deliver(), dhcp_discovery_rx(), dhcp_proxy_rx(), dhcp_proxy_tx(), dhcp_pxebs_accept(), dhcp_pxebs_rx(), dhcp_pxebs_tx(), dhcp_request_rx(), dhcp_request_tx(), efi_snp_mcast_ip_to_mac(), fetch_next_server_and_filename(), format_ipv4_setting(), ibft_ipaddr(), inet_aton_okx(), inet_ntoa_okx(), ipoib_transmit(), ipv4_gratuitous_arp(), ipv4_ntoa(), ipv4_rx(), ipv4_sock_ntoa(), ipv4_tx(), pxenv_udp_open(), pxenv_udp_read(), pxenv_udp_write(), pxenv_undi_get_mcast_address(), route_ipv4_print(), start_pxebs(), tftp_apply_settings(), and tftp_process_multicast().

                                       {
        static char buf[16]; /* "xxx.xxx.xxx.xxx" */
        uint8_t *bytes = ( uint8_t * ) &in;
        
        sprintf ( buf, "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3] );
        return buf;
}
int inet6_aton ( const char *  string,
struct in6_addr in 
)

Parse IPv6 address.

Parameters:
stringIPv6 address string
Return values:
inIPv6 address to fill in
rcReturn status code

Definition at line 824 of file ipv6.c.

References DBG, EINVAL, end, htons, memmove(), memset(), NULL, pad, string, strtoul(), and value.

Referenced by inet6_aton_fail_okx(), inet6_aton_okx(), ipv6_route_okx(), ipv6_sock_aton(), ipv6_table_okx(), and parse_ipv6_setting().

                                                           {
        uint16_t *word = in->s6_addr16;
        uint16_t *end = ( word + ( sizeof ( in->s6_addr16 ) /
                                   sizeof ( in->s6_addr16[0] ) ) );
        uint16_t *pad = NULL;
        const char *nptr = string;
        char *endptr;
        unsigned long value;
        size_t pad_len;
        size_t move_len;

        /* Parse string */
        while ( 1 ) {

                /* Parse current word */
                value = strtoul ( nptr, &endptr, 16 );
                if ( value > 0xffff ) {
                        DBG ( "IPv6 invalid word value %#lx in \"%s\"\n",
                              value, string );
                        return -EINVAL;
                }
                *(word++) = htons ( value );

                /* Parse separator */
                if ( ! *endptr )
                        break;
                if ( *endptr != ':' ) {
                        DBG ( "IPv6 invalid separator '%c' in \"%s\"\n",
                              *endptr, string );
                        return -EINVAL;
                }
                if ( ( endptr == nptr ) && ( nptr != string ) ) {
                        if ( pad ) {
                                DBG ( "IPv6 invalid multiple \"::\" in "
                                      "\"%s\"\n", string );
                                return -EINVAL;
                        }
                        pad = word;
                }
                nptr = ( endptr + 1 );

                /* Check for overrun */
                if ( word == end ) {
                        DBG ( "IPv6 too many words in \"%s\"\n", string );
                        return -EINVAL;
                }
        }

        /* Insert padding if specified */
        if ( pad ) {
                move_len = ( ( ( void * ) word ) - ( ( void * ) pad ) );
                pad_len = ( ( ( void * ) end ) - ( ( void * ) word ) );
                memmove ( ( ( ( void * ) pad ) + pad_len ), pad, move_len );
                memset ( pad, 0, pad_len );
        } else if ( word != end ) {
                DBG ( "IPv6 underlength address \"%s\"\n", string );
                return -EINVAL;
        }

        return 0;
}
char* inet6_ntoa ( const struct in6_addr in)

Convert IPv6 address to standard notation.

Parameters:
inIPv6 address
Return values:
stringIPv6 address string in canonical format

RFC5952 defines the canonical format for IPv6 textual representation.

Definition at line 894 of file ipv6.c.

References dest, len, ntohs, NULL, out, sprintf, start, strcpy(), and value.

Referenced by dhcpv6_rx(), format_ipv6_setting(), inet6_aton_okx(), inet6_ntoa_okx(), ipv6_dump_miniroute(), ipv6_ntoa(), ipv6_route_okx(), ipv6_rx(), ipv6_sock_ntoa(), ipv6_tx(), ndp_rx_neighbour_advertisement_ll_target(), ndp_rx_neighbour_solicitation_ll_source(), ndp_rx_router_advertisement_ll_source(), ndp_rx_router_advertisement_prefix(), and route_ipv6_print().

                                                {
        static char buf[41]; /* ":xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx" */
        char *out = buf;
        char *longest_start = NULL;
        char *start = NULL;
        int longest_len = 1;
        int len = 0;
        char *dest;
        unsigned int i;
        uint16_t value;

        /* Format address, keeping track of longest run of zeros */
        for ( i = 0 ; i < ( sizeof ( in->s6_addr16 ) /
                            sizeof ( in->s6_addr16[0] ) ) ; i++ ) {
                value = ntohs ( in->s6_addr16[i] );
                if ( value == 0 ) {
                        if ( len++ == 0 )
                                start = out;
                        if ( len > longest_len ) {
                                longest_start = start;
                                longest_len = len;
                        }
                } else {
                        len = 0;
                }
                out += sprintf ( out, ":%x", value );
        }

        /* Abbreviate longest run of zeros, if applicable */
        if ( longest_start ) {
                dest = strcpy ( ( longest_start + 1 ),
                                ( longest_start + ( 2 * longest_len ) ) );
                if ( dest[0] == '\0' )
                        dest[1] = '\0';
                dest[0] = ':';
        }
        return ( ( longest_start == buf ) ? buf : ( buf + 1 ) );
}