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_KEEPALIVE
)
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_RCVBUF
)
86 if (option_len
!= sizeof(i
))
91 i
= *(int *)option_value
;
94 /* The receive buffer is limited to 32K at the moment.
99 /* There is no way to reduce the receive buffer, do we have to
100 * let this call fail for smaller buffers?
104 if (level
== SOL_SOCKET
&& option_name
== SO_SNDBUF
)
106 if (option_len
!= sizeof(i
))
111 i
= *(int *)option_value
;
114 /* The send buffer is limited to 32K at the moment.
119 /* There is no way to reduce the send buffer, do we have to
120 * let this call fail for smaller buffers?
124 if (level
== IPPROTO_TCP
&& option_name
== TCP_NODELAY
)
126 if (option_len
!= sizeof(i
))
131 i
= *(int *)option_value
;
134 /* At the moment there is no way to turn on
143 fprintf(stderr
, "_tcp_setsocketopt: level %d, name %d\n",
151 static int _udp_setsockopt(int socket
, int level
, int option_name
,
152 const void *option_value
, socklen_t option_len
)
157 fprintf(stderr
, "_udp_setsocketopt: level %d, name %d\n",