Skip to content

Commit

Permalink
Set bridge addr
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Feb 7, 2024
1 parent 940ed62 commit 7c3df1b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cpp/devices/ctapdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,33 @@ bool CTapDriver::Init(const param_map &const_params)
}
}
else {
const auto [address, netmask] = ExtractAddressAndMask(inet);
if (address.empty() || netmask.empty()) {
return cleanUp("Error extracting inet address and netmask");
}

ifreq ifr_a;
ifr_a.ifr_addr.sa_family = AF_INET;
strncpy(ifr_a.ifr_name, BRIDGE_INTERFACE_NAME.c_str(), IFNAMSIZ - 1); // NOSONAR Using strncpy is safe
if (auto addr = (sockaddr_in*)&ifr_a.ifr_addr;
inet_pton(AF_INET, address.c_str(), &addr->sin_addr) != 1) {
return cleanUp("Can't convert '" + address + "' into a network address");
}

ifreq ifr_n;
ifr_n.ifr_addr.sa_family = AF_INET;
strncpy(ifr_n.ifr_name, BRIDGE_INTERFACE_NAME.c_str(), IFNAMSIZ - 1); // NOSONAR Using strncpy is safe
if (auto mask = (sockaddr_in*)&ifr_n.ifr_addr;
inet_pton(AF_INET, netmask.c_str(), &mask->sin_addr) != 1) {
return cleanUp("Can't convert '" + netmask + "' into a netmask");
}

trace(">ip addr add " + DEFAULT_IP + " brd + dev " + BRIDGE_INTERFACE_NAME);

if (ioctl(ip_fd, SIOCSIFADDR, &ifr_a) == -1 || ioctl(ip_fd, SIOCSIFNETMASK, &ifr_n) == -1) {
return cleanUp("Can't ioctl SIOCSIFADDR or SIOCSIFNETMASK");
}

// TODO
}

Expand Down

0 comments on commit 7c3df1b

Please sign in to comment.