1*043fbe51Sderaadt /* $OpenBSD: bpf_dump.c,v 1.8 2009/10/27 23:59:55 deraadt Exp $ */
2cf4e9b47Sho
3df930be7Sderaadt /*
4dc709136Sbitblt * Copyright (c) 1992, 1993, 1994, 1995, 1996
5df930be7Sderaadt * The Regents of the University of California. All rights reserved.
6df930be7Sderaadt *
7df930be7Sderaadt * Redistribution and use in source and binary forms, with or without
8df930be7Sderaadt * modification, are permitted provided that: (1) source code distributions
9df930be7Sderaadt * retain the above copyright notice and this paragraph in its entirety, (2)
10df930be7Sderaadt * distributions including binary code include the above copyright notice and
11df930be7Sderaadt * this paragraph in its entirety in the documentation or other materials
12df930be7Sderaadt * provided with the distribution, and (3) all advertising materials mentioning
13df930be7Sderaadt * features or use of this software display the following acknowledgement:
14df930be7Sderaadt * ``This product includes software developed by the University of California,
15df930be7Sderaadt * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16df930be7Sderaadt * the University nor the names of its contributors may be used to endorse
17df930be7Sderaadt * or promote products derived from this software without specific prior
18df930be7Sderaadt * written permission.
19df930be7Sderaadt * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20df930be7Sderaadt * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21df930be7Sderaadt * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22df930be7Sderaadt */
23df930be7Sderaadt
24df930be7Sderaadt #include <sys/types.h>
25df930be7Sderaadt #include <sys/time.h>
26df930be7Sderaadt
27df930be7Sderaadt #include <pcap.h>
28df930be7Sderaadt #include <stdio.h>
29df930be7Sderaadt
30df930be7Sderaadt #include "interface.h"
31df930be7Sderaadt
32df930be7Sderaadt extern void bpf_dump(struct bpf_program *, int);
33df930be7Sderaadt
34df930be7Sderaadt void
bpf_dump(struct bpf_program * p,int option)35df930be7Sderaadt bpf_dump(struct bpf_program *p, int option)
36df930be7Sderaadt {
37df930be7Sderaadt struct bpf_insn *insn;
38df930be7Sderaadt int i;
39df930be7Sderaadt int n = p->bf_len;
40df930be7Sderaadt
41df930be7Sderaadt insn = p->bf_insns;
42df930be7Sderaadt if (option > 2) {
43df930be7Sderaadt printf("%d\n", n);
44df930be7Sderaadt for (i = 0; i < n; ++insn, ++i) {
45c15d59edSmickey printf("%u %u %u %u\n", insn->code,
46df930be7Sderaadt insn->jt, insn->jf, insn->k);
47df930be7Sderaadt }
48df930be7Sderaadt return ;
49df930be7Sderaadt }
50df930be7Sderaadt if (option > 1) {
51df930be7Sderaadt for (i = 0; i < n; ++insn, ++i)
52df930be7Sderaadt printf("{ 0x%x, %d, %d, 0x%08x },\n",
53df930be7Sderaadt insn->code, insn->jt, insn->jf, insn->k);
54df930be7Sderaadt return;
55df930be7Sderaadt }
56df930be7Sderaadt for (i = 0; i < n; ++insn, ++i) {
57df930be7Sderaadt #ifdef BDEBUG
58df930be7Sderaadt extern int bids[];
59df930be7Sderaadt printf(bids[i] > 0 ? "[%02d]" : " -- ", bids[i] - 1);
60df930be7Sderaadt #endif
61df930be7Sderaadt puts(bpf_image(insn, i));
62df930be7Sderaadt }
63df930be7Sderaadt }
64