*: s/IF_NAMESIZE/IFNAMSIZ/, regularize its use a bit.
function old new delta
strncpy_IFNAMSIZ - 13 +13
set_slave_mtu 39 37 -2
set_slave_hwaddr 52 50 -2
set_master_hwaddr 52 50 -2
set_if_flags 40 38 -2
get_if_settings 101 98 -3
ifenslave_main 1680 1661 -19
vconfig_main 306 280 -26
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/7 up/down: 13/-56) Total: -43 bytes
diff --git a/networking/ifenslave.c b/networking/ifenslave.c
index b119517..0aa2320 100644
--- a/networking/ifenslave.c
+++ b/networking/ifenslave.c
@@ -148,6 +148,10 @@
static int enslave(char *master_ifname, char *slave_ifname);
static int release(char *master_ifname, char *slave_ifname);
+static void strncpy_IFNAMSIZ(char *dst, const char *src)
+{
+ strncpy(dst, src, IFNAMSIZ);
+}
int ifenslave_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ifenslave_main(int argc ATTRIBUTE_UNUSED, char **argv)
@@ -302,7 +306,7 @@
struct ethtool_drvinfo info;
memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
ifr.ifr_data = (caddr_t)&info;
info.cmd = ETHTOOL_GDRVINFO;
@@ -332,8 +336,8 @@
slave_ifname);
}
- strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
- strncpy(ifr.ifr_slave, slave_ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
+ strncpy_IFNAMSIZ(ifr.ifr_slave, slave_ifname);
if (ioctl(skfd, SIOCBONDCHANGEACTIVE, &ifr) < 0
&& ioctl(skfd, BOND_CHANGE_ACTIVE_OLD, &ifr) < 0
) {
@@ -448,8 +452,8 @@
}
/* Do the real thing */
- strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
- strncpy(ifr.ifr_slave, slave_ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
+ strncpy_IFNAMSIZ(ifr.ifr_slave, slave_ifname);
if (ioctl(skfd, SIOCBONDENSLAVE, &ifr) < 0
&& ioctl(skfd, BOND_ENSLAVE_OLD, &ifr) < 0
) {
@@ -484,8 +488,8 @@
return 1;
}
- strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
- strncpy(ifr.ifr_slave, slave_ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
+ strncpy_IFNAMSIZ(ifr.ifr_slave, slave_ifname);
if (ioctl(skfd, SIOCBONDRELEASE, &ifr) < 0
&& ioctl(skfd, BOND_RELEASE_OLD, &ifr) < 0
) {
@@ -508,11 +512,11 @@
{
int res;
- strncpy(dd->mtu.ifr_name, ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(dd->mtu.ifr_name, ifname);
res = ioctl(skfd, SIOCGIFMTU, &dd->mtu);
- strncpy(dd->flags.ifr_name, ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(dd->flags.ifr_name, ifname);
res |= ioctl(skfd, SIOCGIFFLAGS, &dd->flags);
- strncpy(dd->hwaddr.ifr_name, ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(dd->hwaddr.ifr_name, ifname);
res |= ioctl(skfd, SIOCGIFHWADDR, &dd->hwaddr);
return res;
@@ -520,7 +524,7 @@
static int get_slave_flags(char *slave_ifname)
{
- strncpy(slave.flags.ifr_name, slave_ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(slave.flags.ifr_name, slave_ifname);
return ioctl(skfd, SIOCGIFFLAGS, &slave.flags);
}
@@ -528,7 +532,7 @@
{
struct ifreq ifr;
- strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
memcpy(&(ifr.ifr_hwaddr), hwaddr, sizeof(struct sockaddr));
return ioctl(skfd, SIOCSIFHWADDR, &ifr);
}
@@ -537,7 +541,7 @@
{
struct ifreq ifr;
- strncpy(ifr.ifr_name, slave_ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(ifr.ifr_name, slave_ifname);
memcpy(&(ifr.ifr_hwaddr), hwaddr, sizeof(struct sockaddr));
return ioctl(skfd, SIOCSIFHWADDR, &ifr);
}
@@ -547,7 +551,7 @@
struct ifreq ifr;
ifr.ifr_mtu = mtu;
- strncpy(ifr.ifr_name, slave_ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(ifr.ifr_name, slave_ifname);
return ioctl(skfd, SIOCSIFMTU, &ifr);
}
@@ -556,7 +560,7 @@
struct ifreq ifr;
ifr.ifr_flags = flags;
- strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(ifr.ifr_name, ifname);
return ioctl(skfd, SIOCSIFFLAGS, &ifr);
}
@@ -580,7 +584,7 @@
{
struct ifreq ifr;
- strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(ifr.ifr_name, ifname);
ifr.ifr_addr.sa_family = AF_INET;
memset(ifr.ifr_addr.sa_data, 0, sizeof(ifr.ifr_addr.sa_data));
return ioctl(skfd, SIOCSIFADDR, &ifr);
@@ -603,7 +607,7 @@
int i;
for (i = 0; i < ARRAY_SIZE(ifra); i++) {
- strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
res = ioctl(skfd, ifra[i].g_ioctl, &ifr);
if (res < 0) {
ifr.ifr_addr.sa_family = AF_INET;
@@ -611,7 +615,7 @@
sizeof(ifr.ifr_addr.sa_data));
}
- strncpy(ifr.ifr_name, slave_ifname, IFNAMSIZ);
+ strncpy_IFNAMSIZ(ifr.ifr_name, slave_ifname);
res = ioctl(skfd, ifra[i].s_ioctl, &ifr);
if (res < 0)
return res;