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