Commit 9dfdb3b1 authored by Phil Blundell's avatar Phil Blundell

Add prototype for safe_strncpy()

Move some helper functions to interface.c.
Tweak `netstat -i' output format to allow more
room for packet counts.
parent b2eee02d
......@@ -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:
......
......@@ -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, <waltje@uwalt.nl.mugnet.org>
* 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;
......
......@@ -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;
}
......@@ -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
......
......@@ -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;
......
......@@ -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, <dc6iq@insu1.etec.uni-karlsruhe.de>
* Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
......@@ -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"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment