Optimize integration testing
- Add injection package plug-in - Add libstellar_dynamic.so to facilitate unit testing of upper-level plug-ins
This commit is contained in:
57
test/packet_parser/packet_parser.cpp
Normal file
57
test/packet_parser/packet_parser.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <unistd.h>
|
||||
#include <pcap/pcap.h>
|
||||
#include "packet_priv.h"
|
||||
|
||||
static void packet_handler(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes)
|
||||
{
|
||||
struct packet pkt;
|
||||
packet_parse(&pkt, (const char *)bytes, h->caplen);
|
||||
packet_print_table(&pkt);
|
||||
}
|
||||
|
||||
static void usage(char *cmd)
|
||||
{
|
||||
printf("Usage: %s\n", cmd);
|
||||
printf("Options:\n");
|
||||
printf(" -f <pcap file> pcap file\n");
|
||||
printf(" -h print help\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int opt = 0;
|
||||
char *file = NULL;
|
||||
while ((opt = getopt(argc, argv, "f:h")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'f':
|
||||
file = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
usage(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pcap_t *pcap = pcap_open_offline(file, NULL);
|
||||
if (pcap == NULL)
|
||||
{
|
||||
printf("pcap_open_offline() failed\n");
|
||||
return -1;
|
||||
}
|
||||
pcap_loop(pcap, -1, packet_handler, NULL);
|
||||
pcap_close(pcap);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user