bpf_dump.c revision 190944
124139Sjoerg/*
224139Sjoerg * Copyright (c) 1992, 1993, 1994, 1995, 1996
324139Sjoerg *	The Regents of the University of California.  All rights reserved.
424139Sjoerg *
524139Sjoerg * Redistribution and use in source and binary forms, with or without
624139Sjoerg * modification, are permitted provided that: (1) source code distributions
724139Sjoerg * retain the above copyright notice and this paragraph in its entirety, (2)
824139Sjoerg * distributions including binary code include the above copyright notice and
924139Sjoerg * this paragraph in its entirety in the documentation or other materials
1024139Sjoerg * provided with the distribution, and (3) all advertising materials mentioning
1124139Sjoerg * features or use of this software display the following acknowledgement:
1224139Sjoerg * ``This product includes software developed by the University of California,
1324139Sjoerg * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1424139Sjoerg * the University nor the names of its contributors may be used to endorse
1524139Sjoerg * or promote products derived from this software without specific prior
1624139Sjoerg * written permission.
1724139Sjoerg * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1824139Sjoerg * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1924139Sjoerg * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2024139Sjoerg */
2124139Sjoerg#ifndef lint
2224139Sjoergstatic const char rcsid[] _U_ =
2324139Sjoerg    "@(#) $Header: /tcpdump/master/libpcap/bpf_dump.c,v 1.14.4.1 2008/01/02 04:22:16 guy Exp $ (LBL)";
2424139Sjoerg#endif
2524139Sjoerg
26#ifdef HAVE_CONFIG_H
27#include "config.h"
28#endif
29
30#include <pcap.h>
31#include <stdio.h>
32
33void
34bpf_dump(struct bpf_program *p, int option)
35{
36	const struct bpf_insn *insn;
37	int i;
38	int n = p->bf_len;
39
40	insn = p->bf_insns;
41	if (option > 2) {
42		printf("%d\n", n);
43		for (i = 0; i < n; ++insn, ++i) {
44			printf("%u %u %u %u\n", insn->code,
45			       insn->jt, insn->jf, insn->k);
46		}
47		return ;
48	}
49	if (option > 1) {
50		for (i = 0; i < n; ++insn, ++i)
51			printf("{ 0x%x, %d, %d, 0x%08x },\n",
52			       insn->code, insn->jt, insn->jf, insn->k);
53		return;
54	}
55	for (i = 0; i < n; ++insn, ++i) {
56#ifdef BDEBUG
57		extern int bids[];
58		printf(bids[i] > 0 ? "[%02d]" : " -- ", bids[i] - 1);
59#endif
60		puts(bpf_image(insn, i));
61	}
62}
63