]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/ipfilter/lib/buildopts.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / ipfilter / lib / buildopts.c
1 /*      $FreeBSD$       */
2
3 /*
4  * Copyright (C) 2000-2002 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  *
8  * $Id: buildopts.c,v 1.6.4.1 2006/06/16 17:20:56 darrenr Exp $
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                 for (io = ionames; io->on_name; io++) {
27                         if (strcasecmp(s, io->on_name) || (msk & io->on_bit))
28                                 continue;
29                         if ((inc = addipopt(op, io, len, t))) {
30                                 op += inc;
31                                 len += inc;
32                         }
33                         msk |= io->on_bit;
34                         break;
35                 }
36                 if (!io->on_name) {
37                         fprintf(stderr, "unknown IP option name %s\n", s);
38                         return 0;
39                 }
40         }
41         *op++ = IPOPT_EOL;
42         len++;
43         return len;
44 }