]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/ipfilter/lib/addipopt.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / ipfilter / lib / addipopt.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: addipopt.c,v 1.7.4.1 2006/06/16 17:20:56 darrenr Exp $
9  */
10
11 #include "ipf.h"
12
13
14 int addipopt(op, io, len, class)
15 char *op;
16 struct ipopt_names *io;
17 int len;
18 char *class;
19 {
20         int olen = len;
21         struct in_addr ipadr;
22         u_short val;
23         u_char lvl;
24         char *s;
25
26         if ((len + io->on_siz) > 48) {
27                 fprintf(stderr, "options too long\n");
28                 return 0;
29         }
30         len += io->on_siz;
31         *op++ = io->on_value;
32         if (io->on_siz > 1) {
33                 s = op;
34                 *op++ = io->on_siz;
35                 *op++ = IPOPT_MINOFF;
36
37                 if (class) {
38                         switch (io->on_value)
39                         {
40                         case IPOPT_SECURITY :
41                                 lvl = seclevel(class);
42                                 *(op - 1) = lvl;
43                                 break;
44                         case IPOPT_LSRR :
45                         case IPOPT_SSRR :
46                                 ipadr.s_addr = inet_addr(class);
47                                 s[IPOPT_OLEN] = IPOPT_MINOFF - 1 + 4;
48                                 bcopy((char *)&ipadr, op, sizeof(ipadr));
49                                 break;
50                         case IPOPT_SATID :
51                                 val = atoi(class);
52                                 bcopy((char *)&val, op, 2);
53                                 break;
54                         }
55                 }
56
57                 op += io->on_siz - 3;
58                 if (len & 3) {
59                         *op++ = IPOPT_NOP;
60                         len++;
61                 }
62         }
63         if (opts & OPT_DEBUG)
64                 fprintf(stderr, "bo: %s %d %#x: %d\n",
65                         io->on_name, io->on_value, io->on_bit, len);
66         return len - olen;
67 }