iPXE
Data Structures | Macros | Typedefs | Functions | Variables
socket.h File Reference

Socket addresses. More...

#include <stdint.h>
#include <ipxe/tables.h>

Go to the source code of this file.

Data Structures

struct  sockaddr
 Generalized socket address structure. More...
 
struct  sockaddr_converter
 Socket address converter. More...
 

Macros

#define TCP_SOCK_STREAM   0x1
 
#define SOCK_STREAM   tcp_sock_stream
 
#define UDP_SOCK_DGRAM   0x2
 
#define SOCK_DGRAM   udp_sock_dgram
 
#define PING_SOCK_ECHO   0x3
 
#define SOCK_ECHO   ping_sock_echo
 
#define AF_INET   1
 IPv4 Internet addresses. More...
 
#define AF_INET6   2
 IPv6 Internet addresses. More...
 
#define AF_FC   3
 Fibre Channel addresses. More...
 
#define SA_LEN   32
 Length of a struct sockaddr. More...
 
#define SOCKADDR_CONVERTERS   __table ( struct sockaddr_converter, "sockaddr_converters" )
 Socket address converter table. More...
 
#define __sockaddr_converter   __table_entry ( SOCKADDR_CONVERTERS, 01 )
 Declare a socket address converter. More...
 

Typedefs

typedef uint16_t sa_family_t
 A socket address family. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static const char * socket_semantics_name (int semantics)
 Name communication semantics. More...
 
static const char * socket_family_name (int family)
 Name address family. More...
 
const char * sock_ntoa (struct sockaddr *sa)
 Transcribe socket address. More...
 
int sock_aton (const char *string, struct sockaddr *sa)
 Parse socket address. More...
 

Variables

int tcp_sock_stream
 Connection-based, reliable streams. More...
 
int udp_sock_dgram
 Connectionless, unreliable streams. More...
 
int ping_sock_echo
 Echo testing streams. More...
 

Detailed Description

Socket addresses.

Definition in file socket.h.

Macro Definition Documentation

◆ SA_LEN

#define SA_LEN   32

Length of a struct sockaddr.

Definition at line 88 of file socket.h.

◆ SOCKADDR_CONVERTERS

#define SOCKADDR_CONVERTERS   __table ( struct sockaddr_converter, "sockaddr_converters" )

Socket address converter table.

Definition at line 137 of file socket.h.

◆ __sockaddr_converter

#define __sockaddr_converter   __table_entry ( SOCKADDR_CONVERTERS, 01 )

Declare a socket address converter.

Definition at line 141 of file socket.h.

Typedef Documentation

◆ sa_family_t

A socket address family.

Definition at line 85 of file socket.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ socket_semantics_name()

static const char* socket_semantics_name ( int  semantics)
inlinestatic

Name communication semantics.

Parameters
semanticsCommunication semantics (e.g. SOCK_STREAM)
Return values
nameName of communication semantics

Definition at line 45 of file socket.h.

45  {
46  /* Cannot use a switch() because of the {TCP_UDP}_SOCK_XXX hack */
47  if ( semantics == SOCK_STREAM ) {
48  return "SOCK_STREAM";
49  } else if ( semantics == SOCK_DGRAM ) {
50  return "SOCK_DGRAM";
51  } else if ( semantics == SOCK_ECHO ) {
52  return "SOCK_ECHO";
53  } else {
54  return "SOCK_UNKNOWN";
55  }
56 }
#define SOCK_DGRAM
Definition: socket.h:29
#define SOCK_ECHO
Definition: socket.h:34
#define SOCK_STREAM
Definition: socket.h:24

References SOCK_DGRAM, SOCK_ECHO, and SOCK_STREAM.

Referenced by xfer_open_socket().

◆ socket_family_name()

static const char* socket_family_name ( int  family)
inlinestatic

Name address family.

Parameters
familyAddress family (e.g. AF_INET)
Return values
nameName of address family

Definition at line 75 of file socket.h.

75  {
76  switch ( family ) {
77  case AF_INET: return "AF_INET";
78  case AF_INET6: return "AF_INET6";
79  case AF_FC: return "AF_FC";
80  default: return "AF_UNKNOWN";
81  }
82 }
#define AF_INET6
IPv6 Internet addresses.
Definition: socket.h:64
#define AF_FC
Fibre Channel addresses.
Definition: socket.h:65
#define AF_INET
IPv4 Internet addresses.
Definition: socket.h:63

References AF_FC, AF_INET, and AF_INET6.

Referenced by efi_pxe_start(), and xfer_open_socket().

◆ sock_ntoa()

const char* sock_ntoa ( struct sockaddr sa)

Transcribe socket address.

Parameters
saSocket address
Return values
stringSocket address string

Definition at line 42 of file socket.c.

42  {
43  struct sockaddr_converter *converter;
44 
46  if ( converter->family == sa->sa_family )
47  return converter->ntoa ( sa );
48  }
49  return NULL;
50 }
struct sockaddr sa
Definition: dns.c:68
sa_family_t sa_family
Socket address family.
Definition: socket.h:101
#define SOCKADDR_CONVERTERS
Socket address converter table.
Definition: socket.h:137
Socket address converter.
Definition: socket.h:115
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
sa_family_t family
Socket address family.
Definition: socket.h:120
const char *(* ntoa)(struct sockaddr *sa)
Transcribe socket address.
Definition: socket.h:126
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References sockaddr_converter::family, for_each_table_entry, sockaddr_converter::ntoa, NULL, sa, sockaddr::sa_family, and SOCKADDR_CONVERTERS.

Referenced by apply_dns_settings(), apply_syslog_settings(), dns_resolved(), ping_callback(), pxe_tftp_open(), tcp_open(), tftp_uri(), and x509_check_ipaddress().

◆ sock_aton()

int sock_aton ( const char *  string,
struct sockaddr sa 
)

Parse socket address.

Parameters
stringSocket address string
saSocket address to fill in
Return values
rcReturn status code

Definition at line 59 of file socket.c.

59  {
60  struct sockaddr_converter *converter;
61 
63  if ( converter->aton ( string, sa ) == 0 ) {
64  sa->sa_family = converter->family;
65  return 0;
66  }
67  }
68  return -EINVAL;
69 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct sockaddr sa
Definition: dns.c:68
sa_family_t sa_family
Socket address family.
Definition: socket.h:101
#define SOCKADDR_CONVERTERS
Socket address converter table.
Definition: socket.h:137
Socket address converter.
Definition: socket.h:115
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
sa_family_t family
Socket address family.
Definition: socket.h:120
int(* aton)(const char *string, struct sockaddr *sa)
Parse socket address.
Definition: socket.h:133

References sockaddr_converter::aton, EINVAL, sockaddr_converter::family, for_each_table_entry, sa, sockaddr::sa_family, and SOCKADDR_CONVERTERS.

Referenced by numeric_resolv(), slam_parse_multicast_address(), and x509_check_ipaddress().