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