1335640Shselasky/* 2335640Shselasky * Copyright (c) 1992, 1993, 1994, 1995, 1996 3335640Shselasky * The Regents of the University of California. All rights reserved. 4335640Shselasky * 5335640Shselasky * Redistribution and use in source and binary forms, with or without 6335640Shselasky * modification, are permitted provided that: (1) source code distributions 7335640Shselasky * retain the above copyright notice and this paragraph in its entirety, (2) 8335640Shselasky * distributions including binary code include the above copyright notice and 9335640Shselasky * this paragraph in its entirety in the documentation or other materials 10335640Shselasky * provided with the distribution, and (3) all advertising materials mentioning 11335640Shselasky * features or use of this software display the following acknowledgement: 12335640Shselasky * ``This product includes software developed by the University of California, 13335640Shselasky * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14335640Shselasky * the University nor the names of its contributors may be used to endorse 15335640Shselasky * or promote products derived from this software without specific prior 16335640Shselasky * written permission. 17335640Shselasky * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18335640Shselasky * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19335640Shselasky * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20335640Shselasky */ 21335640Shselasky 22335640Shselasky#ifdef HAVE_CONFIG_H 23335640Shselasky#include <config.h> 24335640Shselasky#endif 25335640Shselasky 26335640Shselasky#include <pcap.h> 27335640Shselasky#include <stdio.h> 28335640Shselasky 29335640Shselasky#include "optimize.h" 30335640Shselasky 31335640Shselaskyvoid 32335640Shselaskybpf_dump(const struct bpf_program *p, int option) 33335640Shselasky{ 34335640Shselasky const struct bpf_insn *insn; 35335640Shselasky int i; 36335640Shselasky int n = p->bf_len; 37335640Shselasky 38335640Shselasky insn = p->bf_insns; 39335640Shselasky if (option > 2) { 40335640Shselasky printf("%d\n", n); 41335640Shselasky for (i = 0; i < n; ++insn, ++i) { 42335640Shselasky printf("%u %u %u %u\n", insn->code, 43335640Shselasky insn->jt, insn->jf, insn->k); 44335640Shselasky } 45335640Shselasky return ; 46335640Shselasky } 47335640Shselasky if (option > 1) { 48335640Shselasky for (i = 0; i < n; ++insn, ++i) 49335640Shselasky printf("{ 0x%x, %d, %d, 0x%08x },\n", 50335640Shselasky insn->code, insn->jt, insn->jf, insn->k); 51335640Shselasky return; 52335640Shselasky } 53335640Shselasky for (i = 0; i < n; ++insn, ++i) { 54335640Shselasky#ifdef BDEBUG 55335640Shselasky if (i < NBIDS && bids[i] > 0) 56335640Shselasky printf("[%02d]", bids[i] - 1); 57335640Shselasky else 58335640Shselasky printf(" -- "); 59335640Shselasky#endif 60335640Shselasky puts(bpf_image(insn, i)); 61335640Shselasky } 62335640Shselasky} 63