Skip to content

Commit

Permalink
Replace casts
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 28, 2025
1 parent e588dfb commit 8214305
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cpp/devices/tap_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ string TapDriver::Init(const param_map &const_params, logger &logger)
ifreq ifr = { };
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
strncpy(ifr.ifr_name, BRIDGE_INTERFACE_NAME.c_str(), IFNAMSIZ - 1); // NOSONAR Using strncpy is safe
if (const int ret = ioctl(tap_fd, TUNSETIFF, reinterpret_cast<void*>(&ifr)); ret == -1) {
if (const int ret = ioctl(tap_fd, TUNSETIFF, static_cast<void*>(&ifr)); ret == -1) {
close(tap_fd);
return fmt::format("Can't ioctl TUNSETIFF: {}", strerror(errno));
}
Expand Down Expand Up @@ -192,15 +192,15 @@ string TapDriver::SetAddressAndNetMask(int fd, const string &interface, logger &
ifreq ifr_a;
ifr_a.ifr_addr.sa_family = AF_INET;
strncpy(ifr_a.ifr_name, interface.c_str(), IFNAMSIZ - 1); // NOSONAR Using strncpy is safe
if (auto *addr = reinterpret_cast<sockaddr_in*>(&ifr_a.ifr_addr);
if (auto *addr = (sockaddr_in*)&ifr_a.ifr_addr;
inet_pton(AF_INET, address.c_str(), &addr->sin_addr) != 1) {
return "Can't convert '" + address + "' into a network address";
}

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

0 comments on commit 8214305

Please sign in to comment.