1 /* $NetBSD: bpf_image.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
4 * Copyright (c) 1990, 1991, 1992, 1994, 1995, 1996
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 #include <sys/cdefs.h>
25 __RCSID("$NetBSD: bpf_image.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
32 #include <pcap-stdinc.h>
39 #ifdef HAVE_SYS_BITYPES_H
40 #include <sys/bitypes.h>
42 #include <sys/types.h>
50 #ifdef HAVE_OS_PROTO_H
56 const struct bpf_insn
*p
;
61 static char image
[256];
83 case BPF_LD
|BPF_W
|BPF_ABS
:
88 case BPF_LD
|BPF_H
|BPF_ABS
:
93 case BPF_LD
|BPF_B
|BPF_ABS
:
98 case BPF_LD
|BPF_W
|BPF_LEN
:
103 case BPF_LD
|BPF_W
|BPF_IND
:
108 case BPF_LD
|BPF_H
|BPF_IND
:
113 case BPF_LD
|BPF_B
|BPF_IND
:
123 case BPF_LDX
|BPF_IMM
:
128 case BPF_LDX
|BPF_MSH
|BPF_B
:
130 fmt
= "4*([%d]&0xf)";
138 case BPF_LDX
|BPF_MEM
:
159 case BPF_JMP
|BPF_JGT
|BPF_K
:
164 case BPF_JMP
|BPF_JGE
|BPF_K
:
169 case BPF_JMP
|BPF_JEQ
|BPF_K
:
174 case BPF_JMP
|BPF_JSET
|BPF_K
:
179 case BPF_JMP
|BPF_JGT
|BPF_X
:
184 case BPF_JMP
|BPF_JGE
|BPF_X
:
189 case BPF_JMP
|BPF_JEQ
|BPF_X
:
194 case BPF_JMP
|BPF_JSET
|BPF_X
:
199 case BPF_ALU
|BPF_ADD
|BPF_X
:
204 case BPF_ALU
|BPF_SUB
|BPF_X
:
209 case BPF_ALU
|BPF_MUL
|BPF_X
:
214 case BPF_ALU
|BPF_DIV
|BPF_X
:
219 case BPF_ALU
|BPF_MOD
|BPF_X
:
224 case BPF_ALU
|BPF_AND
|BPF_X
:
229 case BPF_ALU
|BPF_OR
|BPF_X
:
234 case BPF_ALU
|BPF_XOR
|BPF_X
:
239 case BPF_ALU
|BPF_LSH
|BPF_X
:
244 case BPF_ALU
|BPF_RSH
|BPF_X
:
249 case BPF_ALU
|BPF_ADD
|BPF_K
:
254 case BPF_ALU
|BPF_SUB
|BPF_K
:
259 case BPF_ALU
|BPF_MUL
|BPF_K
:
264 case BPF_ALU
|BPF_DIV
|BPF_K
:
269 case BPF_ALU
|BPF_MOD
|BPF_K
:
274 case BPF_ALU
|BPF_AND
|BPF_K
:
279 case BPF_ALU
|BPF_OR
|BPF_K
:
284 case BPF_ALU
|BPF_XOR
|BPF_K
:
289 case BPF_ALU
|BPF_LSH
|BPF_K
:
294 case BPF_ALU
|BPF_RSH
|BPF_K
:
299 case BPF_ALU
|BPF_NEG
:
304 case BPF_MISC
|BPF_TAX
:
309 case BPF_MISC
|BPF_TXA
:
314 (void)snprintf(operand
, sizeof operand
, fmt
, v
);
315 if (BPF_CLASS(p
->code
) == BPF_JMP
&& BPF_OP(p
->code
) != BPF_JA
) {
316 (void)snprintf(image
, sizeof image
,
317 "(%03d) %-8s %-16s jt %d\tjf %d",
318 n
, op
, operand
, n
+ 1 + p
->jt
, n
+ 1 + p
->jf
);
320 (void)snprintf(image
, sizeof image
,