11077d0bdSPeter Avalos /*
21077d0bdSPeter Avalos * Copyright (c) 1992, 1993, 1994, 1995, 1996
31077d0bdSPeter Avalos * The Regents of the University of California. All rights reserved.
41077d0bdSPeter Avalos *
51077d0bdSPeter Avalos * Redistribution and use in source and binary forms, with or without
61077d0bdSPeter Avalos * modification, are permitted provided that: (1) source code distributions
71077d0bdSPeter Avalos * retain the above copyright notice and this paragraph in its entirety, (2)
81077d0bdSPeter Avalos * distributions including binary code include the above copyright notice and
91077d0bdSPeter Avalos * this paragraph in its entirety in the documentation or other materials
101077d0bdSPeter Avalos * provided with the distribution, and (3) all advertising materials mentioning
111077d0bdSPeter Avalos * features or use of this software display the following acknowledgement:
121077d0bdSPeter Avalos * ``This product includes software developed by the University of California,
131077d0bdSPeter Avalos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
141077d0bdSPeter Avalos * the University nor the names of its contributors may be used to endorse
151077d0bdSPeter Avalos * or promote products derived from this software without specific prior
161077d0bdSPeter Avalos * written permission.
171077d0bdSPeter Avalos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
181077d0bdSPeter Avalos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
191077d0bdSPeter Avalos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
201077d0bdSPeter Avalos */
211077d0bdSPeter Avalos
221077d0bdSPeter Avalos #ifdef HAVE_CONFIG_H
23*3a289941SAaron LI #include <config.h>
241077d0bdSPeter Avalos #endif
251077d0bdSPeter Avalos
261077d0bdSPeter Avalos #include <pcap.h>
271077d0bdSPeter Avalos #include <stdio.h>
281077d0bdSPeter Avalos
29*3a289941SAaron LI #include "optimize.h"
30*3a289941SAaron LI
311077d0bdSPeter Avalos void
bpf_dump(const struct bpf_program * p,int option)32de0d3203SPeter Avalos bpf_dump(const struct bpf_program *p, int option)
331077d0bdSPeter Avalos {
34de0d3203SPeter Avalos const struct bpf_insn *insn;
351077d0bdSPeter Avalos int i;
361077d0bdSPeter Avalos int n = p->bf_len;
371077d0bdSPeter Avalos
381077d0bdSPeter Avalos insn = p->bf_insns;
391077d0bdSPeter Avalos if (option > 2) {
401077d0bdSPeter Avalos printf("%d\n", n);
411077d0bdSPeter Avalos for (i = 0; i < n; ++insn, ++i) {
421077d0bdSPeter Avalos printf("%u %u %u %u\n", insn->code,
431077d0bdSPeter Avalos insn->jt, insn->jf, insn->k);
441077d0bdSPeter Avalos }
451077d0bdSPeter Avalos return ;
461077d0bdSPeter Avalos }
471077d0bdSPeter Avalos if (option > 1) {
481077d0bdSPeter Avalos for (i = 0; i < n; ++insn, ++i)
491077d0bdSPeter Avalos printf("{ 0x%x, %d, %d, 0x%08x },\n",
501077d0bdSPeter Avalos insn->code, insn->jt, insn->jf, insn->k);
511077d0bdSPeter Avalos return;
521077d0bdSPeter Avalos }
531077d0bdSPeter Avalos for (i = 0; i < n; ++insn, ++i) {
541077d0bdSPeter Avalos #ifdef BDEBUG
55*3a289941SAaron LI if (i < NBIDS && bids[i] > 0)
5697a9217aSAntonio Huete Jimenez printf("[%02d]", bids[i] - 1);
5797a9217aSAntonio Huete Jimenez else
5897a9217aSAntonio Huete Jimenez printf(" -- ");
591077d0bdSPeter Avalos #endif
601077d0bdSPeter Avalos puts(bpf_image(insn, i));
611077d0bdSPeter Avalos }
621077d0bdSPeter Avalos }
63