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