10 * debug/add pdump/packetin
11 * debug/add pdump/packetout
15 // TODO per-port dump(file?)
16 int pktevent(struct dbgcl
*tag
,va_list v
);
18 char errbuf
[PCAP_ERRBUF_SIZE
];
20 pcap_dumper_t
*dumper
= NULL
;
21 char *dumpfile
= "vde_dump.cap";
23 struct plugin vde_plugin_data
={
25 .help
="dump packets to file, in pcap format",
28 // FIXME check if dumpfile exists, it will be trucated
29 static int dump(char *arg
)
34 // TODO configurable snaplen
36 desc
= pcap_open_dead(DLT_EN10MB
, 96);
39 dumper
= pcap_dump_open(desc
, dumpfile
);
41 rv
=eventadd(pktevent
,"packet",NULL
);
43 rv
=eventdel(pktevent
,"packet",NULL
);
46 pcap_dump_flush(dumper
);
52 static int setfname(FILE *fd
, char *arg
)
56 pcap_dump_close(dumper
);
58 dumpfile
= strdup(arg
);
60 desc
= pcap_open_dead(DLT_EN10MB
, 96);
61 dumper
= pcap_dump_open(desc
, dumpfile
);
64 printoutc(fd
, "dumpfile=%s", dumpfile
);
69 static struct comlist cl
[]={
70 {"pdump","============","DUMP Packets to file",NULL
,NOARG
},
71 {"pdump/active","0/1","start dumping data",dump
,STRARG
},
72 {"pdump/filename", "<file>", "set/show output filename (default: vde_dump.cap)", setfname
, STRARG
|WITHFILE
},
76 * pcap_t *pcap_open_dead(int linktype, int snaplen)
77 * int pcap_compile(pcap_t *p, struct bpf_program *fp,
78 * char *str, int optimize, bpf_u_int32 netmask)
79 * int pcap_setfilter(pcap_t *p, struct bpf_program *fp)
80 * void pcap_freecode(struct bpf_program *)
83 // TODO activate debug as well when activated?
85 static struct dbgcl dl
[]= {
86 {"pdump/packetin","dump incoming packet to file",D_DUMP
|D_IN
},
87 {"pdump/packetout","dump outgoing packet to file",D_DUMP
|D_OUT
},
91 int pktevent(struct dbgcl
*event
,va_list v
)
93 // forse meglio static?
94 struct pcap_pkthdr hdr
;
96 if( (desc
== NULL
) || (dumper
== NULL
) ){
100 switch (event
->tag
) {
102 case D_PACKET
|D_IN
: {
103 int port
=va_arg(v
,int);
104 unsigned char *buf
=va_arg(v
,char *);
105 int len
=va_arg(v
,int);
107 gettimeofday(&hdr
.ts
, NULL
);
110 pcap_dump((u_char
*)dumper
, &hdr
, buf
);
117 __attribute__ ((constructor
))
125 __attribute__ ((destructor
))
129 pcap_dump_close(dumper
);