xref: /netbsd-src/lib/libwrap/fix_options.c (revision d0fed6c87ddc40a8bffa6f99e7433ddfc864dd83)
1  /*
2   * Routine to disable IP-level socket options. This code was taken from 4.4BSD
3   * rlogind source, but all mistakes in it are my fault.
4   *
5   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
6   */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#) fix_options.c 1.3 94/12/28 17:42:22";
10 #endif
11 
12 #include <sys/types.h>
13 #include <sys/param.h>
14 #include <netinet/in.h>
15 #include <netdb.h>
16 #include <stdio.h>
17 #include <syslog.h>
18 
19 #include "tcpd.h"
20 
21 /* fix_options - get rid of IP-level socket options */
22 
23 fix_options(request)
24 struct request_info *request;
25 {
26 #ifdef IP_OPTIONS
27     unsigned char optbuf[BUFSIZ / 3], *cp;
28     char    lbuf[BUFSIZ], *lp;
29     int     optsize = sizeof(optbuf), ipproto;
30     struct protoent *ip;
31     int     fd = request->fd;
32     int     len = sizeof lbuf;
33 
34     if ((ip = getprotobyname("ip")) != 0)
35 	ipproto = ip->p_proto;
36     else
37 	ipproto = IPPROTO_IP;
38 
39     if (getsockopt(fd, ipproto, IP_OPTIONS, (char *) optbuf, &optsize) == 0
40 	&& optsize != 0) {
41 	lp = lbuf;
42 	for (cp = optbuf; optsize > 0; cp++, optsize--, lp += 3)
43 	    len -= snprintf(lp, len, " %2.2x", *cp);
44 	syslog(LOG_NOTICE,
45 	       "connect from %s with IP options (ignored):%s",
46 	       eval_client(request), lbuf);
47 	if (setsockopt(fd, ipproto, IP_OPTIONS, (char *) 0, optsize) != 0) {
48 	    syslog(LOG_ERR, "setsockopt IP_OPTIONS NULL: %m");
49 	    clean_exit(request);
50 	}
51     }
52 #endif
53 }
54