xref: /titanic_51/usr/src/cmd/ipf/lib/common/addipopt.c (revision fa9e4066f08beec538e775443c5be79dd423fcab)
1 /*
2  * Copyright (C) 1993-2001 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * $Id: addipopt.c,v 1.7 2002/01/28 06:50:45 darrenr Exp $
7  */
8 
9 #include "ipf.h"
10 
11 
12 int addipopt(op, io, len, class)
13 char *op;
14 struct ipopt_names *io;
15 int len;
16 char *class;
17 {
18 	int olen = len;
19 	struct in_addr ipadr;
20 	u_short val;
21 	u_char lvl;
22 	char *s;
23 
24 	if ((len + io->on_siz) > 48) {
25 		fprintf(stderr, "options too long\n");
26 		return 0;
27 	}
28 	len += io->on_siz;
29 	*op++ = io->on_value;
30 	if (io->on_siz > 1) {
31 		s = op;
32 		*op++ = io->on_siz;
33 		*op++ = IPOPT_MINOFF;
34 
35 		if (class) {
36 			switch (io->on_value)
37 			{
38 			case IPOPT_SECURITY :
39 				lvl = seclevel(class);
40 				*(op - 1) = lvl;
41 				break;
42 			case IPOPT_LSRR :
43 			case IPOPT_SSRR :
44 				ipadr.s_addr = inet_addr(class);
45 				s[IPOPT_OLEN] = IPOPT_MINOFF - 1 + 4;
46 				bcopy((char *)&ipadr, op, sizeof(ipadr));
47 				break;
48 			case IPOPT_SATID :
49 				val = atoi(class);
50 				bcopy((char *)&val, op, 2);
51 				break;
52 			}
53 		}
54 
55 		op += io->on_siz - 3;
56 		if (len & 3) {
57 			*op++ = IPOPT_NOP;
58 			len++;
59 		}
60 	}
61 	if (opts & OPT_DEBUG)
62 		fprintf(stderr, "bo: %s %d %#x: %d\n",
63 			io->on_name, io->on_value, io->on_bit, len);
64 	return len - olen;
65 }
66