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: addipopt.c,v 1.7 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
addipopt(op,io,len,class)12*0Sstevel@tonic-gate int addipopt(op, io, len, class)
13*0Sstevel@tonic-gate char *op;
14*0Sstevel@tonic-gate struct ipopt_names *io;
15*0Sstevel@tonic-gate int len;
16*0Sstevel@tonic-gate char *class;
17*0Sstevel@tonic-gate {
18*0Sstevel@tonic-gate int olen = len;
19*0Sstevel@tonic-gate struct in_addr ipadr;
20*0Sstevel@tonic-gate u_short val;
21*0Sstevel@tonic-gate u_char lvl;
22*0Sstevel@tonic-gate char *s;
23*0Sstevel@tonic-gate
24*0Sstevel@tonic-gate if ((len + io->on_siz) > 48) {
25*0Sstevel@tonic-gate fprintf(stderr, "options too long\n");
26*0Sstevel@tonic-gate return 0;
27*0Sstevel@tonic-gate }
28*0Sstevel@tonic-gate len += io->on_siz;
29*0Sstevel@tonic-gate *op++ = io->on_value;
30*0Sstevel@tonic-gate if (io->on_siz > 1) {
31*0Sstevel@tonic-gate s = op;
32*0Sstevel@tonic-gate *op++ = io->on_siz;
33*0Sstevel@tonic-gate *op++ = IPOPT_MINOFF;
34*0Sstevel@tonic-gate
35*0Sstevel@tonic-gate if (class) {
36*0Sstevel@tonic-gate switch (io->on_value)
37*0Sstevel@tonic-gate {
38*0Sstevel@tonic-gate case IPOPT_SECURITY :
39*0Sstevel@tonic-gate lvl = seclevel(class);
40*0Sstevel@tonic-gate *(op - 1) = lvl;
41*0Sstevel@tonic-gate break;
42*0Sstevel@tonic-gate case IPOPT_LSRR :
43*0Sstevel@tonic-gate case IPOPT_SSRR :
44*0Sstevel@tonic-gate ipadr.s_addr = inet_addr(class);
45*0Sstevel@tonic-gate s[IPOPT_OLEN] = IPOPT_MINOFF - 1 + 4;
46*0Sstevel@tonic-gate bcopy((char *)&ipadr, op, sizeof(ipadr));
47*0Sstevel@tonic-gate break;
48*0Sstevel@tonic-gate case IPOPT_SATID :
49*0Sstevel@tonic-gate val = atoi(class);
50*0Sstevel@tonic-gate bcopy((char *)&val, op, 2);
51*0Sstevel@tonic-gate break;
52*0Sstevel@tonic-gate }
53*0Sstevel@tonic-gate }
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gate op += io->on_siz - 3;
56*0Sstevel@tonic-gate if (len & 3) {
57*0Sstevel@tonic-gate *op++ = IPOPT_NOP;
58*0Sstevel@tonic-gate len++;
59*0Sstevel@tonic-gate }
60*0Sstevel@tonic-gate }
61*0Sstevel@tonic-gate if (opts & OPT_DEBUG)
62*0Sstevel@tonic-gate fprintf(stderr, "bo: %s %d %#x: %d\n",
63*0Sstevel@tonic-gate io->on_name, io->on_value, io->on_bit, len);
64*0Sstevel@tonic-gate return len - olen;
65*0Sstevel@tonic-gate }
66