source: mainline/uspace/srv/net/include/socket.h@ f1848d6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f1848d6 was 1a0fb3f8, checked in by Lukas Mejdrech <lukasmejdrech@…>, 15 years ago

+ icmp and libsocket timeouting connecting

  • Property mode set to 100644
File size: 8.8 KB
Line 
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 BSD socket interface.
37 */
38
39#ifndef __NET_SOCKET_H__
40#define __NET_SOCKET_H__
41
42#include "byteorder.h"
43#include "in.h"
44#include "in6.h"
45#include "inet.h"
46
47#include "socket_codes.h"
48#include "socket_errno.h"
49
50/** @name Socket application programming interface
51 */
52/*@{*/
53
54/** Creates a new socket.
55 * @param[in] domain The socket protocol family.
56 * @param[in] type Socket type.
57 * @param[in] protocol Socket protocol.
58 * @returns The socket identifier on success.
59 * @returns EPFNOTSUPPORT if the protocol family is not supported.
60 * @returns ESOCKNOTSUPPORT if the socket type is not supported.
61 * @returns EPROTONOSUPPORT if the protocol is not supported.
62 * @returns ENOMEM if there is not enough memory left.
63 * @returns Other error codes as defined for the NET_SOCKET message.
64 * @returns Other error codes as defined for the bind_service_timeout() function.
65 */
66int socket( int domain, int type, int protocol );
67
68/** Binds the socket to a port address.
69 * @param[in] socket_id Socket identifier.
70 * @param[in] my_addr The port address.
71 * @param[in] addrlen The address length.
72 * @returns EOK on success.
73 * @returns ENOTSOCK if the socket is not found.
74 * @returns EBADMEM if the my_addr parameter is NULL.
75 * @returns NO_DATA if the addlen parameter is zero (0).
76 * @returns Other error codes as defined for the NET_SOCKET_BIND message.
77 */
78int bind( int socket_id, const struct sockaddr * my_addr, socklen_t addrlen );
79
80/** Sets the number of connections waiting to be accepted.
81 * @param[in] socket_id Socket identifier.
82 * @param[in] backlog The maximum number of waiting sockets to be accepted.
83 * @returns EOK on success.
84 * @returns EINVAL if the backlog parameter is not positive (<=0).
85 * @returns ENOTSOCK if the socket is not found.
86 * @returns Other error codes as defined for the NET_SOCKET_LISTEN message.
87 */
88int listen( int socket_id, int backlog );
89
90/** Accepts waiting socket.
91 * Blocks until such a socket exists.
92 * @param[in] socket_id Socket identifier.
93 * @param[out] cliaddr The remote client address.
94 * @param[in] addrlen The address length.
95 * @returns EOK on success.
96 * @returns EBADMEM if the cliaddr or addrlen parameter is NULL.
97 * @returns EINVAL if the backlog parameter is not positive (<=0).
98 * @returns ENOTSOCK if the socket is not found.
99 * @returns Other error codes as defined for the NET_SOCKET_ACCEPT message.
100 */
101int accept( int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen );
102
103/** Connects socket to the remote server.
104 * @param[in] socket_id Socket identifier.
105 * @param[in] serv_addr The remote server address.
106 * @param[in] addrlen The address length.
107 * @returns EOK on success.
108 * @returns EBADMEM if the serv_addr parameter is NULL.
109 * @returns NO_DATA if the addlen parameter is zero (0).
110 * @returns ENOTSOCK if the socket is not found.
111 * @returns Other error codes as defined for the NET_SOCKET_CONNECT message.
112 */
113int connect( int socket_id, const struct sockaddr * serv_addr, socklen_t addrlen );
114
115/** Closes the socket.
116 * @param[in] socket_id Socket identifier.
117 * @returns EOK on success.
118 * @returns ENOTSOCK if the socket is not found.
119 * @returns EINPROGRESS if there is another blocking function in progress.
120 * @returns Other error codes as defined for the NET_SOCKET_CLOSE message.
121 */
122int closesocket( int socket_id );
123
124/** Sends data via the socket.
125 * @param[in] socket_id Socket identifier.
126 * @param[in] data The data to be sent.
127 * @param[in] datalength The data length.
128 * @param[in] flags Various send flags.
129 * @returns EOK on success.
130 * @returns ENOTSOCK if the socket is not found.
131 * @returns EBADMEM if the data parameter is NULL.
132 * @returns NO_DATA if the datalength parameter is zero (0).
133 * @returns Other error codes as defined for the NET_SOCKET_SEND message.
134 */
135int send( int socket_id, void * data, size_t datalength, int flags );
136
137/** Sends data via the socket to the remote address.
138 * Binds the socket to a free port if not already connected/bound.
139 * @param[in] socket_id Socket identifier.
140 * @param[in] data The data to be sent.
141 * @param[in] datalength The data length.
142 * @param[in] flags Various send flags.
143 * @param[in] toaddr The destination address.
144 * @param[in] addrlen The address length.
145 * @returns EOK on success.
146 * @returns ENOTSOCK if the socket is not found.
147 * @returns EBADMEM if the data or toaddr parameter is NULL.
148 * @returns NO_DATA if the datalength or the addrlen parameter is zero (0).
149 * @returns Other error codes as defined for the NET_SOCKET_SENDTO message.
150 */
151int sendto( int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen );
152
153/** Receives data via the socket.
154 * @param[in] socket_id Socket identifier.
155 * @param[out] data The data buffer to be filled.
156 * @param[in] datalength The data length.
157 * @param[in] flags Various receive flags.
158 * @returns EOK on success.
159 * @returns ENOTSOCK if the socket is not found.
160 * @returns EBADMEM if the data parameter is NULL.
161 * @returns NO_DATA if the datalength parameter is zero (0).
162 * @returns Other error codes as defined for the NET_SOCKET_RECV message.
163 */
164int recv( int socket_id, void * data, size_t datalength, int flags );
165
166/** Receives data via the socket.
167 * @param[in] socket_id Socket identifier.
168 * @param[out] data The data buffer to be filled.
169 * @param[in] datalength The data length.
170 * @param[in] flags Various receive flags.
171 * @param[out] fromaddr The source address.
172 * @param[in,out] addrlen The address length. The maximum address length is read. The actual address length is set.
173 * @returns EOK on success.
174 * @returns ENOTSOCK if the socket is not found.
175 * @returns EBADMEM if the data or fromaddr parameter is NULL.
176 * @returns NO_DATA if the datalength or addrlen parameter is zero (0).
177 * @returns Other error codes as defined for the NET_SOCKET_RECVFROM message.
178 */
179int recvfrom( int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen );
180
181/** Gets socket option.
182 * @param[in] socket_id Socket identifier.
183 * @param[in] level The socket options level.
184 * @param[in] optname The socket option to be get.
185 * @param[out] value The value buffer to be filled.
186 * @param[in,out] optlen The value buffer length. The maximum length is read. The actual length is set.
187 * @returns EOK on success.
188 * @returns ENOTSOCK if the socket is not found.
189 * @returns EBADMEM if the value or optlen parameter is NULL.
190 * @returns NO_DATA if the optlen parameter is zero (0).
191 * @returns Other error codes as defined for the NET_SOCKET_GETSOCKOPT message.
192 */
193int getsockopt( int socket_id, int level, int optname, void * value, size_t * optlen );
194
195/** Sets socket option.
196 * @param[in] socket_id Socket identifier.
197 * @param[in] level The socket options level.
198 * @param[in] optname The socket option to be set.
199 * @param[in] value The value to be set.
200 * @param[in] optlen The value length.
201 * @returns EOK on success.
202 * @returns ENOTSOCK if the socket is not found.
203 * @returns EBADMEM if the value parameter is NULL.
204 * @returns NO_DATA if the optlen parameter is zero (0).
205 * @returns Other error codes as defined for the NET_SOCKET_SETSOCKOPT message.
206 */
207int setsockopt( int socket_id, int level, int optname, const void * value, size_t optlen );
208
209/*@}*/
210
211#endif
212
213/** @}
214 */
Note: See TracBrowser for help on using the repository browser.