aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2023-09-15 11:21:31 +0200
committerToni Uhlig <matzeton@googlemail.com>2023-09-15 11:21:31 +0200
commit0cbfbe129934976359460fdbe69fb97632d81d24 (patch)
tree3d4685fc1f02244c80d4f5de2fa6c80fae94a425 /examples
parent37d1e657e5e79bc240ea036cfb8da377b1640490 (diff)
Added C++ (`ksocket/ksocket.hpp`) Socket wrapper classes.
* another flatbuffers example (WiP!) * Makefile improvements Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/apiwrapper.fbs6
-rw-r--r--examples/apiwrapper_builder.h55
-rw-r--r--examples/apiwrapper_reader.h54
-rw-r--r--examples/apiwrapper_verifier.h43
-rw-r--r--examples/driver-flatbuffers-tcp.bat27
-rw-r--r--examples/driver-flatbuffers-tcp.cpp108
-rw-r--r--examples/driver-protobuf-c-tcp.cpp1
-rw-r--r--examples/driver-protobuf-c.cpp1
-rw-r--r--examples/driver.cpp129
-rw-r--r--examples/userspace_client_flatbuffers.cpp82
-rw-r--r--examples/userspace_client_protobuf.cpp1
11 files changed, 498 insertions, 9 deletions
diff --git a/examples/apiwrapper.fbs b/examples/apiwrapper.fbs
new file mode 100644
index 0000000..6de1330
--- /dev/null
+++ b/examples/apiwrapper.fbs
@@ -0,0 +1,6 @@
+table FunctionAddresses {
+ names:[string];
+ addrs:[uint64];
+}
+
+root_type FunctionAddresses;
diff --git a/examples/apiwrapper_builder.h b/examples/apiwrapper_builder.h
new file mode 100644
index 0000000..f0e0c1b
--- /dev/null
+++ b/examples/apiwrapper_builder.h
@@ -0,0 +1,55 @@
+#ifndef APIWRAPPER_BUILDER_H
+#define APIWRAPPER_BUILDER_H
+
+/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */
+
+#ifndef APIWRAPPER_READER_H
+#include "apiwrapper_reader.h"
+#endif
+#ifndef FLATBUFFERS_COMMON_BUILDER_H
+#include "flatbuffers_common_builder.h"
+#endif
+#include "flatcc/flatcc_prologue.h"
+#ifndef flatbuffers_identifier
+#define flatbuffers_identifier 0
+#endif
+#ifndef flatbuffers_extension
+#define flatbuffers_extension "bin"
+#endif
+
+static const flatbuffers_voffset_t __FunctionAddresses_required[] = { 0 };
+typedef flatbuffers_ref_t FunctionAddresses_ref_t;
+static FunctionAddresses_ref_t FunctionAddresses_clone(flatbuffers_builder_t *B, FunctionAddresses_table_t t);
+__flatbuffers_build_table(flatbuffers_, FunctionAddresses, 2)
+
+#define __FunctionAddresses_formal_args , flatbuffers_string_vec_ref_t v0, flatbuffers_uint64_vec_ref_t v1
+#define __FunctionAddresses_call_args , v0, v1
+static inline FunctionAddresses_ref_t FunctionAddresses_create(flatbuffers_builder_t *B __FunctionAddresses_formal_args);
+__flatbuffers_build_table_prolog(flatbuffers_, FunctionAddresses, FunctionAddresses_file_identifier, FunctionAddresses_type_identifier)
+
+__flatbuffers_build_string_vector_field(0, flatbuffers_, FunctionAddresses_names, FunctionAddresses)
+__flatbuffers_build_vector_field(1, flatbuffers_, FunctionAddresses_addrs, flatbuffers_uint64, uint64_t, FunctionAddresses)
+
+static inline FunctionAddresses_ref_t FunctionAddresses_create(flatbuffers_builder_t *B __FunctionAddresses_formal_args)
+{
+ if (FunctionAddresses_start(B)
+ || FunctionAddresses_names_add(B, v0)
+ || FunctionAddresses_addrs_add(B, v1)) {
+ return 0;
+ }
+ return FunctionAddresses_end(B);
+}
+
+static FunctionAddresses_ref_t FunctionAddresses_clone(flatbuffers_builder_t *B, FunctionAddresses_table_t t)
+{
+ __flatbuffers_memoize_begin(B, t);
+ if (FunctionAddresses_start(B)
+ || FunctionAddresses_names_pick(B, t)
+ || FunctionAddresses_addrs_pick(B, t)) {
+ return 0;
+ }
+ __flatbuffers_memoize_end(B, t, FunctionAddresses_end(B));
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* APIWRAPPER_BUILDER_H */
diff --git a/examples/apiwrapper_reader.h b/examples/apiwrapper_reader.h
new file mode 100644
index 0000000..f7e8253
--- /dev/null
+++ b/examples/apiwrapper_reader.h
@@ -0,0 +1,54 @@
+#ifndef APIWRAPPER_READER_H
+#define APIWRAPPER_READER_H
+
+/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */
+
+#ifndef FLATBUFFERS_COMMON_READER_H
+#include "flatbuffers_common_reader.h"
+#endif
+#include "flatcc/flatcc_flatbuffers.h"
+#ifndef __alignas_is_defined
+#include <stdalign.h>
+#endif
+#include "flatcc/flatcc_prologue.h"
+#ifndef flatbuffers_identifier
+#define flatbuffers_identifier 0
+#endif
+#ifndef flatbuffers_extension
+#define flatbuffers_extension "bin"
+#endif
+
+
+typedef const struct FunctionAddresses_table *FunctionAddresses_table_t;
+typedef struct FunctionAddresses_table *FunctionAddresses_mutable_table_t;
+typedef const flatbuffers_uoffset_t *FunctionAddresses_vec_t;
+typedef flatbuffers_uoffset_t *FunctionAddresses_mutable_vec_t;
+#ifndef FunctionAddresses_file_identifier
+#define FunctionAddresses_file_identifier 0
+#endif
+/* deprecated, use FunctionAddresses_file_identifier */
+#ifndef FunctionAddresses_identifier
+#define FunctionAddresses_identifier 0
+#endif
+#define FunctionAddresses_type_hash ((flatbuffers_thash_t)0x73e9a2df)
+#define FunctionAddresses_type_identifier "\xdf\xa2\xe9\x73"
+#ifndef FunctionAddresses_file_extension
+#define FunctionAddresses_file_extension "bin"
+#endif
+
+
+
+struct FunctionAddresses_table { uint8_t unused__; };
+
+static inline size_t FunctionAddresses_vec_len(FunctionAddresses_vec_t vec)
+__flatbuffers_vec_len(vec)
+static inline FunctionAddresses_table_t FunctionAddresses_vec_at(FunctionAddresses_vec_t vec, size_t i)
+__flatbuffers_offset_vec_at(FunctionAddresses_table_t, vec, i, 0)
+__flatbuffers_table_as_root(FunctionAddresses)
+
+__flatbuffers_define_vector_field(0, FunctionAddresses, names, flatbuffers_string_vec_t, 0)
+__flatbuffers_define_vector_field(1, FunctionAddresses, addrs, flatbuffers_uint64_vec_t, 0)
+
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* APIWRAPPER_READER_H */
diff --git a/examples/apiwrapper_verifier.h b/examples/apiwrapper_verifier.h
new file mode 100644
index 0000000..fc88b41
--- /dev/null
+++ b/examples/apiwrapper_verifier.h
@@ -0,0 +1,43 @@
+#ifndef APIWRAPPER_VERIFIER_H
+#define APIWRAPPER_VERIFIER_H
+
+/* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */
+
+#ifndef APIWRAPPER_READER_H
+#include "apiwrapper_reader.h"
+#endif
+#include "flatcc/flatcc_verifier.h"
+#include "flatcc/flatcc_prologue.h"
+
+static int FunctionAddresses_verify_table(flatcc_table_verifier_descriptor_t *td);
+
+static int FunctionAddresses_verify_table(flatcc_table_verifier_descriptor_t *td)
+{
+ int ret;
+ if ((ret = flatcc_verify_string_vector_field(td, 0, 0) /* names */)) return ret;
+ if ((ret = flatcc_verify_vector_field(td, 1, 0, 8, 8, INT64_C(536870911)) /* addrs */)) return ret;
+ return flatcc_verify_ok;
+}
+
+static inline int FunctionAddresses_verify_as_root(const void *buf, size_t bufsiz)
+{
+ return flatcc_verify_table_as_root(buf, bufsiz, FunctionAddresses_identifier, &FunctionAddresses_verify_table);
+}
+
+static inline int FunctionAddresses_verify_as_typed_root(const void *buf, size_t bufsiz)
+{
+ return flatcc_verify_table_as_root(buf, bufsiz, FunctionAddresses_type_identifier, &FunctionAddresses_verify_table);
+}
+
+static inline int FunctionAddresses_verify_as_root_with_identifier(const void *buf, size_t bufsiz, const char *fid)
+{
+ return flatcc_verify_table_as_root(buf, bufsiz, fid, &FunctionAddresses_verify_table);
+}
+
+static inline int FunctionAddresses_verify_as_root_with_type_hash(const void *buf, size_t bufsiz, flatbuffers_thash_t thash)
+{
+ return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &FunctionAddresses_verify_table);
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* APIWRAPPER_VERIFIER_H */
diff --git a/examples/driver-flatbuffers-tcp.bat b/examples/driver-flatbuffers-tcp.bat
new file mode 100644
index 0000000..00d5d8c
--- /dev/null
+++ b/examples/driver-flatbuffers-tcp.bat
@@ -0,0 +1,27 @@
+@echo off
+set SERVICE_NAME=flatbuffers-tcp
+set DRIVER="%~dp0\driver-flatbuffers-tcp.sys"
+
+net session >nul 2>&1
+if NOT %ERRORLEVEL% EQU 0 (
+ echo ERROR: This script requires Administrator privileges!
+ pause
+ exit /b 1
+)
+
+echo ---------------------------------------
+echo -- Service Name: %SERVICE_NAME%
+echo -- Driver......: %DRIVER%
+echo ---------------------------------------
+
+sc create %SERVICE_NAME% binPath= %DRIVER% type= kernel
+echo ---------------------------------------
+sc start %SERVICE_NAME%
+echo ---------------------------------------
+sc query %SERVICE_NAME%
+echo [PRESS A KEY TO STOP THE DRIVER]
+pause
+sc stop %SERVICE_NAME%
+sc delete %SERVICE_NAME%
+echo Done.
+timeout /t 3
diff --git a/examples/driver-flatbuffers-tcp.cpp b/examples/driver-flatbuffers-tcp.cpp
new file mode 100644
index 0000000..00b200c
--- /dev/null
+++ b/examples/driver-flatbuffers-tcp.cpp
@@ -0,0 +1,108 @@
+#include <ksocket/berkeley.h>
+#include <ksocket/helper.hpp>
+#include <ksocket/ksocket.hpp>
+#include <ksocket/ksocket.h>
+#include <ksocket/wsk.h>
+
+#include "apiwrapper_builder.h"
+#include "apiwrapper_reader.h"
+#include "apiwrapper_verifier.h"
+
+extern "C" {
+DRIVER_INITIALIZE DriverEntry;
+DRIVER_UNLOAD DriverUnload;
+
+#define DebuggerPrint(...) \
+ DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, __VA_ARGS__);
+
+NTSTATUS
+NTAPI
+DriverEntry(_In_ PDRIVER_OBJECT DriverObject,
+ _In_ PUNICODE_STRING RegistryPath) {
+ UNREFERENCED_PARAMETER(DriverObject);
+ UNREFERENCED_PARAMETER(RegistryPath);
+
+ NTSTATUS Status;
+
+ KSocketBuffer buf;
+ buf.insert(buf.end(), static_cast<uint16_t>(0x1122));
+ buf.insert(buf.end(), static_cast<uint32_t>(0xFFFFFFFF));
+ buf.insert(buf.end(), "AAAAAAAA");
+ DebuggerPrint("HEX: %s\n", buf.toHex().c_str());
+
+ DebuggerPrint("Hi.\n");
+ Status = KsInitialize();
+
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ int server_sockfd = socket_listen(AF_INET, SOCK_STREAM, 0);
+
+ struct sockaddr_in addr;
+ addr.sin_family = AF_INET;
+ addr.sin_addr.s_addr = INADDR_ANY;
+ addr.sin_port = htons(9096);
+
+ int result = bind(server_sockfd, (struct sockaddr *)&addr, sizeof(addr));
+ if (result != 0) {
+ DebuggerPrint("TCP server bind failed\n");
+ return STATUS_FAILED_DRIVER_ENTRY;
+ }
+
+ result = listen(server_sockfd, 1);
+ if (result != 0) {
+ DebuggerPrint("TCP server listen failed\n");
+ return STATUS_FAILED_DRIVER_ENTRY;
+ }
+
+ socklen_t addrlen = sizeof(addr);
+ int client_sockfd = accept(server_sockfd, (struct sockaddr *)&addr, &addrlen);
+ if (client_sockfd < 0) {
+ DebuggerPrint("TCP accept failed\n");
+ return STATUS_FAILED_DRIVER_ENTRY;
+ }
+
+ int iResult;
+ SocketBuffer<1024> sb_send, sb_recv;
+
+ do {
+ RECV_PDU_BEGIN(client_sockfd, sb_recv, iResult, pdu_type, pdu_len) {
+ DebuggerPrint("PDU type/len: %u/%u\n", pdu_type, pdu_len);
+ if (pdu_type == 0) {
+ int ret = FunctionAddresses_verify_as_root(sb_recv.GetStart(), pdu_len);
+
+ if (ret == 0) {
+ FunctionAddresses_table_t fnaddr = FunctionAddresses_as_root(sb_recv.GetStart());
+
+ if (!fnaddr) {
+ DebuggerPrint("%s\n", "FunctionAddresses not available!");
+ } else {
+ flatbuffers_string_vec_t names = FunctionAddresses_names(fnaddr);
+ size_t name_size = flatbuffers_string_vec_len(names);
+
+ DebuggerPrint("Length of names vector: %zu\n", name_size);
+ }
+ } else {
+ DebuggerPrint("Flatbuffer verification failed with %d: %s\n", ret, flatcc_verify_error_string(ret));
+ }
+ } else {
+ DebuggerPrint("%s\n", "PDU type not supported!");
+ }
+ }
+ RECV_PDU_END(sb_recv, pdu_len);
+ } while (iResult != SOCKET_ERROR && iResult > 0);
+
+ DebuggerPrint("Client gone.\n") closesocket(client_sockfd);
+ closesocket(server_sockfd);
+ KsDestroy();
+
+ return STATUS_SUCCESS;
+}
+
+VOID DriverUnload(_In_ struct _DRIVER_OBJECT *DriverObject) {
+ UNREFERENCED_PARAMETER(DriverObject);
+
+ DebuggerPrint("Bye.\n");
+}
+}
diff --git a/examples/driver-protobuf-c-tcp.cpp b/examples/driver-protobuf-c-tcp.cpp
index fcf4465..a7071ed 100644
--- a/examples/driver-protobuf-c-tcp.cpp
+++ b/examples/driver-protobuf-c-tcp.cpp
@@ -1,6 +1,7 @@
#include <ksocket/berkeley.h>
#include <ksocket/helper.hpp>
#include <ksocket/ksocket.h>
+#include <ksocket/utils.h>
#include <ksocket/wsk.h>
#include "examples/common.hpp"
diff --git a/examples/driver-protobuf-c.cpp b/examples/driver-protobuf-c.cpp
index c3c8445..bbd0b52 100644
--- a/examples/driver-protobuf-c.cpp
+++ b/examples/driver-protobuf-c.cpp
@@ -1,6 +1,7 @@
#include <ksocket/berkeley.h>
#include <ksocket/helper.hpp>
#include <ksocket/ksocket.h>
+#include <ksocket/utils.h>
#include <ksocket/wsk.h>
#include "examples/common.hpp"
diff --git a/examples/driver.cpp b/examples/driver.cpp
index 86e42e9..228acc7 100644
--- a/examples/driver.cpp
+++ b/examples/driver.cpp
@@ -1,9 +1,11 @@
-
-extern "C" {
#include <ksocket/berkeley.h>
#include <ksocket/ksocket.h>
+#include <ksocket/utils.h>
#include <ksocket/wsk.h>
+#include <ksocket/ksocket.hpp>
+
+extern "C" {
DRIVER_INITIALIZE DriverEntry;
DRIVER_UNLOAD DriverUnload;
@@ -34,15 +36,15 @@ DriverEntry(_In_ PDRIVER_OBJECT DriverObject,
// Perform HTTP request to http://httpbin.org/uuid
//
+ const char send_buffer[] = "GET /uuid HTTP/1.1\r\n"
+ "Host: httpbin.org\r\n"
+ "Connection: close\r\n"
+ "\r\n";
+
{
int result;
UNREFERENCED_PARAMETER(result);
- char send_buffer[] = "GET /uuid HTTP/1.1\r\n"
- "Host: httpbin.org\r\n"
- "Connection: close\r\n"
- "\r\n";
-
char recv_buffer[1024] = {};
struct addrinfo hints = {};
@@ -66,7 +68,7 @@ DriverEntry(_In_ PDRIVER_OBJECT DriverObject,
return STATUS_FAILED_DRIVER_ENTRY;
}
- result = send(sockfd, send_buffer, sizeof(send_buffer), 0);
+ result = send(sockfd, send_buffer, sizeof(send_buffer) - 1, 0);
if (result <= 0) {
DebuggerPrint("TCP client send failed\n");
return STATUS_FAILED_DRIVER_ENTRY;
@@ -83,6 +85,48 @@ DriverEntry(_In_ PDRIVER_OBJECT DriverObject,
closesocket(sockfd);
}
+ {
+ KStreamClientIp4 tcp4_client = KStreamClientIp4();
+
+ if (!tcp4_client.setup()) {
+ DebuggerPrint("KStreamClientIp4 setup() failed: %d\n",
+ tcp4_client.getLastError());
+ return STATUS_FAILED_DRIVER_ENTRY;
+ }
+
+ if (!tcp4_client.connect("httpbin.org", "80")) {
+ DebuggerPrint("KStreamClientIp4 connect() failed: %d\n",
+ tcp4_client.getLastError());
+ return STATUS_FAILED_DRIVER_ENTRY;
+ }
+
+ DebuggerPrint("%s\n", "KStreamClientIp4 connected!");
+
+ tcp4_client.getSendBuffer().insert(tcp4_client.getSendBuffer().end(),
+ send_buffer, sizeof(send_buffer) - 1);
+ if (!tcp4_client.send()) {
+ DebuggerPrint("KStreamClientIp4 send() failed: %d\n",
+ tcp4_client.getLastError());
+ return STATUS_FAILED_DRIVER_ENTRY;
+ }
+
+ if (!tcp4_client.recv()) {
+ DebuggerPrint("KStreamClientIp4 recv() failed: %d\n",
+ tcp4_client.getLastError());
+ return STATUS_FAILED_DRIVER_ENTRY;
+ }
+
+ DebuggerPrint("KStreamClientIp4 data received:\n%s\n",
+ tcp4_client.getRecvBuffer().to_string().c_str());
+ DebuggerPrint("KStreamClientIp4 consuming %zu bytes\n",
+ tcp4_client.getRecvBuffer().size());
+ tcp4_client.getRecvBuffer().consume();
+ DebuggerPrint("KStreamClientIp4 receive buffer size: %zu\n",
+ tcp4_client.getRecvBuffer().size());
+
+ DebuggerPrint("%s\n", "KStreamClientIp4 finished.");
+ }
+
//
// TCP server.
// Listen on port 9095, wait for some message,
@@ -114,6 +158,10 @@ DriverEntry(_In_ PDRIVER_OBJECT DriverObject,
return STATUS_FAILED_DRIVER_ENTRY;
}
+ DebuggerPrint(
+ "%s\n",
+ "TCP server is waiting for the user to start userspace_client.exe");
+
socklen_t addrlen = sizeof(addr);
int client_sockfd =
accept(server_sockfd, (struct sockaddr *)&addr, &addrlen);
@@ -124,7 +172,7 @@ DriverEntry(_In_ PDRIVER_OBJECT DriverObject,
result = recv(client_sockfd, recv_buffer, sizeof(recv_buffer) - 1, 0);
if (result > 0) {
- DebuggerPrint("TCP server:\n%.*s\n", result, recv_buffer);
+ DebuggerPrint("TCP server received: \"%.*s\"\n", result, recv_buffer);
} else {
DebuggerPrint("TCP server recv failed\n");
}
@@ -139,6 +187,69 @@ DriverEntry(_In_ PDRIVER_OBJECT DriverObject,
closesocket(server_sockfd);
}
+ {
+ KStreamServerIp4 tcp4_server = KStreamServerIp4();
+
+ if (!tcp4_server.setup()) {
+ DebuggerPrint("KStreamServerIp4 setup() failed: %d\n",
+ tcp4_server.getLastError());
+ return STATUS_FAILED_DRIVER_ENTRY;
+ }
+
+ if (!tcp4_server.bind(9095)) {
+ DebuggerPrint("KStreamServerIp4 bind() failed: %d\n",
+ tcp4_server.getLastError());
+ return STATUS_FAILED_DRIVER_ENTRY;
+ }
+
+ if (!tcp4_server.listen()) {
+ DebuggerPrint("KStreamServerIp4 bind() failed: %d\n",
+ tcp4_server.getLastError());
+ return STATUS_FAILED_DRIVER_ENTRY;
+ }
+
+ DebuggerPrint("%s\n", "KStreamServerIp4 listening for incomining "
+ "connections (run userspace_client.exe again)..");
+
+ const auto &accept_fn = [](KAcceptedSocket &ka) {
+ const auto &remote = ka.getRemote();
+
+ if (remote.addr_used != 4) {
+ return false;
+ }
+ DebuggerPrint("KStreamServerIp4 client connected: %s\n",
+ remote.to_string().c_str());
+
+ if (!ka.recv()) {
+ DebuggerPrint("KStreamServerIp4 recv failed: %d\n", ka.getLastError());
+ return false;
+ }
+ DebuggerPrint("KStreamServerIp4 received %zu bytes: \"%s\"\n",
+ ka.getRecvBuffer().size(),
+ ka.getRecvBuffer().to_string().c_str());
+ ka.getRecvBuffer().consume();
+
+ ka.getSendBuffer().insert_string(ka.getSendBuffer().end(),
+ "KStreamServerIp4 says hello!");
+ if (!ka.send()) {
+ DebuggerPrint("KStreamServerIp4 send failed: %d\n", ka.getLastError());
+ return false;
+ }
+ ka.getSendBuffer().consume();
+
+ // Wait for the connection termination.
+ ka.recv();
+
+ return true;
+ };
+ if (!tcp4_server.accept(accept_fn)) {
+ DebuggerPrint("KStreamServerIp4 accept() failed: %d\n",
+ tcp4_server.getLastError());
+ return STATUS_FAILED_DRIVER_ENTRY;
+ }
+ DebuggerPrint("KStreamServerIp4 done\n");
+ }
+
KsDestroy();
return STATUS_SUCCESS;
diff --git a/examples/userspace_client_flatbuffers.cpp b/examples/userspace_client_flatbuffers.cpp
new file mode 100644
index 0000000..9f43698
--- /dev/null
+++ b/examples/userspace_client_flatbuffers.cpp
@@ -0,0 +1,82 @@
+#include <stdio.h>
+#include <stdlib.h> // Needed for _wtoi
+#include <winsock2.h>
+#include <ws2tcpip.h>
+
+#include <ksocket/ksocket.hpp>
+#include <ksocket/helper.hpp>
+
+#include "apiwrapper_builder.h"
+#include "apiwrapper_reader.h"
+#include "apiwrapper_verifier.h"
+
+int main(int argc, char **argv) {
+ WSADATA wsaData = {};
+ int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
+
+ UNREFERENCED_PARAMETER(argc);
+ UNREFERENCED_PARAMETER(argv);
+
+ if (iResult != 0) {
+ wprintf(L"WSAStartup failed: %d\n", iResult);
+ return 1;
+ }
+
+ SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+
+ if (sock == INVALID_SOCKET) {
+ wprintf(L"socket function failed with error = %d\n", WSAGetLastError());
+ } else {
+ wprintf(L"socket function succeeded\n");
+ }
+
+ sockaddr_in clientService;
+ clientService.sin_family = AF_INET;
+ clientService.sin_addr.s_addr = inet_addr("127.0.0.1");
+ clientService.sin_port = htons(9096);
+
+ do {
+ iResult = connect(sock, (SOCKADDR *)&clientService, sizeof(clientService));
+ if (iResult == SOCKET_ERROR) {
+ wprintf(L"connect function failed with error: %ld\n", WSAGetLastError());
+ Sleep(1000);
+ }
+ } while (iResult == SOCKET_ERROR);
+
+ wprintf(L"Connected to server.\n");
+
+ flatcc_builder_t builder;
+ flatcc_builder_init(&builder);
+ for (size_t i = 0; i < 256; ++i) {
+ FunctionAddresses_start_as_root(&builder);
+ FunctionAddresses_names_add(&builder, flatbuffers_string_create_str(&builder, "A"));
+ FunctionAddresses_names_add(&builder, flatbuffers_string_create_str(&builder, "B"));
+ FunctionAddresses_names_add(&builder, flatbuffers_string_create_str(&builder, "C"));
+ FunctionAddresses_end_as_root(&builder);
+
+ KSocketBuffer buffer;
+ void *buf;
+ size_t siz;
+ buf = flatcc_builder_finalize_aligned_buffer(&builder, &siz);
+ (void)buf;
+ uint8_t a[] = {0x41,0x41,0x41};
+ buffer.insert_u16(buffer.begin(), 65535);
+ buffer.insert_bytebuffer(buffer.begin(), a, 3);
+ }
+
+ wprintf(L"Closing Connection ..\n");
+
+ iResult = closesocket(sock);
+ if (iResult == SOCKET_ERROR) {
+ wprintf(L"closesocket function failed with error: %ld\n",
+ WSAGetLastError());
+ WSACleanup();
+ return 1;
+ }
+
+ WSACleanup();
+
+ system("pause");
+
+ return 0;
+}
diff --git a/examples/userspace_client_protobuf.cpp b/examples/userspace_client_protobuf.cpp
index a387579..1eadc0c 100644
--- a/examples/userspace_client_protobuf.cpp
+++ b/examples/userspace_client_protobuf.cpp
@@ -4,6 +4,7 @@
#include <ws2tcpip.h>
#include <ksocket/helper.hpp>
+#include <ksocket/utils.h>
#include "examples/common.hpp"
#include "examples/example.pb-c.h"