socket.h

Go to the documentation of this file.
00001 #ifndef _GPXE_SOCKET_H
00002 #define _GPXE_SOCKET_H
00003 
00004 /** @file
00005  *
00006  * Socket addresses
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER );
00011 
00012 #include <stdint.h>
00013 
00014 /**
00015  * @defgroup commtypes Communication semantics
00016  *
00017  * @{
00018  */
00019 
00020 /** Connection-based, reliable streams */
00021 extern int tcp_sock_stream;
00022 #define TCP_SOCK_STREAM 0x1
00023 #define SOCK_STREAM tcp_sock_stream
00024 
00025 /** Connectionless, unreliable streams */
00026 extern int udp_sock_dgram;
00027 #define UDP_SOCK_DGRAM 0x2
00028 #define SOCK_DGRAM udp_sock_dgram
00029 
00030 /** @} */
00031 
00032 /**
00033  * Name communication semantics
00034  *
00035  * @v semantics         Communication semantics (e.g. SOCK_STREAM)
00036  * @ret name            Name of communication semantics
00037  */
00038 static inline __attribute__ (( always_inline )) const char *
00039 socket_semantics_name ( int semantics ) {
00040         /* Cannot use a switch() because of the {TCP_UDP}_SOCK_XXX hack */
00041         if ( semantics == SOCK_STREAM ) {
00042                 return "SOCK_STREAM";
00043         } else if ( semantics == SOCK_DGRAM ) {
00044                 return "SOCK_DGRAM";
00045         } else {
00046                 return "SOCK_UNKNOWN";
00047         }
00048 }
00049 
00050 /**
00051  * @defgroup addrfam Address families
00052  *
00053  * @{
00054  */
00055 #define AF_INET         1       /**< IPv4 Internet addresses */
00056 #define AF_INET6        2       /**< IPv6 Internet addresses */
00057 /** @} */
00058 
00059 /**
00060  * Name address family
00061  *
00062  * @v family            Address family (e.g. AF_INET)
00063  * @ret name            Name of address family
00064  */
00065 static inline __attribute__ (( always_inline )) const char *
00066 socket_family_name ( int family ) {
00067         switch ( family ) {
00068         case AF_INET:           return "AF_INET";
00069         case AF_INET6:          return "AF_INET6";
00070         default:                return "AF_UNKNOWN";
00071         }
00072 }
00073 
00074 /** A socket address family */
00075 typedef uint16_t sa_family_t;
00076 
00077 /** Length of a @c struct @c sockaddr */
00078 #define SA_LEN 32
00079 
00080 /**
00081  * Generalized socket address structure
00082  *
00083  * This contains the fields common to socket addresses for all address
00084  * families.
00085  */
00086 struct sockaddr {
00087         /** Socket address family
00088          *
00089          * This is an AF_XXX constant.
00090          */
00091         sa_family_t sa_family;
00092         /** Padding
00093          *
00094          * This ensures that a struct @c sockaddr_tcpip is large
00095          * enough to hold a socket address for any TCP/IP address
00096          * family.
00097          */
00098         char pad[ SA_LEN - sizeof ( sa_family_t ) ];
00099 } __attribute__ (( may_alias ));
00100 
00101 #endif /* _GPXE_SOCKET_H */

Generated on Tue Apr 6 20:01:08 2010 for gPXE by  doxygen 1.5.7.1