Data Structures | Defines | 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...


#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.
#define AF_INET6   2
 IPv6 Internet addresses.
#define AF_FC   3
 Fibre Channel addresses.
#define SA_LEN   32
 Length of a struct sockaddr.
#define SOCKADDR_CONVERTERS   __table ( struct sockaddr_converter, "sockaddr_converters" )
 Socket address converter table.
#define __sockaddr_converter   __table_entry ( SOCKADDR_CONVERTERS, 01 )
 Declare a socket address converter.


typedef uint16_t sa_family_t
 A socket address family.


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


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

Detailed Description

Socket addresses.

Definition in file socket.h.

Define Documentation

#define SA_LEN   32

Length of a struct sockaddr.

Definition at line 88 of file socket.h.

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

Socket address converter table.

Definition at line 137 of file socket.h.

Referenced by sock_aton(), and sock_ntoa().

Declare a socket address converter.

Definition at line 141 of file socket.h.

Typedef Documentation

A socket address family.

Definition at line 85 of file socket.h.

Function Documentation

static const char* socket_semantics_name ( int  semantics) [inline, static]

Name communication semantics.

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

Definition at line 45 of file socket.h.


Referenced by xfer_open_socket().

        /* Cannot use a switch() because of the {TCP_UDP}_SOCK_XXX hack */
        if ( semantics == SOCK_STREAM ) {
                return "SOCK_STREAM";
        } else if ( semantics == SOCK_DGRAM ) {
                return "SOCK_DGRAM";
        } else if ( semantics == SOCK_ECHO ) {
                return "SOCK_ECHO";
        } else {
                return "SOCK_UNKNOWN";
static const char* socket_family_name ( int  family) [inline, static]

Name address family.

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

Definition at line 75 of file socket.h.

References AF_FC, AF_INET, and AF_INET6.

Referenced by efi_pxe_start(), and xfer_open_socket().

        switch ( family ) {
        case AF_INET:           return "AF_INET";
        case AF_INET6:          return "AF_INET6";
        case AF_FC:             return "AF_FC";
        default:                return "AF_UNKNOWN";
const char* sock_ntoa ( struct sockaddr sa)

Transcribe socket address.

saSocket address
Return values:
stringSocket address string

Definition at line 42 of file socket.c.

References sockaddr_converter::family, for_each_table_entry, sockaddr_converter::ntoa, NULL, 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().

        struct sockaddr_converter *converter;

        for_each_table_entry ( converter, SOCKADDR_CONVERTERS ) {
                if ( converter->family == sa->sa_family )
                        return converter->ntoa ( sa );
        return NULL;
int sock_aton ( const char *  string,
struct sockaddr sa 

Parse socket address.

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

Definition at line 59 of file socket.c.

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

Referenced by numeric_resolv(), and x509_check_ipaddress().

        struct sockaddr_converter *converter;

        for_each_table_entry ( converter, SOCKADDR_CONVERTERS ) {
                if ( converter->aton ( string, sa ) == 0 ) {
                        sa->sa_family = converter->family;
                        return 0;
        return -EINVAL;