Subversion Repositories HelenOS

Rev

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