This is the bb_ioctl patch for networking.
Ciao,
Tito
--- busybox.orig/networking/arp.c 2007-05-26 23:23:37.000000000 +0200
+++ busybox/networking/arp.c 2007-07-07 22:09:31.000000000 +0200
@@ -188,9 +188,8 @@
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_vperror_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 @@
/* 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");
- }
+ ioctl_or_die(sockfd, SIOCSARP, &req);
return 0;
}
--- busybox.orig/networking/arping.c 2007-06-18 13:51:32.000000000 +0200
+++ busybox/networking/arping.c 2007-07-07 22:09:55.000000000 +0200
@@ -273,14 +273,11 @@
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_vperror_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");
- }
+ ioctl_or_die(sock, SIOCGIFFLAGS, (char *) &ifr);
+
if (!(ifr.ifr_flags & IFF_UP)) {
bb_error_msg_and_die("interface %s is down", device);
}
--- busybox.orig/networking/ether-wake.c 2007-05-26 23:23:37.000000000 +0200
+++ busybox/networking/ether-wake.c 2007-07-07 22:10:16.000000000 +0200
@@ -220,8 +220,7 @@
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_vperror_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 @@
{
struct ifreq ifr;
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
- if (ioctl(s, SIOCGIFINDEX, &ifr) != 0)
- bb_perror_msg_and_die("SIOCGIFINDEX");
+ ioctl_or_die(s, SIOCGIFINDEX, &ifr);
memset(&whereto, 0, sizeof(whereto));
whereto.sll_family = AF_PACKET;
whereto.sll_ifindex = ifr.ifr_ifindex;
--- busybox.orig/networking/ifconfig.c 2007-06-25 13:53:30.000000000 +0200
+++ busybox/networking/ifconfig.c 2007-07-07 22:10:44.000000000 +0200
@@ -402,12 +402,10 @@
/* 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");
+ ioctl_or_die(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_vperror_and_die(sockfd6, a1op->selector, &ifr6, "%s", a1op->name);
if (ENABLE_FEATURE_CLEAN_UP)
free(lsa);
continue;
@@ -444,8 +442,7 @@
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");
+ ioctl_or_die(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 *) p) = i;
}
- if (ioctl(sockfd, a1op->selector, &ifr) < 0)
- bb_perror_msg_and_die(a1op->name);
+ ioctl_or_vperror_and_die(sockfd, a1op->selector, &ifr, "%s", a1op->name);
#ifdef QUESTIONABLE_ALIAS_CASE
if (mask & A_COLON_CHK) {
/*
@@ -486,15 +482,13 @@
mask = N_SET;
}
- if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0)
- bb_perror_msg_and_die("SIOCGIFFLAGS");
+ ioctl_or_die(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");
+ ioctl_or_die(sockfd, SIOCSIFFLAGS, &ifr);
} /* while () */
if (ENABLE_FEATURE_CLEAN_UP)
--- busybox.orig/networking/interface.c 2007-06-19 13:39:41.000000000 +0200
+++ busybox/networking/interface.c 2007-07-07 16:15:48.000000000 +0200
@@ -521,8 +521,7 @@
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) {
--- busybox.orig/networking/libiproute/ipaddress.c 2007-06-20 23:16:37.000000000 +0200
+++ busybox/networking/libiproute/ipaddress.c 2007-07-07 16:17:11.000000000 +0200
@@ -84,8 +84,7 @@
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;
}
--- busybox.orig/networking/libiproute/iplink.c 2007-06-03 23:37:03.000000000 +0200
+++ busybox/networking/libiproute/iplink.c 2007-07-06 23:06:29.000000000 +0200
@@ -49,14 +49,11 @@
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
fd = get_ctl_fd();
- if (ioctl(fd, SIOCGIFFLAGS, &ifr)) {
- bb_perror_msg_and_die("SIOCGIFFLAGS");
- }
+ ioctl_or_die(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");
+ ioctl_or_die(fd, SIOCSIFFLAGS, &ifr);
}
close(fd);
}
@@ -66,15 +63,11 @@
{
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");
- }
+ ioctl_or_die(fd, SIOCSIFNAME, &ifr);
close(fd);
}
@@ -88,9 +81,7 @@
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");
- }
+ ioctl_or_die(s, SIOCSIFTXQLEN, &ifr);
close(s);
}
@@ -104,9 +95,7 @@
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");
- }
+ ioctl_or_die(s, SIOCSIFMTU, &ifr);
close(s);
}
@@ -122,9 +111,7 @@
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");
- }
+ ioctl_or_die(s, SIOCGIFINDEX, &ifr);
memset(&me, 0, sizeof(me));
me.sll_family = AF_PACKET;
@@ -163,9 +150,7 @@
int s;
s = get_ctl_fd();
- if (ioctl(s, brd ? SIOCSIFHWBROADCAST :SIOCSIFHWADDR, ifr) < 0) {
- bb_perror_msg_and_die(brd ? "SIOCSIFHWBROADCAST" : "SIOCSIFHWADDR");
- }
+ ioctl_or_die(s, brd ? SIOCSIFHWBROADCAST : SIOCSIFHWADDR, ifr);
close(s);
}
--- busybox.orig/networking/libiproute/iptunnel.c 2007-06-21 22:07:34.000000000 +0200
+++ busybox/networking/libiproute/iptunnel.c 2007-07-07 16:18:25.000000000 +0200
@@ -38,9 +38,7 @@
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");
- }
+ ioctl_or_die(fd, SIOCGIFINDEX, &ifr);
close(fd);
return ifr.ifr_ifindex;
}
@@ -52,8 +50,7 @@
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");
+ if (ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr)) {
return -1;
}
close(fd);
@@ -67,8 +64,7 @@
ifr.ifr_ifindex = idx;
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
- if (ioctl(fd, SIOCGIFNAME, &ifr)) {
- bb_perror_msg("SIOCGIFNAME");
+ if (ioctl_or_warn(fd, SIOCGIFNAME, &ifr)) {
return NULL;
}
close(fd);
@@ -84,10 +80,7 @@
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 +98,7 @@
}
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");
- }
+ ioctl_or_die(fd, cmd, &ifr);
close(fd);
return 0;
}
@@ -125,9 +116,7 @@
}
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");
- }
+ ioctl_or_die(fd, SIOCDELTUNNEL, &ifr);
close(fd);
return 0;
}
--- busybox.orig/networking/nameif.c 2007-05-26 23:23:37.000000000 +0200
+++ busybox/networking/nameif.c 2007-07-07 22:11:08.000000000 +0200
@@ -148,9 +148,9 @@
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_vperror_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) {
--- busybox.orig/networking/route.c 2007-06-19 13:39:41.000000000 +0200
+++ busybox/networking/route.c 2007-07-06 23:14:12.000000000 +0200
@@ -327,9 +327,7 @@
/* 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");
- }
+ ioctl_or_die(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt);
if (ENABLE_FEATURE_CLEAN_UP) close(skfd);
}
@@ -423,17 +421,12 @@
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");
- }
+ ioctl_or_die(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");
- }
+ ioctl_or_die(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt);
if (ENABLE_FEATURE_CLEAN_UP) close(skfd);
}
--- busybox.orig/networking/slattach.c 2007-06-21 22:07:34.000000000 +0200
+++ busybox/networking/slattach.c 2007-07-07 16:19:33.000000000 +0200
@@ -50,8 +50,7 @@
bb_perror_msg_and_die("get state");
/* Save line discipline */
- if (ioctl(handle, TIOCGETD, &saved_disc) < 0)
- bb_perror_msg_and_die("get discipline");
+ ioctl_or_die(handle, TIOCGETD, &saved_disc);
}
static int set_termios_state_and_warn(struct termios *state)
@@ -81,8 +80,7 @@
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 @@
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);
}
--- busybox.orig/networking/traceroute.c 2007-06-27 09:12:50.000000000 +0200
+++ busybox/networking/traceroute.c 2007-07-07 22:13:18.000000000 +0200
@@ -445,8 +445,8 @@
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_vperror_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;
--- busybox.orig/networking/udhcp/socket.c 2007-07-02 16:39:36.000000000 +0200
+++ busybox/networking/udhcp/socket.c 2007-07-09 22:19:36.000000000 +0200
@@ -53,9 +53,9 @@
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_vperror(fd, SIOCGIFADDR, &ifr,
+ "is interface %s up and configured?", interface)
+ ) {
close(fd);
return -1;
}
@@ -65,8 +65,7 @@
}
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 @@
}
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;
}
--- busybox.orig/networking/vconfig.c 2007-05-26 23:23:37.000000000 +0200
+++ busybox/networking/vconfig.c 2007-07-07 22:13:59.000000000 +0200
@@ -157,9 +157,8 @@
}
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_vperror_and_die(fd, SIOCSIFVLAN, &ifr,
+ "ioctl error for %s", *argv);
return 0;
}
--- busybox.orig/networking/zcip.c 2007-06-18 13:51:32.000000000 +0200
+++ busybox/networking/zcip.c 2007-07-07 00:51:55.000000000 +0200
@@ -247,9 +247,7 @@
// 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");
- }
+ ioctl_or_die(fd, SIOCGIFHWADDR, &ifr);
memcpy(ð_addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN);
// start with some stable ip address, either a function of
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox