retire BIOS_SEG and umap_bios
[minix3.git] / lib / libc / sys-minix / setsockopt.c
blobff48111777a8c424d87b27da0b305f55d82e79da
1 #include <sys/cdefs.h>
2 #include "namespace.h"
4 #include <assert.h>
5 #include <errno.h>
6 #include <stdio.h>
7 #include <sys/ioctl.h>
8 #include <sys/socket.h>
9 #include <sys/types.h>
10 #include <netinet/tcp.h>
12 #include <net/gen/in.h>
13 #include <net/gen/tcp.h>
14 #include <net/gen/tcp_io.h>
15 #include <net/gen/udp.h>
16 #include <net/gen/udp_io.h>
18 #define DEBUG 0
20 static int _tcp_setsockopt(int sock, int level, int option_name,
21 const void *option_value, socklen_t option_len);
23 static int _udp_setsockopt(int sock, int level, int option_name,
24 const void *option_value, socklen_t option_len);
26 static int _uds_setsockopt(int sock, int level, int option_name,
27 const void *option_value, socklen_t option_len);
29 int setsockopt(int sock, int level, int option_name,
30 const void *option_value, socklen_t option_len)
32 int r;
33 nwio_tcpopt_t tcpopt;
34 nwio_udpopt_t udpopt;
35 struct sockaddr_un uds_addr;
37 r= ioctl(sock, NWIOGTCPOPT, &tcpopt);
38 if (r != -1 || (errno != ENOTTY && errno != EBADIOCTL))
40 if (r == -1)
42 /* Bad file descriptor */
43 return -1;
45 return _tcp_setsockopt(sock, level, option_name,
46 option_value, option_len);
49 r= ioctl(sock, NWIOGUDPOPT, &udpopt);
50 if (r != -1 || (errno != ENOTTY && errno != EBADIOCTL))
52 if (r == -1)
54 /* Bad file descriptor */
55 return -1;
57 return _udp_setsockopt(sock, level, option_name,
58 option_value, option_len);
61 r= ioctl(sock, NWIOGUDSADDR, &uds_addr);
62 if (r != -1 || (errno != ENOTTY && errno != EBADIOCTL))
64 if (r == -1)
66 /* Bad file descriptor */
67 return -1;
69 return _uds_setsockopt(sock, level, option_name,
70 option_value, option_len);
74 #if DEBUG
75 fprintf(stderr, "setsockopt: not implemented for fd %d\n", sock);
76 #endif
77 errno= ENOTSOCK;
78 return -1;
81 static int _tcp_setsockopt(int sock, int level, int option_name,
82 const void *option_value, socklen_t option_len)
84 int i;
86 if (level == SOL_SOCKET && option_name == SO_REUSEADDR)
88 if (option_len != sizeof(i))
90 errno= EINVAL;
91 return -1;
93 i= *(const int *)option_value;
94 if (!i)
96 /* At the moment there is no way to turn off
97 * reusing addresses.
99 errno= ENOSYS;
100 return -1;
102 return 0;
104 if (level == SOL_SOCKET && option_name == SO_KEEPALIVE)
106 if (option_len != sizeof(i))
108 errno= EINVAL;
109 return -1;
111 i= *(const int *)option_value;
112 if (!i)
114 /* At the moment there is no way to turn off
115 * keepalives.
117 errno= ENOSYS;
118 return -1;
120 return 0;
122 if (level == SOL_SOCKET && option_name == SO_RCVBUF)
124 if (option_len != sizeof(i))
126 errno= EINVAL;
127 return -1;
129 i= *(const int *)option_value;
130 if (i > 32*1024)
132 /* The receive buffer is limited to 32K at the moment.
134 errno= ENOSYS;
135 return -1;
137 /* There is no way to reduce the receive buffer, do we have to
138 * let this call fail for smaller buffers?
140 return 0;
142 if (level == SOL_SOCKET && option_name == SO_SNDBUF)
144 if (option_len != sizeof(i))
146 errno= EINVAL;
147 return -1;
149 i= *(const int *)option_value;
150 if (i > 32*1024)
152 /* The send buffer is limited to 32K at the moment.
154 errno= ENOSYS;
155 return -1;
157 /* There is no way to reduce the send buffer, do we have to
158 * let this call fail for smaller buffers?
160 return 0;
162 if (level == IPPROTO_TCP && option_name == TCP_NODELAY)
164 if (option_len != sizeof(i))
166 errno= EINVAL;
167 return -1;
169 i= *(const int *)option_value;
170 if (i)
172 /* At the moment there is no way to turn on
173 * nodelay.
175 errno= ENOSYS;
176 return -1;
178 return 0;
180 #if DEBUG
181 fprintf(stderr, "_tcp_setsocketopt: level %d, name %d\n",
182 level, option_name);
183 #endif
185 errno= ENOSYS;
186 return -1;
189 static int _udp_setsockopt(int sock, int level, int option_name,
190 const void *option_value, socklen_t option_len)
192 #if DEBUG
193 fprintf(stderr, "_udp_setsocketopt: level %d, name %d\n",
194 level, option_name);
195 #endif
197 errno= ENOSYS;
198 return -1;
202 static int _uds_setsockopt(int sock, int level, int option_name,
203 const void *option_value, socklen_t option_len)
205 int i;
206 size_t size;
208 if (level == SOL_SOCKET && option_name == SO_RCVBUF)
210 if (option_len != sizeof(size))
212 errno= EINVAL;
213 return -1;
215 size= *(const size_t *)option_value;
216 return ioctl(sock, NWIOSUDSRCVBUF, &size);
219 if (level == SOL_SOCKET && option_name == SO_SNDBUF)
221 if (option_len != sizeof(size))
223 errno= EINVAL;
224 return -1;
226 size= *(const size_t *)option_value;
227 return ioctl(sock, NWIOSUDSSNDBUF, &size);
230 if (level == SOL_SOCKET && option_name == SO_REUSEADDR)
232 if (option_len != sizeof(i))
234 errno= EINVAL;
235 return -1;
237 i= *(const int *)option_value;
238 if (!i)
240 /* At the moment there is no way to turn off
241 * reusing addresses.
243 errno= ENOSYS;
244 return -1;
246 return 0;
249 if (level == SOL_SOCKET && option_name == SO_PASSCRED)
251 if (option_len != sizeof(i))
253 errno= EINVAL;
254 return -1;
256 i= *(const int *)option_value;
257 if (!i)
259 /* credentials can always be received. */
260 errno= ENOSYS;
261 return -1;
263 return 0;
266 #if DEBUG
267 fprintf(stderr, "_uds_setsocketopt: level %d, name %d\n",
268 level, option_name);
269 #endif
271 errno= ENOSYS;
272 return -1;