initial commit

This commit is contained in:
2026-04-21 11:01:03 +02:00
commit e9a527b5de
19 changed files with 12675 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
extern "C" {
#include <arpa/inet.h>
}
#include <expected>
#include <string>
#include <vector>
#include <span>
#include <iostream>
#include <thread>
#include <chrono>
#include <cstring>
#include <tunnel.hpp>
#include <service.hpp>
using namespace std::chrono_literals;
class Server {
private:
Interface iface;
public:
std::expected<void, std::string> Create(const std::string name, const std::string addr, const int prefix);
};
std::expected<void, std::string> Server::Create(const std::string name, const std::string addr, const int prefix) {
auto createres = iface.Create(name);
if (!createres) {
return std::unexpected(createres.error());
}
auto setaddrres = iface.SetIP4Address(addr);
if (!setaddrres) {
return std::unexpected(setaddrres.error());
}
auto setprefixres = iface.SetIP4Netmask(24);
if (!setprefixres) {
return std::unexpected(setprefixres.error());
}
auto setmtures = iface.SetMTU(1240);
if (!setmtures) {
return std::unexpected(setmtures.error());
}
return {};
}
int main(int argc, char** argv) {
#if 0
Service svc(1025);
auto bindres = svc.Bind();
if (!bindres) {
std::cerr << bindres.error() << std::endl;
return 1;
}
Handler handler;
auto listres = svc.Listen(&handler);
if (!listres) {
std::cerr << listres.error() << std::endl;
return 1;
}
#endif
Server srv;
auto createres = srv.Create("tun10", "10.1.2.1", 30);
if (!createres) {
std::cerr << "Error: " << createres.error() << std::endl;
return 1;
}
std::chrono::milliseconds timesleep(20s);
std::this_thread::sleep_for(timesleep);
return 0;
}