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