From 9dfdb3b1fd41939688f4d154ffc8f01b65640b1e Mon Sep 17 00:00:00 2001 From: Phil Blundell Date: Wed, 18 Nov 1998 13:46:09 +0000 Subject: [PATCH] Add prototype for safe_strncpy() Move some helper functions to interface.c. Tweak `netstat -i' output format to allow more room for packet counts. --- Makefile | 2 +- ifconfig.c | 34 ++-------------------------------- interface.c | 32 +++++++++++++++++++++++++++++++- interface.h | 5 +++++ lib/net-support.h | 8 +++++--- netstat.c | 25 ++++++------------------- 6 files changed, 50 insertions(+), 56 deletions(-) diff --git a/Makefile b/Makefile index 2601a83..af443f6 100644 --- a/Makefile +++ b/Makefile @@ -87,7 +87,7 @@ RESLIB = # -L/usr/inet6/lib -linet6 # -------- end of user definitions -------- MAINTAINER = Philip.Blundell@pobox.com -RELEASE = 981031 +RELEASE = 981118 .EXPORT_ALL_VARIABLES: diff --git a/ifconfig.c b/ifconfig.c index fc00e69..1eb8cbd 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.19 1998/11/17 15:16:14 freitag Exp $ + * Version: $Id: ifconfig.c,v 1.20 1998/11/18 13:46:11 philip Exp $ * * Author: Fred N. van Kempen, * and others. Copyright 1993 MicroWalt Corporation @@ -115,7 +115,7 @@ int opt_v = 0; /* debugging output flag */ int addr_family = 0; /* currently selected AF */ -static void ife_print(struct interface *ptr) +void ife_print(struct interface *ptr) { struct aftype *ap; struct hwtype *hw; @@ -355,36 +355,6 @@ static void ife_print(struct interface *ptr) printf("\n"); } -static int do_if_fetch(struct interface *ife) -{ - if (if_fetch(ife) < 0) { - char *errmsg; - if (errno == ENODEV) { - /* Give better error message for this case. */ - errmsg = _("Device not found"); - } else { - errmsg = strerror(errno); - } - fprintf(stderr, _("%s: error fetching interface information: %s\n"), - ife->name, errmsg); - return -1; - } - return 0; -} - -static int do_if_print(struct interface *ife, void *cookie) -{ - int *opt_a = (int *) cookie; - int res; - - res = do_if_fetch(ife); - if (res >= 0) { - if ((ife->flags & IFF_UP) || *opt_a) - ife_print(ife); - } - return res; -} - static int if_print(char *ifname) { int res; diff --git a/interface.c b/interface.c index e7e1276..6e9ccfb 100644 --- a/interface.c +++ b/interface.c @@ -4,7 +4,7 @@ 10/1998 partly rewriten by Andi Kleen to support an interface list. I don't claim that the list operations are efficient @). - $Id: interface.c,v 1.12 1998/11/18 10:31:58 philip Exp $ + $Id: interface.c,v 1.13 1998/11/18 13:46:12 philip Exp $ */ #include "config.h" @@ -475,3 +475,33 @@ int if_fetch(struct interface *ife) return 0; } + +int do_if_fetch(struct interface *ife) +{ + if (if_fetch(ife) < 0) { + char *errmsg; + if (errno == ENODEV) { + /* Give better error message for this case. */ + errmsg = _("Device not found"); + } else { + errmsg = strerror(errno); + } + fprintf(stderr, _("%s: error fetching interface information: %s\n"), + ife->name, errmsg); + return -1; + } + return 0; +} + +int do_if_print(struct interface *ife, void *cookie) +{ + int *opt_a = (int *) cookie; + int res; + + res = do_if_fetch(ife); + if (res >= 0) { + if ((ife->flags & IFF_UP) || *opt_a) + ife_print(ife); + } + return res; +} diff --git a/interface.h b/interface.h index 10926b4..67076c6 100644 --- a/interface.h +++ b/interface.h @@ -68,6 +68,11 @@ extern int for_all_interfaces(int (*)(struct interface *, void *), void *); extern struct interface *lookup_interface(char *name); extern int if_readlist(void); +extern int do_if_fetch(struct interface *ife); +extern int do_if_print(struct interface *ife, void *cookie); + +extern void ife_print(struct interface *ptr); + /* Defines for poor glibc2.0 users, the feature check is done at runtime */ #if !defined(SIOCSIFTXQLEN) #define SIOCSIFTXQLEN 0x8943 diff --git a/lib/net-support.h b/lib/net-support.h index fd8b1ac..ff8dc14 100644 --- a/lib/net-support.h +++ b/lib/net-support.h @@ -111,10 +111,12 @@ extern int IPX_rinput(int action, int flags, char **argv); extern int NETROM_rinput(int action, int flags, char **argv); extern int AX25_rinput(int action, int flags, char **argv); -int aftrans_opt(const char *arg); -void aftrans_def(char *tool, char *argv0, char *dflt); +extern int aftrans_opt(const char *arg); +extern void aftrans_def(char *tool, char *argv0, char *dflt); -char *get_sname(int socknumber, char *proto, int numeric); +extern char *get_sname(int socknumber, char *proto, int numeric); + +extern char *safe_strncpy(char *dst, const char *src, size_t size); extern int flag_unx; extern int flag_ipx; diff --git a/netstat.c b/netstat.c index 4d94a22..e102807 100644 --- a/netstat.c +++ b/netstat.c @@ -7,7 +7,7 @@ * NET-3 Networking Distribution for the LINUX operating * system. * - * Version: $Id: netstat.c,v 1.10 1998/11/16 10:13:27 philip Exp $ + * Version: $Id: netstat.c,v 1.11 1998/11/18 13:46:16 philip Exp $ * * Authors: Fred Baumgarten, * Fred N. van Kempen, @@ -1060,16 +1060,16 @@ static int ipx_info(void) } #endif -static void ife_print(struct interface *ptr) +void ife_print(struct interface *ptr) { - printf("%-7.7s ", ptr->name); + printf("%-5.5s ", ptr->name); printf("%5d %3d ", ptr->mtu, ptr->metric); /* If needed, display the interface statistics. */ if (ptr->statistics_valid) { - printf("%6lu %6lu %6lu %6lu ", + printf("%8lu %6lu %6lu %6lu ", ptr->stats.rx_packets, ptr->stats.rx_errors, ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors); - printf("%6lu %6lu %6lu %6lu ", + printf("%8lu %6lu %6lu %6lu ", ptr->stats.tx_packets, ptr->stats.tx_errors, ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors); } else { @@ -1100,19 +1100,6 @@ static void ife_print(struct interface *ptr) printf("\n"); } -static int do_if_print(struct interface *ife, void *cookie) -{ - int *opt_a = (int *) cookie; - if (if_fetch(ife->name, ife) < 0) { - fprintf(stderr, _("%s: unknown interface.\n"), ife->name); - return -1; - } - if (!(ife->flags & IFF_UP) && !(*opt_a)) - return 0; - ife_print(ife); - return 0; -} - static int iface_info(void) { if ((skfd = sockets_open(0)) < 0) { @@ -1120,7 +1107,7 @@ static int iface_info(void) exit(1); } printf(_("Kernel Interface table\n")); - printf(_("Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flags\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) { perror(_("missing interface information")); -- 2.7.4