Rev 4603 | Rev 4712 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 3846 | mejdrech | 1 | /* |
| 3912 | mejdrech | 2 | * Copyright (c) 2009 Lukas Mejdrech |
| 3846 | mejdrech | 3 | * All rights reserved. |
| 4 | * |
||
| 5 | * Redistribution and use in source and binary forms, with or without |
||
| 6 | * modification, are permitted provided that the following conditions |
||
| 7 | * are met: |
||
| 8 | * |
||
| 9 | * - Redistributions of source code must retain the above copyright |
||
| 10 | * notice, this list of conditions and the following disclaimer. |
||
| 11 | * - Redistributions in binary form must reproduce the above copyright |
||
| 12 | * notice, this list of conditions and the following disclaimer in the |
||
| 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 |
||
| 15 | * derived from this software without specific prior written permission. |
||
| 16 | * |
||
| 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 |
||
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
| 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 |
||
| 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 |
||
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
| 27 | */ |
||
| 28 | |||
| 4578 | mejdrech | 29 | /** @addtogroup socket |
| 3846 | mejdrech | 30 | * @{ |
| 31 | */ |
||
| 32 | |||
| 33 | /** @file |
||
| 4578 | mejdrech | 34 | * Socket application program interface (API). |
| 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. |
||
| 3846 | mejdrech | 37 | */ |
| 38 | |||
| 39 | #ifndef __NET_SOCKET_H__ |
||
| 40 | #define __NET_SOCKET_H__ |
||
| 41 | |||
| 4578 | mejdrech | 42 | #include <sys/types.h> |
| 43 | |||
| 4603 | mejdrech | 44 | #include "byteorder.h" |
| 4578 | mejdrech | 45 | #include "in.h" |
| 46 | #include "inet.h" |
||
| 47 | |||
| 4701 | mejdrech | 48 | /** @name Address families definitions |
| 49 | */ |
||
| 50 | /*@{*/ |
||
| 3846 | mejdrech | 51 | /** Unspecified address family. |
| 52 | */ |
||
| 53 | #define AF_UNSPEC 0 |
||
| 54 | |||
| 55 | /** Unix domain sockets address family. |
||
| 56 | */ |
||
| 57 | #define AF_UNIXL 1 |
||
| 58 | |||
| 59 | /** POSIX name for AF_UNIX address family. |
||
| 60 | */ |
||
| 61 | #define AF_LOCAL 1 |
||
| 62 | |||
| 63 | /** Internet IP Protocol address family. |
||
| 64 | */ |
||
| 65 | #define AF_INET 2 |
||
| 66 | |||
| 67 | /** Amateur Radio AX.25 address family. |
||
| 68 | */ |
||
| 69 | #define AF_AX25 3 |
||
| 70 | |||
| 71 | /** Novell IPX address family. |
||
| 72 | */ |
||
| 73 | #define AF_IPX 4 |
||
| 74 | |||
| 75 | /** AppleTalk DDP address family. |
||
| 76 | */ |
||
| 77 | #define AF_APPLETALK 5 |
||
| 78 | |||
| 79 | /** Amateur Radio NET/ROM address family. |
||
| 80 | */ |
||
| 81 | #define AF_NETROM 6 |
||
| 82 | |||
| 83 | /** Multiprotocol bridge address family. |
||
| 84 | */ |
||
| 85 | #define AF_BRIDGE 7 |
||
| 86 | |||
| 87 | /** ATM PVCs address family. |
||
| 88 | */ |
||
| 89 | #define AF_ATMPVC 8 |
||
| 90 | |||
| 91 | /** Reserved for X.25 project address family. |
||
| 92 | */ |
||
| 93 | #define AF_X25 9 |
||
| 94 | |||
| 95 | /** IP version 6 address family. |
||
| 96 | */ |
||
| 97 | #define AF_INET6 10 |
||
| 98 | |||
| 99 | /** Amateur Radio X.25 PLP address family. |
||
| 100 | */ |
||
| 101 | #define AF_ROSE 11 |
||
| 102 | |||
| 103 | /** Reserved for DECnet project address family. |
||
| 104 | */ |
||
| 105 | #define AF_DECnet 12 |
||
| 106 | |||
| 107 | /** Reserved for 802.2LLC project address family. |
||
| 108 | */ |
||
| 109 | #define AF_NETBEUI 13 |
||
| 110 | |||
| 111 | /** Security callback pseudo AF address family. |
||
| 112 | */ |
||
| 113 | #define AF_SECURITY 14 |
||
| 114 | |||
| 115 | /** PF_KEY key management API address family. |
||
| 116 | */ |
||
| 117 | #define AF_KEY 15 |
||
| 118 | |||
| 119 | /** Alias to emulate 4.4BSD address family. |
||
| 120 | */ |
||
| 121 | #define AF_NETLINK 16 |
||
| 122 | |||
| 123 | /** Packet family address family. |
||
| 124 | */ |
||
| 125 | #define AF_PACKET 17 |
||
| 126 | |||
| 127 | /** Ash address family. |
||
| 128 | */ |
||
| 129 | #define AF_ASH 18 |
||
| 130 | |||
| 131 | /** Acorn Econet address family. |
||
| 132 | */ |
||
| 133 | #define AF_ECONET 19 |
||
| 134 | |||
| 135 | /** ATM SVCs address family. |
||
| 136 | */ |
||
| 137 | #define AF_ATMSVC 20 |
||
| 138 | |||
| 139 | /** Linux SNA Project (nutters!) address family. |
||
| 140 | */ |
||
| 141 | #define AF_SNA 22 |
||
| 142 | |||
| 143 | /** IRDA sockets address family. |
||
| 144 | */ |
||
| 145 | #define AF_IRDA 23 |
||
| 146 | |||
| 147 | /** PPPoX sockets address family. |
||
| 148 | */ |
||
| 149 | #define AF_PPPOX 24 |
||
| 150 | |||
| 151 | /** Wanpipe API Sockets address family. |
||
| 152 | */ |
||
| 153 | #define AF_WANPIPE 25 |
||
| 154 | |||
| 155 | /** Linux LLC address family. |
||
| 156 | */ |
||
| 157 | #define AF_LLC 26 |
||
| 158 | |||
| 159 | /** Controller Area Network address family. |
||
| 160 | */ |
||
| 161 | #define AF_CAN 29 |
||
| 162 | |||
| 163 | /** TIPC sockets address family. |
||
| 164 | */ |
||
| 165 | #define AF_TIPC 30 |
||
| 166 | |||
| 167 | /** Bluetooth sockets address family. |
||
| 168 | */ |
||
| 169 | #define AF_BLUETOOTH 31 |
||
| 170 | |||
| 171 | /** IUCV sockets address family. |
||
| 172 | */ |
||
| 173 | #define AF_IUCV 32 |
||
| 174 | |||
| 175 | /** RxRPC sockets address family. |
||
| 176 | */ |
||
| 177 | #define AF_RXRPC 33 |
||
| 178 | |||
| 179 | /** Maximum address family. |
||
| 180 | */ |
||
| 181 | #define AF_MAX 34 |
||
| 4701 | mejdrech | 182 | /*@}*/ |
| 3846 | mejdrech | 183 | |
| 4701 | mejdrech | 184 | /** @name Protocol families definitions |
| 185 | * Same as address families. |
||
| 186 | */ |
||
| 187 | /*@{*/ |
||
| 188 | /** Unspecified protocol family. |
||
| 189 | */ |
||
| 190 | #define PF_UNSPEC AF_UNSPEC |
||
| 4578 | mejdrech | 191 | |
| 4701 | mejdrech | 192 | /** Unix domain sockets protocol family. |
| 193 | */ |
||
| 194 | #define PF_UNIXL AF_UNIXL |
||
| 195 | |||
| 196 | /** POSIX name for AF_UNIX protocol family. |
||
| 197 | */ |
||
| 3846 | mejdrech | 198 | #define PF_LOCAL AF_LOCAL |
| 4701 | mejdrech | 199 | |
| 200 | /** Internet IP Protocol protocol family. |
||
| 201 | */ |
||
| 3846 | mejdrech | 202 | #define PF_INET AF_INET |
| 4701 | mejdrech | 203 | |
| 204 | /** Amateur Radio AX.25 protocol family. |
||
| 205 | */ |
||
| 3846 | mejdrech | 206 | #define PF_AX25 AF_AX25 |
| 4701 | mejdrech | 207 | |
| 208 | /** Novell IPX protocol family. |
||
| 209 | */ |
||
| 3846 | mejdrech | 210 | #define PF_IPX AF_IPX |
| 4701 | mejdrech | 211 | |
| 212 | /** AppleTalk DDP protocol family. |
||
| 213 | */ |
||
| 3846 | mejdrech | 214 | #define PF_APPLETALK AF_APPLETALK |
| 4701 | mejdrech | 215 | |
| 216 | /** Amateur Radio NET/ROM protocol family. |
||
| 217 | */ |
||
| 218 | #define PF_NETROM AF_NETROM |
||
| 219 | |||
| 220 | /** Multiprotocol bridge protocol family. |
||
| 221 | */ |
||
| 3846 | mejdrech | 222 | #define PF_BRIDGE AF_BRIDGE |
| 4701 | mejdrech | 223 | |
| 224 | /** ATM PVCs protocol family. |
||
| 225 | */ |
||
| 3846 | mejdrech | 226 | #define PF_ATMPVC AF_ATMPVC |
| 4701 | mejdrech | 227 | |
| 228 | /** Reserved for X.25 project protocol family. |
||
| 229 | */ |
||
| 3846 | mejdrech | 230 | #define PF_X25 AF_X25 |
| 4701 | mejdrech | 231 | |
| 232 | /** IP version 6 protocol family. |
||
| 233 | */ |
||
| 3846 | mejdrech | 234 | #define PF_INET6 AF_INET6 |
| 4701 | mejdrech | 235 | |
| 236 | /** Amateur Radio X.25 PLP protocol family. |
||
| 237 | */ |
||
| 3846 | mejdrech | 238 | #define PF_ROSE AF_ROSE |
| 4701 | mejdrech | 239 | |
| 240 | /** Reserved for DECnet project protocol family. |
||
| 241 | */ |
||
| 3846 | mejdrech | 242 | #define PF_DECnet AF_DECnet |
| 4701 | mejdrech | 243 | |
| 244 | /** Reserved for 802.2LLC project protocol family. |
||
| 245 | */ |
||
| 3846 | mejdrech | 246 | #define PF_NETBEUI AF_NETBEUI |
| 4701 | mejdrech | 247 | |
| 248 | /** Security callback pseudo AF protocol family. |
||
| 249 | */ |
||
| 3846 | mejdrech | 250 | #define PF_SECURITY AF_SECURITY |
| 4701 | mejdrech | 251 | |
| 252 | /** PF_KEY key management API protocol family. |
||
| 253 | */ |
||
| 3846 | mejdrech | 254 | #define PF_KEY AF_KEY |
| 4701 | mejdrech | 255 | |
| 256 | /** Alias to emulate 4.4BSD protocol family. |
||
| 257 | */ |
||
| 3846 | mejdrech | 258 | #define PF_NETLINK AF_NETLINK |
| 4701 | mejdrech | 259 | |
| 260 | /** Packet family protocol family. |
||
| 261 | */ |
||
| 3846 | mejdrech | 262 | #define PF_PACKET AF_PACKET |
| 4701 | mejdrech | 263 | |
| 264 | /** Ash protocol family. |
||
| 265 | */ |
||
| 3846 | mejdrech | 266 | #define PF_ASH AF_ASH |
| 4701 | mejdrech | 267 | |
| 268 | /** Acorn Econet protocol family. |
||
| 269 | */ |
||
| 3846 | mejdrech | 270 | #define PF_ECONET AF_ECONET |
| 4701 | mejdrech | 271 | |
| 272 | /** ATM SVCs protocol family. |
||
| 273 | */ |
||
| 3846 | mejdrech | 274 | #define PF_ATMSVC AF_ATMSVC |
| 4701 | mejdrech | 275 | |
| 276 | /** Linux SNA Project (nutters!) protocol family. |
||
| 277 | */ |
||
| 3846 | mejdrech | 278 | #define PF_SNA AF_SNA |
| 4701 | mejdrech | 279 | |
| 280 | /** IRDA sockets protocol family. |
||
| 281 | */ |
||
| 3846 | mejdrech | 282 | #define PF_IRDA AF_IRDA |
| 4701 | mejdrech | 283 | |
| 284 | /** PPPoX sockets protocol family. |
||
| 285 | */ |
||
| 3846 | mejdrech | 286 | #define PF_PPPOX AF_PPPOX |
| 4701 | mejdrech | 287 | |
| 288 | /** Wanpipe API Sockets protocol family. |
||
| 289 | */ |
||
| 3846 | mejdrech | 290 | #define PF_WANPIPE AF_WANPIPE |
| 4701 | mejdrech | 291 | |
| 292 | /** Linux LLC protocol family. |
||
| 293 | */ |
||
| 3846 | mejdrech | 294 | #define PF_LLC AF_LLC |
| 4701 | mejdrech | 295 | |
| 296 | /** Controller Area Network protocol family. |
||
| 297 | */ |
||
| 3846 | mejdrech | 298 | #define PF_CAN AF_CAN |
| 4701 | mejdrech | 299 | |
| 300 | /** TIPC sockets protocol family. |
||
| 301 | */ |
||
| 3846 | mejdrech | 302 | #define PF_TIPC AF_TIPC |
| 4701 | mejdrech | 303 | |
| 304 | /** Bluetooth sockets protocol family. |
||
| 305 | */ |
||
| 3846 | mejdrech | 306 | #define PF_BLUETOOTH AF_BLUETOOTH |
| 4701 | mejdrech | 307 | |
| 308 | /** IUCV sockets protocol family. |
||
| 309 | */ |
||
| 3846 | mejdrech | 310 | #define PF_IUCV AF_IUCV |
| 4701 | mejdrech | 311 | |
| 312 | /** RxRPC sockets protocol family. |
||
| 313 | */ |
||
| 3846 | mejdrech | 314 | #define PF_RXRPC AF_RXRPC |
| 4701 | mejdrech | 315 | |
| 316 | /** Maximum protocol family. |
||
| 317 | */ |
||
| 3846 | mejdrech | 318 | #define PF_MAX AF_MAX |
| 4701 | mejdrech | 319 | /*@}*/ |
| 4578 | mejdrech | 320 | |
| 4701 | mejdrech | 321 | /** @name Socket option levels definitions |
| 322 | * Thanks to BSD these must match IPPROTO_xxx |
||
| 323 | */ |
||
| 324 | /*@{*/ |
||
| 325 | |||
| 326 | /** IP socket option level. |
||
| 327 | */ |
||
| 4578 | mejdrech | 328 | #define SOL_IP 0 |
| 4701 | mejdrech | 329 | |
| 330 | /** ICMP socket option level. |
||
| 331 | */ |
||
| 3846 | mejdrech | 332 | #define SOL_ICMP 1 |
| 4701 | mejdrech | 333 | |
| 334 | /** TCP socket option level. |
||
| 335 | */ |
||
| 3846 | mejdrech | 336 | #define SOL_TCP 6 |
| 4701 | mejdrech | 337 | |
| 338 | /** UDP socket option level. |
||
| 339 | */ |
||
| 3846 | mejdrech | 340 | #define SOL_UDP 17 |
| 4701 | mejdrech | 341 | |
| 342 | /** IPV socket option level. |
||
| 343 | */ |
||
| 3846 | mejdrech | 344 | #define SOL_IPV6 41 |
| 4701 | mejdrech | 345 | |
| 346 | /** ICMPV socket option level. |
||
| 347 | */ |
||
| 3846 | mejdrech | 348 | #define SOL_ICMPV6 58 |
| 4701 | mejdrech | 349 | |
| 350 | /** SCTP socket option level. |
||
| 351 | */ |
||
| 3846 | mejdrech | 352 | #define SOL_SCTP 132 |
| 4701 | mejdrech | 353 | |
| 354 | /** UDP-Lite (RFC 3828) socket option level. |
||
| 355 | */ |
||
| 356 | #define SOL_UDPLITE 136 |
||
| 357 | |||
| 358 | /** RAW socket option level. |
||
| 359 | */ |
||
| 4578 | mejdrech | 360 | #define SOL_RAW 255 |
| 4701 | mejdrech | 361 | |
| 362 | /** IPX socket option level. |
||
| 363 | */ |
||
| 3846 | mejdrech | 364 | #define SOL_IPX 256 |
| 4701 | mejdrech | 365 | |
| 366 | /** AX socket option level. |
||
| 367 | */ |
||
| 3846 | mejdrech | 368 | #define SOL_AX25 257 |
| 4701 | mejdrech | 369 | |
| 370 | /** ATALK socket option level. |
||
| 371 | */ |
||
| 3846 | mejdrech | 372 | #define SOL_ATALK 258 |
| 4701 | mejdrech | 373 | |
| 374 | /** NETROM socket option level. |
||
| 375 | */ |
||
| 3846 | mejdrech | 376 | #define SOL_NETROM 259 |
| 4701 | mejdrech | 377 | |
| 378 | /** ROSE socket option level. |
||
| 379 | */ |
||
| 3846 | mejdrech | 380 | #define SOL_ROSE 260 |
| 4701 | mejdrech | 381 | |
| 382 | /** DECNET socket option level. |
||
| 383 | */ |
||
| 3846 | mejdrech | 384 | #define SOL_DECNET 261 |
| 4701 | mejdrech | 385 | |
| 386 | /** X25 socket option level. |
||
| 387 | */ |
||
| 3846 | mejdrech | 388 | #define SOL_X25 262 |
| 4701 | mejdrech | 389 | |
| 390 | /** PACKET socket option level. |
||
| 391 | */ |
||
| 3846 | mejdrech | 392 | #define SOL_PACKET 263 |
| 4701 | mejdrech | 393 | |
| 394 | /** ATM layer (cell level) socket option level. |
||
| 395 | */ |
||
| 396 | #define SOL_ATM 264 |
||
| 397 | |||
| 398 | /** ATM Adaption Layer (packet level) socket option level. |
||
| 399 | */ |
||
| 400 | #define SOL_AAL 265 |
||
| 401 | |||
| 402 | /** IRDA socket option level. |
||
| 403 | */ |
||
| 404 | #define SOL_IRDA 266 |
||
| 405 | |||
| 406 | /** NETBEUI socket option level. |
||
| 407 | */ |
||
| 3846 | mejdrech | 408 | #define SOL_NETBEUI 267 |
| 4701 | mejdrech | 409 | |
| 410 | /** LLC socket option level. |
||
| 411 | */ |
||
| 3846 | mejdrech | 412 | #define SOL_LLC 268 |
| 4701 | mejdrech | 413 | |
| 414 | /** DCCP socket option level. |
||
| 415 | */ |
||
| 3846 | mejdrech | 416 | #define SOL_DCCP 269 |
| 4701 | mejdrech | 417 | |
| 418 | /** NETLINK socket option level. |
||
| 419 | */ |
||
| 3846 | mejdrech | 420 | #define SOL_NETLINK 270 |
| 4701 | mejdrech | 421 | |
| 422 | /** TIPC socket option level. |
||
| 423 | */ |
||
| 3846 | mejdrech | 424 | #define SOL_TIPC 271 |
| 4701 | mejdrech | 425 | |
| 426 | /** RXRPC socket option level. |
||
| 427 | */ |
||
| 3846 | mejdrech | 428 | #define SOL_RXRPC 272 |
| 4701 | mejdrech | 429 | |
| 430 | /** PPPOL socket option level. |
||
| 431 | */ |
||
| 3846 | mejdrech | 432 | #define SOL_PPPOL2TP 273 |
| 4701 | mejdrech | 433 | |
| 434 | /** BLUETOOTH socket option level. |
||
| 435 | */ |
||
| 3846 | mejdrech | 436 | #define SOL_BLUETOOTH 274 |
| 4578 | mejdrech | 437 | |
| 4701 | mejdrech | 438 | /*@}*/ |
| 439 | |||
| 3846 | mejdrech | 440 | // |
| 4243 | mejdrech | 441 | /* * IPX options. |
| 442 | */ |
||
| 3846 | mejdrech | 443 | //#define IPX_TYPE 1 |
| 444 | |||
| 4701 | mejdrech | 445 | /** Socket types. |
| 4578 | mejdrech | 446 | */ |
| 447 | typedef enum sock_type{ |
||
| 448 | /** Stream (connection oriented) socket. |
||
| 449 | */ |
||
| 450 | SOCK_STREAM = 1, |
||
| 451 | /** Datagram (connectionless oriented) socket. |
||
| 452 | */ |
||
| 453 | SOCK_DGRAM = 2, |
||
| 454 | /** Raw socket. |
||
| 455 | */ |
||
| 456 | SOCK_RAW = 3 |
||
| 457 | } sock_type_t; |
||
| 458 | |||
| 4701 | mejdrech | 459 | /** Type definition of the socket length. |
| 460 | */ |
||
| 4578 | mejdrech | 461 | typedef int32_t socklen_t; |
| 462 | |||
| 4701 | mejdrech | 463 | /** @name Socket application programming interface |
| 464 | */ |
||
| 465 | /*@{*/ |
||
| 466 | |||
| 467 | /** Creates a new socket. |
||
| 468 | * @param domain The socket protocol family. Input parameter. |
||
| 469 | * @param type Socket type. Input parameter. |
||
| 470 | * @param protocol Socket protocol. Input parameter. |
||
| 471 | * @returns The socket identifier on success. |
||
| 472 | * @returns EPFNOTSUPPORT if the protocol family is not supported. |
||
| 473 | * @returns ESOCKNOTSUPPORT if the socket type is not supported. |
||
| 474 | * @returns EPROTONOSUPPORT if the protocol is not supported. |
||
| 475 | * @returns ENOMEM if there is not enough memory left. |
||
| 476 | * @returns Other error codes as defined for the NET_SOCKET message. |
||
| 477 | */ |
||
| 4578 | mejdrech | 478 | int socket( int domain, int type, int protocol ); |
| 4701 | mejdrech | 479 | |
| 480 | /** Binds the socket to a port address. |
||
| 481 | * @param socket_id Socket identifier. Input parameter. |
||
| 482 | * @param my_addr The port address. Input parameter. |
||
| 483 | * @param addrlen The address length. Input parameter. |
||
| 484 | * @returns EOK on success. |
||
| 485 | * @returns ENOTSOCK if the socket is not found. |
||
| 486 | * @returns EBADMEM if the my_addr parameter is NULL. |
||
| 487 | * @returns NO_DATA if the addlen parameter is zero (0). |
||
| 488 | * @returns Other error codes as defined for the NET_SOCKET_BIND message. |
||
| 489 | */ |
||
| 4578 | mejdrech | 490 | int bind( int socket_id, const struct sockaddr * my_addr, socklen_t addrlen ); |
| 4701 | mejdrech | 491 | |
| 492 | /** Sets the number of connections waiting to be accepted. |
||
| 493 | * @param socket_id Socket identifier. Input parameter. |
||
| 494 | * @param backlog The maximum number of waiting sockets to be accepted. Input parameter. |
||
| 495 | * @returns EOK on success. |
||
| 496 | * @returns EINVAL if the backlog parameter is not positive (<=0). |
||
| 497 | * @returns ENOTSOCK if the socket is not found. |
||
| 498 | * @returns Other error codes as defined for the NET_SOCKET_LISTEN message. |
||
| 499 | */ |
||
| 4578 | mejdrech | 500 | int listen( int socket_id, int backlog ); |
| 4701 | mejdrech | 501 | |
| 502 | /** Accepts waiting socket. |
||
| 503 | * Blocks until such a socket exists. |
||
| 504 | * @param socket_id Socket identifier. Input parameter. |
||
| 505 | * @param cliaddr The remote client address. Output parameter. |
||
| 506 | * @param addrlen The address length. Input parameter. |
||
| 507 | * @returns EOK on success. |
||
| 508 | * @returns EBADMEM if the cliaddr or addrlen parameter is NULL. |
||
| 509 | * @returns EINVAL if the backlog parameter is not positive (<=0). |
||
| 510 | * @returns ENOTSOCK if the socket is not found. |
||
| 511 | * @returns Other error codes as defined for the NET_SOCKET_ACCEPT message. |
||
| 512 | */ |
||
| 4578 | mejdrech | 513 | int accept( int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen ); |
| 4701 | mejdrech | 514 | |
| 515 | /** Connects socket to the remote server. |
||
| 516 | * @param socket_id Socket identifier. Input parameter. |
||
| 517 | * @param serv_addr The remote server address. Input parameter. |
||
| 518 | * @param addrlen The address length. Input parameter. |
||
| 519 | * @returns EOK on success. |
||
| 520 | * @returns EBADMEM if the serv_addr parameter is NULL. |
||
| 521 | * @returns NO_DATA if the addlen parameter is zero (0). |
||
| 522 | * @returns ENOTSOCK if the socket is not found. |
||
| 523 | * @returns Other error codes as defined for the NET_SOCKET_CONNECT message. |
||
| 524 | */ |
||
| 4578 | mejdrech | 525 | int connect( int socket_id, const struct sockaddr * serv_addr, socklen_t addrlen ); |
| 526 | |||
| 4701 | mejdrech | 527 | /** Closes the socket. |
| 528 | * @param socket_id Socket identifier. Input parameter. |
||
| 529 | * @returns EOK on success. |
||
| 530 | * @returns ENOTSOCK if the socket is not found. |
||
| 531 | * @returns Other error codes as defined for the NET_SOCKET_CLOSE message. |
||
| 532 | */ |
||
| 4578 | mejdrech | 533 | int closesocket( int socket_id ); |
| 534 | |||
| 4701 | mejdrech | 535 | /** Sends data via the socket. |
| 536 | * @param socket_id Socket identifier. Input parameter. |
||
| 537 | * @param data The data to be sent. Input parameter. |
||
| 538 | * @param datalength The data length. Input parameter. |
||
| 539 | * @param flags Various send flags. Input parameter. |
||
| 540 | * @returns EOK on success. |
||
| 541 | * @returns ENOTSOCK if the socket is not found. |
||
| 542 | * @returns EBADMEM if the data parameter is NULL. |
||
| 543 | * @returns NO_DATA if the datalength parameter is zero (0). |
||
| 544 | * @returns Other error codes as defined for the NET_SOCKET_SEND message. |
||
| 545 | */ |
||
| 4578 | mejdrech | 546 | int send( int socket_id, void * data, size_t datalength, int flags ); |
| 4701 | mejdrech | 547 | |
| 548 | /** Sends data via the socket to the remote address. |
||
| 549 | * Binds the socket to a free port if not already connected/bound. |
||
| 550 | * @param socket_id Socket identifier. Input parameter. |
||
| 551 | * @param data The data to be sent. Input parameter. |
||
| 552 | * @param datalength The data length. Input parameter. |
||
| 553 | * @param flags Various send flags. Input parameter. |
||
| 554 | * @param toaddr The destination address. Input parameter. |
||
| 555 | * @param addrlen The address length. Input parameter. |
||
| 556 | * @returns EOK on success. |
||
| 557 | * @returns ENOTSOCK if the socket is not found. |
||
| 558 | * @returns EBADMEM if the data or toaddr parameter is NULL. |
||
| 559 | * @returns NO_DATA if the datalength or the addrlen parameter is zero (0). |
||
| 560 | * @returns Other error codes as defined for the NET_SOCKET_SENDTO message. |
||
| 561 | */ |
||
| 4578 | mejdrech | 562 | int sendto( int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen ); |
| 563 | |||
| 4701 | mejdrech | 564 | /** Receives data via the socket. |
| 565 | * @param socket_id Socket identifier. Input parameter. |
||
| 566 | * @param data The data buffer to be filled. Output parameter. |
||
| 567 | * @param datalength The data length. Input parameter. |
||
| 568 | * @param flags Various receive flags. Input parameter. |
||
| 569 | * @returns EOK on success. |
||
| 570 | * @returns ENOTSOCK if the socket is not found. |
||
| 571 | * @returns EBADMEM if the data parameter is NULL. |
||
| 572 | * @returns NO_DATA if the datalength parameter is zero (0). |
||
| 573 | * @returns Other error codes as defined for the NET_SOCKET_RECV message. |
||
| 574 | */ |
||
| 4578 | mejdrech | 575 | int recv( int socket_id, void * data, size_t datalength, int flags ); |
| 4701 | mejdrech | 576 | |
| 577 | /** Receives data via the socket. |
||
| 578 | * @param socket_id Socket identifier. Input parameter. |
||
| 579 | * @param data The data buffer to be filled. Output parameter. |
||
| 580 | * @param datalength The data length. Input parameter. |
||
| 581 | * @param flags Various receive flags. Input parameter. |
||
| 582 | * @param fromaddr The source address. Output parameter. |
||
| 583 | * @param addrlen The address length. The maximum address length is read. The actual address length is set. Input/output parameter. |
||
| 584 | * @returns EOK on success. |
||
| 585 | * @returns ENOTSOCK if the socket is not found. |
||
| 586 | * @returns EBADMEM if the data or fromaddr parameter is NULL. |
||
| 587 | * @returns NO_DATA if the datalength or addrlen parameter is zero (0). |
||
| 588 | * @returns Other error codes as defined for the NET_SOCKET_RECVFROM message. |
||
| 589 | */ |
||
| 4578 | mejdrech | 590 | int recvfrom( int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen ); |
| 591 | |||
| 4701 | mejdrech | 592 | /** Gets socket option. |
| 593 | * @param socket_id Socket identifier. Input parameter. |
||
| 594 | * @param level The socket options level. Input parameter. |
||
| 595 | * @param optname The socket option to be get. Input parameter. |
||
| 596 | * @param value The value buffer to be filled. Output parameter. |
||
| 597 | * @param optlen The value buffer length. The maximum length is read. The actual length is set. Input/output parameter. |
||
| 598 | * @returns EOK on success. |
||
| 599 | * @returns ENOTSOCK if the socket is not found. |
||
| 600 | * @returns EBADMEM if the value or optlen parameter is NULL. |
||
| 601 | * @returns NO_DATA if the optlen parameter is zero (0). |
||
| 602 | * @returns Other error codes as defined for the NET_SOCKET_GETSOCKOPT message. |
||
| 603 | */ |
||
| 4578 | mejdrech | 604 | int getsockopt( int socket_id, int level, int optname, void * value, size_t * optlen ); |
| 4701 | mejdrech | 605 | |
| 606 | /** Sets socket option. |
||
| 607 | * @param socket_id Socket identifier. Input parameter. |
||
| 608 | * @param level The socket options level. Input parameter. |
||
| 609 | * @param optname The socket option to be set. Input parameter. |
||
| 610 | * @param value The value to be set. Input parameter. |
||
| 611 | * @param optlen The value length. Input parameter. |
||
| 612 | * @returns EOK on success. |
||
| 613 | * @returns ENOTSOCK if the socket is not found. |
||
| 614 | * @returns EBADMEM if the value parameter is NULL. |
||
| 615 | * @returns NO_DATA if the optlen parameter is zero (0). |
||
| 616 | * @returns Other error codes as defined for the NET_SOCKET_SETSOCKOPT message. |
||
| 617 | */ |
||
| 4578 | mejdrech | 618 | int setsockopt( int socket_id, int level, int optname, const void * value, size_t optlen ); |
| 619 | |||
| 4701 | mejdrech | 620 | /*@}*/ |
| 621 | |||
| 3846 | mejdrech | 622 | #endif |
| 623 | |||
| 624 | /** @} |
||
| 625 | */ |