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