--- /dev/null
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+/*
+ * show_default_sockopts
+ *
+ * Show the default socket options
+ *
+ * Colin McCabe
+ */
+
+struct option_t {
+ int opt;
+ const char *descr;
+};
+
+void option_query(int s, int type, struct option_t *p)
+{
+ int value, vlen = 4;
+
+ for (; p->descr != NULL; ++p) {
+ if (getsockopt(s, type, p->opt, (void *)&value, &vlen) == -1) {
+ fprintf(stderr,"getsocketopts: could not test %s\n",
+ p->descr);
+ }
+ else {
+ printf("Default %s = %d\n", p->descr, value);
+ }
+ }
+}
+
+struct option_t so_option[] = {
+#ifdef SO_ACCEPTCONN
+ { SO_ACCEPTCONN, "SO_ACCEPTCON: accepting connections" },
+#endif
+#ifdef SO_BROADCAST
+ { SO_BROADCAST, "SO_BROADCAST, broadcast allowed" },
+#endif
+#ifdef SO_REUSEADDR
+ { SO_REUSEADDR, "SO_REUSEADDR, address recycling" },
+#endif
+#ifdef SO_KEEPALIVE
+ { SO_KEEPALIVE, "SO_KEEPALIVE, send keepalive packets" },
+#endif
+ /* { SO_LINGER, "SO_LINGER, lingers on close"}, */
+#ifdef SO_OOBINLINE
+ { SO_OOBINLINE, "SO_OOBINLINE, oob data folded inline"},
+#endif
+#ifdef SO_SNDBUF
+ { SO_SNDBUF, "SO_SNDBUF, send buffer size" },
+#endif
+#ifdef SO_RCVLOWAT
+ { SO_RCVLOWAT, "SO_RCVLOWAT, receive low-water mark"},
+#endif
+#ifdef SO_SNDLOWAT
+ { SO_SNDLOWAT, "SO_SNDLOWAT, send low-water mark"},
+#endif
+#ifdef SO_RCVTIMEO
+ { SO_RCVTIMEO, "SO_RCVTIMEO, receive timeout"},
+#endif
+#ifdef SO_SNDTIMEO
+ { SO_SNDTIMEO, "SO_SNDTIMEO, send timeout"},
+#endif
+#ifdef SO_RCVBUF
+ { SO_RCVBUF, "SO_RCVBUF, receive buffer size"},
+#endif
+#ifdef SO_ERROR
+ { SO_ERROR, "SO_ERROR, error status"},
+#endif
+#ifdef SO_TYPE
+ { SO_TYPE, "SO_TYPE, socket type"},
+#endif
+ { 0, NULL }
+};
+
+struct option_t tcp_option[] = {
+#ifdef TCP_MAXSEG
+ { TCP_MAXSEG, "TCP_MAXSEG, maximum segment size (mss)"},
+#endif
+#ifdef TCP_NODELAY
+ { TCP_NODELAY, "TCP_NODELAY, send even tiny packets"},
+#endif
+ { 0, NULL}
+};
+
+int main(int argc, char **argv)
+{
+ int s;
+ if ((getuid()) != 0) {
+ fprintf(stderr,"%s: you must be root to run this program.\n", argv[0]);
+ return 1;
+ }
+
+ if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+ perror("failed to create a socket to test.");
+ return 1;
+ }
+ option_query(s, SOL_SOCKET, so_option);
+ option_query(s, IPPROTO_TCP, tcp_option);
+
+ (void) close(s);
+ return 0;
+}