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