xref: /titanic_50/usr/src/cmd/ipf/lib/common/buildopts.c (revision 7a286c471efbab8562f7655a82931904703fffe0)
1 /*
2  * Copyright (C) 1993-2001 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * $Id: buildopts.c,v 1.6 2002/01/28 06:50:45 darrenr Exp $
7  */
8 
9 #include "ipf.h"
10 
11 
12 u_32_t buildopts(cp, op, len)
13 char *cp, *op;
14 int len;
15 {
16 	struct ipopt_names *io;
17 	u_32_t msk = 0;
18 	char *s, *t;
19 	int inc;
20 
21 	for (s = strtok(cp, ","); s; s = strtok(NULL, ",")) {
22 		if ((t = strchr(s, '=')))
23 			*t++ = '\0';
24 		for (io = ionames; io->on_name; io++) {
25 			if (strcasecmp(s, io->on_name) || (msk & io->on_bit))
26 				continue;
27 			if ((inc = addipopt(op, io, len, t))) {
28 				op += inc;
29 				len += inc;
30 			}
31 			msk |= io->on_bit;
32 			break;
33 		}
34 		if (!io->on_name) {
35 			fprintf(stderr, "unknown IP option name %s\n", s);
36 			return 0;
37 		}
38 	}
39 	*op++ = IPOPT_EOL;
40 	len++;
41 	return len;
42 }
43