1 #include <netinet/in.h>
2 #include <netinet/tcp.h>
5 #include <sys/socket.h>
10 * show_default_sockopts
12 * Show the default socket options
22 void option_query(int s, int type, struct option_t *p)
26 for (; p->descr != NULL; ++p) {
27 if (getsockopt(s, type, p->opt, (void *)&value, &vlen) == -1) {
28 fprintf(stderr,"getsocketopts: could not test %s\n",
32 printf("Default %s = %d\n", p->descr, value);
37 struct option_t so_option[] = {
39 { SO_ACCEPTCONN, "SO_ACCEPTCON: accepting connections" },
42 { SO_BROADCAST, "SO_BROADCAST, broadcast allowed" },
45 { SO_REUSEADDR, "SO_REUSEADDR, address recycling" },
48 { SO_KEEPALIVE, "SO_KEEPALIVE, send keepalive packets" },
50 /* { SO_LINGER, "SO_LINGER, lingers on close"}, */
52 { SO_OOBINLINE, "SO_OOBINLINE, oob data folded inline"},
55 { SO_SNDBUF, "SO_SNDBUF, send buffer size" },
58 { SO_RCVLOWAT, "SO_RCVLOWAT, receive low-water mark"},
61 { SO_SNDLOWAT, "SO_SNDLOWAT, send low-water mark"},
64 { SO_RCVTIMEO, "SO_RCVTIMEO, receive timeout"},
67 { SO_SNDTIMEO, "SO_SNDTIMEO, send timeout"},
70 { SO_RCVBUF, "SO_RCVBUF, receive buffer size"},
73 { SO_ERROR, "SO_ERROR, error status"},
76 { SO_TYPE, "SO_TYPE, socket type"},
81 struct option_t tcp_option[] = {
83 { TCP_MAXSEG, "TCP_MAXSEG, maximum segment size (mss)"},
86 { TCP_NODELAY, "TCP_NODELAY, send even tiny packets"},
91 int main(int argc, char **argv)
94 if ((getuid()) != 0) {
95 fprintf(stderr,"%s: you must be root to run this program.\n", argv[0]);
99 if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
100 perror("failed to create a socket to test.");
103 option_query(s, SOL_SOCKET, so_option);
104 option_query(s, IPPROTO_TCP, tcp_option);