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)
27 for (; p->descr != NULL; ++p) {
28 if (getsockopt(s, type, p->opt, (void *)&value, &vlen) == -1) {
29 fprintf(stderr,"getsocketopts: could not test %s\n",
33 printf("Default %s = %d\n", p->descr, value);
38 struct option_t so_option[] = {
40 { SO_ACCEPTCONN, "SO_ACCEPTCON: accepting connections" },
43 { SO_BROADCAST, "SO_BROADCAST, broadcast allowed" },
46 { SO_REUSEADDR, "SO_REUSEADDR, address recycling" },
49 { SO_KEEPALIVE, "SO_KEEPALIVE, send keepalive packets" },
51 /* { SO_LINGER, "SO_LINGER, lingers on close"}, */
53 { SO_OOBINLINE, "SO_OOBINLINE, oob data folded inline"},
56 { SO_SNDBUF, "SO_SNDBUF, send buffer size" },
59 { SO_RCVLOWAT, "SO_RCVLOWAT, receive low-water mark"},
62 { SO_SNDLOWAT, "SO_SNDLOWAT, send low-water mark"},
65 { SO_RCVTIMEO, "SO_RCVTIMEO, receive timeout"},
68 { SO_SNDTIMEO, "SO_SNDTIMEO, send timeout"},
71 { SO_RCVBUF, "SO_RCVBUF, receive buffer size"},
74 { SO_ERROR, "SO_ERROR, error status"},
77 { SO_TYPE, "SO_TYPE, socket type"},
82 struct option_t tcp_option[] = {
84 { TCP_MAXSEG, "TCP_MAXSEG, maximum segment size (mss)"},
87 { TCP_NODELAY, "TCP_NODELAY, send even tiny packets"},
92 int main(int argc, char **argv)
95 if ((getuid()) != 0) {
96 fprintf(stderr,"%s: you must be root to run this program.\n", argv[0]);
100 if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
101 perror("failed to create a socket to test.");
104 option_query(s, SOL_SOCKET, so_option);
105 option_query(s, IPPROTO_TCP, tcp_option);