117680Spst/* 226180Sfenner * Copyright (c) 1992, 1993, 1994, 1995, 1996 317680Spst * The Regents of the University of California. All rights reserved. 417680Spst * 517680Spst * Redistribution and use in source and binary forms, with or without 617680Spst * modification, are permitted provided that: (1) source code distributions 717680Spst * retain the above copyright notice and this paragraph in its entirety, (2) 817680Spst * distributions including binary code include the above copyright notice and 917680Spst * this paragraph in its entirety in the documentation or other materials 1017680Spst * provided with the distribution, and (3) all advertising materials mentioning 1117680Spst * features or use of this software display the following acknowledgement: 1217680Spst * ``This product includes software developed by the University of California, 1317680Spst * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 1417680Spst * the University nor the names of its contributors may be used to endorse 1517680Spst * or promote products derived from this software without specific prior 1617680Spst * written permission. 1717680Spst * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 1817680Spst * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 1917680Spst * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 2017680Spst */ 2117680Spst#ifndef lint 22127668Sbmsstatic const char rcsid[] _U_ = 23214478Srpaulo "@(#) $Header: /tcpdump/master/tcpdump/bpf_dump.c,v 1.17 2008-02-14 20:53:49 guy Exp $ (LBL)"; 2417680Spst#endif 2517680Spst 2656893Sfenner#ifdef HAVE_CONFIG_H 2756893Sfenner#include "config.h" 2856893Sfenner#endif 2956893Sfenner 30127668Sbms#include <tcpdump-stdinc.h> 3117680Spst 3217680Spst#include <pcap.h> 3317680Spst#include <stdio.h> 3417680Spst 3517680Spst#include "interface.h" 3617680Spst 3717680Spstvoid 38190207Srpaulobpf_dump(const struct bpf_program *p, int option) 3917680Spst{ 4017680Spst struct bpf_insn *insn; 4117680Spst int i; 4217680Spst int n = p->bf_len; 4317680Spst 4417680Spst insn = p->bf_insns; 4517680Spst if (option > 2) { 4617680Spst printf("%d\n", n); 4717680Spst for (i = 0; i < n; ++insn, ++i) { 4817680Spst printf("%u %u %u %u\n", insn->code, 4917680Spst insn->jt, insn->jf, insn->k); 5017680Spst } 5117680Spst return ; 5217680Spst } 5317680Spst if (option > 1) { 5417680Spst for (i = 0; i < n; ++insn, ++i) 5517680Spst printf("{ 0x%x, %d, %d, 0x%08x },\n", 5617680Spst insn->code, insn->jt, insn->jf, insn->k); 5717680Spst return; 5817680Spst } 5917680Spst for (i = 0; i < n; ++insn, ++i) { 6017680Spst#ifdef BDEBUG 6117680Spst extern int bids[]; 6217680Spst printf(bids[i] > 0 ? "[%02d]" : " -- ", bids[i] - 1); 6317680Spst#endif 6417680Spst puts(bpf_image(insn, i)); 6517680Spst } 6617680Spst} 67