175107Sfenner/*
275107Sfenner * Copyright (c) 1992, 1993, 1994, 1995, 1996
375107Sfenner *	The Regents of the University of California.  All rights reserved.
475107Sfenner *
575107Sfenner * Redistribution and use in source and binary forms, with or without
675107Sfenner * modification, are permitted provided that: (1) source code distributions
775107Sfenner * retain the above copyright notice and this paragraph in its entirety, (2)
875107Sfenner * distributions including binary code include the above copyright notice and
975107Sfenner * this paragraph in its entirety in the documentation or other materials
1075107Sfenner * provided with the distribution, and (3) all advertising materials mentioning
1175107Sfenner * features or use of this software display the following acknowledgement:
1275107Sfenner * ``This product includes software developed by the University of California,
1375107Sfenner * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1475107Sfenner * the University nor the names of its contributors may be used to endorse
1575107Sfenner * or promote products derived from this software without specific prior
1675107Sfenner * written permission.
1775107Sfenner * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1875107Sfenner * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1975107Sfenner * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2075107Sfenner */
2175107Sfenner#ifndef lint
22127664Sbmsstatic const char rcsid[] _U_ =
23214518Srpaulo    "@(#) $Header: /tcpdump/master/libpcap/bpf_dump.c,v 1.15 2008-01-02 04:16:46 guy Exp $ (LBL)";
2475107Sfenner#endif
2575107Sfenner
2675107Sfenner#ifdef HAVE_CONFIG_H
2775107Sfenner#include "config.h"
2875107Sfenner#endif
2975107Sfenner
3075107Sfenner#include <pcap.h>
3175107Sfenner#include <stdio.h>
3275107Sfenner
3375107Sfennervoid
34190944Srpaulobpf_dump(struct bpf_program *p, int option)
3575107Sfenner{
36190225Srpaulo	const struct bpf_insn *insn;
3775107Sfenner	int i;
3875107Sfenner	int n = p->bf_len;
3975107Sfenner
4075107Sfenner	insn = p->bf_insns;
4175107Sfenner	if (option > 2) {
4275107Sfenner		printf("%d\n", n);
4375107Sfenner		for (i = 0; i < n; ++insn, ++i) {
4475107Sfenner			printf("%u %u %u %u\n", insn->code,
4575107Sfenner			       insn->jt, insn->jf, insn->k);
4675107Sfenner		}
4775107Sfenner		return ;
4875107Sfenner	}
4975107Sfenner	if (option > 1) {
5075107Sfenner		for (i = 0; i < n; ++insn, ++i)
5175107Sfenner			printf("{ 0x%x, %d, %d, 0x%08x },\n",
5275107Sfenner			       insn->code, insn->jt, insn->jf, insn->k);
5375107Sfenner		return;
5475107Sfenner	}
5575107Sfenner	for (i = 0; i < n; ++insn, ++i) {
5675107Sfenner#ifdef BDEBUG
5775107Sfenner		extern int bids[];
5875107Sfenner		printf(bids[i] > 0 ? "[%02d]" : " -- ", bids[i] - 1);
5975107Sfenner#endif
6075107Sfenner		puts(bpf_image(insn, i));
6175107Sfenner	}
6275107Sfenner}
63