All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sir_socket_defs.h
Go to the documentation of this file.
1 /*
2  * sir_socket_defs.h
3  *
4  * Created on: Feb 11, 2015
5  * Author: root
6  */
7  // Needed by doxygen
9 
10 #ifndef SIR_SOCKET_DEFS_H_
11 #define SIR_SOCKET_DEFS_H_
12 
13 #include <stdint.h>
14 #include "ip/packet-defines.h"
15 #ifdef __cplusplus
16 #include <common.h>
17 #include "common/sir_common.h"
18 #include "tcp/sir_tcp_syncache.h"
19 #endif
20 
21 #define SIR_PORT_DEFAULT_IPV4_ARP_ENTRIES 512
22 #define SIR_PORT_DEFAULT_IPV4_VLAN_ENTRIES 16
23 #define SIR_PORT_DEFAULT_IPV6_CACHE_ENTRIES_POW2 8
24 #define SIR_PORT_DEFAULT_IPV6_INTERFACE_ENTRIES 32
25 #define SIR_PORT_DEFAULT_IPV6_ROUTER_ENTRIES 16
26 #define SIR_PORT_DEFAULT_IPV6_PREFIX_ENTRIES 16
27 
28 
29 #define SIR_IP_IPPROTO_TCP 6
30 #define SIR_IP_IPPROTO_UDP 17
31 
32 #define SIR_IP_INADDR_ANY TIPAddr(0) //CSocketMisc::m_tZeroIP
33 
34 // Address families
35 #define SIR_SO_AF_INET 2
36 #define SIR_SO_AF_INET6 10
37 
38 
39 // Types
40 #define SIR_SO_SOCK_NONE 0
41 #define SIR_SO_SOCK_STREAM 1
42 #define SIR_SO_SOCK_DGRAM 2
43 #define SIR_SO_SOCK_RAW 3
44 
45 // Socket error codes
46 #define SIR_COMMON_OK 0 // No error
47 #define SIR_COMMON_EPERM 1 // Operation not permitted
48 #define SIR_COMMON_ENXIO 6 // No such device or address
49 #define SIR_COMMON_EBADF 9 // Bad file descriptor
50 #define SIR_COMMON_EFAULT 14 // Bad address
51 #define SIR_COMMON_EINVAL 22 // Invalid argument
52 #define SIR_COMMON_EMFILE 24 // Too many open files
53 #define SIR_COMMON_EPIPE 32 // Broken pipe
54 #define SIR_COMMON_EAGAIN 35 // Resource temporarily unavailable
55 
56 #define SIR_COMMON_EPROTONOSOPPORT 43 // Protocol or type not supported
57 #define SIR_COMMON_EAFNOSUPPORT 47 // Address family not supported by protocol family
58 #define SIR_COMMON_EADDRNOTAVAIL 49 // Can't assign requested address
59 #define SIR_COMMON_ENOBUFS 55 // No buffer space available
60 #define SIR_COMMON_ENOSR 63 // Out of stream resources
61 #define SIR_COMMON_ENOPROTOOPT 92 // Protocol not available
62 #define SIR_COMMON_IPNOARP 93 // IP Layer returned NO_ARP error
63 
64 #define SIR_COMMON_ENOTCONN 134 // Connection closing
65 #define SIR_COMMON_ECONNREFUSED 146 // Connection refused
66 #define SIR_COMMON_EALREADY 149 // Connection already in use
67 
68 // Socket receive flags
69 #define SIR_SO_PEEK 0x2 // Do not delete data after it has been read.
70 
72 typedef enum
73 {
82 
84 typedef enum
85 {
112 }ESockOptName;
113 
115 typedef enum
116 {
118 }EPortConfig;
119 
122 {
123  uint8_t ui8Sin_Family;
124  uint16_t ui16Sin_Port;
126 #ifdef __cplusplus
127  bool operator==(const sir_ip_sockaddr_t &T) const
128  {
129  return ((T.ui8Sin_Family == this->ui8Sin_Family) && (T.ui16Sin_Port == this->ui16Sin_Port) && (T.tSin_Addr == this->tSin_Addr)) ? true : false;
130  }
131  bool operator!=(const sir_ip_sockaddr_t &T) const
132  {
133  return ((T.ui8Sin_Family != this->ui8Sin_Family) || (T.ui16Sin_Port != this->ui16Sin_Port) || (T.tSin_Addr != this->tSin_Addr)) ? true : false;
134  }
135 #endif
136 };
137 
138 // Struct contains config info of a port
140 {
141  uint16_t ui16PortNr;
142  uint64_t ui64MAC;
143 
144  uint16_t ui16Vlan;
145  struct TIPAddr tIPaddr;
146  struct TIPAddr tGw;
147  uint8_t ui8NetMask;
148 };
149 
150 #ifdef __cplusplus
151 // This is the main bookkeeping struct for a socket
152 typedef struct
153 {
154  TIPAddr tBindAddr; // Address that was used when the socket was bound
155  uint64_t ui64Handle_ID; // Should be SIR_SO_HANDLE_ID
156  uint64_t ui64Signature;
157  void *pNotification; // User notification. Probably a reference to user data
158 
159  TSendAccelerate tSendAccelerate; // Contains data so send can be accelerated
160 
162  uint32_t ui32AppTag; // Application tag can be used to protect app data
163  bool bBoundSocket; // Socket is bound and not converted to client socket (via So_connect)
164  bool bIsListenSocket; // Set this if it is TCP listen socket, used to speed op searching
165  bool bSocketIsIPV6; // Socket is IPV6
166  bool bAcceptIPV6Only; // Only accept IPV6 traffic when socket is IPV6 and listens to SIR_IPV6_V6ONLY
167  bool bIsInDualStackMode; // IPV6 Socket handles IPV4 traffic
168  bool bSourcePortIsEphemeral; // Source port nr has been determined by user of stack (= ephemeral)
169  bool bListenToAnyAddress; // This listen socket will listen to any address
170  bool bBindOverload; // Socket was bind via BindOverload
171  bool bMSSWasModified; // User changed MSS size of this socket
172 
173  sir_tcp_tcb tTCBBound; // TCP transmission control block for this session when in listen mode
174  sir_tcp_tcb *ptTCB; // TCP transmission control block for this session
175 
176  int iBackLog; // So_listen backlog parameter
177  int16_t i16PhysicalPort; // Physical port which connection uses
178  uint16_t ui16PendingConnections; // Nr of pending connections on a listen socket that wait to be accepted
179 
180  // SOCKOPT parameters
181  uint16_t ui16MSS; // MSS value, set by setsockopt (SIR_IPPROTO_TCP/SIR_TCP_MAXMSS)
182 
183  uint8_t ui8Type; // protocol type of this socket (UDP, TCP or RAW)
184  uint8_t ui8Protocol; // protocol of this socket
185 
187 
188 #endif /* cplusplus */
189 #endif /* SIR_SOCKET_DEFS_H_ */
struct TIPAddr tIPaddr
When requesting IP configuration, the IP address.
struct TIPAddr tGw
When requesting IP configuration, the gateway.
sir_tcp_tcb tTCBBound
uint16_t ui16Sin_Port
TCP/UDP port number.
sir_tcp_tcb * ptTCB
bool operator!=(const sir_ip_sockaddr_t &T) const
uint16_t ui16Vlan
When requesting IP configuration, the VLAN.
ESockOptName
SetSocknames enumeration.
Struct contains an IPV4 or an IPV6 address.
Definition: packet-defines.h:7
uint8_t ui8NetMask
When requesting IP configuration, the net mask.
uint64_t ui64MAC
&lt;AC address of the physical port
Struct contains address information.
uint16_t ui16PortNr
Physical port for this configuration information.
uint64_t ui64Handle_ID
struct TIPAddr tSin_Addr
IP4/IPV6 address struct.
uint16_t ui16PendingConnections
TSendAccelerate tSendAccelerate
ESockOptLevel
SetSocklevels.
uint8_t ui8Sin_Family
Address family type (SIR_SO_AF_INET = IPv4, SIR_SO_AF_INET6 = IPV6)
EPortConfig
Enumerations for port config.
bool operator==(const sir_ip_sockaddr_t &T) const
uint64_t ui64Signature