fd-net-device: Fix -Werror=stringop-truncation with GCC 8. Using IFNAMSIZ - 1 is safe because in all cases the dest structure is initialized with 0.
This commit is contained in:
@@ -107,7 +107,7 @@ EmuFdNetDeviceHelper::SetFileDescriptor (Ptr<FdNetDevice> device) const
|
||||
//
|
||||
struct ifreq ifr;
|
||||
bzero (&ifr, sizeof(ifr));
|
||||
strncpy ((char *)ifr.ifr_name, m_deviceName.c_str (), IFNAMSIZ);
|
||||
strncpy ((char *)ifr.ifr_name, m_deviceName.c_str (), IFNAMSIZ - 1);
|
||||
|
||||
NS_LOG_LOGIC ("Getting interface index");
|
||||
int32_t rc = ioctl (fd, SIOCGIFINDEX, &ifr);
|
||||
|
||||
@@ -121,7 +121,7 @@ SetIpv4 (const char *deviceName, const char *ip, const char *netmask)
|
||||
// Set the IP address of the new interface/device.
|
||||
//
|
||||
memset(&ifr, 0, sizeof(struct ifreq));
|
||||
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ);
|
||||
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ - 1);
|
||||
|
||||
sin = (struct sockaddr_in*) &ifr.ifr_addr;
|
||||
inet_pton(AF_INET, ip, &sin->sin_addr);
|
||||
@@ -136,7 +136,7 @@ SetIpv4 (const char *deviceName, const char *ip, const char *netmask)
|
||||
// Set the net mask of the new interface/device
|
||||
//
|
||||
memset(&ifr, 0, sizeof(struct ifreq));
|
||||
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ);
|
||||
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ - 1);
|
||||
|
||||
sin = (struct sockaddr_in*) &ifr.ifr_netmask;
|
||||
inet_pton(AF_INET, netmask, &sin->sin_addr);
|
||||
@@ -158,7 +158,7 @@ SetIpv6 (const char* deviceName, const char *ip, int netprefix)
|
||||
|
||||
int sock = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
memset(&ifr, 0, sizeof(struct ifreq));
|
||||
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ);
|
||||
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ - 1);
|
||||
|
||||
ABORT_IF (ioctl (sock, SIOGIFINDEX, &ifr) == -1,
|
||||
"Could not get interface index", true);
|
||||
@@ -206,7 +206,7 @@ SetUp (char *deviceName)
|
||||
int sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
memset(&ifr, 0, sizeof(struct ifreq));
|
||||
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ);
|
||||
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ - 1);
|
||||
|
||||
ABORT_IF (ioctl (sock, SIOCGIFFLAGS, &ifr) == -1,
|
||||
"Could not get flags for interface", true);
|
||||
@@ -248,7 +248,7 @@ CreateTap (char *deviceName, const char *mac, const int ifftap, const int iffpi,
|
||||
//
|
||||
if (*deviceName)
|
||||
{
|
||||
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ);
|
||||
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ - 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user