working commit
This commit is contained in:
+14
-1
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user