working commit

This commit is contained in:
2026-05-15 15:30:29 +02:00
parent 879481feab
commit 886684e224
28 changed files with 629 additions and 81 deletions
+1 -4
View File
@@ -155,14 +155,12 @@ std::expected<void, std::string> Interface::SetIP4Address(std::string ipaddr) {
std::string error = std::strerror(errnocopy);
return std::unexpected("Set address error: " + error);
}
int sockfd = 0;
if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
int errnocopy = errno;
std::string error = std::strerror(errnocopy);
return std::unexpected("Set address error: " + error);
}
if (ioctl(sockfd, SIOCSIFADDR, &ifr) < 0) {
close(sockfd);
int errnocopy = errno;
@@ -177,8 +175,7 @@ std::expected<void, std::string> Interface::SetIP4Netmask(int prefix) {
if (prefix < 0 || prefix > 32) {
return std::unexpected("Invalid prefix");
}
//uint32_t mask = (prefix == 0) ? 0 : (~0U << (32 - prefix));
uint32_t mask = (prefix == 0) ? 0 : htonl(~((1U << (32 - prefix)) - 1));
uint32_t mask = (prefix == 0) ? 0 : (~0U << (32 - prefix));
struct in_addr maskaddr;
maskaddr.s_addr = htonl(mask);