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