]>
The Tcpdump Group git mirrors - libpcap/blob - bpf_image.c
2 * Copyright (c) 1990, 1991, 1992, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 #include <pcap-types.h>
33 #ifdef HAVE_OS_PROTO_H
39 const struct bpf_insn
*p
;
44 static char image
[256];
66 case BPF_LD
|BPF_W
|BPF_ABS
:
71 case BPF_LD
|BPF_H
|BPF_ABS
:
76 case BPF_LD
|BPF_B
|BPF_ABS
:
81 case BPF_LD
|BPF_W
|BPF_LEN
:
86 case BPF_LD
|BPF_W
|BPF_IND
:
91 case BPF_LD
|BPF_H
|BPF_IND
:
96 case BPF_LD
|BPF_B
|BPF_IND
:
106 case BPF_LDX
|BPF_IMM
:
111 case BPF_LDX
|BPF_MSH
|BPF_B
:
113 fmt
= "4*([%d]&0xf)";
121 case BPF_LDX
|BPF_MEM
:
142 case BPF_JMP
|BPF_JGT
|BPF_K
:
147 case BPF_JMP
|BPF_JGE
|BPF_K
:
152 case BPF_JMP
|BPF_JEQ
|BPF_K
:
157 case BPF_JMP
|BPF_JSET
|BPF_K
:
162 case BPF_JMP
|BPF_JGT
|BPF_X
:
167 case BPF_JMP
|BPF_JGE
|BPF_X
:
172 case BPF_JMP
|BPF_JEQ
|BPF_X
:
177 case BPF_JMP
|BPF_JSET
|BPF_X
:
182 case BPF_ALU
|BPF_ADD
|BPF_X
:
187 case BPF_ALU
|BPF_SUB
|BPF_X
:
192 case BPF_ALU
|BPF_MUL
|BPF_X
:
197 case BPF_ALU
|BPF_DIV
|BPF_X
:
202 case BPF_ALU
|BPF_MOD
|BPF_X
:
207 case BPF_ALU
|BPF_AND
|BPF_X
:
212 case BPF_ALU
|BPF_OR
|BPF_X
:
217 case BPF_ALU
|BPF_XOR
|BPF_X
:
222 case BPF_ALU
|BPF_LSH
|BPF_X
:
227 case BPF_ALU
|BPF_RSH
|BPF_X
:
232 case BPF_ALU
|BPF_ADD
|BPF_K
:
237 case BPF_ALU
|BPF_SUB
|BPF_K
:
242 case BPF_ALU
|BPF_MUL
|BPF_K
:
247 case BPF_ALU
|BPF_DIV
|BPF_K
:
252 case BPF_ALU
|BPF_MOD
|BPF_K
:
257 case BPF_ALU
|BPF_AND
|BPF_K
:
262 case BPF_ALU
|BPF_OR
|BPF_K
:
267 case BPF_ALU
|BPF_XOR
|BPF_K
:
272 case BPF_ALU
|BPF_LSH
|BPF_K
:
277 case BPF_ALU
|BPF_RSH
|BPF_K
:
282 case BPF_ALU
|BPF_NEG
:
287 case BPF_MISC
|BPF_TAX
:
292 case BPF_MISC
|BPF_TXA
:
297 (void)pcap_snprintf(operand
, sizeof operand
, fmt
, v
);
298 if (BPF_CLASS(p
->code
) == BPF_JMP
&& BPF_OP(p
->code
) != BPF_JA
) {
299 (void)pcap_snprintf(image
, sizeof image
,
300 "(%03d) %-8s %-16s jt %d\tjf %d",
301 n
, op
, operand
, n
+ 1 + p
->jt
, n
+ 1 + p
->jf
);
303 (void)pcap_snprintf(image
, sizeof image
,