Subversion Repositories HelenOS

Rev

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