• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
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  *  * 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
13  *    distribution.
14  *
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
26  * SUCH DAMAGE.
27  */
28 #include <unistd.h>
29 #include <sys/socket.h>
30 #include <sys/linux-syscalls.h>
31 
32 enum
33 {
34     SYS_SOCKET = 1,
35     SYS_BIND,
36     SYS_CONNECT,
37     SYS_LISTEN,
38     SYS_ACCEPT,
39     SYS_GETSOCKNAME,
40     SYS_GETPEERNAME,
41     SYS_SOCKETPAIR,
42     SYS_SEND,
43     SYS_RECV,
44     SYS_SENDTO,
45     SYS_RECVFROM,
46     SYS_SHUTDOWN,
47     SYS_SETSOCKOPT,
48     SYS_GETSOCKOPT,
49     SYS_SENDMSG,
50     SYS_RECVMSG
51 };
52 
53 #ifndef __NR_socket
socket(int domain,int type,int protocol)54 int socket(int domain, int type, int protocol)
55 {
56     unsigned long  t[3];
57 
58     t[0] = (unsigned long) domain;
59     t[1] = (unsigned long) type;
60     t[2] = (unsigned long) protocol;
61 
62     return (int) __socketcall( SYS_SOCKET, t );
63 }
64 #endif /* !__NR_socket */
65 
66 
67 #ifndef __NR_bind
bind(int sockfd,const struct sockaddr * my_addr,socklen_t addrlen)68 int bind(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen)
69 {
70     unsigned long  t[3];
71 
72     t[0] = (unsigned long) sockfd;
73     t[1] = (unsigned long) my_addr;
74     t[2] = (unsigned long) addrlen;
75 
76     return (int) __socketcall( SYS_BIND, t );
77 }
78 #endif  /* !__NR_bind */
79 
80 #ifndef __NR_connect
connect(int sockfd,const struct sockaddr * serv_addr,socklen_t addrlen)81 int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t  addrlen )
82 {
83     unsigned long  t[3];
84 
85     t[0] = (unsigned long) sockfd;
86     t[1] = (unsigned long) serv_addr;
87     t[2] = (unsigned long) addrlen;
88 
89     return (int) __socketcall( SYS_CONNECT, t );
90 }
91 #endif /* !__NR_connect */
92 
93 #ifndef __NR_listen
listen(int s,int backlog)94 int listen(int s, int backlog)
95 {
96     unsigned long  t[2];
97 
98     t[0] = (unsigned long) s;
99     t[1] = (unsigned long) backlog;
100 
101     return (int) __socketcall( SYS_LISTEN, t );
102 }
103 #endif /* __NR_listen */
104 
105 #ifndef __NR_accept
accept(int sock,struct sockaddr * adresse,socklen_t * longueur)106 int accept(int sock, struct sockaddr *adresse, socklen_t *longueur)
107 {
108     unsigned long  t[3];
109 
110     t[0] = (unsigned long) sock;
111     t[1] = (unsigned long) adresse;
112     t[2] = (unsigned long) longueur;
113 
114     return (int) __socketcall( SYS_ACCEPT, t );
115 }
116 #endif /* __NR_accept */
117 
118 #ifndef __NR_getsockname
getsockname(int s,struct sockaddr * name,socklen_t * namelen)119 int getsockname(int s, struct sockaddr * name, socklen_t * namelen )
120 {
121     unsigned long  t[3];
122 
123     t[0] = (unsigned long) s;
124     t[1] = (unsigned long) name;
125     t[2] = (unsigned long) namelen;
126 
127     return (int) __socketcall( SYS_GETSOCKNAME, t );
128 }
129 #endif /* __NR_getsockname */
130 
131 #ifndef __NR_getpeername
getpeername(int s,struct sockaddr * name,socklen_t * namelen)132 int getpeername(int s, struct sockaddr *name, socklen_t *namelen)
133 {
134     unsigned long  t[3];
135 
136     t[0] = (unsigned long) s;
137     t[1] = (unsigned long) name;
138     t[2] = (unsigned long) namelen;
139 
140     return (int) __socketcall( SYS_GETPEERNAME, t );
141 }
142 #endif /* !__NR_getpeername */
143 
144 #ifndef __NR_socketpair
socketpair(int d,int type,int protocol,int sv[2])145 int socketpair(int d, int type, int protocol, int sv[2])
146 {
147     unsigned long  t[4];
148 
149     t[0] = (unsigned long) d;
150     t[1] = (unsigned long) type;
151     t[2] = (unsigned long) protocol;
152     t[3] = (unsigned long) sv;
153 
154     return (int) __socketcall( SYS_SOCKETPAIR, t );
155 }
156 #endif /* __NR_socketpair */
157 
158 #ifndef __NR_sendto
sendto(int socket,const void * message,size_t length,int flags,const struct sockaddr * dest_addr,socklen_t dest_len)159 ssize_t sendto(int socket, const void *message, size_t length, int flags,
160       const struct sockaddr *dest_addr, socklen_t dest_len)
161 {
162     unsigned long  t[6];
163 
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;
170 
171    return __socketcall( SYS_SENDTO, t );
172 }
173 #endif /* !__NR_sendto */
174 
175 #ifndef __NR_recvfrom
recvfrom(int socket,void * buffer,size_t length,unsigned int flags,const struct sockaddr * address,socklen_t * address_len)176 ssize_t recvfrom(int socket, void *buffer, size_t length, unsigned int flags,
177              const struct sockaddr *address, socklen_t *address_len)
178 {
179     unsigned long  t[6];
180 
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;
187 
188    return __socketcall( SYS_RECVFROM, t );
189 }
190 #endif /* !__NR_recvfrom */
191 
192 #ifndef __NR_shutdown
shutdown(int socket,int how)193 int shutdown(int socket, int how)
194 {
195     unsigned long  t[2];
196 
197     t[0] = (unsigned long) socket;
198     t[1] = (unsigned long) how;
199 
200    return (int) __socketcall( SYS_SHUTDOWN, t );
201 }
202 #endif /* !__NR_shutdown */
203 
204 #ifndef __NR_setsockopt
setsockopt(int s,int level,int optname,const void * optval,socklen_t optlen)205 int  setsockopt( int  s, int  level, int  optname, const void*  optval, socklen_t  optlen )
206 {
207     unsigned long  t[5];
208 
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;
214 
215    return (int) __socketcall( SYS_SETSOCKOPT, t );
216 }
217 #endif /* !__NR_setsockopt */
218 
219 #ifndef __NR_getsockopt
getsockopt(int s,int level,int optname,void * optval,socklen_t * optlen)220 int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
221 {
222     unsigned long  t[5];
223 
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;
229 
230     return (int) __socketcall( SYS_GETSOCKOPT, t );
231 }
232 #endif /* !__NR_getsockopt */
233 
234 #ifndef __NR_sendmsg
sendmsg(int socket,const struct msghdr * message,unsigned int flags)235 int sendmsg (int socket, const struct msghdr *message, unsigned int flags)
236 {
237     unsigned long  t[3];
238 
239     t[0] = (unsigned long) socket;
240     t[1] = (unsigned long) message;
241     t[2] = (unsigned long) flags;
242 
243    return __socketcall( SYS_SENDMSG, t );
244 }
245 #endif /* __NR_sendmsg */
246 
247 #ifndef __NR_recvmsg
recvmsg(int socket,struct msghdr * message,unsigned int flags)248 int recvmsg(int socket, struct msghdr *message, unsigned int flags)
249 {
250     unsigned long  t[3];
251 
252     t[0] = (unsigned long) socket;
253     t[1] = (unsigned long) message;
254     t[2] = (unsigned long) flags;
255 
256    return __socketcall( SYS_RECVMSG, t );
257 }
258 #endif /* __NR_recvmsg */
259 
260