Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / addipopt.c
blob1f9fba096d4faa4dad1de32dd7a941ae6cd6bf79
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2000-2002 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Id: addipopt.c,v 1.7.4.1 2006/06/16 17:20:56 darrenr Exp
9 */
11 #include "ipf.h"
14 int addipopt(op, io, len, class)
15 char *op;
16 struct ipopt_names *io;
17 int len;
18 char *class;
20 int olen = len;
21 struct in_addr ipadr;
22 u_short val;
23 u_char lvl;
24 char *s;
26 if ((len + io->on_siz) > 48) {
27 fprintf(stderr, "options too long\n");
28 return 0;
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;
37 if (class) {
38 switch (io->on_value)
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;
57 op += io->on_siz - 3;
58 if (len & 3) {
59 *op++ = IPOPT_NOP;
60 len++;
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;