优化
This commit is contained in:
10
cap.c
10
cap.c
@@ -23,6 +23,7 @@ char *command_result = NULL; // 执行命令的结果
|
||||
|
||||
void Processing_IP_addresses(char *src_ip)
|
||||
{
|
||||
|
||||
// 地域白名单
|
||||
char _region_list[WHITELIST_IP_NUM][WHITELIST_IP_NUM] = { { 0 }, { 0 } };
|
||||
char _REGION_LIST[BUFFER] = { 0 };
|
||||
@@ -108,11 +109,11 @@ void Processing_IP_addresses(char *src_ip)
|
||||
fprintf(stderr, "Failed to parse JSON.\n");
|
||||
}
|
||||
|
||||
if (p != NULL)
|
||||
if (p != NULL) {
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ip2region_area != NULL) {
|
||||
free(ip2region_area);
|
||||
ip2region_area = NULL;
|
||||
@@ -125,9 +126,14 @@ void Processing_IP_addresses(char *src_ip)
|
||||
void packet_handler(u_char *args, const struct pcap_pkthdr *header, const u_char *packet)
|
||||
{
|
||||
int ethernet_header_len = 14;
|
||||
//struct ip *ip_header = (struct ip *)(packet + ethernet_header_len);
|
||||
struct ip *ip_header = (struct ip *)(packet + ethernet_header_len);
|
||||
if (ip_header->ip_v != 4) return; // 只处理 IPv4
|
||||
|
||||
char src_ip[INET_ADDRSTRLEN] = { 0 };
|
||||
|
||||
|
||||
|
||||
inet_ntop(AF_INET, &(ip_header->ip_src), src_ip, INET_ADDRSTRLEN);
|
||||
Processing_IP_addresses(src_ip);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user