Rev 4578 | Rev 4712 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4578 | Rev 4603 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Lukas Mejdrech |
2 | * Copyright (c) 2009 Lukas Mejdrech |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup socket |
29 | /** @addtogroup socket |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | * Socket application program interface (API). |
34 | * Socket application program interface (API). |
35 | * This is a part of the network application library. |
35 | * This is a part of the network application library. |
36 | * Based on the linux src/include/linux/socket.h header file and BSD socket interface. |
36 | * Based on the linux src/include/linux/socket.h header file and BSD socket interface. |
37 | */ |
37 | */ |
38 | 38 | ||
39 | #ifndef __NET_SOCKET_H__ |
39 | #ifndef __NET_SOCKET_H__ |
40 | #define __NET_SOCKET_H__ |
40 | #define __NET_SOCKET_H__ |
41 | 41 | ||
42 | #include <sys/types.h> |
42 | #include <sys/types.h> |
43 | 43 | ||
- | 44 | #include "byteorder.h" |
|
44 | #include "in.h" |
45 | #include "in.h" |
45 | #include "inet.h" |
46 | #include "inet.h" |
46 | 47 | ||
47 | /* Supported address families. */ |
48 | /* Supported address families. */ |
48 | /** Unspecified address family. |
49 | /** Unspecified address family. |
49 | */ |
50 | */ |
50 | #define AF_UNSPEC 0 |
51 | #define AF_UNSPEC 0 |
51 | 52 | ||
52 | /** Unix domain sockets address family. |
53 | /** Unix domain sockets address family. |
53 | */ |
54 | */ |
54 | #define AF_UNIXL 1 |
55 | #define AF_UNIXL 1 |
55 | 56 | ||
56 | /** POSIX name for AF_UNIX address family. |
57 | /** POSIX name for AF_UNIX address family. |
57 | */ |
58 | */ |
58 | #define AF_LOCAL 1 |
59 | #define AF_LOCAL 1 |
59 | 60 | ||
60 | /** Internet IP Protocol address family. |
61 | /** Internet IP Protocol address family. |
61 | */ |
62 | */ |
62 | #define AF_INET 2 |
63 | #define AF_INET 2 |
63 | 64 | ||
64 | /** Amateur Radio AX.25 address family. |
65 | /** Amateur Radio AX.25 address family. |
65 | */ |
66 | */ |
66 | #define AF_AX25 3 |
67 | #define AF_AX25 3 |
67 | 68 | ||
68 | /** Novell IPX address family. |
69 | /** Novell IPX address family. |
69 | */ |
70 | */ |
70 | #define AF_IPX 4 |
71 | #define AF_IPX 4 |
71 | 72 | ||
72 | /** AppleTalk DDP address family. |
73 | /** AppleTalk DDP address family. |
73 | */ |
74 | */ |
74 | #define AF_APPLETALK 5 |
75 | #define AF_APPLETALK 5 |
75 | 76 | ||
76 | /** Amateur Radio NET/ROM address family. |
77 | /** Amateur Radio NET/ROM address family. |
77 | */ |
78 | */ |
78 | #define AF_NETROM 6 |
79 | #define AF_NETROM 6 |
79 | 80 | ||
80 | /** Multiprotocol bridge address family. |
81 | /** Multiprotocol bridge address family. |
81 | */ |
82 | */ |
82 | #define AF_BRIDGE 7 |
83 | #define AF_BRIDGE 7 |
83 | 84 | ||
84 | /** ATM PVCs address family. |
85 | /** ATM PVCs address family. |
85 | */ |
86 | */ |
86 | #define AF_ATMPVC 8 |
87 | #define AF_ATMPVC 8 |
87 | 88 | ||
88 | /** Reserved for X.25 project address family. |
89 | /** Reserved for X.25 project address family. |
89 | */ |
90 | */ |
90 | #define AF_X25 9 |
91 | #define AF_X25 9 |
91 | 92 | ||
92 | /** IP version 6 address family. |
93 | /** IP version 6 address family. |
93 | */ |
94 | */ |
94 | #define AF_INET6 10 |
95 | #define AF_INET6 10 |
95 | 96 | ||
96 | /** Amateur Radio X.25 PLP address family. |
97 | /** Amateur Radio X.25 PLP address family. |
97 | */ |
98 | */ |
98 | #define AF_ROSE 11 |
99 | #define AF_ROSE 11 |
99 | 100 | ||
100 | /** Reserved for DECnet project address family. |
101 | /** Reserved for DECnet project address family. |
101 | */ |
102 | */ |
102 | #define AF_DECnet 12 |
103 | #define AF_DECnet 12 |
103 | 104 | ||
104 | /** Reserved for 802.2LLC project address family. |
105 | /** Reserved for 802.2LLC project address family. |
105 | */ |
106 | */ |
106 | #define AF_NETBEUI 13 |
107 | #define AF_NETBEUI 13 |
107 | 108 | ||
108 | /** Security callback pseudo AF address family. |
109 | /** Security callback pseudo AF address family. |
109 | */ |
110 | */ |
110 | #define AF_SECURITY 14 |
111 | #define AF_SECURITY 14 |
111 | 112 | ||
112 | /** PF_KEY key management API address family. |
113 | /** PF_KEY key management API address family. |
113 | */ |
114 | */ |
114 | #define AF_KEY 15 |
115 | #define AF_KEY 15 |
115 | 116 | ||
116 | /** Alias to emulate 4.4BSD address family. |
117 | /** Alias to emulate 4.4BSD address family. |
117 | */ |
118 | */ |
118 | #define AF_NETLINK 16 |
119 | #define AF_NETLINK 16 |
119 | 120 | ||
120 | /** Packet family address family. |
121 | /** Packet family address family. |
121 | */ |
122 | */ |
122 | #define AF_PACKET 17 |
123 | #define AF_PACKET 17 |
123 | 124 | ||
124 | /** Ash address family. |
125 | /** Ash address family. |
125 | */ |
126 | */ |
126 | #define AF_ASH 18 |
127 | #define AF_ASH 18 |
127 | 128 | ||
128 | /** Acorn Econet address family. |
129 | /** Acorn Econet address family. |
129 | */ |
130 | */ |
130 | #define AF_ECONET 19 |
131 | #define AF_ECONET 19 |
131 | 132 | ||
132 | /** ATM SVCs address family. |
133 | /** ATM SVCs address family. |
133 | */ |
134 | */ |
134 | #define AF_ATMSVC 20 |
135 | #define AF_ATMSVC 20 |
135 | 136 | ||
136 | /** Linux SNA Project (nutters!) address family. |
137 | /** Linux SNA Project (nutters!) address family. |
137 | */ |
138 | */ |
138 | #define AF_SNA 22 |
139 | #define AF_SNA 22 |
139 | 140 | ||
140 | /** IRDA sockets address family. |
141 | /** IRDA sockets address family. |
141 | */ |
142 | */ |
142 | #define AF_IRDA 23 |
143 | #define AF_IRDA 23 |
143 | 144 | ||
144 | /** PPPoX sockets address family. |
145 | /** PPPoX sockets address family. |
145 | */ |
146 | */ |
146 | #define AF_PPPOX 24 |
147 | #define AF_PPPOX 24 |
147 | 148 | ||
148 | /** Wanpipe API Sockets address family. |
149 | /** Wanpipe API Sockets address family. |
149 | */ |
150 | */ |
150 | #define AF_WANPIPE 25 |
151 | #define AF_WANPIPE 25 |
151 | 152 | ||
152 | /** Linux LLC address family. |
153 | /** Linux LLC address family. |
153 | */ |
154 | */ |
154 | #define AF_LLC 26 |
155 | #define AF_LLC 26 |
155 | 156 | ||
156 | /** Controller Area Network address family. |
157 | /** Controller Area Network address family. |
157 | */ |
158 | */ |
158 | #define AF_CAN 29 |
159 | #define AF_CAN 29 |
159 | 160 | ||
160 | /** TIPC sockets address family. |
161 | /** TIPC sockets address family. |
161 | */ |
162 | */ |
162 | #define AF_TIPC 30 |
163 | #define AF_TIPC 30 |
163 | 164 | ||
164 | /** Bluetooth sockets address family. |
165 | /** Bluetooth sockets address family. |
165 | */ |
166 | */ |
166 | #define AF_BLUETOOTH 31 |
167 | #define AF_BLUETOOTH 31 |
167 | 168 | ||
168 | /** IUCV sockets address family. |
169 | /** IUCV sockets address family. |
169 | */ |
170 | */ |
170 | #define AF_IUCV 32 |
171 | #define AF_IUCV 32 |
171 | 172 | ||
172 | /** RxRPC sockets address family. |
173 | /** RxRPC sockets address family. |
173 | */ |
174 | */ |
174 | #define AF_RXRPC 33 |
175 | #define AF_RXRPC 33 |
175 | 176 | ||
176 | /** Maximum address family. |
177 | /** Maximum address family. |
177 | */ |
178 | */ |
178 | #define AF_MAX 34 |
179 | #define AF_MAX 34 |
179 | 180 | ||
180 | /* Protocol families, same as address families. */ |
181 | /* Protocol families, same as address families. */ |
181 | 182 | ||
182 | #define PF_UNSPEC AF_UNSPEC |
183 | #define PF_UNSPEC AF_UNSPEC |
183 | #define PF_UNIX AF_UNIX |
184 | #define PF_UNIX AF_UNIX |
184 | #define PF_LOCAL AF_LOCAL |
185 | #define PF_LOCAL AF_LOCAL |
185 | #define PF_INET AF_INET |
186 | #define PF_INET AF_INET |
186 | #define PF_AX25 AF_AX25 |
187 | #define PF_AX25 AF_AX25 |
187 | #define PF_IPX AF_IPX |
188 | #define PF_IPX AF_IPX |
188 | #define PF_APPLETALK AF_APPLETALK |
189 | #define PF_APPLETALK AF_APPLETALK |
189 | #define PF_NETROM AF_NETROM |
190 | #define PF_NETROM AF_NETROM |
190 | #define PF_BRIDGE AF_BRIDGE |
191 | #define PF_BRIDGE AF_BRIDGE |
191 | #define PF_ATMPVC AF_ATMPVC |
192 | #define PF_ATMPVC AF_ATMPVC |
192 | #define PF_X25 AF_X25 |
193 | #define PF_X25 AF_X25 |
193 | #define PF_INET6 AF_INET6 |
194 | #define PF_INET6 AF_INET6 |
194 | #define PF_ROSE AF_ROSE |
195 | #define PF_ROSE AF_ROSE |
195 | #define PF_DECnet AF_DECnet |
196 | #define PF_DECnet AF_DECnet |
196 | #define PF_NETBEUI AF_NETBEUI |
197 | #define PF_NETBEUI AF_NETBEUI |
197 | #define PF_SECURITY AF_SECURITY |
198 | #define PF_SECURITY AF_SECURITY |
198 | #define PF_KEY AF_KEY |
199 | #define PF_KEY AF_KEY |
199 | #define PF_NETLINK AF_NETLINK |
200 | #define PF_NETLINK AF_NETLINK |
200 | #define PF_ROUTE AF_ROUTE |
201 | #define PF_ROUTE AF_ROUTE |
201 | #define PF_PACKET AF_PACKET |
202 | #define PF_PACKET AF_PACKET |
202 | #define PF_ASH AF_ASH |
203 | #define PF_ASH AF_ASH |
203 | #define PF_ECONET AF_ECONET |
204 | #define PF_ECONET AF_ECONET |
204 | #define PF_ATMSVC AF_ATMSVC |
205 | #define PF_ATMSVC AF_ATMSVC |
205 | #define PF_SNA AF_SNA |
206 | #define PF_SNA AF_SNA |
206 | #define PF_IRDA AF_IRDA |
207 | #define PF_IRDA AF_IRDA |
207 | #define PF_PPPOX AF_PPPOX |
208 | #define PF_PPPOX AF_PPPOX |
208 | #define PF_WANPIPE AF_WANPIPE |
209 | #define PF_WANPIPE AF_WANPIPE |
209 | #define PF_LLC AF_LLC |
210 | #define PF_LLC AF_LLC |
210 | #define PF_CAN AF_CAN |
211 | #define PF_CAN AF_CAN |
211 | #define PF_TIPC AF_TIPC |
212 | #define PF_TIPC AF_TIPC |
212 | #define PF_BLUETOOTH AF_BLUETOOTH |
213 | #define PF_BLUETOOTH AF_BLUETOOTH |
213 | #define PF_IUCV AF_IUCV |
214 | #define PF_IUCV AF_IUCV |
214 | #define PF_RXRPC AF_RXRPC |
215 | #define PF_RXRPC AF_RXRPC |
215 | #define PF_MAX AF_MAX |
216 | #define PF_MAX AF_MAX |
216 | 217 | ||
217 | /* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx */ |
218 | /* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx */ |
218 | #define SOL_IP 0 |
219 | #define SOL_IP 0 |
219 | #define SOL_ICMP 1 |
220 | #define SOL_ICMP 1 |
220 | #define SOL_TCP 6 |
221 | #define SOL_TCP 6 |
221 | #define SOL_UDP 17 |
222 | #define SOL_UDP 17 |
222 | #define SOL_IPV6 41 |
223 | #define SOL_IPV6 41 |
223 | #define SOL_ICMPV6 58 |
224 | #define SOL_ICMPV6 58 |
224 | #define SOL_SCTP 132 |
225 | #define SOL_SCTP 132 |
225 | #define SOL_UDPLITE 136 /* UDP-Lite (RFC 3828) */ |
226 | #define SOL_UDPLITE 136 /* UDP-Lite (RFC 3828) */ |
226 | #define SOL_RAW 255 |
227 | #define SOL_RAW 255 |
227 | #define SOL_IPX 256 |
228 | #define SOL_IPX 256 |
228 | #define SOL_AX25 257 |
229 | #define SOL_AX25 257 |
229 | #define SOL_ATALK 258 |
230 | #define SOL_ATALK 258 |
230 | #define SOL_NETROM 259 |
231 | #define SOL_NETROM 259 |
231 | #define SOL_ROSE 260 |
232 | #define SOL_ROSE 260 |
232 | #define SOL_DECNET 261 |
233 | #define SOL_DECNET 261 |
233 | #define SOL_X25 262 |
234 | #define SOL_X25 262 |
234 | #define SOL_PACKET 263 |
235 | #define SOL_PACKET 263 |
235 | #define SOL_ATM 264 /* ATM layer (cell level) */ |
236 | #define SOL_ATM 264 /* ATM layer (cell level) */ |
236 | #define SOL_AAL 265 /* ATM Adaption Layer (packet level) */ |
237 | #define SOL_AAL 265 /* ATM Adaption Layer (packet level) */ |
237 | #define SOL_IRDA 266 |
238 | #define SOL_IRDA 266 |
238 | #define SOL_NETBEUI 267 |
239 | #define SOL_NETBEUI 267 |
239 | #define SOL_LLC 268 |
240 | #define SOL_LLC 268 |
240 | #define SOL_DCCP 269 |
241 | #define SOL_DCCP 269 |
241 | #define SOL_NETLINK 270 |
242 | #define SOL_NETLINK 270 |
242 | #define SOL_TIPC 271 |
243 | #define SOL_TIPC 271 |
243 | #define SOL_RXRPC 272 |
244 | #define SOL_RXRPC 272 |
244 | #define SOL_PPPOL2TP 273 |
245 | #define SOL_PPPOL2TP 273 |
245 | #define SOL_BLUETOOTH 274 |
246 | #define SOL_BLUETOOTH 274 |
246 | 247 | ||
247 | // |
248 | // |
248 | /* * IPX options. |
249 | /* * IPX options. |
249 | */ |
250 | */ |
250 | //#define IPX_TYPE 1 |
251 | //#define IPX_TYPE 1 |
251 | 252 | ||
252 | /** Socket type type definition. |
253 | /** Socket type type definition. |
253 | */ |
254 | */ |
254 | typedef enum sock_type{ |
255 | typedef enum sock_type{ |
255 | /** Stream (connection oriented) socket. |
256 | /** Stream (connection oriented) socket. |
256 | */ |
257 | */ |
257 | SOCK_STREAM = 1, |
258 | SOCK_STREAM = 1, |
258 | /** Datagram (connectionless oriented) socket. |
259 | /** Datagram (connectionless oriented) socket. |
259 | */ |
260 | */ |
260 | SOCK_DGRAM = 2, |
261 | SOCK_DGRAM = 2, |
261 | /** Raw socket. |
262 | /** Raw socket. |
262 | */ |
263 | */ |
263 | SOCK_RAW = 3 |
264 | SOCK_RAW = 3 |
264 | } sock_type_t; |
265 | } sock_type_t; |
265 | 266 | ||
266 | typedef int32_t socklen_t; |
267 | typedef int32_t socklen_t; |
267 | 268 | ||
268 | int socket( int domain, int type, int protocol ); |
269 | int socket( int domain, int type, int protocol ); |
269 | int bind( int socket_id, const struct sockaddr * my_addr, socklen_t addrlen ); |
270 | int bind( int socket_id, const struct sockaddr * my_addr, socklen_t addrlen ); |
270 | int listen( int socket_id, int backlog ); |
271 | int listen( int socket_id, int backlog ); |
271 | int accept( int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen ); |
272 | int accept( int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen ); |
272 | int connect( int socket_id, const struct sockaddr * serv_addr, socklen_t addrlen ); |
273 | int connect( int socket_id, const struct sockaddr * serv_addr, socklen_t addrlen ); |
273 | 274 | ||
274 | int closesocket( int socket_id ); |
275 | int closesocket( int socket_id ); |
275 | 276 | ||
276 | int send( int socket_id, void * data, size_t datalength, int flags ); |
277 | int send( int socket_id, void * data, size_t datalength, int flags ); |
277 | int sendto( int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen ); |
278 | int sendto( int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen ); |
278 | 279 | ||
279 | int recv( int socket_id, void * data, size_t datalength, int flags ); |
280 | int recv( int socket_id, void * data, size_t datalength, int flags ); |
280 | int recvfrom( int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen ); |
281 | int recvfrom( int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen ); |
281 | 282 | ||
282 | int getsockopt( int socket_id, int level, int optname, void * value, size_t * optlen ); |
283 | int getsockopt( int socket_id, int level, int optname, void * value, size_t * optlen ); |
283 | int setsockopt( int socket_id, int level, int optname, const void * value, size_t optlen ); |
284 | int setsockopt( int socket_id, int level, int optname, const void * value, size_t optlen ); |
284 | 285 | ||
285 | #endif |
286 | #endif |
286 | 287 | ||
287 | /** @} |
288 | /** @} |
288 | */ |
289 | */ |
289 | 290 |