commit 93258ec1fc91d68016112d4a72f8d4b8473d4d9a Author: xiaoan <419177984@qq.com> Date: Sat Oct 31 09:46:12 2026 +0800 创建项目结构v0.1.0 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..00a5a8b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# 编译产物 +build/ \ No newline at end of file diff --git a/READEME.md b/READEME.md new file mode 100644 index 0000000..341a16c --- /dev/null +++ b/READEME.md @@ -0,0 +1,5 @@ +NetSentry:高性能网络流量实时分析与入侵检测引擎(mini-NIDS) + + +一句话定义:用 C++11 从零写一个用户态流量检测引擎——读取 pcap 流量包(进阶:在线抓包),多线程流水线解析协议,基于规则库(类 Snort 语法)实时匹配攻击特征并输出告警,附带性能统计报告。 + diff --git a/netsentry/CMakeLists.txt b/netsentry/CMakeLists.txt new file mode 100644 index 0000000..9a98924 --- /dev/null +++ b/netsentry/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.10) +project(netsentry CXX) + +# ---- 全局语言标准:C++11,写死,不给编译器自由发挥的机会 ---- +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) # 编译器不支持 C++11 就直接报错,而不是悄悄降级 +set(CMAKE_CXX_EXTENSIONS OFF) # 用 -std=c++11,而不是 -std=gnu++11 + +# 不指定构建类型时默认 Debug,保证第一次跑就有调试信息 +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Debug) + message(STATUS "No build type specified, defaulting to Debug") +endif() + +add_subdirectory(src) +# add_subdirectory(tests) # 下一步接好 GoogleTest 后打开 diff --git a/netsentry/include/netsentry/version.h b/netsentry/include/netsentry/version.h new file mode 100644 index 0000000..7e13bab --- /dev/null +++ b/netsentry/include/netsentry/version.h @@ -0,0 +1,17 @@ +#ifndef NETSENTRY_VERSION_H +#define NETSENTRY_VERSION_H + + +namespace netsentry { + + + //只声明,不定义。定义放在stc/version中 + extern const char* const kVersion; + + + +} //namespace netsentry + + + +#endif \ No newline at end of file diff --git a/netsentry/src/CMakeLists.txt b/netsentry/src/CMakeLists.txt new file mode 100644 index 0000000..9023a20 --- /dev/null +++ b/netsentry/src/CMakeLists.txt @@ -0,0 +1,13 @@ +# ---- 核心静态库:以后所有模块代码都长在这里 ---- +add_library(netsentry_core STATIC + version.cpp +) + +# 对外暴露头文件目录。PUBLIC 的意思是:链接我这个库的目标,自动继承这个 include 路径 +target_include_directories(netsentry_core PUBLIC ${PROJECT_SOURCE_DIR}/include) +target_compile_options(netsentry_core PRIVATE -Wall -Wextra) + +# ---- 可执行文件:只负责组装入口,业务逻辑都放 core 里 ---- +add_executable(netsentry main.cpp) +target_link_libraries(netsentry PRIVATE netsentry_core) +target_compile_options(netsentry PRIVATE -Wall -Wextra) diff --git a/netsentry/src/main.cpp b/netsentry/src/main.cpp new file mode 100644 index 0000000..86fa15c --- /dev/null +++ b/netsentry/src/main.cpp @@ -0,0 +1,14 @@ +#include + +#include "netsentry/version.h" + +int main(int argc,char* argv[]) +{ + //阶段1的任务,这里会替换成为真正的命令行解析,先占位 + std::cout << "Netsentry v" << netsentry::kVersion << "\n"; + std::cout << "Usage:netsentry -r \n"; + (void)argc; + (void)argv; + + return 0; +} \ No newline at end of file diff --git a/netsentry/src/version.cpp b/netsentry/src/version.cpp new file mode 100644 index 0000000..b4c8943 --- /dev/null +++ b/netsentry/src/version.cpp @@ -0,0 +1,7 @@ +#include "netsentry/version.h" + +namespace netsentry{ + + const char* const kVersion = "0.1.0"; + +} \ No newline at end of file