bpf_dump.c revision 75107
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 2275107Sfennerstatic const char rcsid[] = 2375107Sfenner "@(#) $Header: /tcpdump/master/libpcap/bpf_dump.c,v 1.12 2000/06/26 04:17:05 assar Exp $ (LBL)"; 2475107Sfenner#endif 2575107Sfenner 2675107Sfenner#ifdef HAVE_CONFIG_H 2775107Sfenner#include "config.h" 2875107Sfenner#endif 2975107Sfenner 3075107Sfenner#include <sys/types.h> 3175107Sfenner#include <sys/time.h> 3275107Sfenner 3375107Sfenner#include <pcap.h> 3475107Sfenner#include <stdio.h> 3575107Sfenner 3675107Sfennervoid 3775107Sfennerbpf_dump(struct bpf_program *p, int option) 3875107Sfenner{ 3975107Sfenner struct bpf_insn *insn; 4075107Sfenner int i; 4175107Sfenner int n = p->bf_len; 4275107Sfenner 4375107Sfenner insn = p->bf_insns; 4475107Sfenner if (option > 2) { 4575107Sfenner printf("%d\n", n); 4675107Sfenner for (i = 0; i < n; ++insn, ++i) { 4775107Sfenner printf("%u %u %u %u\n", insn->code, 4875107Sfenner insn->jt, insn->jf, insn->k); 4975107Sfenner } 5075107Sfenner return ; 5175107Sfenner } 5275107Sfenner if (option > 1) { 5375107Sfenner for (i = 0; i < n; ++insn, ++i) 5475107Sfenner printf("{ 0x%x, %d, %d, 0x%08x },\n", 5575107Sfenner insn->code, insn->jt, insn->jf, insn->k); 5675107Sfenner return; 5775107Sfenner } 5875107Sfenner for (i = 0; i < n; ++insn, ++i) { 5975107Sfenner#ifdef BDEBUG 6075107Sfenner extern int bids[]; 6175107Sfenner printf(bids[i] > 0 ? "[%02d]" : " -- ", bids[i] - 1); 6275107Sfenner#endif 6375107Sfenner puts(bpf_image(insn, i)); 6475107Sfenner } 6575107Sfenner} 66