iPXE
Data Structures | Macros | 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...
 

Macros

#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 IN_IS_SMALL(mask)   ( (mask) & htonl ( 0x00000003 ) )
 
#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)
 
 FILE_SECBOOT (PERMITTED)
 
int inet_aton (const char *cp, struct in_addr *inp)
 Parse IPv4 address. More...
 
char * inet_ntoa (struct in_addr in)
 Convert IPv4 address to dotted-quad notation. More...
 
int inet6_aton (const char *string, struct in6_addr *in)
 Parse IPv6 address. More...
 
char * inet6_ntoa (const struct in6_addr *in)
 Convert IPv6 address to standard notation. More...
 

Macro Definition Documentation

◆ IP_ICMP

#define IP_ICMP   1

Definition at line 13 of file in.h.

◆ IP_TCP

#define IP_TCP   6

Definition at line 14 of file in.h.

◆ IP_UDP

#define IP_UDP   17

Definition at line 15 of file in.h.

◆ IP_ICMP6

#define IP_ICMP6   58

Definition at line 16 of file in.h.

◆ INADDR_NONE

#define INADDR_NONE   htonl ( 0xffffffff )

Definition at line 20 of file in.h.

◆ INADDR_BROADCAST

#define INADDR_BROADCAST   htonl ( 0xffffffff )

Definition at line 22 of file in.h.

◆ INADDR_NET_CLASSA

#define INADDR_NET_CLASSA   htonl ( 0xff000000 )

Definition at line 24 of file in.h.

◆ INADDR_NET_CLASSB

#define INADDR_NET_CLASSB   htonl ( 0xffff0000 )

Definition at line 25 of file in.h.

◆ INADDR_NET_CLASSC

#define INADDR_NET_CLASSC   htonl ( 0xffffff00 )

Definition at line 26 of file in.h.

◆ IN_IS_CLASSA

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

Definition at line 28 of file in.h.

◆ IN_IS_CLASSB

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

Definition at line 30 of file in.h.

◆ IN_IS_CLASSC

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

Definition at line 32 of file in.h.

◆ IN_IS_MULTICAST

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

Definition at line 34 of file in.h.

◆ IN_IS_SMALL

#define IN_IS_SMALL (   mask)    ( (mask) & htonl ( 0x00000003 ) )

Definition at line 37 of file in.h.

◆ s6_addr

#define s6_addr   in6_u.u6_addr8

Definition at line 57 of file in.h.

◆ s6_addr16

#define s6_addr16   in6_u.u6_addr16

Definition at line 58 of file in.h.

◆ s6_addr32

#define s6_addr32   in6_u.u6_addr32

Definition at line 59 of file in.h.

◆ IN6_IS_ADDR_UNSPECIFIED

#define IN6_IS_ADDR_UNSPECIFIED (   addr)
Value:
( ( ( ( ( const uint32_t * ) (addr) )[0] ) | \
( ( ( const uint32_t * ) (addr) )[1] ) | \
( ( ( const uint32_t * ) (addr) )[2] ) | \
( ( ( const uint32_t * ) (addr) )[3] ) ) == 0 )
uint32_t addr
Buffer address.
Definition: dwmac.h:20
unsigned int uint32_t
Definition: stdint.h:12

Definition at line 62 of file in.h.

◆ IN6_IS_ADDR_MULTICAST

#define IN6_IS_ADDR_MULTICAST (   addr)    ( *( ( const uint8_t * ) (addr) ) == 0xff )

Definition at line 68 of file in.h.

◆ IN6_IS_ADDR_LINKLOCAL

#define IN6_IS_ADDR_LINKLOCAL (   addr)
Value:
( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) == \
htons ( 0xfe80 ) )
unsigned short uint16_t
Definition: stdint.h:11
uint32_t addr
Buffer address.
Definition: dwmac.h:20
#define htons(value)
Definition: byteswap.h:136

Definition at line 71 of file in.h.

◆ IN6_IS_ADDR_SITELOCAL

#define IN6_IS_ADDR_SITELOCAL (   addr)
Value:
( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) == \
htons ( 0xfec0 ) )
unsigned short uint16_t
Definition: stdint.h:11
uint32_t addr
Buffer address.
Definition: dwmac.h:20
#define htons(value)
Definition: byteswap.h:136

Definition at line 75 of file in.h.

◆ IN6_IS_ADDR_ULA

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

Definition at line 79 of file in.h.

Typedef Documentation

◆ in_addr

typedef struct in_addr in_addr

Definition at line 46 of file in.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ inet_aton()

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 787 of file ipv4.c.

787  {
788  const char *separator = "...";
789  uint8_t *byte = ( ( uint8_t * ) in );
790  char *endp;
791  unsigned long value;
792 
793  while ( 1 ) {
794  value = strtoul ( string, &endp, 0 );
795  if ( string == endp )
796  return 0;
797  if ( value > 0xff )
798  return 0;
799  *(byte++) = value;
800  if ( *endp != *separator )
801  return 0;
802  if ( ! *(separator++) )
803  return 1;
804  string = ( endp + 1 );
805  }
806 }
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:485
__be32 in[4]
Definition: CIB_PRM.h:35
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
unsigned char uint8_t
Definition: stdint.h:10

References in, strtoul(), and value.

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

◆ inet_ntoa()

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 814 of file ipv4.c.

814  {
815  static char buf[16]; /* "xxx.xxx.xxx.xxx" */
816  uint8_t *bytes = ( uint8_t * ) &in;
817 
818  sprintf ( buf, "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3] );
819  return buf;
820 }
__be32 in[4]
Definition: CIB_PRM.h:35
#define sprintf(buf, fmt,...)
Write a formatted string to a buffer.
Definition: stdio.h:37
unsigned char uint8_t
Definition: stdint.h:10
uint8_t bytes[64]
Definition: ib_mad.h:17

References bytes, in, and sprintf.

Referenced by 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(), gve_describe(), ibft_ipaddr(), inet_aton_okx(), inet_ntoa_okx(), ipoib_transmit(), ipv4_add_miniroute(), ipv4_del_miniroute(), ipv4_gratuitous_arp(), ipv4_ntoa(), ipv4_route_okx(), 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().

◆ inet6_aton()

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 825 of file ipv6.c.

825  {
826  uint16_t *word = in->s6_addr16;
827  uint16_t *end = ( word + ( sizeof ( in->s6_addr16 ) /
828  sizeof ( in->s6_addr16[0] ) ) );
829  uint16_t *pad = NULL;
830  const char *nptr = string;
831  char *endptr;
832  unsigned long value;
833  size_t pad_len;
834  size_t move_len;
835 
836  /* Parse string */
837  while ( 1 ) {
838 
839  /* Parse current word */
840  value = strtoul ( nptr, &endptr, 16 );
841  if ( value > 0xffff ) {
842  DBG ( "IPv6 invalid word value %#lx in \"%s\"\n",
843  value, string );
844  return -EINVAL;
845  }
846  *(word++) = htons ( value );
847 
848  /* Parse separator */
849  if ( ! *endptr )
850  break;
851  if ( *endptr != ':' ) {
852  DBG ( "IPv6 invalid separator '%c' in \"%s\"\n",
853  *endptr, string );
854  return -EINVAL;
855  }
856  if ( ( endptr == nptr ) && ( nptr != string ) ) {
857  if ( pad ) {
858  DBG ( "IPv6 invalid multiple \"::\" in "
859  "\"%s\"\n", string );
860  return -EINVAL;
861  }
862  pad = word;
863  }
864  nptr = ( endptr + 1 );
865 
866  /* Check for overrun */
867  if ( word == end ) {
868  DBG ( "IPv6 too many words in \"%s\"\n", string );
869  return -EINVAL;
870  }
871  }
872 
873  /* Insert padding if specified */
874  if ( pad ) {
875  move_len = ( ( ( void * ) word ) - ( ( void * ) pad ) );
876  pad_len = ( ( ( void * ) end ) - ( ( void * ) word ) );
877  memmove ( ( ( ( void * ) pad ) + pad_len ), pad, move_len );
878  memset ( pad, 0, pad_len );
879  } else if ( word != end ) {
880  DBG ( "IPv6 underlength address \"%s\"\n", string );
881  return -EINVAL;
882  }
883 
884  return 0;
885 }
#define EINVAL
Invalid argument.
Definition: errno.h:429
unsigned short uint16_t
Definition: stdint.h:11
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:485
__be32 in[4]
Definition: CIB_PRM.h:35
uint32_t string
Definition: multiboot.h:14
u32 pad[9]
Padding.
Definition: ar9003_mac.h:47
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
void * memmove(void *dest, const void *src, size_t len) __nonnull
long pad_len
Definition: bigint.h:31
unsigned short word
Definition: smc9000.h:39
uint32_t end
Ending offset.
Definition: netvsc.h:18
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
#define htons(value)
Definition: byteswap.h:136
void * memset(void *dest, int character, size_t len) __nonnull

References DBG, EINVAL, end, htons, in, memmove(), memset(), NULL, pad, pad_len, 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().

◆ inet6_ntoa()

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 895 of file ipv6.c.

895  {
896  static char buf[41]; /* ":xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx" */
897  char *out = buf;
898  char *longest_start = NULL;
899  char *start = NULL;
900  int longest_len = 1;
901  int len = 0;
902  char *dest;
903  unsigned int i;
904  uint16_t value;
905 
906  /* Format address, keeping track of longest run of zeros */
907  for ( i = 0 ; i < ( sizeof ( in->s6_addr16 ) /
908  sizeof ( in->s6_addr16[0] ) ) ; i++ ) {
909  value = ntohs ( in->s6_addr16[i] );
910  if ( value == 0 ) {
911  if ( len++ == 0 )
912  start = out;
913  if ( len > longest_len ) {
914  longest_start = start;
915  longest_len = len;
916  }
917  } else {
918  len = 0;
919  }
920  out += sprintf ( out, ":%x", value );
921  }
922 
923  /* Abbreviate longest run of zeros, if applicable */
924  if ( longest_start ) {
925  dest = strcpy ( ( longest_start + 1 ),
926  ( longest_start + ( 2 * longest_len ) ) );
927  if ( dest[0] == '\0' )
928  dest[1] = '\0';
929  dest[0] = ':';
930  }
931  return ( ( longest_start == buf ) ? buf : ( buf + 1 ) );
932 }
unsigned short uint16_t
Definition: stdint.h:11
__be32 in[4]
Definition: CIB_PRM.h:35
#define sprintf(buf, fmt,...)
Write a formatted string to a buffer.
Definition: stdio.h:37
#define ntohs(value)
Definition: byteswap.h:137
__be32 out[4]
Definition: CIB_PRM.h:36
uint32_t start
Starting offset.
Definition: netvsc.h:12
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
ring len
Length.
Definition: dwmac.h:231
char * strcpy(char *dest, const char *src)
Copy string.
Definition: string.c:347
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:151
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References dest, in, 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_prefix_fetch_ip6(), 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().