73 lines
1.9 KiB
C++
73 lines
1.9 KiB
C++
|
|
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;
|
|
}
|