添加gtest测试用例.
This commit is contained in:
@@ -1,2 +1,9 @@
|
||||
all: test_jump_layer gtest_jump_layer
|
||||
|
||||
CFLAGS = -g -Wall -fPIC -std=c++11 -DSAPP_V4=1 -D_XOPEN_SOURCE
|
||||
|
||||
test_jump_layer:test_jump_layer.c
|
||||
gcc -g -o $@ test_jump_layer.c -D_GNU_SOURCE -L/opt/MESA/lib -lMESA_jump_layer -I ../inc -I/opt/MESA/include/MESA -l pcap
|
||||
|
||||
gtest_jump_layer:gtest_jump_layer.cpp
|
||||
g++ -g -o $@ $^ $(CFLAGS) -D_GNU_SOURCE -L/opt/MESA/lib -lMESA_jump_layer -I ../inc -I/opt/MESA/include/MESA -lpcap -lgtest -lpthread
|
||||
|
||||
1185
test/gtest_jump_layer.cpp
Normal file
1185
test/gtest_jump_layer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
BIN
test/sample_pcap/tcp_simple.pcap
Normal file
BIN
test/sample_pcap/tcp_simple.pcap
Normal file
Binary file not shown.
@@ -11,6 +11,9 @@ static char *g_input_pcap_name;
|
||||
static char *g_input_bpf_string;
|
||||
static struct bpf_program g_bpf_filter;
|
||||
|
||||
static int g_raw_input_layer_type = (int )ADDR_TYPE_MAC;
|
||||
static int g_expect_layer_type = (int )ADDR_TYPE_IPV4;
|
||||
|
||||
static void usage(const char *prog)
|
||||
{
|
||||
printf("Usage:\n");
|
||||
@@ -59,9 +62,68 @@ static int pcap_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _pcap_pkt_handle(u_char *user, const struct pcap_pkthdr *hdr, const u_char *data)
|
||||
static void _jump_from_udp(const void *uhdr)
|
||||
{
|
||||
const void *next_hdr;
|
||||
|
||||
next_hdr = MESA_jump_layer(uhdr, ADDR_TYPE_UDP, ADDR_TYPE_GPRS_TUNNEL);
|
||||
if(next_hdr){
|
||||
printf("bingo! jump to gtp from udp succ!\n");
|
||||
}
|
||||
|
||||
next_hdr = MESA_jump_layer(uhdr, ADDR_TYPE_UDP, ADDR_TYPE_L2TP);
|
||||
if(next_hdr){
|
||||
printf("bingo! jump to l2tp from udp succ!\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void _jump_from_ipv4(const void *ip4_hdr)
|
||||
{
|
||||
const void *next_hdr;
|
||||
|
||||
next_hdr = MESA_jump_layer(ip4_hdr, ADDR_TYPE_IPV4, ADDR_TYPE_TCP);
|
||||
if(next_hdr){
|
||||
printf("bingo! jump to tcp from ipv4 succ!\n");
|
||||
}
|
||||
|
||||
next_hdr = MESA_jump_layer(ip4_hdr, ADDR_TYPE_IPV4, ADDR_TYPE_UDP);
|
||||
if(next_hdr){
|
||||
printf("bingo! jump to udp from ipv4 succ!\n");
|
||||
_jump_from_udp(next_hdr);
|
||||
}
|
||||
}
|
||||
|
||||
static void _jump_from_ipv6(const void *ip4_hdr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void _jump_from_ethernet(const void *ehdr)
|
||||
{
|
||||
const void *next_hdr;
|
||||
|
||||
next_hdr = MESA_jump_layer(ehdr, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
||||
if(next_hdr){
|
||||
printf("bingo! jump to ipv4 from ethernet succ!\n");
|
||||
_jump_from_ipv4(next_hdr);
|
||||
}
|
||||
|
||||
next_hdr = MESA_jump_layer(ehdr, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
|
||||
if(next_hdr){
|
||||
printf("bingo! jump to ipv6 from ethernet succ!\n");
|
||||
_jump_from_ipv6(next_hdr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void _jump_greedy(const struct pcap_pkthdr *hdr, const u_char *data)
|
||||
{
|
||||
const void *ip4_hdr, *ip6_h;
|
||||
|
||||
char print_buf[128];
|
||||
int offset_to_eth;
|
||||
static int pkt_index = 0;
|
||||
@@ -69,6 +131,7 @@ static void _pcap_pkt_handle(u_char *user, const struct pcap_pkthdr *hdr, const
|
||||
ip4_hdr = MESA_jump_layer_greedy(data, ADDR_TYPE_MAC, ADDR_TYPE_IPV4);
|
||||
ip6_h = MESA_jump_layer_greedy(data, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
|
||||
|
||||
|
||||
printf("-----------------------------packet index:%d------------------------------------------\n", pkt_index++);
|
||||
if(ip4_hdr){
|
||||
offset_to_eth = (u_char *)ip4_hdr-data;
|
||||
@@ -92,6 +155,16 @@ static void _pcap_pkt_handle(u_char *user, const struct pcap_pkthdr *hdr, const
|
||||
done:
|
||||
|
||||
printf("--------------------------------------------------------------------------------------\n\n");
|
||||
|
||||
}
|
||||
|
||||
static void _pcap_pkt_handle(u_char *user, const struct pcap_pkthdr *hdr, const u_char *data)
|
||||
{
|
||||
|
||||
_jump_from_ethernet(data);
|
||||
|
||||
_jump_greedy(hdr, data);
|
||||
|
||||
}
|
||||
|
||||
static void pcap_run(void)
|
||||
|
||||
Reference in New Issue
Block a user