diff --git a/blockip/Makefile b/blockip/Makefile index d79fa3e..15ae467 100644 --- a/blockip/Makefile +++ b/blockip/Makefile @@ -45,6 +45,7 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(DEPS) | $(OBJ_DIR) # 链接生成可执行文件 $(TARGET): $(OBJS) $(CC) $(OBJS) $(LDFLAGS) -o $(TARGET) + @strip $(TARGET) @echo "编译完成: $(TARGET)" # 安装 diff --git a/blockip/bip b/blockip/bip index 26a3e31..c08e051 100644 Binary files a/blockip/bip and b/blockip/bip differ diff --git a/blockip/src/stats.c b/blockip/src/stats.c index 06c2d8a..b41f6a5 100644 --- a/blockip/src/stats.c +++ b/blockip/src/stats.c @@ -182,11 +182,23 @@ void show_subnet_aggregation(void) { } fclose(fp); - /* 第一步:按count降序排序 */ + /* 第一步:按count降序排序,同count时按IP第一段数字排序 */ for (int i = 0; i < agg_count - 1; ++i) { for (int j = i + 1; j < agg_count; ++j) { - if (agg[j].count > agg[i].count || - (agg[j].count == agg[i].count && strcmp(agg[j].subnet, agg[i].subnet) < 0)) { + bool should_swap = false; + + if (agg[j].count > agg[i].count) { + should_swap = true; + } else if (agg[j].count == agg[i].count) { + /* 同count时,按IP第一段数字排序 */ + int ip_i = atoi(agg[i].subnet); + int ip_j = atoi(agg[j].subnet); + if (ip_j < ip_i) { + should_swap = true; + } + } + + if (should_swap) { char tmp_subnet[64]; int tmp_count = agg[i].count, tmp_mask = agg[i].mask; strcpy(tmp_subnet, agg[i].subnet);