From cc24ad71633291d03694a13c52d01b50448abe08 Mon Sep 17 00:00:00 2001 From: ecki Date: Tue, 10 Dec 2002 00:56:41 +0000 Subject: [PATCH] - change columns of netstat -i/ifconfig -s to avoid run-into (Stefan Illner) - prevent segfault on protocol families without host error member - use /128 as default prefix if not specified instead of /0 --- ifconfig.c | 45 ++++++++++++++++++++++++++++++++------------- lib/interface.c | 8 ++++---- netstat.c | 4 ++-- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/ifconfig.c b/ifconfig.c index 6f172cfec..ac470b584 100644 --- a/ifconfig.c +++ b/ifconfig.c @@ -3,7 +3,7 @@ * that either displays or sets the characteristics of * one or more of the system's networking interfaces. * - * Version: $Id: ifconfig.c,v 1.56 2002/07/05 17:36:02 ecki Exp $ + * Version: $Id: ifconfig.c,v 1.57 2002/12/10 00:56:41 ecki Exp $ * * Author: Fred N. van Kempen, * and others. Copyright 1993 MicroWalt Corporation @@ -104,7 +104,7 @@ static int if_print(char *ifname) int res; if (ife_short) - printf(_("Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n")); + printf(_("Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n")); if (!ifname) { res = for_all_interfaces(do_if_print, &opt_a); @@ -529,7 +529,10 @@ int main(int argc, char **argv) if (*++spp != NULL) { safe_strncpy(host, *spp, (sizeof host)); if (ap->input(0, host, &sa) < 0) { - ap->herror(host); + if (ap->herror) + ap->herror(host); + else + fprintf(stderr, _("ifconfig: Error resolving '%s' for broadcast\n"), host); goterr = 1; spp++; continue; @@ -551,7 +554,10 @@ int main(int argc, char **argv) usage(); safe_strncpy(host, *spp, (sizeof host)); if (ap->input(0, host, &sa) < 0) { - ap->herror(host); + if (ap->herror) + ap->herror(host); + else + fprintf(stderr, _("ifconfig: Error resolving '%s' for dstaddr\n"), host); goterr = 1; spp++; continue; @@ -571,7 +577,10 @@ int main(int argc, char **argv) usage(); safe_strncpy(host, *spp, (sizeof host)); if (ap->input(0, host, &sa) < 0) { - ap->herror(host); + if (ap->herror) + ap->herror(host); + else + fprintf(stderr, _("ifconfig: Error resolving '%s' for netmask\n"), host); goterr = 1; spp++; continue; @@ -658,7 +667,10 @@ int main(int argc, char **argv) spp++; safe_strncpy(host, *spp, (sizeof host)); if (ap->input(0, host, &sa)) { - ap->herror(host); + if (ap->herror) + ap->herror(host); + else + fprintf(stderr, _("ifconfig: Error resolving '%s' for pointopoint\n"), host); goterr = 1; spp++; continue; @@ -723,12 +735,15 @@ int main(int argc, char **argv) usage(); *cp = 0; } else { - prefix_len = 0; + prefix_len = 128; } safe_strncpy(host, *spp, (sizeof host)); if (inet6_aftype.input(1, host, (struct sockaddr *) &sa6) < 0) { - inet6_aftype.herror(host); + if (inet6_aftype.herror) + inet6_aftype.herror(host); + else + fprintf(stderr, _("ifconfig: Error resolving '%s' for add\n"), host); goterr = 1; spp++; continue; @@ -813,7 +828,7 @@ int main(int argc, char **argv) usage(); *cp = 0; } else { - prefix_len = 0; + prefix_len = 128; } safe_strncpy(host, *spp, (sizeof host)); if (inet6_aftype.input(1, host, @@ -842,6 +857,8 @@ int main(int argc, char **argv) } ifr6.ifr6_ifindex = ifr.ifr_ifindex; ifr6.ifr6_prefixlen = prefix_len; + if (opt_v) + fprintf(stderr, "now deleting: ioctl(SIOCDIFADDR,{ifindex=%d,prefixlen=%ld})\n",ifr.ifr_ifindex,prefix_len); if (ioctl(fd, SIOCDIFADDR, &ifr6) < 0) { fprintf(stderr, "SIOCDIFADDR: %s\n", strerror(errno)); @@ -901,7 +918,7 @@ int main(int argc, char **argv) usage(); *cp = 0; } else { - prefix_len = 0; + prefix_len = 128; } safe_strncpy(host, *spp, (sizeof host)); if (inet6_aftype.input(1, host, (struct sockaddr *) &sa6) < 0) { @@ -963,9 +980,11 @@ int main(int argc, char **argv) exit(1); } if (ap->input(0, host, &sa) < 0) { - ap->herror(host); - fprintf(stderr, _("ifconfig: `--help' gives usage information.\n")); - exit(1); + if (ap->herror) + ap->herror(host); + else + fprintf(stderr,_("ifconfig: error resolving '%s' to set address for af=%s\n"), host, ap->name); fprintf(stderr, + _("ifconfig: `--help' gives usage information.\n")); exit(1); } memcpy((char *) &ifr.ifr_addr, (char *) &sa, sizeof(struct sockaddr)); { diff --git a/lib/interface.c b/lib/interface.c index 331250542..94993703a 100644 --- a/lib/interface.c +++ b/lib/interface.c @@ -7,7 +7,7 @@ 8/2000 Andi Kleen make the list operations a bit more efficient. People are crazy enough to use thousands of aliases now. - $Id: interface.c,v 1.26 2002/12/05 22:10:32 ecki Exp $ + $Id: interface.c,v 1.27 2002/12/10 00:56:41 ecki Exp $ */ #include "config.h" @@ -594,13 +594,13 @@ int do_if_print(struct interface *ife, void *cookie) void ife_print_short(struct interface *ptr) { printf("%-5.5s ", ptr->name); - printf("%5d %-2d", ptr->mtu, ptr->metric); + printf("%5d %-2d ", ptr->mtu, ptr->metric); /* If needed, display the interface statistics. */ if (ptr->statistics_valid) { - printf("%9llu %6lu %6lu %-5lu", + printf("%8llu %6lu %6lu %-6lu ", ptr->stats.rx_packets, ptr->stats.rx_errors, ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors); - printf("%9llu %6lu %6lu %6lu ", + printf("%8llu %6lu %6lu %6lu ", ptr->stats.tx_packets, ptr->stats.tx_errors, ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors); } else { diff --git a/netstat.c b/netstat.c index 6feaf5816..d45477dee 100644 --- a/netstat.c +++ b/netstat.c @@ -6,7 +6,7 @@ * NET-3 Networking Distribution for the LINUX operating * system. * - * Version: $Id: netstat.c,v 1.49 2002/07/23 21:08:16 ecki Exp $ + * Version: $Id: netstat.c,v 1.50 2002/12/10 00:56:41 ecki Exp $ * * Authors: Fred Baumgarten, * Fred N. van Kempen, @@ -1462,7 +1462,7 @@ static int iface_info(void) } if (flag_exp < 2) { ife_short = 1; - printf(_("Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n")); + printf(_("Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n")); } if (for_all_interfaces(do_if_print, &flag_all) < 0) { -- 2.11.4.GIT