diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-14 22:07:14 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-14 22:07:14 +0000 |
commit | fb79a2e2cfe33002398f1898c26d8e4f341db006 (patch) | |
tree | f5b3ee27db5bc8c9b181fbec171f8fa430a75ba5 /networking | |
parent | fcfaf2e18aba06dd90b16958ecfbfcfbf59ceb02 (diff) | |
download | busybox-w32-fb79a2e2cfe33002398f1898c26d8e4f341db006.tar.gz busybox-w32-fb79a2e2cfe33002398f1898c26d8e4f341db006.tar.bz2 busybox-w32-fb79a2e2cfe33002398f1898c26d8e4f341db006.zip |
xioctl and friends by Tito <farmatito@tiscali.it>
function old new delta
do_iptunnel 203 977 +774
process_dev 5328 5494 +166
ioctl_or_perror - 54 +54
ioctl_or_perror_and_die - 51 +51
ioctl_alt_func - 49 +49
bb_ioctl_or_warn - 47 +47
do_add_ioctl 102 145 +43
bb_xioctl - 39 +39
print_value_on_off - 31 +31
get_lcm 105 123 +18
arp_main 2155 2167 +12
..................
zcip_main 1576 1566 -10
setlogcons_main 92 82 -10
dumpkmap_main 263 253 -10
do_get_ioctl 85 75 -10
setkeycodes_main 165 154 -11
write_table 244 232 -12
vconfig_main 318 306 -12
do_del_ioctl 93 81 -12
set_address 75 62 -13
maybe_set_utc 30 16 -14
loadfont_main 495 479 -16
slattach_main 712 695 -17
do_loadfont 191 174 -17
do_iplink 1155 1136 -19
getty_main 2583 2562 -21
fbset_main 2058 2035 -23
do_time 588 565 -23
xioctl 25 - -25
read_rtc 186 160 -26
parse_conf 1299 1270 -29
udhcp_read_interface 269 239 -30
bb_ioctl 45 - -45
bb_ioctl_alt 70 - -70
bb_ioctl_on_off 78 - -78
.rodata 129370 129018 -352
do_show 799 - -799
------------------------------------------------------------------------------
(add/remove: 6/5 grow/shrink: 13/49 up/down: 1316/-1864) Total: -548 bytes
text data bss dec hex filename
675352 2740 13968 692060 a8f5c busybox_old
674804 2740 13968 691512 a8d38 busybox_unstripped
Diffstat (limited to 'networking')
-rw-r--r-- | networking/arp.c | 9 | ||||
-rw-r--r-- | networking/arping.c | 9 | ||||
-rw-r--r-- | networking/ether-wake.c | 6 | ||||
-rw-r--r-- | networking/ifconfig.c | 18 | ||||
-rw-r--r-- | networking/interface.c | 3 | ||||
-rw-r--r-- | networking/libiproute/ipaddress.c | 3 | ||||
-rw-r--r-- | networking/libiproute/iplink.c | 32 | ||||
-rw-r--r-- | networking/libiproute/iptunnel.c | 80 | ||||
-rw-r--r-- | networking/nameif.c | 6 | ||||
-rw-r--r-- | networking/route.c | 19 | ||||
-rw-r--r-- | networking/slattach.c | 12 | ||||
-rw-r--r-- | networking/traceroute.c | 4 | ||||
-rw-r--r-- | networking/udhcp/socket.c | 12 | ||||
-rw-r--r-- | networking/vconfig.c | 5 | ||||
-rw-r--r-- | networking/zcip.c | 4 |
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, | |||
188 | const struct hwtype *xhw; | 188 | const struct hwtype *xhw; |
189 | 189 | ||
190 | strcpy(ifr.ifr_name, ifname); | 190 | strcpy(ifr.ifr_name, ifname); |
191 | if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) < 0) { | 191 | ioctl_or_perror_and_die(sockfd, SIOCGIFHWADDR, &ifr, |
192 | bb_perror_msg_and_die("cant get HW-Address for '%s'", ifname); | 192 | "cant get HW-Address for '%s'", ifname); |
193 | } | ||
194 | if (hwt && (ifr.ifr_hwaddr.sa_family != hw->type)) { | 193 | if (hwt && (ifr.ifr_hwaddr.sa_family != hw->type)) { |
195 | bb_error_msg_and_die("protocol type mismatch"); | 194 | bb_error_msg_and_die("protocol type mismatch"); |
196 | } | 195 | } |
@@ -306,9 +305,7 @@ static int arp_set(char **args) | |||
306 | /* Call the kernel. */ | 305 | /* Call the kernel. */ |
307 | if (option_mask32 & ARP_OPT_v) | 306 | if (option_mask32 & ARP_OPT_v) |
308 | bb_error_msg("SIOCSARP()"); | 307 | bb_error_msg("SIOCSARP()"); |
309 | if (ioctl(sockfd, SIOCSARP, &req) < 0) { | 308 | xioctl(sockfd, SIOCSARP, &req); |
310 | bb_perror_msg_and_die("SIOCSARP"); | ||
311 | } | ||
312 | return 0; | 309 | return 0; |
313 | } | 310 | } |
314 | 311 | ||
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) | |||
273 | 273 | ||
274 | memset(&ifr, 0, sizeof(ifr)); | 274 | memset(&ifr, 0, sizeof(ifr)); |
275 | strncpy(ifr.ifr_name, device, IFNAMSIZ - 1); | 275 | strncpy(ifr.ifr_name, device, IFNAMSIZ - 1); |
276 | if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0) { | 276 | ioctl_or_perror_and_die(sock, SIOCGIFINDEX, &ifr, "interface %s not found", device); |
277 | bb_error_msg_and_die("interface %s not found", device); | ||
278 | } | ||
279 | ifindex = ifr.ifr_ifindex; | 277 | ifindex = ifr.ifr_ifindex; |
280 | 278 | ||
281 | if (ioctl(sock, SIOCGIFFLAGS, (char *) &ifr)) { | 279 | xioctl(sock, SIOCGIFFLAGS, (char *) &ifr); |
282 | bb_error_msg_and_die("SIOCGIFFLAGS"); | 280 | |
283 | } | ||
284 | if (!(ifr.ifr_flags & IFF_UP)) { | 281 | if (!(ifr.ifr_flags & IFF_UP)) { |
285 | bb_error_msg_and_die("interface %s is down", device); | 282 | bb_error_msg_and_die("interface %s is down", device); |
286 | } | 283 | } |
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) | |||
220 | struct ifreq if_hwaddr; | 220 | struct ifreq if_hwaddr; |
221 | 221 | ||
222 | strncpy(if_hwaddr.ifr_name, ifname, sizeof(if_hwaddr.ifr_name)); | 222 | strncpy(if_hwaddr.ifr_name, ifname, sizeof(if_hwaddr.ifr_name)); |
223 | if (ioctl(s, SIOCGIFHWADDR, &if_hwaddr) != 0) | 223 | ioctl_or_perror_and_die(s, SIOCGIFHWADDR, &if_hwaddr, "SIOCGIFHWADDR on %s failed", ifname); |
224 | bb_perror_msg_and_die("SIOCGIFHWADDR on %s failed", ifname); | ||
225 | 224 | ||
226 | memcpy(outpack+6, if_hwaddr.ifr_hwaddr.sa_data, 6); | 225 | memcpy(outpack+6, if_hwaddr.ifr_hwaddr.sa_data, 6); |
227 | 226 | ||
@@ -257,8 +256,7 @@ int ether_wake_main(int argc, char **argv) | |||
257 | { | 256 | { |
258 | struct ifreq ifr; | 257 | struct ifreq ifr; |
259 | strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); | 258 | strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
260 | if (ioctl(s, SIOCGIFINDEX, &ifr) != 0) | 259 | xioctl(s, SIOCGIFINDEX, &ifr); |
261 | bb_perror_msg_and_die("SIOCGIFINDEX"); | ||
262 | memset(&whereto, 0, sizeof(whereto)); | 260 | memset(&whereto, 0, sizeof(whereto)); |
263 | whereto.sll_family = AF_PACKET; | 261 | whereto.sll_family = AF_PACKET; |
264 | whereto.sll_ifindex = ifr.ifr_ifindex; | 262 | 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) | |||
402 | 402 | ||
403 | /* Create a channel to the NET kernel. */ | 403 | /* Create a channel to the NET kernel. */ |
404 | sockfd6 = xsocket(AF_INET6, SOCK_DGRAM, 0); | 404 | sockfd6 = xsocket(AF_INET6, SOCK_DGRAM, 0); |
405 | if (ioctl(sockfd6, SIOGIFINDEX, &ifr) < 0) | 405 | xioctl(sockfd6, SIOGIFINDEX, &ifr); |
406 | bb_perror_msg_and_die("SIOGIFINDEX"); | ||
407 | ifr6.ifr6_ifindex = ifr.ifr_ifindex; | 406 | ifr6.ifr6_ifindex = ifr.ifr_ifindex; |
408 | ifr6.ifr6_prefixlen = prefix_len; | 407 | ifr6.ifr6_prefixlen = prefix_len; |
409 | if (ioctl(sockfd6, a1op->selector, &ifr6) < 0) | 408 | ioctl_or_perror_and_die(sockfd6, a1op->selector, &ifr6, "%s", a1op->name); |
410 | bb_perror_msg_and_die(a1op->name); | ||
411 | if (ENABLE_FEATURE_CLEAN_UP) | 409 | if (ENABLE_FEATURE_CLEAN_UP) |
412 | free(lsa); | 410 | free(lsa); |
413 | continue; | 411 | continue; |
@@ -444,8 +442,7 @@ int ifconfig_main(int argc, char **argv) | |||
444 | p = ((char *)&ifr) + a1op->ifr_offset; | 442 | p = ((char *)&ifr) + a1op->ifr_offset; |
445 | #if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ | 443 | #if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ |
446 | if (mask & A_MAP_TYPE) { | 444 | if (mask & A_MAP_TYPE) { |
447 | if (ioctl(sockfd, SIOCGIFMAP, &ifr) < 0) | 445 | xioctl(sockfd, SIOCGIFMAP, &ifr); |
448 | bb_perror_msg_and_die("SIOCGIFMAP"); | ||
449 | if ((mask & A_MAP_UCHAR) == A_MAP_UCHAR) | 446 | if ((mask & A_MAP_UCHAR) == A_MAP_UCHAR) |
450 | *((unsigned char *) p) = i; | 447 | *((unsigned char *) p) = i; |
451 | else if (mask & A_MAP_USHORT) | 448 | else if (mask & A_MAP_USHORT) |
@@ -460,8 +457,7 @@ int ifconfig_main(int argc, char **argv) | |||
460 | *((int *) p) = i; | 457 | *((int *) p) = i; |
461 | } | 458 | } |
462 | 459 | ||
463 | if (ioctl(sockfd, a1op->selector, &ifr) < 0) | 460 | ioctl_or_perror_and_die(sockfd, a1op->selector, &ifr, "%s", a1op->name); |
464 | bb_perror_msg_and_die(a1op->name); | ||
465 | #ifdef QUESTIONABLE_ALIAS_CASE | 461 | #ifdef QUESTIONABLE_ALIAS_CASE |
466 | if (mask & A_COLON_CHK) { | 462 | if (mask & A_COLON_CHK) { |
467 | /* | 463 | /* |
@@ -486,15 +482,13 @@ int ifconfig_main(int argc, char **argv) | |||
486 | mask = N_SET; | 482 | mask = N_SET; |
487 | } | 483 | } |
488 | 484 | ||
489 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) | 485 | xioctl(sockfd, SIOCGIFFLAGS, &ifr); |
490 | bb_perror_msg_and_die("SIOCGIFFLAGS"); | ||
491 | selector = op->selector; | 486 | selector = op->selector; |
492 | if (mask & SET_MASK) | 487 | if (mask & SET_MASK) |
493 | ifr.ifr_flags |= selector; | 488 | ifr.ifr_flags |= selector; |
494 | else | 489 | else |
495 | ifr.ifr_flags &= ~selector; | 490 | ifr.ifr_flags &= ~selector; |
496 | if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0) | 491 | xioctl(sockfd, SIOCSIFFLAGS, &ifr); |
497 | bb_perror_msg_and_die("SIOCSIFFLAGS"); | ||
498 | } /* while () */ | 492 | } /* while () */ |
499 | 493 | ||
500 | if (ENABLE_FEATURE_CLEAN_UP) | 494 | 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) | |||
521 | ifc.ifc_len = sizeof(struct ifreq) * numreqs; | 521 | ifc.ifc_len = sizeof(struct ifreq) * numreqs; |
522 | ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len); | 522 | ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len); |
523 | 523 | ||
524 | if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) { | 524 | if (ioctl_or_warn(skfd, SIOCGIFCONF, &ifc) < 0) { |
525 | bb_perror_msg("SIOCGIFCONF"); | ||
526 | goto out; | 525 | goto out; |
527 | } | 526 | } |
528 | if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) { | 527 | 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) | |||
84 | 84 | ||
85 | memset(&ifr, 0, sizeof(ifr)); | 85 | memset(&ifr, 0, sizeof(ifr)); |
86 | strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); | 86 | strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); |
87 | if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) { | 87 | if (ioctl_or_warn(s, SIOCGIFTXQLEN, &ifr) < 0) { |
88 | bb_perror_msg("SIOCGIFXQLEN"); | ||
89 | close(s); | 88 | close(s); |
90 | return; | 89 | return; |
91 | } | 90 | } |
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) | |||
49 | 49 | ||
50 | strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); | 50 | strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); |
51 | fd = get_ctl_fd(); | 51 | fd = get_ctl_fd(); |
52 | if (ioctl(fd, SIOCGIFFLAGS, &ifr)) { | 52 | xioctl(fd, SIOCGIFFLAGS, &ifr); |
53 | bb_perror_msg_and_die("SIOCGIFFLAGS"); | ||
54 | } | ||
55 | if ((ifr.ifr_flags ^ flags) & mask) { | 53 | if ((ifr.ifr_flags ^ flags) & mask) { |
56 | ifr.ifr_flags &= ~mask; | 54 | ifr.ifr_flags &= ~mask; |
57 | ifr.ifr_flags |= mask & flags; | 55 | ifr.ifr_flags |= mask & flags; |
58 | if (ioctl(fd, SIOCSIFFLAGS, &ifr)) | 56 | xioctl(fd, SIOCSIFFLAGS, &ifr); |
59 | bb_perror_msg_and_die("SIOCSIFFLAGS"); | ||
60 | } | 57 | } |
61 | close(fd); | 58 | close(fd); |
62 | } | 59 | } |
@@ -66,15 +63,11 @@ static void do_changename(char *dev, char *newdev) | |||
66 | { | 63 | { |
67 | struct ifreq ifr; | 64 | struct ifreq ifr; |
68 | int fd; | 65 | int fd; |
69 | int err; | ||
70 | 66 | ||
71 | strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); | 67 | strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); |
72 | strncpy(ifr.ifr_newname, newdev, sizeof(ifr.ifr_newname)); | 68 | strncpy(ifr.ifr_newname, newdev, sizeof(ifr.ifr_newname)); |
73 | fd = get_ctl_fd(); | 69 | fd = get_ctl_fd(); |
74 | err = ioctl(fd, SIOCSIFNAME, &ifr); | 70 | xioctl(fd, SIOCSIFNAME, &ifr); |
75 | if (err) { | ||
76 | bb_perror_msg_and_die("SIOCSIFNAME"); | ||
77 | } | ||
78 | close(fd); | 71 | close(fd); |
79 | } | 72 | } |
80 | 73 | ||
@@ -88,9 +81,7 @@ static void set_qlen(char *dev, int qlen) | |||
88 | memset(&ifr, 0, sizeof(ifr)); | 81 | memset(&ifr, 0, sizeof(ifr)); |
89 | strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); | 82 | strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); |
90 | ifr.ifr_qlen = qlen; | 83 | ifr.ifr_qlen = qlen; |
91 | if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) { | 84 | xioctl(s, SIOCSIFTXQLEN, &ifr); |
92 | bb_perror_msg_and_die("SIOCSIFXQLEN"); | ||
93 | } | ||
94 | close(s); | 85 | close(s); |
95 | } | 86 | } |
96 | 87 | ||
@@ -104,9 +95,7 @@ static void set_mtu(char *dev, int mtu) | |||
104 | memset(&ifr, 0, sizeof(ifr)); | 95 | memset(&ifr, 0, sizeof(ifr)); |
105 | strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); | 96 | strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); |
106 | ifr.ifr_mtu = mtu; | 97 | ifr.ifr_mtu = mtu; |
107 | if (ioctl(s, SIOCSIFMTU, &ifr) < 0) { | 98 | xioctl(s, SIOCSIFMTU, &ifr); |
108 | bb_perror_msg_and_die("SIOCSIFMTU"); | ||
109 | } | ||
110 | close(s); | 99 | close(s); |
111 | } | 100 | } |
112 | 101 | ||
@@ -122,9 +111,7 @@ static int get_address(char *dev, int *htype) | |||
122 | 111 | ||
123 | memset(&ifr, 0, sizeof(ifr)); | 112 | memset(&ifr, 0, sizeof(ifr)); |
124 | strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); | 113 | strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); |
125 | if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) { | 114 | xioctl(s, SIOCGIFINDEX, &ifr); |
126 | bb_perror_msg_and_die("SIOCGIFINDEX"); | ||
127 | } | ||
128 | 115 | ||
129 | memset(&me, 0, sizeof(me)); | 116 | memset(&me, 0, sizeof(me)); |
130 | me.sll_family = AF_PACKET; | 117 | me.sll_family = AF_PACKET; |
@@ -163,9 +150,10 @@ static void set_address(struct ifreq *ifr, int brd) | |||
163 | int s; | 150 | int s; |
164 | 151 | ||
165 | s = get_ctl_fd(); | 152 | s = get_ctl_fd(); |
166 | if (ioctl(s, brd ? SIOCSIFHWBROADCAST :SIOCSIFHWADDR, ifr) < 0) { | 153 | if (brd) |
167 | bb_perror_msg_and_die(brd ? "SIOCSIFHWBROADCAST" : "SIOCSIFHWADDR"); | 154 | xioctl(s, SIOCSIFHWBROADCAST, ifr); |
168 | } | 155 | else |
156 | xioctl(s, SIOCSIFHWADDR, ifr); | ||
169 | close(s); | 157 | close(s); |
170 | } | 158 | } |
171 | 159 | ||
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 @@ | |||
14 | * Phil Karn <karn@ka9q.ampr.org> 990408: "pmtudisc" flag | 14 | * Phil Karn <karn@ka9q.ampr.org> 990408: "pmtudisc" flag |
15 | */ | 15 | */ |
16 | 16 | ||
17 | //#include <sys/socket.h> | ||
18 | //#include <sys/ioctl.h> | ||
19 | #include <netinet/ip.h> | 17 | #include <netinet/ip.h> |
20 | #include <net/if.h> | 18 | #include <net/if.h> |
21 | #include <net/if_arp.h> | 19 | #include <net/if_arp.h> |
@@ -38,9 +36,7 @@ static int do_ioctl_get_ifindex(char *dev) | |||
38 | 36 | ||
39 | strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); | 37 | strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); |
40 | fd = xsocket(AF_INET, SOCK_DGRAM, 0); | 38 | fd = xsocket(AF_INET, SOCK_DGRAM, 0); |
41 | if (ioctl(fd, SIOCGIFINDEX, &ifr)) { | 39 | xioctl(fd, SIOCGIFINDEX, &ifr); |
42 | bb_perror_msg_and_die("SIOCGIFINDEX"); | ||
43 | } | ||
44 | close(fd); | 40 | close(fd); |
45 | return ifr.ifr_ifindex; | 41 | return ifr.ifr_ifindex; |
46 | } | 42 | } |
@@ -49,30 +45,26 @@ static int do_ioctl_get_iftype(char *dev) | |||
49 | { | 45 | { |
50 | struct ifreq ifr; | 46 | struct ifreq ifr; |
51 | int fd; | 47 | int fd; |
48 | int err; | ||
52 | 49 | ||
53 | strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); | 50 | strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); |
54 | fd = xsocket(AF_INET, SOCK_DGRAM, 0); | 51 | fd = xsocket(AF_INET, SOCK_DGRAM, 0); |
55 | if (ioctl(fd, SIOCGIFHWADDR, &ifr)) { | 52 | err = ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr); |
56 | bb_perror_msg("SIOCGIFHWADDR"); | ||
57 | return -1; | ||
58 | } | ||
59 | close(fd); | 53 | close(fd); |
60 | return ifr.ifr_addr.sa_family; | 54 | return err ? -1 : ifr.ifr_addr.sa_family; |
61 | } | 55 | } |
62 | 56 | ||
63 | static char *do_ioctl_get_ifname(int idx) | 57 | static char *do_ioctl_get_ifname(int idx) |
64 | { | 58 | { |
65 | struct ifreq ifr; | 59 | struct ifreq ifr; |
66 | int fd; | 60 | int fd; |
61 | int err; | ||
67 | 62 | ||
68 | ifr.ifr_ifindex = idx; | 63 | ifr.ifr_ifindex = idx; |
69 | fd = xsocket(AF_INET, SOCK_DGRAM, 0); | 64 | fd = xsocket(AF_INET, SOCK_DGRAM, 0); |
70 | if (ioctl(fd, SIOCGIFNAME, &ifr)) { | 65 | err = ioctl_or_warn(fd, SIOCGIFNAME, &ifr); |
71 | bb_perror_msg("SIOCGIFNAME"); | ||
72 | return NULL; | ||
73 | } | ||
74 | close(fd); | 66 | close(fd); |
75 | return xstrndup(ifr.ifr_name, sizeof(ifr.ifr_name)); | 67 | return err ? NULL : xstrndup(ifr.ifr_name, sizeof(ifr.ifr_name)); |
76 | } | 68 | } |
77 | 69 | ||
78 | static int do_get_ioctl(const char *basedev, struct ip_tunnel_parm *p) | 70 | 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) | |||
84 | strncpy(ifr.ifr_name, basedev, sizeof(ifr.ifr_name)); | 76 | strncpy(ifr.ifr_name, basedev, sizeof(ifr.ifr_name)); |
85 | ifr.ifr_ifru.ifru_data = (void*)p; | 77 | ifr.ifr_ifru.ifru_data = (void*)p; |
86 | fd = xsocket(AF_INET, SOCK_DGRAM, 0); | 78 | fd = xsocket(AF_INET, SOCK_DGRAM, 0); |
87 | err = ioctl(fd, SIOCGETTUNNEL, &ifr); | 79 | err = ioctl_or_warn(fd, SIOCGETTUNNEL, &ifr); |
88 | if (err) { | ||
89 | bb_perror_msg("SIOCGETTUNNEL"); | ||
90 | } | ||
91 | close(fd); | 80 | close(fd); |
92 | return err; | 81 | return err; |
93 | } | 82 | } |
@@ -105,9 +94,15 @@ static int do_add_ioctl(int cmd, const char *basedev, struct ip_tunnel_parm *p) | |||
105 | } | 94 | } |
106 | ifr.ifr_ifru.ifru_data = (void*)p; | 95 | ifr.ifr_ifru.ifru_data = (void*)p; |
107 | fd = xsocket(AF_INET, SOCK_DGRAM, 0); | 96 | fd = xsocket(AF_INET, SOCK_DGRAM, 0); |
108 | if (ioctl(fd, cmd, &ifr)) { | 97 | #if ENABLE_IOCTL_HEX2STR_ERROR |
109 | bb_perror_msg_and_die("ioctl"); | 98 | /* #define magic will turn ioctl# into string */ |
110 | } | 99 | if (cmd == SIOCCHGTUNNEL) |
100 | xioctl(fd, SIOCCHGTUNNEL, &ifr); | ||
101 | else | ||
102 | xioctl(fd, SIOCADDTUNNEL, &ifr); | ||
103 | #else | ||
104 | xioctl(fd, cmd, &ifr); | ||
105 | #endif | ||
111 | close(fd); | 106 | close(fd); |
112 | return 0; | 107 | return 0; |
113 | } | 108 | } |
@@ -125,9 +120,7 @@ static int do_del_ioctl(const char *basedev, struct ip_tunnel_parm *p) | |||
125 | } | 120 | } |
126 | ifr.ifr_ifru.ifru_data = (void*)p; | 121 | ifr.ifr_ifru.ifru_data = (void*)p; |
127 | fd = xsocket(AF_INET, SOCK_DGRAM, 0); | 122 | fd = xsocket(AF_INET, SOCK_DGRAM, 0); |
128 | if (ioctl(fd, SIOCDELTUNNEL, &ifr)) { | 123 | xioctl(fd, SIOCDELTUNNEL, &ifr); |
129 | bb_perror_msg_and_die("SIOCDELTUNNEL"); | ||
130 | } | ||
131 | close(fd); | 124 | close(fd); |
132 | return 0; | 125 | return 0; |
133 | } | 126 | } |
@@ -526,29 +519,24 @@ static int do_show(int argc, char **argv) | |||
526 | /* Return value becomes exitcode. It's okay to not return at all */ | 519 | /* Return value becomes exitcode. It's okay to not return at all */ |
527 | int do_iptunnel(int argc, char **argv) | 520 | int do_iptunnel(int argc, char **argv) |
528 | { | 521 | { |
529 | static const char * const keywords[] = { | 522 | static const char *const keywords[] = { |
530 | "add", "change", "delete", "show", "list", "lst", NULL | 523 | "add", "change", "delete", "show", "list", "lst", NULL |
531 | }; | 524 | }; |
532 | enum {ARG_add = 1, ARG_change, ARG_del, ARG_show, ARG_list, ARG_lst}; | 525 | enum { ARG_add = 0, ARG_change, ARG_del, ARG_show, ARG_list, ARG_lst }; |
533 | smalluint key = 4; /* show */ | 526 | int key; |
534 | if (argc > 0) { | 527 | |
535 | key = index_in_substr_array(keywords, *argv) +1; | 528 | if (argc) { |
529 | key = index_in_substr_array(keywords, *argv); | ||
530 | if (key < 0) | ||
531 | bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); | ||
536 | --argc; | 532 | --argc; |
537 | ++argv; | 533 | ++argv; |
538 | } else | 534 | if (key == ARG_add) |
539 | return do_show(0, NULL); | 535 | return do_add(SIOCADDTUNNEL, argc, argv); |
540 | if (key < ARG_add) | 536 | if (key == ARG_change) |
541 | bail: | 537 | return do_add(SIOCCHGTUNNEL, argc, argv); |
542 | bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); | 538 | if (key == ARG_del) |
543 | 539 | return do_del(argc, argv); | |
544 | if (key == ARG_add) | 540 | } |
545 | return do_add(SIOCADDTUNNEL, argc, argv); | 541 | return do_show(argc, argv); |
546 | if (key == ARG_change) | ||
547 | return do_add(SIOCCHGTUNNEL, argc, argv); | ||
548 | if (key == ARG_del) | ||
549 | return do_del(argc, argv); | ||
550 | if (key == ARG_show || key == ARG_list || key == ARG_lst) | ||
551 | return do_show(argc, argv); | ||
552 | /* be gentle to gcc; avoid warning about non returning */ | ||
553 | goto bail; /* never reached */ | ||
554 | } | 542 | } |
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) | |||
148 | continue; | 148 | continue; |
149 | 149 | ||
150 | strcpy(ifr.ifr_newname, ch->ifname); | 150 | strcpy(ifr.ifr_newname, ch->ifname); |
151 | if (ioctl(ctl_sk, SIOCSIFNAME, &ifr) < 0) | 151 | ioctl_or_perror_and_die(ctl_sk, SIOCSIFNAME, &ifr, |
152 | bb_perror_msg_and_die("cannot change ifname %s to %s", | 152 | "cannot change ifname %s to %s", |
153 | ifr.ifr_name, ch->ifname); | 153 | ifr.ifr_name, ch->ifname); |
154 | 154 | ||
155 | /* Remove list entry of renamed interface */ | 155 | /* Remove list entry of renamed interface */ |
156 | if (ch->prev != NULL) { | 156 | 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) | |||
327 | /* Create a socket to the INET kernel. */ | 327 | /* Create a socket to the INET kernel. */ |
328 | skfd = xsocket(AF_INET, SOCK_DGRAM, 0); | 328 | skfd = xsocket(AF_INET, SOCK_DGRAM, 0); |
329 | 329 | ||
330 | if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) { | 330 | if (action == RTACTION_ADD) |
331 | bb_perror_msg_and_die("SIOC[ADD|DEL]RT"); | 331 | xioctl(skfd, SIOCADDRT, &rt); |
332 | } | 332 | else |
333 | xioctl(skfd, SIOCDELRT, &rt); | ||
333 | 334 | ||
334 | if (ENABLE_FEATURE_CLEAN_UP) close(skfd); | 335 | if (ENABLE_FEATURE_CLEAN_UP) close(skfd); |
335 | } | 336 | } |
@@ -423,17 +424,15 @@ static void INET6_setroute(int action, char **args) | |||
423 | struct ifreq ifr; | 424 | struct ifreq ifr; |
424 | memset(&ifr, 0, sizeof(ifr)); | 425 | memset(&ifr, 0, sizeof(ifr)); |
425 | strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name)); | 426 | strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name)); |
426 | 427 | xioctl(skfd, SIOGIFINDEX, &ifr); | |
427 | if (ioctl(skfd, SIOGIFINDEX, &ifr) < 0) { | ||
428 | bb_perror_msg_and_die("SIOGIFINDEX"); | ||
429 | } | ||
430 | rt.rtmsg_ifindex = ifr.ifr_ifindex; | 428 | rt.rtmsg_ifindex = ifr.ifr_ifindex; |
431 | } | 429 | } |
432 | 430 | ||
433 | /* Tell the kernel to accept this route. */ | 431 | /* Tell the kernel to accept this route. */ |
434 | if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) { | 432 | if (action == RTACTION_ADD) |
435 | bb_perror_msg_and_die("SIOC[ADD|DEL]RT"); | 433 | xioctl(skfd, SIOCADDRT, &rt); |
436 | } | 434 | else |
435 | xioctl(skfd, SIOCDELRT, &rt); | ||
437 | 436 | ||
438 | if (ENABLE_FEATURE_CLEAN_UP) close(skfd); | 437 | if (ENABLE_FEATURE_CLEAN_UP) close(skfd); |
439 | } | 438 | } |
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) | |||
50 | bb_perror_msg_and_die("get state"); | 50 | bb_perror_msg_and_die("get state"); |
51 | 51 | ||
52 | /* Save line discipline */ | 52 | /* Save line discipline */ |
53 | if (ioctl(handle, TIOCGETD, &saved_disc) < 0) | 53 | xioctl(handle, TIOCGETD, &saved_disc); |
54 | bb_perror_msg_and_die("get discipline"); | ||
55 | } | 54 | } |
56 | 55 | ||
57 | static int set_termios_state_and_warn(struct termios *state) | 56 | static int set_termios_state_and_warn(struct termios *state) |
@@ -81,8 +80,7 @@ static void restore_state_and_exit(int exitcode) | |||
81 | struct termios state; | 80 | struct termios state; |
82 | 81 | ||
83 | /* Restore line discipline */ | 82 | /* Restore line discipline */ |
84 | if (ioctl(handle, TIOCSETD, &saved_disc) < 0) { | 83 | if (ioctl_or_warn(handle, TIOCSETD, &saved_disc) < 0) { |
85 | bb_perror_msg("set discipline"); | ||
86 | exitcode = 1; | 84 | exitcode = 1; |
87 | } | 85 | } |
88 | 86 | ||
@@ -115,14 +113,12 @@ static void set_state(struct termios *state, int encap) | |||
115 | goto bad; | 113 | goto bad; |
116 | /* Set line discliple (N_SLIP always) */ | 114 | /* Set line discliple (N_SLIP always) */ |
117 | disc = N_SLIP; | 115 | disc = N_SLIP; |
118 | if (ioctl(handle, TIOCSETD, &disc) < 0) { | 116 | if (ioctl_or_warn(handle, TIOCSETD, &disc) < 0) { |
119 | bb_perror_msg("set discipline"); | ||
120 | goto bad; | 117 | goto bad; |
121 | } | 118 | } |
122 | 119 | ||
123 | /* Set encapsulation (SLIP, CSLIP, etc) */ | 120 | /* Set encapsulation (SLIP, CSLIP, etc) */ |
124 | if (ioctl(handle, SIOCSIFENCAP, &encap) < 0) { | 121 | if (ioctl_or_warn(handle, SIOCSIFENCAP, &encap) < 0) { |
125 | bb_perror_msg("set encapsulation"); | ||
126 | bad: | 122 | bad: |
127 | restore_state_and_exit(1); | 123 | restore_state_and_exit(1); |
128 | } | 124 | } |
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) | |||
445 | if (strchr(al->device, ':') != NULL) | 445 | if (strchr(al->device, ':') != NULL) |
446 | continue; | 446 | continue; |
447 | #endif | 447 | #endif |
448 | if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) | 448 | ioctl_or_perror_and_die(fd, SIOCGIFADDR, (char *)&ifr, |
449 | bb_perror_msg_and_die("SIOCGIFADDR: %s", al->device); | 449 | "SIOCGIFADDR: %s", al->device); |
450 | 450 | ||
451 | addr_sin = (struct sockaddr_in *)&ifr.ifr_addr; | 451 | addr_sin = (struct sockaddr_in *)&ifr.ifr_addr; |
452 | al->addr = addr_sin->sin_addr.s_addr; | 452 | 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 | |||
53 | ifr.ifr_addr.sa_family = AF_INET; | 53 | ifr.ifr_addr.sa_family = AF_INET; |
54 | strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); | 54 | strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); |
55 | if (addr) { | 55 | if (addr) { |
56 | if (ioctl(fd, SIOCGIFADDR, &ifr) != 0) { | 56 | if (ioctl_or_perror(fd, SIOCGIFADDR, &ifr, |
57 | bb_perror_msg("SIOCGIFADDR failed (is interface %s " | 57 | "is interface %s up and configured?", interface) |
58 | "up and configured?)", interface); | 58 | ) { |
59 | close(fd); | 59 | close(fd); |
60 | return -1; | 60 | return -1; |
61 | } | 61 | } |
@@ -65,8 +65,7 @@ int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t | |||
65 | } | 65 | } |
66 | 66 | ||
67 | if (ifindex) { | 67 | if (ifindex) { |
68 | if (ioctl(fd, SIOCGIFINDEX, &ifr) != 0) { | 68 | if (ioctl_or_warn(fd, SIOCGIFINDEX, &ifr) != 0) { |
69 | bb_perror_msg("SIOCGIFINDEX failed"); | ||
70 | close(fd); | 69 | close(fd); |
71 | return -1; | 70 | return -1; |
72 | } | 71 | } |
@@ -75,8 +74,7 @@ int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t | |||
75 | } | 74 | } |
76 | 75 | ||
77 | if (arp) { | 76 | if (arp) { |
78 | if (ioctl(fd, SIOCGIFHWADDR, &ifr) != 0) { | 77 | if (ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr) != 0) { |
79 | bb_perror_msg("SIOCGIFHWADDR failed"); | ||
80 | close(fd); | 78 | close(fd); |
81 | return -1; | 79 | return -1; |
82 | } | 80 | } |
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) | |||
157 | } | 157 | } |
158 | 158 | ||
159 | fd = xsocket(AF_INET, SOCK_STREAM, 0); | 159 | fd = xsocket(AF_INET, SOCK_STREAM, 0); |
160 | if (ioctl(fd, SIOCSIFVLAN, &ifr) < 0) { | 160 | ioctl_or_perror_and_die(fd, SIOCSIFVLAN, &ifr, |
161 | bb_perror_msg_and_die("ioctl error for %s", *argv); | 161 | "ioctl error for %s", *argv); |
162 | } | ||
163 | 162 | ||
164 | return 0; | 163 | return 0; |
165 | } | 164 | } |
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) | |||
247 | // get the interface's ethernet address | 247 | // get the interface's ethernet address |
248 | //memset(&ifr, 0, sizeof(ifr)); | 248 | //memset(&ifr, 0, sizeof(ifr)); |
249 | strncpy(ifr.ifr_name, intf, sizeof(ifr.ifr_name)); | 249 | strncpy(ifr.ifr_name, intf, sizeof(ifr.ifr_name)); |
250 | if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) { | 250 | xioctl(fd, SIOCGIFHWADDR, &ifr); |
251 | bb_perror_msg_and_die("get ethernet address"); | ||
252 | } | ||
253 | memcpy(ð_addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN); | 251 | memcpy(ð_addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN); |
254 | 252 | ||
255 | // start with some stable ip address, either a function of | 253 | // start with some stable ip address, either a function of |