Deleted Added
full compact
addipopt.c (145519) addipopt.c (153881)
1/* $FreeBSD: head/contrib/ipfilter/lib/addipopt.c 145519 2005-04-25 18:20:15Z darrenr $ */
1/* $FreeBSD: head/contrib/ipfilter/lib/addipopt.c 153881 2005-12-30 11:52:26Z guido $ */
2
3/*
4 * Copyright (C) 1993-2001 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
2
3/*
4 * Copyright (C) 1993-2001 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 * Id: addipopt.c,v 1.7 2002/01/28 06:50:45 darrenr Exp
8 * $Id: addipopt.c,v 1.7 2002/01/28 06:50:45 darrenr Exp $
9 */
10
11#include "ipf.h"
12
13
14int addipopt(op, io, len, class)
15char *op;
16struct ipopt_names *io;
17int len;
18char *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}
9 */
10
11#include "ipf.h"
12
13
14int addipopt(op, io, len, class)
15char *op;
16struct ipopt_names *io;
17int len;
18char *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}