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