Skip to content
Open
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
40 changes: 40 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: cmake

'on':
pull_request:
push:
branches:
- master
- develop
- feature/**

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
runs-on: ubuntu-${{ matrix.ubuntu_version }}
name: Ubuntu-${{ matrix.ubuntu_version }}
strategy:
fail-fast: false
matrix:
ubuntu_version: [22.04]

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0


- name: Install packages
run: |
sudo apt-get install -y gcc g++ cmake wget git libdumbnet-dev libpcap-dev


- name: Configure
run: cmake -DCMAKE_BUILD_TYPE="${{env.BUILD_TYPE}}" -B "${{github.workspace}}/build"

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
53 changes: 53 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cmake_minimum_required(VERSION 3.14)

project(usipp LANGUAGES C CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set (CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

find_package(PCAP REQUIRED)
find_package(DUMBNET REQUIRED)


# Checks for header files.
include(CheckIncludeFiles)
foreach (header stdbool.h stdint.h stdlib.h strings.h string.h sys/ioctl.h sys/stat.h
sys/types.h unistd.h netdb.h netinet/in.h inttypes.h memory.h)
string(TOUPPER HAVE_${header} var)
string(REGEX REPLACE "\\.|/" "_" var ${var})
check_include_files(${header} ${var})
message(STATUS "${var}")
endforeach ()
check_include_files(stdio.h STDC_HEADERS)

include(CheckFunctionExists)
set(CMAKE_REQUIRED_LIBRARIES )
check_function_exists(gethostbyaddr HAVE_GETHOSTBYADDR)
check_function_exists(gethostbyname HAVE_GETHOSTBYNAME)
check_function_exists(gethostname HAVE_GETHOSTNAME)
check_function_exists(inet_ntoa HAVE_INET_NTOA)
check_function_exists(memset HAVE_MEMSET)
check_function_exists(select HAVE_SELECT)
check_function_exists(socket HAVE_SOCKET)
check_function_exists(strerror HAVE_STRERROR)


if (${HAVE_SOCKET})
set(HAVE_LIBSOCKET True)
endif()

configure_file(config.h.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)

file(GLOB_RECURSE files_cpp src/*.cc)
file(GLOB_RECURSE files_h usi++/*.h)

add_library(
${PROJECT_NAME} STATIC
${files_cpp} ${files_h})


target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(${PROJECT_NAME} PUBLIC pcap dumbnet)

add_subdirectory(samples)
61 changes: 61 additions & 0 deletions cmake/FindDUMBNET.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# - Try to find libdumbnet include dirs and libraries
#
# Usage of this module as follows:
#
# find_package(DUMBNET)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# DUMPNET_ROOT_DIR Set this variable to the root installation of
# libpcap if the module has problems finding the
# proper installation path.
#
# Variables defined by this module:
#
# DUMBNET_INCLUDE_DIR The libdumbnet include directories
# DUMBNET_LIBRARY The libdumbnet library
# DUMBNET_FOUND System has libdumbnet, include and library dirs found
# HAVE_LIBDUMBNET True if found dumbnet

find_path(DUMPNET_ROOT_DIR
NAMES include/dumbnet.h Include/dumbnet.h
)

find_path(DUMBNET_INCLUDE_DIR
NAMES dumbnet.h
HINTS ${DUMPNET_ROOT_DIR}/include
)

if ( MSVC AND COMPILER_ARCHITECTURE STREQUAL "x86_64" )
set(_dumbnet_lib_hint_path ${DUMPNET_ROOT_DIR}/lib/x64)
else()
set(_dumbnet_lib_hint_path ${DUMPNET_ROOT_DIR}/lib)
endif()

find_library(DUMBNET_LIBRARY
NAMES dumbnet
HINTS ${_dumbnet_lib_hint_path}
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(DUMBNET DEFAULT_MSG
DUMBNET_LIBRARY
DUMBNET_INCLUDE_DIR
)

mark_as_advanced(
DUMPNET_ROOT_DIR
DUMBNET_INCLUDE_DIR
DUMBNET_LIBRARY
)

set(HAVE_LIBDUMBNET True)

message(STATUS "DUMBNET_INCLUDE_DIR ${DUMBNET_INCLUDE_DIR}")
message(STATUS "DUMBNET_LIBRARY ${DUMBNET_LIBRARY}")

add_library(dumbnet SHARED IMPORTED)
set_property(TARGET dumbnet PROPERTY
IMPORTED_LOCATION "${DUMBNET_LIBRARY}")
target_include_directories(pcap INTERFACE ${DUMBNET_INCLUDE_DIR})
110 changes: 110 additions & 0 deletions cmake/FindPCAP.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# - Try to find libpcap include dirs and libraries
#
# Usage of this module as follows:
#
# find_package(PCAP)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# PCAP_ROOT_DIR Set this variable to the root installation of
# libpcap if the module has problems finding the
# proper installation path.
#
# Variables defined by this module:
#
# PCAP_FOUND System has libpcap, include and library dirs found
# PCAP_INCLUDE_DIR The libpcap include directories
# PCAP_LIBRARY The libpcap library (possibly includes a thread
# library e.g. required by pf_ring's libpcap)
# HAVE_PF_RING If a found version of libpcap supports PF_RING
# HAVE_PCAP_DUMP_OPEN_APPEND If a found version of libpcap supports DUMP_OPEN_APPEND
# HAVE_PCAP_OPEN_LIVE If a found version of libpcap supports OPEN_LIVE
# HAVE_PCAP_INJECT If a found version of libpcap supports INJECT
# HAVE_RADIOTAP If a found version of libpcap supports RADIOTAP
# HAVE_PCAP_SET_IMMEDIATE_MODE If a found version of libpcap supports SET_IMMEDIATE_MODE


find_path(PCAP_ROOT_DIR
NAMES include/pcap.h Include/pcap.h
)

find_path(PCAP_INCLUDE_DIR
NAMES pcap.h
HINTS ${PCAP_ROOT_DIR}/include
)

if ( MSVC AND COMPILER_ARCHITECTURE STREQUAL "x86_64" )
set(_pcap_lib_hint_path ${PCAP_ROOT_DIR}/lib/x64)
else()
set(_pcap_lib_hint_path ${PCAP_ROOT_DIR}/lib)
endif()

find_library(PCAP_LIBRARY
NAMES pcap wpcap
HINTS ${_pcap_lib_hint_path}
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PCAP DEFAULT_MSG
PCAP_LIBRARY
PCAP_INCLUDE_DIR
)

include(CheckCSourceCompiles)
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO)
set(CMAKE_REQUIRED_LIBRARIES)

# check if linking against libpcap also needs to link against a thread library
if (NOT PCAP_LINKS_SOLO)
find_package(Threads)
if (Threads_FOUND)
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS)
set(CMAKE_REQUIRED_LIBRARIES)
endif ()
if (THREADS_FOUND AND PCAP_NEEDS_THREADS)
set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
list(REMOVE_DUPLICATES _tmp)
set(PCAP_LIBRARY ${_tmp}
CACHE STRING "Libraries needed to link against libpcap" FORCE)
else ()
message(FATAL_ERROR "Couldn't determine how to link against libpcap")
endif ()
endif ()

string(FIND "${PCAP_LIBRARY}" "wpcap" _pcap_lib_is_wpcap)
if ( _pcap_lib_is_wpcap GREATER_EQUAL 0 )
set(HAVE_WPCAP TRUE)
endif()

set(HAVE_LIBPCAP TRUE)

include(CheckFunctionExists)
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
check_function_exists(pcap_dump_open_append HAVE_PCAP_DUMP_OPEN_APPEND)
check_function_exists(pcap_open_live HAVE_PCAP_OPEN_LIVE)
check_function_exists(pcap_inject HAVE_PCAP_INJECT)

include(CheckSymbolExists)
check_symbol_exists(DLT_IEEE802_11_RADIO ${PCAP_INCLUDE_DIR}/pcap/dlt.h HAVE_RADIOTAP)
check_symbol_exists(pcap_set_immediate_mode ${PCAP_INCLUDE_DIR}/pcap/pcap.h HAVE_PCAP_SET_IMMEDIATE_MODE)


set(CMAKE_REQUIRED_LIBRARIES)

mark_as_advanced(
PCAP_ROOT_DIR
PCAP_INCLUDE_DIR
PCAP_LIBRARY
)

message(STATUS "PCAP_INCLUDE_DIR ${PCAP_INCLUDE_DIR}")
message(STATUS "PCAP_LIBRARY ${PCAP_LIBRARY}")

add_library(pcap SHARED IMPORTED)
set_property(TARGET pcap PROPERTY
IMPORTED_LOCATION "${PCAP_LIBRARY}")
target_include_directories(pcap INTERFACE ${PCAP_INCLUDE_DIR})
115 changes: 115 additions & 0 deletions config.h.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* Define to 1 if you have the `gethostbyaddr' function. */
#cmakedefine HAVE_GETHOSTBYADDR

/* Define to 1 if you have the `gethostbyname' function. */
#cmakedefine HAVE_GETHOSTBYNAME

/* Define to 1 if you have the `gethostname' function. */
#cmakedefine HAVE_GETHOSTNAME

/* Define to 1 if you have the `inet_ntoa' function. */
#cmakedefine HAVE_INET_NTOA

/* Define to 1 if you have the <inttypes.h> header file. */
#cmakedefine HAVE_INTTYPES_H

/* Define to 1 if you have the `dnet' library (-ldnet). */
#cmakedefine HAVE_LIBDNET

/* Define to 1 if you have the `dumbnet' library (-ldumbnet). */
#cmakedefine HAVE_LIBDUMBNET

/* Define to 1 if you have the `nsl' library (-lnsl). */
#cmakedefine HAVE_LIBNSL

/* Define to 1 if you have the `pcap' library (-lpcap). */
#cmakedefine HAVE_LIBPCAP

/* Define to 1 if you have the `socket' library (-lsocket). */
#cmakedefine HAVE_LIBSOCKET

/* Define to 1 if you have the <memory.h> header file. */
#cmakedefine HAVE_MEMORY_H

/* Define to 1 if you have the `memset' function. */
#cmakedefine HAVE_MEMSET

/* Define to 1 if you have the <netdb.h> header file. */
#cmakedefine HAVE_NETDB_H

/* Define to 1 if you have the <netinet/in.h> header file. */
#cmakedefine HAVE_NETINET_IN_H

/* Define to 1 if you have the `pcap_inject' function. */
#cmakedefine HAVE_PCAP_INJECT

/* Define if you have pcap_set_immediate_mode. */
#cmakedefine HAVE_PCAP_SET_IMMEDIATE_MODE

/* Define if radiotap exists. */
#cmakedefine HAVE_RADIOTAP

/* Define to 1 if you have the `select' function. */
#cmakedefine HAVE_SELECT

/* Define to 1 if you have the `socket' function. */
#cmakedefine HAVE_SOCKET

/* Define to 1 if stdbool.h conforms to C99. */
#cmakedefine HAVE_STDBOOL_H

/* Define to 1 if you have the <stdint.h> header file. */
#cmakedefine HAVE_STDINT_H

/* Define to 1 if you have the <stdlib.h> header file. */
#cmakedefine HAVE_STDLIB_H

/* Define to 1 if you have the `strerror' function. */
#cmakedefine HAVE_STRERROR

/* Define to 1 if you have the <strings.h> header file. */
#cmakedefine HAVE_STRINGS_H

/* Define to 1 if you have the <string.h> header file. */
#cmakedefine HAVE_STRING_H

/* Define to 1 if you have the <sys/ioctl.h> header file. */
#cmakedefine HAVE_SYS_IOCTL_H

/* Define to 1 if you have the <sys/stat.h> header file. */
#cmakedefine HAVE_SYS_STAT_H

/* Define to 1 if you have the <sys/types.h> header file. */
#cmakedefine HAVE_SYS_TYPES_H

/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H

/* Define to 1 if the system has the type `_Bool'. */
#cmakedefine HAVE__BOOL

/* Define to the address where bug reports for this package should be sent. */
#cmakedefine PACKAGE_BUGREPORT

/* Define to the full name of this package. */
#cmakedefine PACKAGE_NAME

/* Define to the full name and version of this package. */
#cmakedefine PACKAGE_STRING

/* Define to the one symbol short name of this package. */
#cmakedefine PACKAGE_TARNAME

/* Define to the home page for this package. */
#cmakedefine PACKAGE_URL

/* Define to the version of this package. */
#cmakedefine PACKAGE_VERSION

/* Define to 1 if you have the ANSI C header files. */
#ifndef STDC_HEADERS
#cmakedefine STDC_HEADERS
#endif

/* Define to `unsigned int' if <sys/types.h> does not define. */
#cmakedefine size_t
Loading