working commit

This commit is contained in:
2026-04-22 18:15:05 +02:00
parent f1b7d9783d
commit 76c797b489
13 changed files with 207 additions and 135 deletions
+14 -1
View File
@@ -270,6 +270,19 @@ std::expected<void, std::string> Interface::Down(void) {
return {};
}
std::expected<std::string, std::string> Interface::Read() {
char buffer[mtu];
int rsize = 0;
if ((rsize = read(tunfd, buffer, sizeof(buffer))) < 0) {
int errnocopy = errno;
std::string error = std::strerror(errnocopy);
return std::unexpected("Read interface error: " + error);
}
std::string rdata;
rdata.append(buffer, rsize);
return rdata;
}
std::string Interface::Name() {
return ifname;
}
@@ -282,6 +295,7 @@ Interface::~Interface() {
close(tunfd);
}
std::expected<void, std::string> Interface::UpN(void) {
int netlinkfd = 0;
if ((netlinkfd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE)) < 0) {
@@ -313,7 +327,6 @@ std::expected<void, std::string> Interface::UpN(void) {
return {};
}
std::expected<void, std::string> Interface::SetIP4AddrMask(const std::string address, const int prefix) {
int netlinkfd = 0;
if ((netlinkfd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE)) < 0) {