[contrib] Allow Network Protocol header to display in rom-o-matic
[gpxe.git] / src / include / gpxe / socket.h
blob9ea0db9499a886671f1080f7cb118010bf169dcc
1 #ifndef _GPXE_SOCKET_H
2 #define _GPXE_SOCKET_H
4 /** @file
6 * Socket addresses
8 */
10 FILE_LICENCE ( GPL2_OR_LATER );
12 #include <stdint.h>
14 /**
15 * @defgroup commtypes Communication semantics
17 * @{
20 /** Connection-based, reliable streams */
21 extern int tcp_sock_stream;
22 #define TCP_SOCK_STREAM 0x1
23 #define SOCK_STREAM tcp_sock_stream
25 /** Connectionless, unreliable streams */
26 extern int udp_sock_dgram;
27 #define UDP_SOCK_DGRAM 0x2
28 #define SOCK_DGRAM udp_sock_dgram
30 /** @} */
32 /**
33 * Name communication semantics
35 * @v semantics Communication semantics (e.g. SOCK_STREAM)
36 * @ret name Name of communication semantics
38 static inline __attribute__ (( always_inline )) const char *
39 socket_semantics_name ( int semantics ) {
40 /* Cannot use a switch() because of the {TCP_UDP}_SOCK_XXX hack */
41 if ( semantics == SOCK_STREAM ) {
42 return "SOCK_STREAM";
43 } else if ( semantics == SOCK_DGRAM ) {
44 return "SOCK_DGRAM";
45 } else {
46 return "SOCK_UNKNOWN";
50 /**
51 * @defgroup addrfam Address families
53 * @{
55 #define AF_INET 1 /**< IPv4 Internet addresses */
56 #define AF_INET6 2 /**< IPv6 Internet addresses */
57 /** @} */
59 /**
60 * Name address family
62 * @v family Address family (e.g. AF_INET)
63 * @ret name Name of address family
65 static inline __attribute__ (( always_inline )) const char *
66 socket_family_name ( int family ) {
67 switch ( family ) {
68 case AF_INET: return "AF_INET";
69 case AF_INET6: return "AF_INET6";
70 default: return "AF_UNKNOWN";
74 /** A socket address family */
75 typedef uint16_t sa_family_t;
77 /** Length of a @c struct @c sockaddr */
78 #define SA_LEN 32
80 /**
81 * Generalized socket address structure
83 * This contains the fields common to socket addresses for all address
84 * families.
86 struct sockaddr {
87 /** Socket address family
89 * This is an AF_XXX constant.
91 sa_family_t sa_family;
92 /** Padding
94 * This ensures that a struct @c sockaddr_tcpip is large
95 * enough to hold a socket address for any TCP/IP address
96 * family.
98 char pad[ SA_LEN - sizeof ( sa_family_t ) ];
99 } __attribute__ (( may_alias ));
101 #endif /* _GPXE_SOCKET_H */