Subversion Repositories HelenOS

Rev

Rev 4243 | Rev 4701 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2009 Lukas 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.  
  29. /** @addtogroup socket
  30.  *  @{
  31.  */
  32.  
  33. /** @file
  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.
  37.  */
  38.  
  39. #ifndef __NET_SOCKET_H__
  40. #define __NET_SOCKET_H__
  41.  
  42. #include <sys/types.h>
  43.  
  44. #include "in.h"
  45. #include "inet.h"
  46.  
  47. /* Supported address families. */
  48. /** Unspecified address family.
  49.  */
  50. #define AF_UNSPEC   0
  51.  
  52. /** Unix domain sockets address family.
  53.  */
  54. #define AF_UNIXL    1
  55.  
  56. /** POSIX name for AF_UNIX address family.
  57.  */
  58. #define AF_LOCAL    1
  59.  
  60. /** Internet IP Protocol address family.
  61.  */
  62. #define AF_INET     2
  63.  
  64. /** Amateur Radio AX.25 address family.
  65.  */
  66. #define AF_AX25     3
  67.  
  68. /** Novell IPX address family.
  69.  */
  70. #define AF_IPX      4
  71.  
  72. /** AppleTalk DDP address family.
  73.  */
  74. #define AF_APPLETALK    5
  75.  
  76. /** Amateur Radio NET/ROM address family.
  77.  */
  78. #define AF_NETROM   6
  79.  
  80. /** Multiprotocol bridge address family.
  81.  */
  82. #define AF_BRIDGE   7
  83.  
  84. /** ATM PVCs address family.
  85.  */
  86. #define AF_ATMPVC   8
  87.  
  88. /** Reserved for X.25 project address family.
  89.  */
  90. #define AF_X25      9
  91.  
  92. /** IP version 6 address family.
  93.  */
  94. #define AF_INET6    10
  95.  
  96. /** Amateur Radio X.25 PLP address family.
  97.  */
  98. #define AF_ROSE     11
  99.  
  100. /** Reserved for DECnet project address family.
  101.  */
  102. #define AF_DECnet   12
  103.  
  104. /** Reserved for 802.2LLC project address family.
  105.  */
  106. #define AF_NETBEUI  13
  107.  
  108. /** Security callback pseudo AF address family.
  109.  */
  110. #define AF_SECURITY 14
  111.  
  112. /** PF_KEY key management API address family.
  113.  */
  114. #define AF_KEY      15
  115.  
  116. /** Alias to emulate 4.4BSD address family.
  117.  */
  118. #define AF_NETLINK  16
  119.  
  120. /** Packet family address family.
  121.  */
  122. #define AF_PACKET   17
  123.  
  124. /** Ash address family.
  125.  */
  126. #define AF_ASH      18
  127.  
  128. /** Acorn Econet address family.
  129.  */
  130. #define AF_ECONET   19
  131.  
  132. /** ATM SVCs address family.
  133.  */
  134. #define AF_ATMSVC   20
  135.  
  136. /** Linux SNA Project (nutters!) address family.
  137.  */
  138. #define AF_SNA      22
  139.  
  140. /** IRDA sockets address family.
  141.  */
  142. #define AF_IRDA     23
  143.  
  144. /** PPPoX sockets address family.
  145.  */
  146. #define AF_PPPOX    24
  147.  
  148. /** Wanpipe API Sockets address family.
  149.  */
  150. #define AF_WANPIPE  25
  151.  
  152. /** Linux LLC address family.
  153.  */
  154. #define AF_LLC      26
  155.  
  156. /** Controller Area Network address family.
  157.  */
  158. #define AF_CAN      29
  159.  
  160. /** TIPC sockets address family.
  161.  */
  162. #define AF_TIPC     30
  163.  
  164. /** Bluetooth sockets address family.
  165.  */
  166. #define AF_BLUETOOTH    31
  167.  
  168. /** IUCV sockets address family.
  169.  */
  170. #define AF_IUCV     32
  171.  
  172. /** RxRPC sockets address family.
  173.  */
  174. #define AF_RXRPC    33
  175.  
  176. /** Maximum address family.
  177.  */
  178. #define AF_MAX      34
  179.  
  180. /* Protocol families, same as address families. */
  181.  
  182. #define PF_UNSPEC   AF_UNSPEC
  183. #define PF_UNIX     AF_UNIX
  184. #define PF_LOCAL    AF_LOCAL
  185. #define PF_INET     AF_INET
  186. #define PF_AX25     AF_AX25
  187. #define PF_IPX      AF_IPX
  188. #define PF_APPLETALK    AF_APPLETALK
  189. #define PF_NETROM   AF_NETROM
  190. #define PF_BRIDGE   AF_BRIDGE
  191. #define PF_ATMPVC   AF_ATMPVC
  192. #define PF_X25      AF_X25
  193. #define PF_INET6    AF_INET6
  194. #define PF_ROSE     AF_ROSE
  195. #define PF_DECnet   AF_DECnet
  196. #define PF_NETBEUI  AF_NETBEUI
  197. #define PF_SECURITY AF_SECURITY
  198. #define PF_KEY      AF_KEY
  199. #define PF_NETLINK  AF_NETLINK
  200. #define PF_ROUTE    AF_ROUTE
  201. #define PF_PACKET   AF_PACKET
  202. #define PF_ASH      AF_ASH
  203. #define PF_ECONET   AF_ECONET
  204. #define PF_ATMSVC   AF_ATMSVC
  205. #define PF_SNA      AF_SNA
  206. #define PF_IRDA     AF_IRDA
  207. #define PF_PPPOX    AF_PPPOX
  208. #define PF_WANPIPE  AF_WANPIPE
  209. #define PF_LLC      AF_LLC
  210. #define PF_CAN      AF_CAN
  211. #define PF_TIPC     AF_TIPC
  212. #define PF_BLUETOOTH    AF_BLUETOOTH
  213. #define PF_IUCV     AF_IUCV
  214. #define PF_RXRPC    AF_RXRPC
  215. #define PF_MAX      AF_MAX
  216.  
  217. /* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx */
  218. #define SOL_IP      0
  219. #define SOL_ICMP    1
  220. #define SOL_TCP     6
  221. #define SOL_UDP     17
  222. #define SOL_IPV6    41
  223. #define SOL_ICMPV6  58
  224. #define SOL_SCTP    132
  225. #define SOL_UDPLITE 136     /* UDP-Lite (RFC 3828) */
  226. #define SOL_RAW     255
  227. #define SOL_IPX     256
  228. #define SOL_AX25    257
  229. #define SOL_ATALK   258
  230. #define SOL_NETROM  259
  231. #define SOL_ROSE    260
  232. #define SOL_DECNET  261
  233. #define SOL_X25     262
  234. #define SOL_PACKET  263
  235. #define SOL_ATM     264 /* ATM layer (cell level) */
  236. #define SOL_AAL     265 /* ATM Adaption Layer (packet level) */
  237. #define SOL_IRDA        266
  238. #define SOL_NETBEUI 267
  239. #define SOL_LLC     268
  240. #define SOL_DCCP    269
  241. #define SOL_NETLINK 270
  242. #define SOL_TIPC    271
  243. #define SOL_RXRPC   272
  244. #define SOL_PPPOL2TP    273
  245. #define SOL_BLUETOOTH   274
  246.  
  247. //
  248. /* * IPX options.
  249.  */
  250. //#define IPX_TYPE  1
  251.  
  252. /** Socket type type definition.
  253.  */
  254. typedef enum sock_type{
  255.     /** Stream (connection oriented) socket.
  256.      */
  257.     SOCK_STREAM = 1,
  258.     /** Datagram (connectionless oriented) socket.
  259.      */
  260.     SOCK_DGRAM  = 2,
  261.     /** Raw socket.
  262.      */
  263.     SOCK_RAW    = 3
  264. } sock_type_t;
  265.  
  266. typedef int32_t socklen_t;
  267.  
  268. int socket( int domain, int type, int protocol );
  269. int bind( int socket_id, const struct sockaddr * my_addr, socklen_t addrlen );
  270. int listen( int socket_id, int backlog );
  271. 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.  
  274. int closesocket( int socket_id );
  275.  
  276. 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.  
  279. 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.  
  282. 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.  
  285. #endif
  286.  
  287. /** @}
  288.  */
  289.