1 /*
2 * Copyright 2012, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include <socket_portable.h>
20
21
22 #if SOL_SOCKET_PORTABLE==SOL_SOCKET
23 #error Build environment
24 #endif
25
mips_change_level(int level)26 static inline int mips_change_level(int level)
27 {
28 switch (level) {
29 case SOL_SOCKET_PORTABLE:
30 level = SOL_SOCKET;
31 break;
32 }
33 return level;
34 }
35
36
mips_change_optname(int optname)37 static inline int mips_change_optname(int optname)
38 {
39 switch (optname) {
40 case SO_DEBUG_PORTABLE:
41 return SO_DEBUG;
42 case SO_REUSEADDR_PORTABLE:
43 return SO_REUSEADDR;
44 case SO_TYPE_PORTABLE:
45 return SO_TYPE;
46 case SO_ERROR_PORTABLE:
47 return SO_ERROR;
48 case SO_DONTROUTE_PORTABLE:
49 return SO_DONTROUTE;
50 case SO_BROADCAST_PORTABLE:
51 return SO_BROADCAST;
52 case SO_SNDBUF_PORTABLE:
53 return SO_SNDBUF;
54 case SO_RCVBUF_PORTABLE:
55 return SO_RCVBUF;
56 case SO_SNDBUFFORCE_PORTABLE:
57 return SO_SNDBUFFORCE;
58 case SO_RCVBUFFORCE_PORTABLE:
59 return SO_RCVBUFFORCE;
60 case SO_KEEPALIVE_PORTABLE:
61 return SO_KEEPALIVE;
62 case SO_OOBINLINE_PORTABLE:
63 return SO_OOBINLINE;
64 case SO_NO_CHECK_PORTABLE:
65 return SO_NO_CHECK;
66 case SO_PRIORITY_PORTABLE:
67 return SO_PRIORITY;
68 case SO_LINGER_PORTABLE:
69 return SO_LINGER;
70 case SO_BSDCOMPAT_PORTABLE:
71 return SO_BSDCOMPAT;
72 case SO_PASSCRED_PORTABLE:
73 return SO_PASSCRED;
74 case SO_PEERCRED_PORTABLE:
75 return SO_PEERCRED;
76 case SO_RCVLOWAT_PORTABLE:
77 return SO_RCVLOWAT;
78 case SO_SNDLOWAT_PORTABLE:
79 return SO_SNDLOWAT;
80 case SO_RCVTIMEO_PORTABLE:
81 return SO_RCVTIMEO;
82 case SO_SNDTIMEO_PORTABLE:
83 return SO_SNDTIMEO;
84 case SO_SECURITY_AUTHENTICATION_PORTABLE:
85 return SO_SECURITY_AUTHENTICATION;
86 case SO_SECURITY_ENCRYPTION_TRANSPORT_PORTABLE:
87 return SO_SECURITY_ENCRYPTION_TRANSPORT;
88 case SO_SECURITY_ENCRYPTION_NETWORK_PORTABLE:
89 return SO_SECURITY_ENCRYPTION_NETWORK;
90 case SO_BINDTODEVICE_PORTABLE:
91 return SO_BINDTODEVICE;
92 case SO_ATTACH_FILTER_PORTABLE:
93 return SO_ATTACH_FILTER;
94 case SO_DETACH_FILTER_PORTABLE:
95 return SO_DETACH_FILTER;
96 case SO_PEERNAME_PORTABLE:
97 return SO_PEERNAME;
98 case SO_TIMESTAMP_PORTABLE:
99 return SO_TIMESTAMP;
100 case SO_ACCEPTCONN_PORTABLE:
101 return SO_ACCEPTCONN;
102 case SO_PEERSEC_PORTABLE:
103 return SO_PEERSEC;
104 case SO_PASSSEC_PORTABLE:
105 return SO_PASSSEC;
106 }
107 return optname;
108 }
109
110 extern int setsockopt(int, int, int, const void *, socklen_t);
setsockopt_portable(int s,int level,int optname,const void * optval,socklen_t optlen)111 int setsockopt_portable(int s, int level, int optname, const void *optval, socklen_t optlen)
112 {
113 return setsockopt(s, mips_change_level(level), mips_change_optname(optname), optval, optlen);
114 }
115
116 extern int getsockopt (int, int, int, void *, socklen_t *);
getsockopt_portable(int s,int level,int optname,void * optval,socklen_t * optlen)117 int getsockopt_portable(int s, int level, int optname, void *optval, socklen_t *optlen)
118 {
119 return getsockopt(s, mips_change_level(level), mips_change_optname(optname), optval, optlen);
120 }
121