secondary cache feature in vm.
[minix.git] / lib / libc / ip / setsockopt.c
blobc5d362ac50c8c9df19d86af6c56c4469aca7bc45
1 #include <assert.h>
2 #include <errno.h>
3 #include <stdio.h>
4 #include <sys/ioctl.h>
5 #include <sys/socket.h>
6 #include <sys/types.h>
7 #include <netinet/tcp.h>
9 #include <net/gen/in.h>
10 #include <net/gen/tcp.h>
11 #include <net/gen/tcp_io.h>
12 #include <net/gen/udp.h>
13 #include <net/gen/udp_io.h>
15 #define DEBUG 0
17 static int _tcp_setsockopt(int socket, int level, int option_name,
18 const void *option_value, socklen_t option_len);
20 static int _udp_setsockopt(int socket, int level, int option_name,
21 const void *option_value, socklen_t option_len);
23 int setsockopt(int socket, int level, int option_name,
24 const void *option_value, socklen_t option_len)
26 int r;
27 nwio_tcpopt_t tcpopt;
28 nwio_udpopt_t udpopt;
30 r= ioctl(socket, NWIOGTCPOPT, &tcpopt);
31 if (r != -1 || errno != ENOTTY)
33 if (r == -1)
35 /* Bad file descriptor */
36 return -1;
38 return _tcp_setsockopt(socket, level, option_name,
39 option_value, option_len);
42 r= ioctl(socket, NWIOGUDPOPT, &udpopt);
43 if (r != -1 || errno != ENOTTY)
45 if (r == -1)
47 /* Bad file descriptor */
48 return -1;
50 return _udp_setsockopt(socket, level, option_name,
51 option_value, option_len);
54 #if DEBUG
55 fprintf(stderr, "setsockopt: not implemented for fd %d\n", socket);
56 #endif
57 errno= ENOTSOCK;
58 return -1;
61 static int _tcp_setsockopt(int socket, int level, int option_name,
62 const void *option_value, socklen_t option_len)
64 int i;
66 if (level == SOL_SOCKET && option_name == SO_REUSEADDR)
68 if (option_len != sizeof(i))
70 errno= EINVAL;
71 return -1;
73 i= *(int *)option_value;
74 if (!i)
76 /* At the moment there is no way to turn off
77 * reusing addresses.
79 errno= ENOSYS;
80 return -1;
82 return 0;
84 if (level == SOL_SOCKET && option_name == SO_KEEPALIVE)
86 if (option_len != sizeof(i))
88 errno= EINVAL;
89 return -1;
91 i= *(int *)option_value;
92 if (!i)
94 /* At the moment there is no way to turn off
95 * keepalives.
97 errno= ENOSYS;
98 return -1;
100 return 0;
102 if (level == SOL_SOCKET && option_name == SO_RCVBUF)
104 if (option_len != sizeof(i))
106 errno= EINVAL;
107 return -1;
109 i= *(int *)option_value;
110 if (i > 32*1024)
112 /* The receive buffer is limited to 32K at the moment.
114 errno= ENOSYS;
115 return -1;
117 /* There is no way to reduce the receive buffer, do we have to
118 * let this call fail for smaller buffers?
120 return 0;
122 if (level == SOL_SOCKET && option_name == SO_SNDBUF)
124 if (option_len != sizeof(i))
126 errno= EINVAL;
127 return -1;
129 i= *(int *)option_value;
130 if (i > 32*1024)
132 /* The send buffer is limited to 32K at the moment.
134 errno= ENOSYS;
135 return -1;
137 /* There is no way to reduce the send buffer, do we have to
138 * let this call fail for smaller buffers?
140 return 0;
142 if (level == IPPROTO_TCP && option_name == TCP_NODELAY)
144 if (option_len != sizeof(i))
146 errno= EINVAL;
147 return -1;
149 i= *(int *)option_value;
150 if (i)
152 /* At the moment there is no way to turn on
153 * nodelay.
155 errno= ENOSYS;
156 return -1;
158 return 0;
160 #if DEBUG
161 fprintf(stderr, "_tcp_setsocketopt: level %d, name %d\n",
162 level, option_name);
163 #endif
165 errno= ENOSYS;
166 return -1;
169 static int _udp_setsockopt(int socket, int level, int option_name,
170 const void *option_value, socklen_t option_len)
172 #if DEBUG
173 fprintf(stderr, "_udp_setsocketopt: level %d, name %d\n",
174 level, option_name);
175 #endif
177 errno= ENOSYS;
178 return -1;