Fix setMtu() on Linux. Add error checking (#1860)

* Fix setMtu() on Linux. Add error checking

* Slightly tweak ioctl MTU error message
This commit is contained in:
Joseph Henry 2023-01-26 10:26:12 -08:00 committed by GitHub
parent b88d7091c8
commit e0a3291235
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -553,8 +553,11 @@ void LinuxEthernetTap::setMtu(unsigned int mtu)
if (sock > 0) {
struct ifreq ifr;
memset(&ifr,0,sizeof(ifr));
strcpy(ifr.ifr_name,_dev.c_str());
ifr.ifr_ifru.ifru_mtu = (int)mtu;
ioctl(sock,SIOCSIFMTU,(void *)&ifr);
if (ioctl(sock,SIOCSIFMTU,(void *)&ifr) < 0) {
printf("WARNING: ioctl() failed updating existing Linux tap device (set MTU)\n");
}
close(sock);
}
}