Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI

on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
build_type: [Release]

steps:
- uses: actions/checkout@v4

- name: Install dependencies (Ubuntu)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
cmake \
libpcap-dev \
libjson-c-dev \
pkg-config \
libgtest-dev

- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew install \
cmake \
libpcap \
json-c \
pkg-config \
googletest

- name: Build
run: |
make clean
make BUILD_TYPE=${{matrix.build_type}}

- name: Verify executable
run: |
ls -la bin/
./bin/http-sniffer --help

- name: Run unit tests
run: |
make test
123 changes: 121 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,129 @@
# Build directories
bin/*
lib/*
build/
out/
dist/
target/

# IDE and editor files
.idea/
*.iml
.vscode/
*.swp
*.swo
*~

# Compiled object files
*.o
*.obj
*.ko
*.elf

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.x*.app
*.ipa
*.apk

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

# Database files
*.dblite
lib/*
*.db
*.sqlite
*.sqlite3

# Log files
*.log
*.txt
*.o

# Temporary files
*.tmp
*.temp
*.bak
*.backup
*.orig

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# CMake
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
*.cmake
!CMakeLists.txt

# SCons
.sconsign.dblite
.sconf_temp/

# Coverage reports
*.gcov
*.gcda
*.gcno
coverage/
*.info

# Profiling
*.prof
gmon.out

# Valgrind
valgrind-out.txt

# Doxygen
doxygen/

# Package files
*.tar.gz
*.tar.bz2
*.zip
*.rar

# Backup files
*~
*.swp
*.swo
*#

# Test files
test_*
*_test
*.test
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

152 changes: 152 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
cmake_minimum_required(VERSION 3.10)
project(http-sniffer C CXX)

# Set C standard
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)

# Set compiler flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w -g")

# Find required packages
find_package(PkgConfig REQUIRED)
find_package(Threads REQUIRED)

# Find Google Test (optional for unit tests)
find_package(GTest QUIET)

if(GTest_FOUND)
message(STATUS "Google Test found - unit tests enabled")
set(ENABLE_TESTS ON)
else()
message(STATUS "Google Test not found - unit tests will be disabled")
set(ENABLE_TESTS OFF)
endif()

# Find pcap library
find_library(PCAP_LIBRARY pcap)
if(NOT PCAP_LIBRARY)
message(FATAL_ERROR "pcap library not found. Please install libpcap-dev")
endif()

# Find json-c library
find_library(JSON_C_LIBRARY json-c)
if(NOT JSON_C_LIBRARY)
message(FATAL_ERROR "json-c library not found. Please install libjson-c-dev")
endif()

# Find json-c headers
find_path(JSON_C_INCLUDE_DIR json-c/json.h
PATHS
/usr/include
/usr/local/include
/opt/homebrew/include
/opt/local/include
)

if(NOT JSON_C_INCLUDE_DIR)
message(FATAL_ERROR "json-c headers not found. Please install libjson-c-dev")
endif()

# Check for NFM libraries (optional, controlled by debug flag)
option(ENABLE_NFM "Enable NFM libraries for network processor card driver" OFF)

if(ENABLE_NFM)
message(STATUS "NFM enabled.")
set(NFM_LIBRARIES
nfm
nfm_framework
nfm_error
nfm_packet
nfm_rules
nfm_platform
nfe
nfp
)

# Add NFM include and library paths
list(APPEND CMAKE_PREFIX_PATH "/opt/netronome")
include_directories("/opt/netronome/nfm/include")
link_directories("/opt/netronome/lib")
endif()

# Set include directories
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${JSON_C_INCLUDE_DIR})

# Collect all source files
file(GLOB SOURCES "src/*.c")

# Create executable
add_executable(http-sniffer ${SOURCES})

# Link libraries
target_link_libraries(http-sniffer
${PCAP_LIBRARY}
${JSON_C_LIBRARY}
Threads::Threads
)

# Add NFM libraries if enabled
if(ENABLE_NFM)
target_link_libraries(http-sniffer ${NFM_LIBRARIES})
endif()

# Set output directory
set_target_properties(http-sniffer PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin
)

# Unit tests
if(ENABLE_TESTS)
enable_testing()

# Collect test source files and application source files (excluding main.c)
file(GLOB TEST_SOURCES "tests/*.cpp")
file(GLOB APP_SOURCES "src/*.c")
list(REMOVE_ITEM APP_SOURCES "${CMAKE_SOURCE_DIR}/src/main.c")

# Create test executable (C++ for Google Test)
add_executable(unit-tests ${TEST_SOURCES} ${APP_SOURCES})
set_target_properties(unit-tests PROPERTIES
LINKER_LANGUAGE CXX
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
)

# Link test libraries
target_link_libraries(unit-tests
${PCAP_LIBRARY}
${JSON_C_LIBRARY}
Threads::Threads
GTest::gtest
GTest::gtest_main
)

# Include directories for tests
target_include_directories(unit-tests PRIVATE
${CMAKE_SOURCE_DIR}/include
${JSON_C_INCLUDE_DIR}
)

# Set output directory for tests
set_target_properties(unit-tests PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin
)

# Add test
add_test(NAME UnitTests COMMAND unit-tests)

message(STATUS "Unit tests enabled")
else()
message(STATUS "Unit tests disabled - missing dependencies")
endif()

# Print status messages
message(STATUS "Checking pthread ... true")
message(STATUS "Checking pcap ... true")
message(STATUS "Checking json-c ... true")

if(ENABLE_NFM)
message(STATUS "NFM libraries enabled")
endif()
Loading
Loading