aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
Diffstat (limited to 'networking')
-rw-r--r--networking/arp.c9
-rw-r--r--networking/arping.c9
-rw-r--r--networking/ether-wake.c6
-rw-r--r--networking/ifconfig.c18
-rw-r--r--networking/interface.c3
-rw-r--r--networking/libiproute/ipaddress.c3
-rw-r--r--networking/libiproute/iplink.c32
-rw-r--r--networking/libiproute/iptunnel.c80
-rw-r--r--networking/nameif.c6
-rw-r--r--networking/route.c19
-rw-r--r--networking/slattach.c12
-rw-r--r--networking/traceroute.c4
-rw-r--r--networking/udhcp/socket.c12
-rw-r--r--networking/vconfig.c5
-rw-r--r--networking/zcip.c4
15 files changed, 86 insertions, 136 deletions
diff --git a/networking/arp.c b/networking/arp.c
index 6a7c862b8..e529257a8 100644
--- a/networking/arp.c
+++ b/networking/arp.c
@@ -188,9 +188,8 @@ static void arp_getdevhw(char *ifname, struct sockaddr *sa,
const struct hwtype *xhw;
strcpy(ifr.ifr_name, ifname);
- if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) < 0) {
- bb_perror_msg_and_die("cant get HW-Address for '%s'", ifname);
- }
+ ioctl_or_perror_and_die(sockfd, SIOCGIFHWADDR, &ifr,
+ "cant get HW-Address for '%s'", ifname);
if (hwt && (ifr.ifr_hwaddr.sa_family != hw->type)) {
bb_error_msg_and_die("protocol type mismatch");
}
@@ -306,9 +305,7 @@ static int arp_set(char **args)
/* Call the kernel. */
if (option_mask32 & ARP_OPT_v)
bb_error_msg("SIOCSARP()");
- if (ioctl(sockfd, SIOCSARP, &req) < 0) {
- bb_perror_msg_and_die("SIOCSARP");
- }
+ xioctl(sockfd, SIOCSARP, &req);
return 0;
}
diff --git a/networking/arping.c b/networking/arping.c
index 7a9fbc2f4..8e457b13a 100644
--- a/networking/arping.c
+++ b/networking/arping.c
@@ -273,14 +273,11 @@ int arping_main(int argc, char **argv)
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, device, IFNAMSIZ - 1);
- if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0) {
- bb_error_msg_and_die("interface %s not found", device);
- }
+ ioctl_or_perror_and_die(sock, SIOCGIFINDEX, &ifr, "interface %s not found", device);
ifindex = ifr.ifr_ifindex;
- if (ioctl(sock, SIOCGIFFLAGS, (char *) &ifr)) {
- bb_error_msg_and_die("SIOCGIFFLAGS");
- }
+ xioctl(sock, SIOCGIFFLAGS, (char *) &ifr);
+
if (!(ifr.ifr_flags & IFF_UP)) {
bb_error_msg_and_die("interface %s is down", device);
}
diff --git a/networking/ether-wake.c b/networking/ether-wake.c
index 9de0d489b..b67e1b5d8 100644
--- a/networking/ether-wake.c
+++ b/networking/ether-wake.c
@@ -220,8 +220,7 @@ int ether_wake_main(int argc, char **argv)
struct ifreq if_hwaddr;
strncpy(if_hwaddr.ifr_name, ifname, sizeof(if_hwaddr.ifr_name));
- if (ioctl(s, SIOCGIFHWADDR, &if_hwaddr) != 0)
- bb_perror_msg_and_die("SIOCGIFHWADDR on %s failed", ifname);
+ ioctl_or_perror_and_die(s, SIOCGIFHWADDR, &if_hwaddr, "SIOCGIFHWADDR on %s failed", ifname);
memcpy(outpack+6, if_hwaddr.ifr_hwaddr.sa_data, 6);
@@ -257,8 +256,7 @@ int ether_wake_main(int argc, char **argv)
{
struct ifreq ifr;
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
- if (ioctl(s, SIOCGIFINDEX, &ifr) != 0)
- bb_perror_msg_and_die("SIOCGIFINDEX");
+ xioctl(s, SIOCGIFINDEX, &ifr);
memset(&whereto, 0, sizeof(whereto));
whereto.sll_family = AF_PACKET;
whereto.sll_ifindex = ifr.ifr_ifindex;
diff --git a/networking/ifconfig.c b/networking/ifconfig.c
index 5e11b2b7c..0d53676cd 100644
--- a/networking/ifconfig.c
+++ b/networking/ifconfig.c
@@ -402,12 +402,10 @@ int ifconfig_main(int argc, char **argv)
/* Create a channel to the NET kernel. */
sockfd6 = xsocket(AF_INET6, SOCK_DGRAM, 0);
- if (ioctl(sockfd6, SIOGIFINDEX, &ifr) < 0)
- bb_perror_msg_and_die("SIOGIFINDEX");
+ xioctl(sockfd6, SIOGIFINDEX, &ifr);
ifr6.ifr6_ifindex = ifr.ifr_ifindex;
ifr6.ifr6_prefixlen = prefix_len;
- if (ioctl(sockfd6, a1op->selector, &ifr6) < 0)
- bb_perror_msg_and_die(a1op->name);
+ ioctl_or_perror_and_die(sockfd6, a1op->selector, &ifr6, "%s", a1op->name);
if (ENABLE_FEATURE_CLEAN_UP)
free(lsa);
continue;
@@ -444,8 +442,7 @@ int ifconfig_main(int argc, char **argv)
p = ((char *)&ifr) + a1op->ifr_offset;
#if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
if (mask & A_MAP_TYPE) {
- if (ioctl(sockfd, SIOCGIFMAP, &ifr) < 0)
- bb_perror_msg_and_die("SIOCGIFMAP");
+ xioctl(sockfd, SIOCGIFMAP, &ifr);
if ((mask & A_MAP_UCHAR) == A_MAP_UCHAR)
*((unsigned char *) p) = i;
else if (mask & A_MAP_USHORT)
@@ -460,8 +457,7 @@ int ifconfig_main(int argc, char **argv)
*((int *) p) = i;
}
- if (ioctl(sockfd, a1op->selector, &ifr) < 0)
- bb_perror_msg_and_die(a1op->name);
+ ioctl_or_perror_and_die(sockfd, a1op->selector, &ifr, "%s", a1op->name);
#ifdef QUESTIONABLE_ALIAS_CASE
if (mask & A_COLON_CHK) {
/*
@@ -486,15 +482,13 @@ int ifconfig_main(int argc, char **argv)
mask = N_SET;
}
- if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0)
- bb_perror_msg_and_die("SIOCGIFFLAGS");
+ xioctl(sockfd, SIOCGIFFLAGS, &ifr);
selector = op->selector;
if (mask & SET_MASK)
ifr.ifr_flags |= selector;
else
ifr.ifr_flags &= ~selector;
- if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0)
- bb_perror_msg_and_die("SIOCSIFFLAGS");
+ xioctl(sockfd, SIOCSIFFLAGS, &ifr);
} /* while () */
if (ENABLE_FEATURE_CLEAN_UP)
diff --git a/networking/interface.c b/networking/interface.c
index 204febf7d..ea02f4cc9 100644
--- a/networking/interface.c
+++ b/networking/interface.c
@@ -521,8 +521,7 @@ static int if_readconf(void)
ifc.ifc_len = sizeof(struct ifreq) * numreqs;
ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len);
- if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) {
- bb_perror_msg("SIOCGIFCONF");
+ if (ioctl_or_warn(skfd, SIOCGIFCONF, &ifc) < 0) {
goto out;
}
if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) {
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index a4add6a47..fc10ba37c 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -84,8 +84,7 @@ static void print_queuelen(char *name)
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
- if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) {
- bb_perror_msg("SIOCGIFXQLEN");
+ if (ioctl_or_warn(s, SIOCGIFTXQLEN, &ifr) < 0) {
close(s);
return;
}
diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c
index 7db4d7e15..3d3ea2a23 100644
--- a/networking/libiproute/iplink.c
+++ b/networking/libiproute/iplink.c
@@ -49,14 +49,11 @@ static void do_chflags(char *dev, uint32_t flags, uint32_t mask)
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
fd = get_ctl_fd();
- if (ioctl(fd, SIOCGIFFLAGS, &ifr)) {
- bb_perror_msg_and_die("SIOCGIFFLAGS");
- }
+ xioctl(fd, SIOCGIFFLAGS, &ifr);
if ((ifr.ifr_flags ^ flags) & mask) {
ifr.ifr_flags &= ~mask;
ifr.ifr_flags |= mask & flags;
- if (ioctl(fd, SIOCSIFFLAGS, &ifr))
- bb_perror_msg_and_die("SIOCSIFFLAGS");
+ xioctl(fd, SIOCSIFFLAGS, &ifr);
}
close(fd);
}
@@ -66,15 +63,11 @@ static void do_changename(char *dev, char *newdev)
{
struct ifreq ifr;
int fd;
- int err;
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
strncpy(ifr.ifr_newname, newdev, sizeof(ifr.ifr_newname));
fd = get_ctl_fd();
- err = ioctl(fd, SIOCSIFNAME, &ifr);
- if (err) {
- bb_perror_msg_and_die("SIOCSIFNAME");
- }
+ xioctl(fd, SIOCSIFNAME, &ifr);
close(fd);
}
@@ -88,9 +81,7 @@ static void set_qlen(char *dev, int qlen)
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
ifr.ifr_qlen = qlen;
- if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) {
- bb_perror_msg_and_die("SIOCSIFXQLEN");
- }
+ xioctl(s, SIOCSIFTXQLEN, &ifr);
close(s);
}
@@ -104,9 +95,7 @@ static void set_mtu(char *dev, int mtu)
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
ifr.ifr_mtu = mtu;
- if (ioctl(s, SIOCSIFMTU, &ifr) < 0) {
- bb_perror_msg_and_die("SIOCSIFMTU");
- }
+ xioctl(s, SIOCSIFMTU, &ifr);
close(s);
}
@@ -122,9 +111,7 @@ static int get_address(char *dev, int *htype)
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
- if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
- bb_perror_msg_and_die("SIOCGIFINDEX");
- }
+ xioctl(s, SIOCGIFINDEX, &ifr);
memset(&me, 0, sizeof(me));
me.sll_family = AF_PACKET;
@@ -163,9 +150,10 @@ static void set_address(struct ifreq *ifr, int brd)
int s;
s = get_ctl_fd();
- if (ioctl(s, brd ? SIOCSIFHWBROADCAST :SIOCSIFHWADDR, ifr) < 0) {
- bb_perror_msg_and_die(brd ? "SIOCSIFHWBROADCAST" : "SIOCSIFHWADDR");
- }
+ if (brd)
+ xioctl(s, SIOCSIFHWBROADCAST, ifr);
+ else
+ xioctl(s, SIOCSIFHWADDR, ifr);
close(s);
}
diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c
index b12bceb45..90d0e1186 100644
--- a/networking/libiproute/iptunnel.c
+++ b/networking/libiproute/iptunnel.c
@@ -14,8 +14,6 @@
* Phil Karn <karn@ka9q.ampr.org> 990408: "pmtudisc" flag
*/
-//#include <sys/socket.h>
-//#include <sys/ioctl.h>
#include <netinet/ip.h>
#include <net/if.h>
#include <net/if_arp.h>
@@ -38,9 +36,7 @@ static int do_ioctl_get_ifindex(char *dev)
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
- if (ioctl(fd, SIOCGIFINDEX, &ifr)) {
- bb_perror_msg_and_die("SIOCGIFINDEX");
- }
+ xioctl(fd, SIOCGIFINDEX, &ifr);
close(fd);
return ifr.ifr_ifindex;
}
@@ -49,30 +45,26 @@ static int do_ioctl_get_iftype(char *dev)
{
struct ifreq ifr;
int fd;
+ int err;
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
- if (ioctl(fd, SIOCGIFHWADDR, &ifr)) {
- bb_perror_msg("SIOCGIFHWADDR");
- return -1;
- }
+ err = ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr);
close(fd);
- return ifr.ifr_addr.sa_family;
+ return err ? -1 : ifr.ifr_addr.sa_family;
}
static char *do_ioctl_get_ifname(int idx)
{
struct ifreq ifr;
int fd;
+ int err;
ifr.ifr_ifindex = idx;
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
- if (ioctl(fd, SIOCGIFNAME, &ifr)) {
- bb_perror_msg("SIOCGIFNAME");
- return NULL;
- }
+ err = ioctl_or_warn(fd, SIOCGIFNAME, &ifr);
close(fd);
- return xstrndup(ifr.ifr_name, sizeof(ifr.ifr_name));
+ return err ? NULL : xstrndup(ifr.ifr_name, sizeof(ifr.ifr_name));
}
static int do_get_ioctl(const char *basedev, struct ip_tunnel_parm *p)
@@ -84,10 +76,7 @@ static int do_get_ioctl(const char *basedev, struct ip_tunnel_parm *p)
strncpy(ifr.ifr_name, basedev, sizeof(ifr.ifr_name));
ifr.ifr_ifru.ifru_data = (void*)p;
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
- err = ioctl(fd, SIOCGETTUNNEL, &ifr);
- if (err) {
- bb_perror_msg("SIOCGETTUNNEL");
- }
+ err = ioctl_or_warn(fd, SIOCGETTUNNEL, &ifr);
close(fd);
return err;
}
@@ -105,9 +94,15 @@ static int do_add_ioctl(int cmd, const char *basedev, struct ip_tunnel_parm *p)
}
ifr.ifr_ifru.ifru_data = (void*)p;
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
- if (ioctl(fd, cmd, &ifr)) {
- bb_perror_msg_and_die("ioctl");
- }
+#if ENABLE_IOCTL_HEX2STR_ERROR
+ /* #define magic will turn ioctl# into string */
+ if (cmd == SIOCCHGTUNNEL)
+ xioctl(fd, SIOCCHGTUNNEL, &ifr);
+ else
+ xioctl(fd, SIOCADDTUNNEL, &ifr);
+#else
+ xioctl(fd, cmd, &ifr);
+#endif
close(fd);
return 0;
}
@@ -125,9 +120,7 @@ static int do_del_ioctl(const char *basedev, struct ip_tunnel_parm *p)
}
ifr.ifr_ifru.ifru_data = (void*)p;
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
- if (ioctl(fd, SIOCDELTUNNEL, &ifr)) {
- bb_perror_msg_and_die("SIOCDELTUNNEL");
- }
+ xioctl(fd, SIOCDELTUNNEL, &ifr);
close(fd);
return 0;
}
@@ -526,29 +519,24 @@ static int do_show(int argc, char **argv)
/* Return value becomes exitcode. It's okay to not return at all */
int do_iptunnel(int argc, char **argv)
{
- static const char * const keywords[] = {
+ static const char *const keywords[] = {
"add", "change", "delete", "show", "list", "lst", NULL
};
- enum {ARG_add = 1, ARG_change, ARG_del, ARG_show, ARG_list, ARG_lst};
- smalluint key = 4; /* show */
- if (argc > 0) {
- key = index_in_substr_array(keywords, *argv) +1;
+ enum { ARG_add = 0, ARG_change, ARG_del, ARG_show, ARG_list, ARG_lst };
+ int key;
+
+ if (argc) {
+ key = index_in_substr_array(keywords, *argv);
+ if (key < 0)
+ bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
--argc;
++argv;
- } else
- return do_show(0, NULL);
- if (key < ARG_add)
- bail:
- bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
-
- if (key == ARG_add)
- return do_add(SIOCADDTUNNEL, argc, argv);
- if (key == ARG_change)
- return do_add(SIOCCHGTUNNEL, argc, argv);
- if (key == ARG_del)
- return do_del(argc, argv);
- if (key == ARG_show || key == ARG_list || key == ARG_lst)
- return do_show(argc, argv);
- /* be gentle to gcc; avoid warning about non returning */
- goto bail; /* never reached */
+ if (key == ARG_add)
+ return do_add(SIOCADDTUNNEL, argc, argv);
+ if (key == ARG_change)
+ return do_add(SIOCCHGTUNNEL, argc, argv);
+ if (key == ARG_del)
+ return do_del(argc, argv);
+ }
+ return do_show(argc, argv);
}
diff --git a/networking/nameif.c b/networking/nameif.c
index a65f30819..fd081fd63 100644
--- a/networking/nameif.c
+++ b/networking/nameif.c
@@ -148,9 +148,9 @@ int nameif_main(int argc, char **argv)
continue;
strcpy(ifr.ifr_newname, ch->ifname);
- if (ioctl(ctl_sk, SIOCSIFNAME, &ifr) < 0)
- bb_perror_msg_and_die("cannot change ifname %s to %s",
- ifr.ifr_name, ch->ifname);
+ ioctl_or_perror_and_die(ctl_sk, SIOCSIFNAME, &ifr,
+ "cannot change ifname %s to %s",
+ ifr.ifr_name, ch->ifname);
/* Remove list entry of renamed interface */
if (ch->prev != NULL) {
diff --git a/networking/route.c b/networking/route.c
index b5490ddd8..530c51b10 100644
--- a/networking/route.c
+++ b/networking/route.c
@@ -327,9 +327,10 @@ static void INET_setroute(int action, char **args)
/* Create a socket to the INET kernel. */
skfd = xsocket(AF_INET, SOCK_DGRAM, 0);
- if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) {
- bb_perror_msg_and_die("SIOC[ADD|DEL]RT");
- }
+ if (action == RTACTION_ADD)
+ xioctl(skfd, SIOCADDRT, &rt);
+ else
+ xioctl(skfd, SIOCDELRT, &rt);
if (ENABLE_FEATURE_CLEAN_UP) close(skfd);
}
@@ -423,17 +424,15 @@ static void INET6_setroute(int action, char **args)
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name));
-
- if (ioctl(skfd, SIOGIFINDEX, &ifr) < 0) {
- bb_perror_msg_and_die("SIOGIFINDEX");
- }
+ xioctl(skfd, SIOGIFINDEX, &ifr);
rt.rtmsg_ifindex = ifr.ifr_ifindex;
}
/* Tell the kernel to accept this route. */
- if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) {
- bb_perror_msg_and_die("SIOC[ADD|DEL]RT");
- }
+ if (action == RTACTION_ADD)
+ xioctl(skfd, SIOCADDRT, &rt);
+ else
+ xioctl(skfd, SIOCDELRT, &rt);
if (ENABLE_FEATURE_CLEAN_UP) close(skfd);
}
diff --git a/networking/slattach.c b/networking/slattach.c
index 3495df598..1a4423b72 100644
--- a/networking/slattach.c
+++ b/networking/slattach.c
@@ -50,8 +50,7 @@ static void save_state(void)
bb_perror_msg_and_die("get state");
/* Save line discipline */
- if (ioctl(handle, TIOCGETD, &saved_disc) < 0)
- bb_perror_msg_and_die("get discipline");
+ xioctl(handle, TIOCGETD, &saved_disc);
}
static int set_termios_state_and_warn(struct termios *state)
@@ -81,8 +80,7 @@ static void restore_state_and_exit(int exitcode)
struct termios state;
/* Restore line discipline */
- if (ioctl(handle, TIOCSETD, &saved_disc) < 0) {
- bb_perror_msg("set discipline");
+ if (ioctl_or_warn(handle, TIOCSETD, &saved_disc) < 0) {
exitcode = 1;
}
@@ -115,14 +113,12 @@ static void set_state(struct termios *state, int encap)
goto bad;
/* Set line discliple (N_SLIP always) */
disc = N_SLIP;
- if (ioctl(handle, TIOCSETD, &disc) < 0) {
- bb_perror_msg("set discipline");
+ if (ioctl_or_warn(handle, TIOCSETD, &disc) < 0) {
goto bad;
}
/* Set encapsulation (SLIP, CSLIP, etc) */
- if (ioctl(handle, SIOCSIFENCAP, &encap) < 0) {
- bb_perror_msg("set encapsulation");
+ if (ioctl_or_warn(handle, SIOCSIFENCAP, &encap) < 0) {
bad:
restore_state_and_exit(1);
}
diff --git a/networking/traceroute.c b/networking/traceroute.c
index ad3ec4eda..c87f7ffc5 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -445,8 +445,8 @@ ifaddrlist(struct IFADDRLIST **ipaddrp)
if (strchr(al->device, ':') != NULL)
continue;
#endif
- if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0)
- bb_perror_msg_and_die("SIOCGIFADDR: %s", al->device);
+ ioctl_or_perror_and_die(fd, SIOCGIFADDR, (char *)&ifr,
+ "SIOCGIFADDR: %s", al->device);
addr_sin = (struct sockaddr_in *)&ifr.ifr_addr;
al->addr = addr_sin->sin_addr.s_addr;
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c
index be5985f88..21a058545 100644
--- a/networking/udhcp/socket.c
+++ b/networking/udhcp/socket.c
@@ -53,9 +53,9 @@ int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t
ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
if (addr) {
- if (ioctl(fd, SIOCGIFADDR, &ifr) != 0) {
- bb_perror_msg("SIOCGIFADDR failed (is interface %s "
- "up and configured?)", interface);
+ if (ioctl_or_perror(fd, SIOCGIFADDR, &ifr,
+ "is interface %s up and configured?", interface)
+ ) {
close(fd);
return -1;
}
@@ -65,8 +65,7 @@ int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t
}
if (ifindex) {
- if (ioctl(fd, SIOCGIFINDEX, &ifr) != 0) {
- bb_perror_msg("SIOCGIFINDEX failed");
+ if (ioctl_or_warn(fd, SIOCGIFINDEX, &ifr) != 0) {
close(fd);
return -1;
}
@@ -75,8 +74,7 @@ int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t
}
if (arp) {
- if (ioctl(fd, SIOCGIFHWADDR, &ifr) != 0) {
- bb_perror_msg("SIOCGIFHWADDR failed");
+ if (ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr) != 0) {
close(fd);
return -1;
}
diff --git a/networking/vconfig.c b/networking/vconfig.c
index e063d0a49..4776e1324 100644
--- a/networking/vconfig.c
+++ b/networking/vconfig.c
@@ -157,9 +157,8 @@ int vconfig_main(int argc, char **argv)
}
fd = xsocket(AF_INET, SOCK_STREAM, 0);
- if (ioctl(fd, SIOCSIFVLAN, &ifr) < 0) {
- bb_perror_msg_and_die("ioctl error for %s", *argv);
- }
+ ioctl_or_perror_and_die(fd, SIOCSIFVLAN, &ifr,
+ "ioctl error for %s", *argv);
return 0;
}
diff --git a/networking/zcip.c b/networking/zcip.c
index de4ee0b1a..281f551d7 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -247,9 +247,7 @@ int zcip_main(int argc, char **argv)
// get the interface's ethernet address
//memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, intf, sizeof(ifr.ifr_name));
- if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
- bb_perror_msg_and_die("get ethernet address");
- }
+ xioctl(fd, SIOCGIFHWADDR, &ifr);
memcpy(&eth_addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN);
// start with some stable ip address, either a function of