2
* Copyright (C) 2008 The Android Open Source Project
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* * Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* * Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in
12
* the documentation and/or other materials provided with the
15
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29
#include <sys/socket.h>
30
#include <sys/linux-syscalls.h>
54
int socket(int domain, int type, int protocol)
58
t[0] = (unsigned long) domain;
59
t[1] = (unsigned long) type;
60
t[2] = (unsigned long) protocol;
62
return (int) __socketcall( SYS_SOCKET, t );
64
#endif /* !__NR_socket */
68
int bind(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen)
72
t[0] = (unsigned long) sockfd;
73
t[1] = (unsigned long) my_addr;
74
t[2] = (unsigned long) addrlen;
76
return (int) __socketcall( SYS_BIND, t );
78
#endif /* !__NR_bind */
81
int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen )
85
t[0] = (unsigned long) sockfd;
86
t[1] = (unsigned long) serv_addr;
87
t[2] = (unsigned long) addrlen;
89
return (int) __socketcall( SYS_CONNECT, t );
91
#endif /* !__NR_connect */
94
int listen(int s, int backlog)
98
t[0] = (unsigned long) s;
99
t[1] = (unsigned long) backlog;
101
return (int) __socketcall( SYS_LISTEN, t );
103
#endif /* __NR_listen */
106
int accept(int sock, struct sockaddr *adresse, socklen_t *longueur)
110
t[0] = (unsigned long) sock;
111
t[1] = (unsigned long) adresse;
112
t[2] = (unsigned long) longueur;
114
return (int) __socketcall( SYS_ACCEPT, t );
116
#endif /* __NR_accept */
118
#ifndef __NR_getsockname
119
int getsockname(int s, struct sockaddr * name, socklen_t * namelen )
123
t[0] = (unsigned long) s;
124
t[1] = (unsigned long) name;
125
t[2] = (unsigned long) namelen;
127
return (int) __socketcall( SYS_GETSOCKNAME, t );
129
#endif /* __NR_getsockname */
131
#ifndef __NR_getpeername
132
int getpeername(int s, struct sockaddr *name, socklen_t *namelen)
136
t[0] = (unsigned long) s;
137
t[1] = (unsigned long) name;
138
t[2] = (unsigned long) namelen;
140
return (int) __socketcall( SYS_GETPEERNAME, t );
142
#endif /* !__NR_getpeername */
144
#ifndef __NR_socketpair
145
int socketpair(int d, int type, int protocol, int sv[2])
149
t[0] = (unsigned long) d;
150
t[1] = (unsigned long) type;
151
t[2] = (unsigned long) protocol;
152
t[3] = (unsigned long) sv;
154
return (int) __socketcall( SYS_SOCKETPAIR, t );
156
#endif /* __NR_socketpair */
159
ssize_t sendto(int socket, const void *message, size_t length, int flags,
160
const struct sockaddr *dest_addr, socklen_t dest_len)
164
t[0] = (unsigned long) socket;
165
t[1] = (unsigned long) message;
166
t[2] = (unsigned long) length;
167
t[3] = (unsigned long) flags;
168
t[4] = (unsigned long) dest_addr;
169
t[5] = (unsigned long) dest_len;
171
return __socketcall( SYS_SENDTO, t );
173
#endif /* !__NR_sendto */
175
#ifndef __NR_recvfrom
176
ssize_t recvfrom(int socket, void *buffer, size_t length, unsigned int flags,
177
const struct sockaddr *address, socklen_t *address_len)
181
t[0] = (unsigned long) socket;
182
t[1] = (unsigned long) buffer;
183
t[2] = (unsigned long) length;
184
t[3] = (unsigned long) flags;
185
t[4] = (unsigned long) address;
186
t[5] = (unsigned long) address_len;
188
return __socketcall( SYS_RECVFROM, t );
190
#endif /* !__NR_recvfrom */
192
#ifndef __NR_shutdown
193
int shutdown(int socket, int how)
197
t[0] = (unsigned long) socket;
198
t[1] = (unsigned long) how;
200
return (int) __socketcall( SYS_SHUTDOWN, t );
202
#endif /* !__NR_shutdown */
204
#ifndef __NR_setsockopt
205
int setsockopt( int s, int level, int optname, const void* optval, socklen_t optlen )
209
t[0] = (unsigned long) s;
210
t[1] = (unsigned long) level;
211
t[2] = (unsigned long) optname;
212
t[3] = (unsigned long) optval;
213
t[4] = (unsigned long) optlen;
215
return (int) __socketcall( SYS_SETSOCKOPT, t );
217
#endif /* !__NR_setsockopt */
219
#ifndef __NR_getsockopt
220
int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
224
t[0] = (unsigned long) s;
225
t[1] = (unsigned long) level;
226
t[2] = (unsigned long) optname;
227
t[3] = (unsigned long) optval;
228
t[4] = (unsigned long) optlen;
230
return (int) __socketcall( SYS_GETSOCKOPT, t );
232
#endif /* !__NR_getsockopt */
235
int sendmsg (int socket, const struct msghdr *message, unsigned int flags)
239
t[0] = (unsigned long) socket;
240
t[1] = (unsigned long) message;
241
t[2] = (unsigned long) flags;
243
return __socketcall( SYS_SENDMSG, t );
245
#endif /* __NR_sendmsg */
248
int recvmsg(int socket, struct msghdr *message, unsigned int flags)
252
t[0] = (unsigned long) socket;
253
t[1] = (unsigned long) message;
254
t[2] = (unsigned long) flags;
256
return __socketcall( SYS_RECVMSG, t );
258
#endif /* __NR_recvmsg */