Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3030ad1
implement async i/o and async_sock for linux
jacnils Jul 25, 2026
dd319cf
delegate existing socket abstractions to underlying native classes
jacnils Jul 25, 2026
f69aebb
introduce concept of streams. will be used to build socket abstractions
jacnils Jul 25, 2026
b158ef6
introduce tcp_connection class which will allow tcp clients to be made
jacnils Jul 26, 2026
a174eb9
introduce async_tcp... classes
jacnils Jul 26, 2026
fb31b9b
remove linux guards in some io headers
jacnils Jul 26, 2026
6979165
move linux specifics
jacnils Jul 26, 2026
7c5bead
add fallback for when epoll() is not available
jacnils Jul 27, 2026
77d45f4
rename tcp_connection to tcp_stream
jacnils Jul 27, 2026
c56b3c4
some windows refactoring
jacnils Jul 27, 2026
5962e11
example refactoring, remove examples that don't build
jacnils Jul 29, 2026
372346b
fix all current socket types for windows
jacnils Jul 29, 2026
7b4f2c7
add udp abstractions
jacnils Jul 29, 2026
5eccaad
fix dns socket usage
jacnils Jul 30, 2026
0fdd32c
implement back support for tls/ssl
jacnils Jul 30, 2026
49c8854
http fixes
jacnils Jul 31, 2026
b6ee0e3
update github ci
jacnils Jul 31, 2026
8d6eab5
unistd include on unix only
jacnils Jul 31, 2026
93273cb
unix includes
jacnils Jul 31, 2026
29193b5
ci: disable catch2 tests
jacnils Jul 31, 2026
00c98e7
declaration/definition signature mismatch fix
jacnils Jul 31, 2026
fb05f14
include more headers as needed
jacnils Jul 31, 2026
2c16f8e
windows crap
jacnils Jul 31, 2026
1ef6afd
more...
jacnils Jul 31, 2026
0cafd9c
more...
jacnils Jul 31, 2026
dddeb5d
more complete shit for windows
jacnils Jul 31, 2026
18b402a
dont explicitly include unistd in network_interface example (its usel…
jacnils Jul 31, 2026
b1a796a
more shit
jacnils Jul 31, 2026
e5ed747
commit these
jacnils Jul 31, 2026
f847723
linux fixes
jacnils Jul 31, 2026
8100ef4
linux fixes 2
jacnils Jul 31, 2026
e44b3af
linux fixes 3
jacnils Jul 31, 2026
4364765
linux fixes 4
jacnils Jul 31, 2026
b4f00f9
macos fix
jacnils Jul 31, 2026
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
18 changes: 1 addition & 17 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,6 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Install OpenSSL
run: |
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then
sudo apt update
sudo apt install -y libssl-dev libwolfssl-dev
echo "CMAKE_PREFIX_PATH=/usr" >> $GITHUB_ENV
elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then
brew update
brew install openssl
OPENSSL_DIR=$(brew --prefix openssl)
echo "CMAKE_PREFIX_PATH=${OPENSSL_DIR}" >> $GITHUB_ENV
elif [[ "${{ matrix.os }}" == "windows-latest" ]]; then
choco install openssl.light -y
echo "CMAKE_PREFIX_PATH=C:/Program Files/OpenSSL-Win64" >> $GITHUB_ENV
fi
shell: bash

- name: Set reusable strings
id: strings
shell: bash
Expand All @@ -61,6 +44,7 @@ jobs:
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DNETKIT_ENABLE_TESTS=OFF
-DCMAKE_PREFIX_PATH=${{ env.CMAKE_PREFIX_PATH }}
-S ${{ github.workspace }}

Expand Down
106 changes: 59 additions & 47 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
cmake_minimum_required(VERSION 3.28)
project(netkit LANGUAGES C CXX)

option(NETKIT_ENABLE_OPENSSL "Enable OpenSSL support in netkit" OFF)
option(NETKIT_ENABLE_WOLFSSL "Enable WolfSSL support in netkit" ON)
option(NETKIT_ENABLE_TESTS "Enable building tests" OFF)
option(NETKIT_ENABLE_C_BINDINGS "Enable experimental C bindings for netkit" ON)
option(NETKIT_ENABLE_C_BINDINGS "Enable experimental C bindings for netkit" OFF)
option(NETKIT_ENABLE_C_TESTS "Enable C building tests" OFF)
option(NETKIT_ENABLE_WINDOWS_CERTSTORE "Enable getting CA certificates from the Windows store" ON)
option(NETKIT_ENABLE_FALLBACK_CA "Enable fallback CA certficate (required for DevkitPro)" ON)
option(NETKIT_ENABLE_SOCK_CUSTOM_RESOLVER "Enable using netkit's DNS resolver instead of the system resolver" OFF)
option(NETKIT_ENABLE_EPOLL "Enable using epoll backend (Linux only)" ON)
option(NETKIT_ENABLE_WSAPOLL "Enable using wsapoll backend (Windows only)" ON)
option(NETKIT_ENABLE_HTTP "Enable netkit's HTTP abstractions" ON)
option(NETKIT_ENABLE_DNS "Enable netkit's DNS features" ON)
option(NETKIT_WOLFSSL_DEBUG "Enable WolfSSL debugging" OFF)
option(NETKIT_BUILD_SHARED "Build netkit as a shared library" ON)
option(NETKIT_USE_SYSTEM_WOLFSSL "Use system WolfSSL if found (not recommended)" OFF)
option(NETKIT_BUILD_EXAMPLES "Build netkit's examples" OFF)

if (CMAKE_SYSTEM_NAME STREQUAL "NintendoWii" OR CMAKE_SYSTEM_NAME STREQUAL "NintendoGameCube")
set(NETKIT_DKP ON)
else()
set(NETKIT_DKP OFF)
endif()

if (NETKIT_DKP)
set(NETKIT_ENABLE_OPENSSL OFF CACHE BOOL "" FORCE)
endif()

if (NETKIT_BUILD_SHARED)
set(NETKIT_LIB_TYPE SHARED)
else()
Expand All @@ -41,6 +41,10 @@ if (NOT NETKIT_BUILD_SHARED AND WIN32)
)
endif()

if (WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
Expand All @@ -59,23 +63,40 @@ add_library(netkit ${NETKIT_LIB_TYPE}
src/network/ip_list.cpp
src/dns/record_type.cpp
src/dns/nameserver_list.cpp
src/sock/addr.cpp
src/socket/addr.cpp
src/dns/response_parser.cpp
src/dns/query_builder.cpp
src/sock/sock_peer.cpp
src/sock/sync_sock.cpp
src/socket/native/native_sync_socket.cpp
src/dns/cache.cpp
src/sock/openssl/ssl_sync_sock.cpp
src/sock/wolfssl/ssl_sync_sock.cpp
src/http/predefined.cpp
src/http/sync_client.cpp
src/crypto/windows/certs.cpp
src/body/stream_body.cpp
src/http/multipart.cpp
src/http/multipart_reader.cpp
src/body/multipart_part_body.cpp
src/io/io_awaitable.cpp
src/io/linux/io_backend.cpp
src/socket/native/native_async_socket.cpp
src/socket/native/native_sync_listener.cpp
src/socket/native/native_async_listener.cpp
src/socket/native/peer_helper.cpp
src/tcp/tcp_server.cpp
src/tcp/tcp_stream.cpp
src/stream/socket_stream.cpp
src/stream/socket_stream.cpp
src/stream/async_socket_stream.cpp
src/tcp/async_tcp_stream.cpp
src/tcp/async_tcp_server.cpp
src/io/fallback/io_backend.cpp
src/io/windows/io_backend.cpp
src/udp/udp_datagram.cpp
src/udp/async_udp_datagram.cpp
src/stream/wolfssl/tls_stream.cpp
)

add_library(netkit::netkit ALIAS netkit)

set_target_properties(netkit PROPERTIES
EXPORT_NAME netkit
POSITION_INDEPENDENT_CODE ON
Expand All @@ -95,40 +116,7 @@ target_include_directories(netkit
$<INSTALL_INTERFACE:include>
)

if (NETKIT_ENABLE_OPENSSL AND NETKIT_ENABLE_WOLFSSL)
message(STATUS "NETKIT_ENABLE_WOLFSSL AND NETKIT_ENABLE_OPENSSL cannot be used simultaneously.")
set(NETKIT_ENABLE_OPENSSL Off)
endif()

if (NETKIT_ENABLE_OPENSSL)
find_package(OpenSSL)

if (NOT NETKIT_BUILD_SHARED)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
endif()

if (NOT OpenSSL_FOUND)
message(STATUS "OpenSSL not found. You can install it via system package manager or vcpkg.")

if (DEFINED ENV{VCPKG_ROOT})
set(CMAKE_TOOLCHAIN_FILE
"$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING ""
)
find_package(OpenSSL REQUIRED)
else()
message(STATUS "Not using VCPKG")
endif()
endif()

if (OpenSSL_FOUND)
message(STATUS "OpenSSL enabled in netkit")
target_compile_definitions(netkit PUBLIC NETKIT_OPENSSL)
target_link_libraries(netkit PUBLIC OpenSSL::SSL OpenSSL::Crypto)
else()
message(FATAL_ERROR "OpenSSL requested but not found.")
endif()
elseif (NETKIT_ENABLE_WOLFSSL)
if (NETKIT_ENABLE_WOLFSSL)
find_package(wolfSSL QUIET)

if (NOT NETKIT_BUILD_SHARED)
Expand Down Expand Up @@ -158,7 +146,7 @@ elseif (NETKIT_ENABLE_WOLFSSL)
WOLFSSL_USER_SETTINGS_FILE="user_settings.h"
)

include_directories(${CMAKE_SOURCE_DIR}/include/netkit/sock/wolfssl)
include_directories(${CMAKE_SOURCE_DIR}/include/netkit/stream/wolfssl)
endif()

FetchContent_Declare(
Expand Down Expand Up @@ -204,6 +192,26 @@ if (NETKIT_ENABLE_SOCK_CUSTOM_RESOLVER)
target_compile_definitions(netkit PUBLIC NETKIT_ENABLE_SOCK_CUSTOM_RESOLVER)
endif()

if (NETKIT_ENABLE_HTTP)
target_compile_definitions(netkit PUBLIC NETKIT_HTTP)
endif()

if (NETKIT_ENABLE_DNS)
target_compile_definitions(netkit PUBLIC NETKIT_DNS)
endif()

if (NETKIT_ENABLE_EPOLL)
target_compile_definitions(netkit PUBLIC NETKIT_EPOLL)
endif()

if (NETKIT_ENABLE_WSAPOLL)
target_compile_definitions(netkit PUBLIC NETKIT_WSAPOLL)
endif()

if (WIN32)
add_definitions(-DNOMINMAX)
endif()

if (WIN32)
target_link_libraries(netkit PUBLIC ws2_32 iphlpapi dnsapi crypt32)
elseif (UNIX AND NOT APPLE)
Expand Down Expand Up @@ -249,7 +257,7 @@ install(TARGETS netkit
if (NETKIT_DKP AND NETKIT_ENABLE_WOLFSSL)
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/include/netkit/sock/wolfssl/user_settings.h
${CMAKE_CURRENT_SOURCE_DIR}/include/netkit/stream/wolfssl/user_settings.h
DESTINATION
include/wolfssl/wolfcrypt/
)
Expand Down Expand Up @@ -367,4 +375,8 @@ if (NETKIT_ENABLE_C_BINDINGS)
endif()
else()
message(STATUS "C bindings disabled")
endif()

if (NETKIT_BUILD_EXAMPLES)
add_subdirectory(examples/cpp)
endif()
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@

C++23 cross-platform networking toolkit library providing safe Unix-style sockets and protocol abstractions.

## Warning

Please note, this library is still work in progress. Usage is not recommended yet, aside from tests. Contributions and bug reports are much appreciated!

If you still intend to use the library, there are two ways to go. You can either use the unstable master branch directly which may change its API entirely.

The other alternative is to use the latest release, which doesn't have a changing API but will make migration later potentially time-consuming.

## Features

- Binding, connecting, sending, receiving and closing synchronous TCP/UDP sockets
- OS-independent socket abstractions, both synchronous and asynchronous
- Higher-level socket abstractions
- HTTP/1.0 and HTTP/1.1 body parser, including headers and body.
- IPv4 and IPv6 support
- TCP and UDP support
- TLS/SSL sockets and HTTP abstraction (OpenSSL or WolfSSL integration)
- TLS/SSL sockets and HTTP abstraction (WolfSSL integration)
- DNS resolution
- Network interface enumeration
- Exceptions for errors
Expand All @@ -24,22 +31,22 @@ Please note, this library is still work in progress. Usage is not recommended ye

Still missing:

- Asynchronous I/O
- Schannel support for Windows
- Asynchronous I/O for non-Linux platforms
- Threaded fallback is available
- Schannel support for Windows (waste of time I reckon)
- WebSocket abstraction

## Dependencies

- OpenSSL or WolfSSL (optional)
- WolfSSL (optional)
- C++23 compiler
- CMake

## Options

netkit's CMakeLists.txt offers multiple options:

- NETKIT_ENABLE_OPENSSL: Enable OpenSSL-backed SSL/TLS (not compatible with DevkitPro)
- NETKIT_ENABLE_WOLFSSL: Enable WolfSSL-backed SSL/TLS (cannot be used with NETKIT_ENABLE_OPENSSL)
- NETKIT_ENABLE_WOLFSSL: Enable WolfSSL-backed SSL/TLS
- NETKIT_ENABLE_TESTS: Enable Catch2 tests for the main C++ library
- NETKIT_ENABLE_C_BINDINGS: Enable C bindings for netkit
- NETKIT_ENABLE_C_TESTS: Enable tests for netkit C bindings
Expand Down Expand Up @@ -87,4 +94,4 @@ Netkit can also be statically linked, and for users of DevkitPro it will be auto

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

Copyright (c) 2025-2026 Jacob Nilsson
Copyright (c) 2025-2026 Jacob Nilsson
4 changes: 3 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Reporting a Vulnerability

Please report vulnerabilities to me through email. You can email me at `contact@jacobnilsson.com`.
As of now, before the v1.0.0 release, we will discuss vulnerabilities in the open, as we don't expect
anyone to use this in security critical applications. Please file an issue on the GitHub repository,
or pull request if you have a fix.
6 changes: 6 additions & 0 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
file(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
foreach(child ${children})
if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${child})
add_subdirectory(${child})
endif()
endforeach()
15 changes: 8 additions & 7 deletions examples/cpp/buffer_body/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
cmake_minimum_required(VERSION 3.11)

project(netkit-example LANGUAGES CXX)
project(buffer_body LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

find_package(netkit)
if (NOT TARGET netkit::netkit)
find_package(netkit REQUIRED)
endif()

add_executable(buffer_body main.cpp)

add_executable(
netkit-example
main.cpp
)
target_link_libraries(netkit-example PRIVATE netkit::netkit)
target_link_libraries(buffer_body PRIVATE netkit::netkit)
18 changes: 0 additions & 18 deletions examples/cpp/dkp_socket_ssl/CMakeLists.txt

This file was deleted.

Loading
Loading