修改目录结构

This commit is contained in:
2024-10-16 10:00:47 +08:00
parent 82b400b45c
commit 7b1e27db87
16 changed files with 27 additions and 13 deletions

View File

@@ -1,17 +1,16 @@
CROSS_COMPILE ?= CROSS_COMPILE ?=
CC := $(CROSS_COMPILE)gcc CC := $(CROSS_COMPILE)gcc
STRIP := $(CROSS_COMPILE)strip STRIP := $(CROSS_COMPILE)strip
CFLAGS += -g -Os -Wall CFLAGS += -g -Os -Wall -Iip2region -Iqqwry
LIBS = -lm -static LIBS = -lm -static
OBJ := denyip BIN := denyip
all: main.o ip2region.o xdb_searcher.o qqwry.o all: main.o ip2region/ip2region.o ip2region/xdb_searcher.o qqwry/qqwry.o
$(CC) $(CFLAGS) -o $(OBJ) $^ $(LIBS) $(CC) $(CFLAGS) -o $(BIN) $^ $(LIBS)
.c.o:
$(CC) $(CFLAGS) -c $< %.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
clean: clean:
rm -rf *.o rm -rf $(BIN)
rm -rf $(OBJ) rm -rf main.o ip2region/ip2region.o ip2region/xdb_searcher.o qqwry/qqwry.o

BIN
denyip

Binary file not shown.

13
main.c
View File

@@ -145,6 +145,7 @@ void restart_process(pid_t pid1, pid_t pid2, char *argv[])
void cleanup_(int signum) void cleanup_(int signum)
{ {
int r;
printf("Received signal %d, cleaning up...\n", signum); printf("Received signal %d, cleaning up...\n", signum);
// 终止子进程 // 终止子进程
@@ -154,10 +155,14 @@ void cleanup_(int signum)
if (pid2 > 0) { if (pid2 > 0) {
kill(pid2, SIGTERM); kill(pid2, SIGTERM);
} }
// 终止所有 tcpdump 进程
system("pkill tcpdump");
// 退出主进程 // 终止所有 tcpdump 进程
r = system("pkill tcpdump");
if (r == 0) {
puts("pkill tcpdump");
}
// 退出主进程
exit(0); exit(0);
return ; return ;
@@ -242,6 +247,7 @@ int main(int argc, char *argv[])
r = system("apt -y install tcpdump > /dev/null 2>&1"); r = system("apt -y install tcpdump > /dev/null 2>&1");
} }
// 子进程 // 子进程
pid1 = fork(); // 创建子进程 pid1 = fork(); // 创建子进程
if (pid1 == 0) { if (pid1 == 0) {
@@ -262,6 +268,7 @@ int main(int argc, char *argv[])
sleep(3); sleep(3);
} }
} }
// 子进程 // 子进程
pid2 = fork(); // 创建子进程 pid2 = fork(); // 创建子进程
if (pid2 == 0) { if (pid2 == 0) {

BIN
main.o

Binary file not shown.

BIN
qqwry.o

Binary file not shown.

View File

@@ -349,6 +349,14 @@ int get_location(char *ip)
char *qqwry_(char *ip) char *qqwry_(char *ip)
{ {
char *qqdb_path = "qqwry.dat";
if (access(qqdb_path, F_OK) == -1) { // 判断 ip2region 地址定位库是否存在
qqdb_path = "qqwry/qqwry.dat";
if (access(qqdb_path, F_OK) == -1) {
printf("qqwry.dat DOESN'T EXIST!\n");
return NULL;
}
}
qqwry_init("qqwry.dat"); qqwry_init("qqwry.dat");

BIN
qqwry/qqwry.o Normal file

Binary file not shown.