Uninitialized vector entry?
[minix3.git] / lib / ip / setsockopt.c
blobe6ef3631d15d3231d04fd1145c14826b9d002052
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_KEEPALIVE)
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 * keepalives.
79 errno= ENOSYS;
80 return -1;
82 return 0;
84 if (level == SOL_SOCKET && option_name == SO_RCVBUF)
86 if (option_len != sizeof(i))
88 errno= EINVAL;
89 return -1;
91 i= *(int *)option_value;
92 if (i > 32*1024)
94 /* The receive buffer is limited to 32K at the moment.
96 errno= ENOSYS;
97 return -1;
99 /* There is no way to reduce the receive buffer, do we have to
100 * let this call fail for smaller buffers?
102 return 0;
104 if (level == SOL_SOCKET && option_name == SO_SNDBUF)
106 if (option_len != sizeof(i))
108 errno= EINVAL;
109 return -1;
111 i= *(int *)option_value;
112 if (i > 32*1024)
114 /* The send buffer is limited to 32K at the moment.
116 errno= ENOSYS;
117 return -1;
119 /* There is no way to reduce the send buffer, do we have to
120 * let this call fail for smaller buffers?
122 return 0;
124 if (level == IPPROTO_TCP && option_name == TCP_NODELAY)
126 if (option_len != sizeof(i))
128 errno= EINVAL;
129 return -1;
131 i= *(int *)option_value;
132 if (i)
134 /* At the moment there is no way to turn on
135 * nodelay.
137 errno= ENOSYS;
138 return -1;
140 return 0;
142 #if DEBUG
143 fprintf(stderr, "_tcp_setsocketopt: level %d, name %d\n",
144 level, option_name);
145 #endif
147 errno= ENOSYS;
148 return -1;
151 static int _udp_setsockopt(int socket, int level, int option_name,
152 const void *option_value, socklen_t option_len)
154 int i;
156 #if DEBUG
157 fprintf(stderr, "_udp_setsocketopt: level %d, name %d\n",
158 level, option_name);
159 #endif
161 errno= ENOSYS;
162 return -1;