5 #include <sys/socket.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>
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
)
30 r
= ioctl(socket
, NWIOGTCPOPT
, &tcpopt
);
31 if (r
!= -1 || errno
!= ENOTTY
)
35 /* Bad file descriptor */
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
)
47 /* Bad file descriptor */
50 return _udp_setsockopt(socket
, level
, option_name
,
51 option_value
, option_len
);
55 fprintf(stderr
, "setsockopt: not implemented for fd %d\n", socket
);
61 static int _tcp_setsockopt(int socket
, int level
, int option_name
,
62 const void *option_value
, socklen_t option_len
)
66 if (level
== SOL_SOCKET
&& option_name
== SO_REUSEADDR
)
68 if (option_len
!= sizeof(i
))
73 i
= *(int *)option_value
;
76 /* At the moment there is no way to turn off
84 if (level
== SOL_SOCKET
&& option_name
== SO_KEEPALIVE
)
86 if (option_len
!= sizeof(i
))
91 i
= *(int *)option_value
;
94 /* At the moment there is no way to turn off
102 if (level
== SOL_SOCKET
&& option_name
== SO_RCVBUF
)
104 if (option_len
!= sizeof(i
))
109 i
= *(int *)option_value
;
112 /* The receive buffer is limited to 32K at the moment.
117 /* There is no way to reduce the receive buffer, do we have to
118 * let this call fail for smaller buffers?
122 if (level
== SOL_SOCKET
&& option_name
== SO_SNDBUF
)
124 if (option_len
!= sizeof(i
))
129 i
= *(int *)option_value
;
132 /* The send buffer is limited to 32K at the moment.
137 /* There is no way to reduce the send buffer, do we have to
138 * let this call fail for smaller buffers?
142 if (level
== IPPROTO_TCP
&& option_name
== TCP_NODELAY
)
144 if (option_len
!= sizeof(i
))
149 i
= *(int *)option_value
;
152 /* At the moment there is no way to turn on
161 fprintf(stderr
, "_tcp_setsocketopt: level %d, name %d\n",
169 static int _udp_setsockopt(int socket
, int level
, int option_name
,
170 const void *option_value
, socklen_t option_len
)
173 fprintf(stderr
, "_udp_setsocketopt: level %d, name %d\n",