diff options
author | 1999-01-05 20:52:48 +0000 | |
---|---|---|
committer | 1999-01-05 20:52:48 +0000 | |
commit | b72719fcb2f2e067e870c6b6730231804f72c050 (patch) | |
tree | c5a1a6d081f51fd9b6b1af1f9d083cda11b1bc64 | |
parent | sipx_network is defined __u32 in the kernel, so it should not be (diff) | |
download | net-tools-b72719fcb2f2e067e870c6b6730231804f72c050.tar.gz net-tools-b72719fcb2f2e067e870c6b6730231804f72c050.tar.bz2 net-tools-b72719fcb2f2e067e870c6b6730231804f72c050.zip |
A whole pile of fixes from Bernd, plus a fix for an arp
problem reported by Klaus Kudielka <kudielka@ieee.org>.
Also an ifconfig patch for alias deletion from
Roman Sulzhyk <roman@staff.prodigy.com>. I'm not too happy
with this one but I put it in anyway. Andi, see what you
think (look at ifconfig.c about line 1100). Is there really
no better way to delete an alias?
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | README | 26 | ||||
-rw-r--r-- | arp.c | 42 | ||||
-rw-r--r-- | hostname.c | 4 | ||||
-rw-r--r-- | ifconfig.c | 68 | ||||
-rw-r--r-- | lib/Makefile | 2 | ||||
-rw-r--r-- | lib/af.c | 25 | ||||
-rw-r--r-- | lib/ash.c | 5 | ||||
-rw-r--r-- | lib/ax25_gr.c | 3 | ||||
-rw-r--r-- | lib/econet.c | 9 | ||||
-rw-r--r-- | lib/hdlclapb.c | 12 | ||||
-rw-r--r-- | lib/hippi.c | 8 | ||||
-rw-r--r-- | lib/hw.c | 25 | ||||
-rw-r--r-- | lib/inet.c | 15 | ||||
-rw-r--r-- | lib/inet6_gr.c | 6 | ||||
-rw-r--r-- | lib/inet6_sr.c | 2 | ||||
-rw-r--r-- | lib/inet_gr.c | 276 | ||||
-rw-r--r-- | lib/inet_sr.c | 2 | ||||
-rw-r--r-- | lib/ipx_gr.c | 16 | ||||
-rw-r--r-- | lib/net-features.h | 11 | ||||
-rw-r--r-- | lib/net-support.h | 77 | ||||
-rw-r--r-- | lib/netrom_gr.c | 13 | ||||
-rw-r--r-- | lib/netrom_sr.c | 2 | ||||
-rw-r--r-- | lib/proc.c | 26 | ||||
-rw-r--r-- | lib/proc.h | 1 | ||||
-rw-r--r-- | lib/rose.c | 16 | ||||
-rw-r--r-- | lib/rose_gr.c | 10 | ||||
-rw-r--r-- | lib/sit.c | 7 | ||||
-rw-r--r-- | man/en_US/arp.8 | 25 | ||||
-rw-r--r-- | netstat.c | 358 | ||||
-rw-r--r-- | rarp.c | 28 | ||||
-rw-r--r-- | route.c | 27 | ||||
-rw-r--r-- | statistics.c | 92 |
33 files changed, 809 insertions, 436 deletions
@@ -87,7 +87,7 @@ RESLIB = # -L/usr/inet6/lib -linet6 # -------- end of user definitions -------- MAINTAINER = Philip.Blundell@pobox.com -RELEASE = 1.49 +RELEASE = 1.50 .EXPORT_ALL_VARIABLES: @@ -99,7 +99,7 @@ endif NET-LIB = $(NET_LIB_PATH)/lib$(NET_LIB_NAME).a -CFLAGS = $(COPTS) -I. -I./include/ -I$(NET_LIB_PATH) +CFLAGS = $(COPTS) -I. -idirafter ./include/ -I$(NET_LIB_PATH) LDFLAGS = $(LOPTS) -L$(NET_LIB_PATH) SUBDIRS = man/ $(NET_LIB_PATH)/ @@ -136,7 +136,7 @@ clobber: clean dist: clobber @echo Creating net-tools-$(RELEASE) in .. - @tar -cvz -f ../net-tools-$(RELEASE).tar.gz -C .. net-tools + @tar -cvz -f ../net-tools-$(RELEASE).tar.gz -C .. net-tools-${RELEASE} config.h: config.in Makefile @@ -28,7 +28,14 @@ Contents: Notes ----- -This is net-tools 1.49. Notable changes since 1.48 include: +This is net-tools 1.50. Notable changes since 1.49 include: + + - netstat supports a new option `--listening' to show only listening + sockets. + - netstat -s is improved. + - route/netstat -r display the routing cache correctly. + +Notable changes since 1.48 include: - IP masquerading support is now selectable. - The -t and -u switches to netstat now work as expected. @@ -72,16 +79,23 @@ route/netstat -r do not yet support different AF cleanly. IPX/DDP/AX25 people, please feel free to add the code. ifconfig now supports changing media types for interfaces. This requires -a recent 2.1.x kernel, and many devices do not support it yet. +a recent 2.1.x or 2.2.x kernel, and many devices do not support it yet. The documentation is slimmed down. I think most of it was out of date. -Some configuration options require recent 2.1.x kernels and/or particular -versions of the C library. The defaults should be safe for all common -environments but some of the more esoteric hardware and protocol families -may be more touchy. Feel free to send patches if you have problems. +The tools now support the layout of the 2.2.0 /proc files (Bernd Eckenfels). + +Some configuration options require recent 2.1.x or 2.2.x kernels +and/or particular versions of the C library. The defaults should be +safe for all common environments but some of the more esoteric +hardware and protocol families may be more touchy. Feel free to send +patches if you have problems. Phil Blundell philb@gnu.org 11th December 1998 + +Bernd Eckenfels +net-tools@lina.inka.de +1999-01-02 @@ -8,7 +8,7 @@ * NET-3 Networking Distribution for the LINUX operating * system. * - * Version: $Id: arp.c,v 1.10 1998/11/17 15:16:09 freitag Exp $ + * Version: $Id: arp.c,v 1.11 1999/01/05 20:52:54 philip Exp $ * * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> * @@ -41,7 +41,8 @@ *970925 {1.82} Bernd Eckenfels : include fix for libc6 *980213 (1.83) Phil Blundell: set ATF_COM on new entries *980629 (1.84) Arnaldo Carvalho de Melo: gettext instead of catgets - * + *990101 {1.85} Bernd Eckenfels fixed usage and return codes + *990105 (1.86) Phil Blundell: don't ignore EINVAL in arp_set * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General @@ -77,7 +78,7 @@ #define FEATURE_ARP #include "lib/net-features.h" -char *Release = RELEASE, *Version = "arp 1.84 (1998-06-29)"; +char *Release = RELEASE, *Version = "arp 1.85 (1999-01-05)"; int opt_n = 0; /* do not resolve addresses */ int opt_N = 0; /* use symbolic names */ @@ -366,10 +367,8 @@ static int arp_set(char **args) if (opt_v) fprintf(stderr, "arp: SIOCSARP()\n"); if (ioctl(sockfd, SIOCSARP, &req) < 0) { - if (errno != EINVAL) { - perror("SIOCSARP"); - return (-1); - } + perror("SIOCSARP"); + return (-1); } return (0); } @@ -597,18 +596,31 @@ static int arp_show(char *name) static void version(void) { fprintf(stderr, "%s\n%s\n%s\n", Release, Version, Features); - exit(-1); + exit(E_VERSION); } static void usage(void) { - fprintf(stderr, _("Usage: arp [-vn] [-H type] [-i if] -a [hostname]\n")); - fprintf(stderr, _(" arp [-v] [-i if] -d hostname [pub][nopub]\n")); - fprintf(stderr, _(" arp [-v] [-H type] [-i if] -s hostname hw_addr [temp][nopub]\n")); - fprintf(stderr, _(" arp [-v] [-H type] [-i if] -s hostname hw_addr [netmask nm] pub\n")); - fprintf(stderr, _(" arp [-v] [-H type] [-i if] -Ds hostname if [netmask nm] pub\n")); - fprintf(stderr, _(" arp [-vnD] [-H type] [-i if] -f filename\n")); - exit(-1); + fprintf(stderr, _("Usage:\n arp [-vn] [<HW>] [-i <if>] [-a] [<hostname>] <-Display ARP cache\n")); + fprintf(stderr, _(" arp [-v] [-i <if>] -d <hostname> [pub][nopub] <-Delete ARP entry\n")); + fprintf(stderr, _(" arp [-vnD] [<HW>] [-i <if>] -f <filename> <-Add entry from file\n")); + fprintf(stderr, _(" arp [-v] [<HW>] [-i <if>] -s <hostname> <hwaddr> [temp][nopub] <-Add entry\n")); + fprintf(stderr, _(" arp [-v] [<HW>] [-i <if>] -s <hostname> <hwaddr> [netmask <nm>] pub <-''-\n")); + fprintf(stderr, _(" arp [-v] [<HW>] [-i <if>] -Ds <hostname> <if> [netmask <nm>] pub <-''-\n\n")); + + fprintf(stderr, _(" -a display (all) hosts in alternative (BSD) style\n")); + fprintf(stderr, _(" -s, --set set a new ARP entry\n")); + fprintf(stderr, _(" -d, --delete delete a specified entry\n")); + fprintf(stderr, _(" -v, --verbose be verbose\n")); + fprintf(stderr, _(" -n, --numeric dont resolve names\n")); + fprintf(stderr, _(" -i, --device specify network interface (e.g. eth0)\n")); + fprintf(stderr, _(" -D, --use-device read <hwaddr> from given device\n")); + fprintf(stderr, _(" -f, --file read new entries from file\n\n")); + + fprintf(stderr, _(" <HW>=Use '-H <hw>' to specify hardware address type. Default: %s\n"), DFLT_HW); + fprintf(stderr, _(" List of possible hardware types (which support ARP):\n")); + print_hwlist(1); /* 1 = ARPable */ + exit(E_USAGE); } int main(int argc, char **argv) @@ -180,7 +180,7 @@ static void setfilename(char *name, int what) static void version(void) { fprintf(stderr, "%s\n%s\n", Release, Version); - exit(-1); + exit(5); /* E_VERSION */ } static void usage(void) @@ -203,7 +203,7 @@ static void usage(void) fprintf(stderr, _(" Unless you are using bind or NIS for host lookups you can change the\n")); fprintf(stderr, _(" FQDN (Fully Qualified Domain Name) and the DNS domain name (which is\n")); fprintf(stderr, _(" part of the FQDN) in the /etc/hosts file.\n")); - exit(-1); + exit(4); /* E_USAGE */ } @@ -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.25 1998/12/06 16:17:44 philip Exp $ + * Version: $Id: ifconfig.c,v 1.26 1999/01/05 20:52:58 philip Exp $ * * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> * and others. Copyright 1993 MicroWalt Corporation @@ -18,6 +18,8 @@ * 10/1998 - Andi Kleen. Use interface list primitives. */ +#define DFLT_AF "inet" + #include "config.h" #include <features.h> @@ -107,7 +109,7 @@ static const char *if_port_text[][4] = #include "sockets.h" #include "util.h" -char *Release = RELEASE, *Version = "ifconfig 1.37 (1998-12-05)"; +char *Release = RELEASE, *Version = "ifconfig 1.38 (1999-01-05)"; int opt_a = 0; /* show all interfaces */ int opt_i = 0; /* show the statistics */ @@ -418,42 +420,42 @@ static int clr_flag(char *ifname, short flag) static void usage(void) { - fprintf(stderr, _("Usage: ifconfig [-a] [-i] [-v] interface\n")); - fprintf(stderr, _(" [[family] address]\n")); + fprintf(stderr, _("Usage:\n ifconfig [-a] [-i] [-v] <interface> [[<AF>] <address>]\n")); /* XXX: it would be useful to have the add/del syntax even without IPv6. the 2.1 interface address lists make this natural */ #ifdef HAVE_AFINET6 - fprintf(stderr, _(" [add address[/prefixlen]]\n")); + fprintf(stderr, _(" [add <address>[/<prefixlen>]]\n")); #ifdef SIOCDIFADDR - fprintf(stderr, _(" [del address[/prefixlen]]\n")); + fprintf(stderr, _(" [del <address>[/<prefixlen>]]\n")); #endif /* XXX the kernel supports tunneling even without ipv6 */ - fprintf(stderr, _(" [tunnel aa.bb.cc.dd]\n")); #endif #if HAVE_AFINET - fprintf(stderr, _(" [[-]broadcast [aa.bb.cc.dd]]\n")); - fprintf(stderr, _(" [[-]pointopoint [aa.bb.cc.dd]]\n")); - fprintf(stderr, _(" [netmask aa.bb.cc.dd]\n")); - fprintf(stderr, _(" [dstaddr aa.bb.cc.dd]\n")); + fprintf(stderr, _(" [[-]broadcast [<address>]] [[-]pointopoint [<address>]]\n")); + fprintf(stderr, _(" [netmask <address>] [dstaddr <address>] [tunnel <adress>]\n")); #endif - fprintf(stderr, _(" [hw class address]\n")); - fprintf(stderr, _(" [metric NN] [mtu NN]\n")); #ifdef SIOCSKEEPALIVE - fprintf(stderr, _(" [outfill NN] [keepalive NN]\n")); + fprintf(stderr, _(" [outfill <NN>] [keepalive <NN>]\n")); #endif - fprintf(stderr, _(" [[-]trailers] [[-]arp]\n")); - fprintf(stderr, _(" [[-]allmulti] [[-]promisc]\n")); - fprintf(stderr, _(" [multicast]\n")); - fprintf(stderr, _(" [mem_start NN] [io_addr NN] [irq NN]\n")); - fprintf(stderr, _(" [media type]\n")); + fprintf(stderr, _(" [hw <HW> <address>] [metric <NN>] [mtu <NN>]\n")); + fprintf(stderr, _(" [[-]trailers] [[-]arp] [[-]allmulti]\n")); + fprintf(stderr, _(" [multicast] [[-]promisc]\n")); + fprintf(stderr, _(" [mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]\n")); #ifdef HAVE_TXQUEUELEN - fprintf(stderr, _(" [txqueuelen len]\n")); + fprintf(stderr, _(" [txqueuelen len]\n")); #endif #ifdef HAVE_DYNAMIC - fprintf(stderr, _(" [[-]dynamic]\n")); + fprintf(stderr, _(" [[-]dynamic]\n")); #endif - fprintf(stderr, _(" [up] [down] ...\n")); - exit(1); + fprintf(stderr, _(" [up|down] ...\n\n")); + + fprintf(stderr, _(" <HW>=Hardware Type.\n")); + fprintf(stderr, _(" List of possible hardware types:\n")); + print_hwlist(0); /* 1 = ARPable */ + fprintf(stderr, _(" <AF>=Address family. Default: %s\n"), DFLT_AF); + fprintf(stderr, _(" List of possible address families:\n")); + print_aflist(0); /* 1 = routeable */ + exit(E_USAGE); } static void version(void) @@ -543,7 +545,7 @@ int main(int argc, char **argv) } /* The next argument is either an address family name, or an option. */ if ((ap = get_aftype(*spp)) == NULL) - ap = get_aftype("inet"); + ap = get_aftype(DFLT_AF); else { /* XXX: should print the current setup if no args left, but only for this family */ @@ -1089,7 +1091,23 @@ int main(int argc, char **argv) goterr = 1; } } - goterr |= set_flag(ifr.ifr_name, (IFF_UP | IFF_RUNNING)); + /* + * Don't do the set_flag() if the address is an alias with a - at the + * end, since it's deleted already! - Roman + * + * Should really use regex.h here, not sure though how well it'll go + * with the cross-platform support etc. + */ + { + char *ptr; + short int found_colon = 0; + for (ptr = ifr.ifr_name; *ptr; ptr++ ) + if (*ptr == ':') found_colon++; + + if (!(found_colon && *(ptr - 1) == '-')) + goterr |= set_flag(ifr.ifr_name, (IFF_UP | IFF_RUNNING)); + } + spp++; } diff --git a/lib/Makefile b/lib/Makefile index d9815c8..7afb61c 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -29,7 +29,7 @@ OBJS = $(sort $(VARIA) $(AFOBJS) $(HWOBJS) \ # This can be overwritten by the TOPLEVEL Makefile TOPDIR=.. -CFLAGS += -I$(TOPDIR) -I$(TOPDIR)/include # -fPIC +CFLAGS += -I$(TOPDIR) -idirafter $(TOPDIR)/include # -fPIC SONAME=libnet-tools.so.0 .SUFFIXES: .a .so @@ -2,7 +2,7 @@ * lib/af.c This file contains the top-level part of the protocol * support functions module for the NET-2 base distribution. * - * Version: $Id: af.c,v 1.9 1998/12/01 09:30:30 philip Exp $ + * Version: $Id: af.c,v 1.10 1999/01/05 20:53:18 philip Exp $ * * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> * Copyright 1993 MicroWalt Corporation @@ -291,3 +291,26 @@ int aftrans_opt(const char *arg) return (0); } + +/* type: 0=all, 1=getroute */ +void print_aflist(int type) { + int count = 0; + char * txt; + struct aftype **afp; + + if (!sVafinit) + afinit(); + + afp = aftypes; + while (*afp != NULL) { + if ((type == 1 && ((*afp)->rprint == NULL)) || ((*afp)->af == 0)) { + afp++; continue; + } + if ((count % 3) == 0) fprintf(stderr,count?"\n ":" "); + txt = (*afp)->name; if (!txt) txt = ".."; + fprintf(stderr,"%s (%s) ",txt,(*afp)->title); + count++; + afp++; + } + fprintf(stderr,"\n"); +} @@ -1,7 +1,7 @@ /* * lib/ash.c This file contains an implementation of the Ash * support functions for the NET-2 base distribution. - * $Id: ash.c,v 1.8 1998/11/26 10:16:38 philip Exp $ + * $Id: ash.c,v 1.9 1999/01/05 20:53:20 philip Exp $ */ #include "config.h" @@ -23,7 +23,8 @@ #include "util.h" #ifndef ARPHRD_ASH -#error No support for Ash on this system +#warning "No definition of ARPHRD_ASH in <net/if_arp.h>, using private value 517" +#define ARPHRD_ASH 517 #endif #define ASH_ALEN 64 diff --git a/lib/ax25_gr.c b/lib/ax25_gr.c index 69f0793..4dce92d 100644 --- a/lib/ax25_gr.c +++ b/lib/ax25_gr.c @@ -2,7 +2,7 @@ * lib/ax25_gr.c This file contains an implementation of the "AX.25" * route print support functions. * - * Version: $Id: ax25_gr.c,v 1.3 1998/11/15 20:09:22 freitag Exp $ + * Version: $Id: ax25_gr.c,v 1.4 1999/01/05 20:53:21 philip Exp $ * * Author: Bernd Eckenfels, <ecki@lina.inka.de> * Copyright 1999 Bernd Eckenfels, Germany @@ -43,6 +43,7 @@ int AX25_rprint(int options) int use; if (f == NULL) { + perror(_PATH_PROCNET_AX25_ROUTE); printf(_("AX.25 not configured in this system.\n")); /* xxx */ return 1; } diff --git a/lib/econet.c b/lib/econet.c index 14d9202..4c2c322 100644 --- a/lib/econet.c +++ b/lib/econet.c @@ -3,7 +3,7 @@ * support functions for the net-tools. * (NET-3 base distribution). * - * Version: $Id: econet.c,v 1.5 1998/11/18 10:32:06 philip Exp $ + * Version: $Id: econet.c,v 1.6 1999/01/05 20:53:23 philip Exp $ * * Author: Philip Blundell <philb@gnu.org> * @@ -24,14 +24,15 @@ #include <sys/socket.h> #include <stdio.h> +#ifndef _NETECONET_EC_H +#include <linux/if_ec.h> +#endif + #include "version.h" #include "net-support.h" #include "pathnames.h" #include "intl.h" -#ifndef _NETECONET_EC_H -#include <linux/if_ec.h> -#endif /* Display an Econet address */ static char * diff --git a/lib/hdlclapb.c b/lib/hdlclapb.c index 4cac136..1753745 100644 --- a/lib/hdlclapb.c +++ b/lib/hdlclapb.c @@ -3,7 +3,7 @@ * This file contains the HDLC/LAPB support for the NET-2 base * distribution. * - * Version: $Id: hdlclapb.c,v 1.3 1998/11/15 20:09:55 freitag Exp $ + * Version: $Id: hdlclapb.c,v 1.4 1999/01/05 20:53:26 philip Exp $ * * Original Author: * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> @@ -36,6 +36,16 @@ #include "net-support.h" #include "pathnames.h" +#ifndef ARPHRD_HDLC +#warning "No definition of ARPHRD_HDLC in <net/if_arp.h>, using private value 513" +#define ARPHRD_HDLC 513 +#endif + +#ifndef ARPHRD_LAPB +#warning "No definition of ARPHRD_HDLC in <net/if_arp.h>, using private value 516" +#define ARPHRD_LAPB 516 +#endif + struct hwtype hdlc_hwtype = { "hdlc", NULL, /*"(Cisco) HDLC", */ ARPHRD_HDLC, 0, diff --git a/lib/hippi.c b/lib/hippi.c index 3bb0a6b..5e9885a 100644 --- a/lib/hippi.c +++ b/lib/hippi.c @@ -21,10 +21,6 @@ #include <sys/types.h> #include <sys/socket.h> #include <net/if_arp.h> -#ifndef ARPHRD_HIPPI -#error "No HIPPI Support in your current Kernelsource Tree." -#error "Disable HW Type HIPPI" -#endif #include <stdlib.h> #include <stdio.h> #include <errno.h> @@ -41,6 +37,10 @@ */ #define HIPPI_ALEN 6 /* Bytes in one HIPPI hw-addr */ +#ifndef ARPHRD_HIPPI +#define ARPHRD_HIPPI 780 +#warning "ARPHRD_HIPPI is not defined in <net/if_arp.h>. Using private value 708" +#endif extern struct hwtype hippi_hwtype; @@ -2,7 +2,7 @@ * lib/hw.c This file contains the top-level part of the hardware * support functions module. * - * Version: $Id: hw.c,v 1.9 1998/11/16 15:13:48 philip Exp $ + * Version: $Id: hw.c,v 1.10 1999/01/05 20:53:31 philip Exp $ * * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> * @@ -214,3 +214,26 @@ struct hwtype *get_hwntype(int type) } return (NULL); } + +/* type: 0=all, 1=ARPable */ +void print_hwlist(int type) { + int count = 0; + char * txt; + struct hwtype **hwp; + + if (!sVhwinit) + hwinit(); + + hwp = hwtypes; + while (*hwp != NULL) { + if (((type == 1) && ((*hwp)->alen == 0)) || ((*hwp)->type == -1)) { + hwp++; continue; + } + if ((count % 3) == 0) fprintf(stderr,count?"\n ":" "); + txt = (*hwp)->name; if (!txt) txt = ".."; + fprintf(stderr,"%s (%s) ",txt,(*hwp)->title); + count++; + hwp++; + } + fprintf(stderr,"\n"); +} @@ -3,7 +3,7 @@ * support functions for the net-tools. * (NET-3 base distribution). * - * Version: $Id: inet.c,v 1.7 1998/11/19 13:01:58 philip Exp $ + * Version: $Id: inet.c,v 1.8 1999/01/05 20:53:33 philip Exp $ * * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> * Copyright 1993 MicroWalt Corporation @@ -15,6 +15,7 @@ *960217 {1.24} Bernd Eckenfels : get_sname *960219 {1.25} Bernd Eckenfels : extern int h_errno *960329 {1.26} Bernd Eckenfels : resolve 255.255.255.255 + *980101 {1.27} Bernd Eckenfels : resolve raw sockets in /etc/protocols * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General @@ -312,6 +313,7 @@ static struct service *searchlist(struct service *servicebase, int number) static int read_services(void) { struct servent *se; + struct protoent *pe; struct service *item; setservent(1); @@ -333,6 +335,17 @@ static int read_services(void) } } endservent(); + setprotoent(1); + while ((pe = getprotoent())) { + /* Allocate a service entry. */ + item = (struct service *) malloc(sizeof(struct service)); + if (item == NULL) + perror("netstat"); + item->name = strdup(pe->p_name); + item->number = htons(pe->p_proto); + add2list(&raw_name, item); + } + endprotoent(); return (0); } diff --git a/lib/inet6_gr.c b/lib/inet6_gr.c index 42f8839..6b6bbf8 100644 --- a/lib/inet6_gr.c +++ b/lib/inet6_gr.c @@ -14,7 +14,7 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> -#include <net/route.h> +/* #include <net/route.h> realy broken */ #include <ctype.h> #include <errno.h> #include <netdb.h> @@ -71,10 +71,12 @@ int rprint_fib6(int ext, int numeric) struct sockaddr_in6 saddr6, snaddr6; int num, iflags, metric, refcnt, use, prefix_len, slen; FILE *fp = fopen(_PATH_PROCNET_ROUTE6, "r"); + char addr6p[8][5], saddr6p[8][5], naddr6p[8][5]; if (!fp) { - ESYSNOT("getroute", "INET6 FIB"); + perror(_PATH_PROCNET_ROUTE6); + printf(_("INET6 (IPv6) not configured in this system.\n")); return 1; } printf(_("Kernel IPv6 routing table\n")); diff --git a/lib/inet6_sr.c b/lib/inet6_sr.c index 7aa0c4d..e4656a0 100644 --- a/lib/inet6_sr.c +++ b/lib/inet6_sr.c @@ -13,7 +13,7 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> -#include <net/route.h> +/* #include <net/route.h> realy broken */ #include <net/if.h> #include <sys/ioctl.h> #include <ctype.h> diff --git a/lib/inet_gr.c b/lib/inet_gr.c index 3d09348..6324f88 100644 --- a/lib/inet_gr.c +++ b/lib/inet_gr.c @@ -1,8 +1,9 @@ /* - $Id: inet_gr.c,v 1.9 1998/11/15 20:10:48 freitag Exp $ + $Id: inet_gr.c,v 1.10 1999/01/05 20:53:43 philip Exp $ Modifications: 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets + 1999-01-01 - Bernd Eckenfels - fixed the routing cache printouts */ #include "config.h" @@ -13,7 +14,7 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> -#include <net/route.h> +/* #include <net/route.h> realy broken */ #include <ctype.h> #include <errno.h> #include <netdb.h> @@ -28,22 +29,22 @@ #include "intl.h" #include "net-features.h" #include "proc.h" - extern struct aftype inet_aftype; int rprint_fib(int ext, int numeric) { - char buff[1024], iface[16], flags[16]; + char buff[1024], iface[16], flags[64]; char gate_addr[128], net_addr[128]; char mask_addr[128]; - struct sockaddr snet, sgate, smask; + struct sockaddr snet; int num, iflags, metric, refcnt, use, mss, window, irtt; FILE *fp = fopen(_PATH_PROCNET_ROUTE, "r"); char *fmt; if (!fp) { - ESYSNOT("getroute", "INET FIB"); + perror(_PATH_PROCNET_ROUTE); + printf(_("INET (IPv4) not configured in this system.\n")); return 1; } printf(_("Kernel IP routing table\n")); @@ -95,17 +96,19 @@ int rprint_fib(int ext, int numeric) net_addr[15] = '\0'; /* Fetch and resolve the gateway address. */ - (void) inet_aftype.input(1, gate_addr, &sgate); - strcpy(gate_addr, inet_aftype.sprint(&sgate, numeric)); + (void) inet_aftype.input(1, gate_addr, &snet); + strcpy(gate_addr, inet_aftype.sprint(&snet, numeric)); gate_addr[15] = '\0'; /* Fetch and resolve the genmask. */ - (void) inet_aftype.input(1, mask_addr, &smask); - strcpy(mask_addr, inet_aftype.sprint(&smask, 1)); + (void) inet_aftype.input(1, mask_addr, &snet); + strcpy(mask_addr, inet_aftype.sprint(&snet, 1)); mask_addr[15] = '\0'; /* Decode the flags. */ - strcpy(flags, "U"); + flags[0] = '\0'; + if (iflags & RTF_UP) + strcat(flags, "U"); if (iflags & RTF_GATEWAY) strcat(flags, "G"); #if HAVE_RTF_REJECT @@ -120,6 +123,33 @@ int rprint_fib(int ext, int numeric) strcat(flags, "D"); if (iflags & RTF_MODIFIED) strcat(flags, "M"); + if (iflags & RTF_DEFAULT) + strcat(flags, "d"); + if (iflags & RTF_ALLONLINK) + strcat(flags, "a"); + if (iflags & RTF_ADDRCONF) + strcat(flags, "c"); + if (iflags & RTF_NONEXTHOP) + strcat(flags, "o"); + if (iflags & RTF_EXPIRES) + strcat(flags, "e"); + if (iflags & RTF_CACHE) + strcat(flags, "c"); + if (iflags & RTF_FLOW) + strcat(flags, "f"); + if (iflags & RTF_POLICY) + strcat(flags, "p"); + if (iflags & RTF_LOCAL) + strcat(flags, "l"); + if (iflags & RTF_MTU) + strcat(flags, "u"); + if (iflags & RTF_WINDOW) + strcat(flags, "w"); + if (iflags & RTF_IRTT) + strcat(flags, "i"); + if (iflags & RTF_NOTCACHED) /* 2.0.36 */ + strcat(flags, "n"); + /* Print the info. */ if (ext == 1) { #if HAVE_RTF_REJECT @@ -163,31 +193,69 @@ int rprint_fib(int ext, int numeric) int rprint_cache(int ext, int numeric) { - char buff[1024], iface[16], flags[16]; - char gate_addr[128], net_addr[128]; - char mask_addr[128]; - struct sockaddr snet, sgate, smask; - int num, iflags, metric, refcnt, use, mss, window, irtt, hh, arp; - char *fmt; + char buff[1024], iface[16], flags[64]; + char gate_addr[128], dest_addr[128], specdst[128]; + char src_addr[128]; + struct sockaddr snet; + unsigned int iflags; + int num, format, metric, refcnt, use, mss, window, irtt, hh, hhref, hhuptod, arp, tos; + char *fmt = NULL; FILE *fp = fopen(_PATH_PROCNET_RTCACHE, "r"); if (!fp) { - ESYSNOT("getroute", "INET CACHE"); + perror(_PATH_PROCNET_RTCACHE); + printf(_("INET (IPv4) not configured in this system.\n")); return 1; } + + /* Okay, first thing we need to know is the format of the rt_cache. + * I am aware of two possible layouts: + * 2.2.0 + * "Iface\tDestination\tGateway \tFlags\t\tRefCnt\tUse\tMetric\tSource\t\tMTU\tWindow\tIRTT\tTOS\tHHRef\tHHUptod\tSpecDst" + * "%s\t%08lX\t%08lX\t%8X\t%d\t%u\t%d\t%08lX\t%d\t%u\t%u\t%02X\t%d\t%1d\t%08X" + * + * 2.0.36 + * "Iface\tDestination\tGateway \tFlags\tRefCnt\tUse\tMetric\tSource\t\tMTU\tWindow\tIRTT\tHH\tARP" + * "%s\t%08lX\t%08lX\t%02X\t%d\t%u\t%d\t%08lX\t%d\t%lu\t%u\t%d\t%1d" + */ + + format = proc_guess_fmt(_PATH_PROCNET_RTCACHE, fp, "IRTT",1,"TOS",2,"HHRef",4,"HHUptod",8,"SpecDst",16,"HH",32,"ARP",64,NULL); + + printf(_("Kernel IP routing cache\n")); + + switch(format) { + case -1: /* I/O Error */ + perror(_PATH_PROCNET_RTCACHE); + exit(-1); + break; + case 63: /* 2.2.0 Format */ + format = 2; + break; + case 97: /* 2.0.36 Format */ + format = 1; + break; + default: + printf("ERROR: proc_guess_fmt(%s,... returned: %d\n",_PATH_PROCNET_RTCACHE, format); + break; + } + + rewind(fp); + if (ext == 1) - printf(_("Destination Gateway Source " - "Flags Metric Ref Use Iface\n")); + printf(_("Source Destination Gateway " + "Flags Metric Ref Use Iface\n")); if (ext == 2) - printf(_("Destination Gateway Source " - "Flags MSS Window irtt Iface\n")); - if (ext >= 3) - printf(_("Destination Gateway Source " + printf(_("Source Destination Gateway " + "Flags MSS Window irtt Iface\n")); + + if (format == 1) { + if (ext >= 3) + printf(_("Source Destination Gateway " "Flags Metric Ref Use Iface " - "MSS Window irtt HH Arp\n")); + "MSS Window irtt HH Arp\n")); - fmt = proc_gen_fmt(_PATH_PROCNET_ROUTE, 0, fp, + fmt = proc_gen_fmt(_PATH_PROCNET_RTCACHE, 0, fp, "Iface", "%16s", "Destination", "%128s", "Gateway", "%128s", @@ -195,92 +263,164 @@ int rprint_cache(int ext, int numeric) "RefCnt", "%d", "Use", "%d", "Metric", "%d", - "Mask", "%128s", + "Source", "%128s", "MTU", "%d", "Window", "%d", "IRTT", "%d", + "HH", "%d", + "ARP", "%d", NULL); - /* "%16s %128s %128s %X %d %d %d %128s %d %d %d %d %d\n" */ + /* "%16s %128s %128s %X %d %d %d %128s %d %d %d %d %d\n" */ + } + + if (format == 2) { + if (ext >= 3) + printf(_("Source Destination Gateway " + "Flags Metric Ref Use Iface " + "MSS Window irtt TOS HHRef HHUptod SpecDst\n")); + fmt = proc_gen_fmt(_PATH_PROCNET_RTCACHE, 0, fp, + "Iface", "%16s", + "Destination", "%128s", + "Gateway", "%128s", + "Flags", "%X", + "RefCnt", "%d", + "Use", "%d", + "Metric", "%d", + "Source", "%128s", + "MTU", "%d", + "Window", "%d", + "IRTT", "%d", + "TOS", "%d", + "HHRef", "%d", + "HHUptod", "%d", + "SpecDst", "%128s", + NULL); + /* "%16s %128s %128s %X %d %d %d %128s %d %d %d %d %d %128s\n" */ + } + irtt = 0; window = 0; mss = 0; - hh = 0; - arp = 0; + hh = 0; hhref = 0; hhuptod = 0; + arp = 0; tos = 0; while (fgets(buff, 1023, fp)) { - num = sscanf(buff, fmt, - iface, net_addr, gate_addr, - &iflags, &refcnt, &use, &metric, mask_addr, + if (format == 1) { + num = sscanf(buff, fmt, + iface, dest_addr, gate_addr, + &iflags, &refcnt, &use, &metric, src_addr, &mss, &window, &irtt, &hh, &arp); - if (num < 12) + if (num < 12) continue; + } + if (format == 2) { + num = sscanf(buff, fmt, + iface, dest_addr, gate_addr, + &iflags, &refcnt, &use, &metric, src_addr, + &mss, &window, &irtt, &tos, &hhref, &hhuptod, &specdst); + if (num < 12) + continue; + } + /* Fetch and resolve the target address. */ - (void) inet_aftype.input(1, net_addr, &snet); - strcpy(net_addr, inet_aftype.sprint(&snet, (numeric | 0x8000))); - net_addr[15] = '\0'; + (void) inet_aftype.input(1, dest_addr, &snet); + strcpy(dest_addr, inet_aftype.sprint(&snet, numeric)); + dest_addr[15] = '\0'; /* Fetch and resolve the gateway address. */ - (void) inet_aftype.input(1, gate_addr, &sgate); - strcpy(gate_addr, inet_aftype.sprint(&sgate, numeric)); + (void) inet_aftype.input(1, gate_addr, &snet); + strcpy(gate_addr, inet_aftype.sprint(&snet, numeric)); gate_addr[15] = '\0'; - /* Fetch and resolve the genmask. */ - (void) inet_aftype.input(1, mask_addr, &smask); - strcpy(mask_addr, inet_aftype.sprint(&smask, 1)); - mask_addr[15] = '\0'; + /* Fetch and resolve the source. */ + (void) inet_aftype.input(1, src_addr, &snet); + strcpy(src_addr, inet_aftype.sprint(&snet, numeric)); + src_addr[15] = '\0'; + + /* Fetch and resolve the SpecDst addrerss. */ + (void) inet_aftype.input(1, specdst, &snet); + strcpy(specdst, inet_aftype.sprint(&snet, numeric)); + specdst[15] = '\0'; /* Decode the flags. */ flags[0] = '\0'; +if (format == 1) { if (iflags & RTF_UP) strcat(flags, "U"); + if (iflags & RTF_HOST) + strcat(flags, "H"); +} if (iflags & RTF_GATEWAY) strcat(flags, "G"); #if HAVE_RTF_REJECT if (iflags & RTF_REJECT) strcpy(flags, "!"); #endif - if (iflags & RTF_HOST) - strcat(flags, "H"); if (iflags & RTF_REINSTATE) strcat(flags, "R"); if (iflags & RTF_DYNAMIC) strcat(flags, "D"); if (iflags & RTF_MODIFIED) strcat(flags, "M"); + +/* possible collision with 2.0 flags U and H */ +if (format == 2) { + if (iflags & RTCF_DEAD) + strcat(flags, "-"); + if (iflags & RTCF_ONLINK) + strcat(flags, "o"); +} + if (iflags & RTCF_NOTIFY) + strcat(flags, "n"); + if (iflags & RTCF_DIRECTDST) + strcat(flags, "d"); + if (iflags & RTCF_TPROXY) + strcat(flags, "t"); + if (iflags & RTCF_FAST) + strcat(flags, "f"); + if (iflags & RTCF_MASQ) + strcat(flags, "q"); + if (iflags & RTCF_SNAT) + strcat(flags, "Ns"); + if (iflags & RTCF_DOREDIRECT) + strcat(flags, "r"); + if (iflags & RTCF_DIRECTSRC) + strcat(flags, "i"); + if (iflags & RTCF_DNAT) + strcat(flags, "Nd"); + if (iflags & RTCF_BROADCAST) + strcat(flags, "b"); + if (iflags & RTCF_MULTICAST) + strcat(flags, "m"); + if (iflags & RTCF_REJECT) + strcat(flags, "#"); + if (iflags & RTCF_LOCAL) + strcat(flags, "l"); /* Print the info. */ if (ext == 1) { -#if HAVE_RTF_REJECT - if (iflags & RTF_REJECT) - printf("%-15s - %-15s %-5s %-6d - %7d -\n", - net_addr, mask_addr, flags, metric, use); - else -#endif printf("%-15s %-15s %-15s %-5s %-6d %-2d %7d %s\n", - net_addr, gate_addr, mask_addr, flags, + src_addr, dest_addr, gate_addr, flags, metric, refcnt, use, iface); } if (ext == 2) { -#if HAVE_RTF_REJECT - if (iflags & RTF_REJECT) - printf("%-15s - %-15s %-5s - - - -\n", - net_addr, mask_addr, flags); - else -#endif printf("%-15s %-15s %-15s %-5s %5d %-5d %6d %s\n", - net_addr, gate_addr, mask_addr, flags, + src_addr, dest_addr, gate_addr, flags, mss, window, irtt, iface); } - if (ext >= 3) { -#if HAVE_RTF_REJECT - if (iflags & RTF_REJECT) - printf("%-15s - %-15s %-5s %-6d - %7d - - - -\n", - net_addr, mask_addr, flags, metric, use); - else -#endif - printf("%-15s %-15s %-15s %-5s %-6d %-3d %6d %-6.6s %-5d %-6d %-6d %-3d %d\n", - net_addr, gate_addr, mask_addr, flags, + if (format == 1) { + if (ext >= 3) { + printf("%-15s %-15s %-15s %-5s %-6d %-3d %6d %-6.6s %-5d %-6d %-5d %-3d %d\n", + src_addr, dest_addr, gate_addr, flags, metric, refcnt, use, iface, mss, window, irtt, hh, arp); + } + } + if (format == 2) { + if (ext >= 3) { + printf("%-15s %-15s %-15s %-5s %-6d %-3d %6d %-6.6s %-5d %-6d %-5d %-3d %-3d %-3d %15s\n", + src_addr, dest_addr, gate_addr, flags, + metric, refcnt, use, iface, mss, window, irtt, tos, hhref, hhuptod, specdst); + } } } diff --git a/lib/inet_sr.c b/lib/inet_sr.c index 4fb73b5..bae2437 100644 --- a/lib/inet_sr.c +++ b/lib/inet_sr.c @@ -13,7 +13,7 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> -#include <net/route.h> +#include <net/route.h> /* realy broken */ #include <sys/ioctl.h> #include <ctype.h> #include <errno.h> diff --git a/lib/ipx_gr.c b/lib/ipx_gr.c index 757720a..b0a740d 100644 --- a/lib/ipx_gr.c +++ b/lib/ipx_gr.c @@ -38,22 +38,24 @@ int IPX_rprint(int options) char net[128], router_net[128]; char router_node[128]; int num; - FILE *fp; + FILE *fp = fopen(_PATH_PROCNET_IPX_ROUTE, "r"); struct aftype *ap; struct sockaddr sa; - printf(_("Kernel IPX routing table\n")); /* xxx */ - if ((ap = get_afntype(AF_IPX)) == NULL) { EINTERN("lib/ipx_rt.c", "AF_IPX missing"); return (-1); } - printf(_("Destination Router Net Router Node\n")); - if ((fp = fopen(_PATH_PROCNET_IPX_ROUTE, "r")) == NULL) { - perror(_PATH_PROCNET_IPX_ROUTE); - return (-1); + if (!fp) { + perror(_PATH_PROCNET_IPX_ROUTE); + printf(_("IPX not configured in this system.\n")); + return 1; } + + printf(_("Kernel IPX routing table\n")); /* xxx */ + printf(_("Destination Router Net Router Node\n")); + fgets(buff, 1023, fp); while (fgets(buff, 1023, fp)) { diff --git a/lib/net-features.h b/lib/net-features.h index 3084e8a..9ff45d0 100644 --- a/lib/net-features.h +++ b/lib/net-features.h @@ -43,10 +43,6 @@ #define HAVE_RTF_REJECT 1 #endif -#ifdef RTMSG_NEWROUTE /* netstat */ -#define HAVE_RT_NETLINK 1 -#endif - /* compose the feature information string */ #if defined (FEATURE_ARP) || defined (FEATURE_ROUTE) || defined (FEATURE_NETSTAT) @@ -104,13 +100,6 @@ static char *Features = #endif "RTF_REJECT " -#if HAVE_RT_NETLINK -"+" -#else -"-" -#endif -"RT_NETLINK " - #if HAVE_FW_MASQUERADE "+" #else diff --git a/lib/net-support.h b/lib/net-support.h index cdb38b4..254b0b9 100644 --- a/lib/net-support.h +++ b/lib/net-support.h @@ -8,7 +8,7 @@ * NET-3 Networking Distribution for the LINUX operating * system. (net-tools, net-drivers) * - * Version: lib/net-support.h 1.34 (1996-04-13) + * Version: lib/net-support.h 1.35 (1996-01-01) * * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> * @@ -22,6 +22,7 @@ *960219 {1.32} Bernd Eckenfels: type for ap->input() *960322 {1.33} Bernd Eckenfels: activate_ld and const in get_hwtype *960413 {1.34} Bernd Eckenfels: new RTACTION suport + *990101 {1.35} Bernd Eckenfels: print_(hw|af)list support, added kerneldefines * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General @@ -68,8 +69,10 @@ struct hwtype { extern struct hwtype *get_hwtype(const char *name); extern struct hwtype *get_hwntype(int type); +extern void print_hwlist(int type); extern struct aftype *get_aftype(const char *name); extern struct aftype *get_afntype(int type); +extern void print_aflist(int type); extern int getargs(char *string, char *arguments[]); @@ -158,4 +161,76 @@ extern char afname[]; #define E_INTERN 2 #define E_NOSUPP 1 + +/* ========== Kernel Defines ============= + * Since it is not a good idea to depend on special kernel sources for the headers + * and since the libc6 Headers are not always up to date, we keep a copy of the + * most often used Flags in this file. We realy need a way to keep them up-to-date. + * Perhaps anybody knows how the glibc2 folk is doing it? -ecki + */ + +/* Keep this ins sync with /usr/src/linux/include/linux/rtnetlink.h */ +#define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */ +#define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */ +#define RTNH_F_ONLINK 4 /* Gateway is forced on link */ + +/* Keep this in sync with /usr/src/linux/include/linux/in_route.h */ +#define RTCF_DEAD RTNH_F_DEAD +#define RTCF_ONLINK RTNH_F_ONLINK +/* #define RTCF_NOPMTUDISC RTM_F_NOPMTUDISC */ +#define RTCF_NOTIFY 0x00010000 +#define RTCF_DIRECTDST 0x00020000 +#define RTCF_REDIRECTED 0x00040000 +#define RTCF_TPROXY 0x00080000 +#define RTCF_FAST 0x00200000 +#define RTCF_MASQ 0x00400000 +#define RTCF_SNAT 0x00800000 +#define RTCF_DOREDIRECT 0x01000000 +#define RTCF_DIRECTSRC 0x04000000 +#define RTCF_DNAT 0x08000000 +#define RTCF_BROADCAST 0x10000000 +#define RTCF_MULTICAST 0x20000000 +#define RTCF_REJECT 0x40000000 +#define RTCF_LOCAL 0x80000000 + +/* Keep this in sync with /usr/src/linux/include/linux/ipv6_route.h */ +#ifndef RTF_DEFAULT +#define RTF_DEFAULT 0x00010000 /* default - learned via ND */ +#endif +#define RTF_ALLONLINK 0x00020000 /* fallback, no routers on link */ +#ifndef RTF_ADDRCONF +#define RTF_ADDRCONF 0x00040000 /* addrconf route - RA */ +#endif +#define RTF_NONEXTHOP 0x00200000 /* route with no nexthop */ +#define RTF_EXPIRES 0x00400000 +#define RTF_CACHE 0x01000000 /* cache entry */ +#define RTF_FLOW 0x02000000 /* flow significant route */ +#define RTF_POLICY 0x04000000 /* policy route */ +#define RTF_LOCAL 0x80000000 + +/* Keep this in sync with /usr/src/linux/include/linux/route.h */ +#define RTF_UP 0x0001 /* route usable */ +#define RTF_GATEWAY 0x0002 /* destination is a gateway */ +#define RTF_HOST 0x0004 /* host entry (net otherwise) */ +#define RTF_REINSTATE 0x0008 /* reinstate route after tmout */ +#define RTF_DYNAMIC 0x0010 /* created dyn. (by redirect) */ +#define RTF_MODIFIED 0x0020 /* modified dyn. (by redirect) */ +#define RTF_MTU 0x0040 /* specific MTU for this route */ +#ifndef RTF_MSS +#define RTF_MSS RTF_MTU /* Compatibility :-( */ +#endif +#define RTF_WINDOW 0x0080 /* per route window clamping */ +#define RTF_IRTT 0x0100 /* Initial round trip time */ +#define RTF_REJECT 0x0200 /* Reject route */ + +/* this is a 2.0.36 flag from /usr/src/linux/include/linux/route.h */ +#define RTF_NOTCACHED 0x0400 /* this route isn't cached */ + +#ifdef HAVE_AFECONET +#ifndef AF_ECONET +#define AF_ECONET 19 /* Acorn Econet */ +#endif +#endif + /* End of lib/support.h */ + diff --git a/lib/netrom_gr.c b/lib/netrom_gr.c index 1ff8008..08a3e42 100644 --- a/lib/netrom_gr.c +++ b/lib/netrom_gr.c @@ -2,7 +2,7 @@ * lib/netrom_gr.c This file contains an implementation of the NET/ROM * route support functions. * - * Version: $Id: netrom_gr.c,v 1.3 1998/11/15 20:11:29 freitag Exp $ + * Version: $Id: netrom_gr.c,v 1.4 1999/01/05 20:53:55 philip Exp $ * * Author: Bernd Eckenfels, <ecki@lina.inka.de> * Copyright 1999 Bernd Eckenfels, Germany @@ -39,12 +39,17 @@ int NETROM_rprint(int options) /*int ext = options & FLAG_EXT; int numeric = options & FLAG_NUM; */ + f1 = fopen(_PATH_PROCNET_NR_NODES, "r"); + if (!f1) perror(_PATH_PROCNET_NR_NODES); + f2 = fopen(_PATH_PROCNET_NR_NEIGH, "r"); + if (!f2) perror(_PATH_PROCNET_NR_NEIGH); + if (f1 == NULL || f2 == NULL) { - printf(_("NET/ROM not configured in this system.\n")); /* xxx */ + printf(_("NET/ROM not configured in this system.\n")); return 1; } - printf(_("Kernel NET/ROM routing table\n")); /* xxx */ - printf(_("Destination Mnemonic Quality Neighbour Iface\n")); /* xxx */ + printf(_("Kernel NET/ROM routing table\n")); + printf(_("Destination Mnemonic Quality Neighbour Iface\n")); fgets(buffer, 256, f1); while (fgets(buffer, 256, f1)) { buffer[9] = 0; diff --git a/lib/netrom_sr.c b/lib/netrom_sr.c index b085344..12815a1 100644 --- a/lib/netrom_sr.c +++ b/lib/netrom_sr.c @@ -7,7 +7,7 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> -#include <net/route.h> +/* #include <net/route.h> realy broken */ #include <sys/ioctl.h> #include <ctype.h> #include <errno.h> @@ -1,5 +1,5 @@ /* Tolerant /proc file parser. Copyright 1998 Andi Kleen */ -/* $Id: proc.c,v 1.3 1998/11/15 20:11:55 freitag Exp $ */ +/* $Id: proc.c,v 1.4 1999/01/05 20:54:00 philip Exp $ */ /* Fixme: cannot currently cope with removed fields */ #include <string.h> @@ -48,3 +48,27 @@ char *proc_gen_fmt(char *name, int more, FILE * fh,...) } return strdup(format); } + +/* + * this will generate a bitmask of present/missing fields in the header of + * a /proc file. + */ +int proc_guess_fmt(char *name, FILE *fh, ...) +{ + char buf[512]; + char *tmp; + int flag = 0; + va_list ap; + + if (!fgets(buf, (sizeof buf) - 1, fh)) + return -1; + strcat(buf, "\0"); + va_start(ap, fh); + while((tmp = va_arg(ap, char *))) { + int f = va_arg(ap, int); + if (strstr(buf,tmp) != 0) + flag |= f; + } + va_end(ap); + return flag; +} @@ -2,3 +2,4 @@ /* Generate a suitable scanf format for a column title line */ char *proc_gen_fmt(char *name, int more, FILE * fh,...); +int proc_guess_fmt(char *name, FILE* fh,...); @@ -2,7 +2,7 @@ * lib/rose.c This file contains an implementation of the "ROSE" * support functions for the NET-2 base distribution. * - * Version: $Id: rose.c,v 1.5 1998/11/15 20:12:00 freitag Exp $ + * Version: $Id: rose.c,v 1.6 1999/01/05 20:54:04 philip Exp $ * * Author: Terry Dawson, VK2KTJ, <terry@perf.no.itg.telstra.com.au> * based on ax25.c by: @@ -35,8 +35,18 @@ #include "pathnames.h" #include "intl.h" -#if __GLIBC__ >= 2 -#include <netrose/rose.h> +#ifndef _NETROSE_ROSE_H +#include <linux/ax25.h> +#include <linux/rose.h> +/* this will check for the broken #define PF_ROSE AF_ROSE define in some older kernel headers */ +#undef AF_ROSE +#if PF_ROSE == AF_ROSE +#warning "Your <linux/rose.h> is broken and defines PF_ROSE, better remove the define in /usr/include/linux/rose.h (using private define for PF_ROSE meanwhile)" +#undef PF_ROSE +#define PF_ROSE 11 /* Amateur Radio X.25 PLP */ +#endif +/* now restore the value of AF_ROSE (which had to be deleted to catch the case where #define AF_ROSE PF_ROSE) */ +#define AF_ROSE PF_ROSE #endif static char ROSE_errmsg[128]; diff --git a/lib/rose_gr.c b/lib/rose_gr.c index e67750b..cf0a60a 100644 --- a/lib/rose_gr.c +++ b/lib/rose_gr.c @@ -3,7 +3,7 @@ * lib/rose_gr.c This file contains an implementation of the "ROSE" * route print support functions. * - * Version: $Id: rose_gr.c,v 1.3 1998/11/15 20:12:03 freitag Exp $ + * Version: $Id: rose_gr.c,v 1.4 1999/01/05 20:54:07 philip Exp $ * * Author: Terry Dawson, VK2KTJ, <terry@perf.no.itg.telstra.com.au> * based on ax25_gr.c by: @@ -41,16 +41,18 @@ int ROSE_rprint(int options) { - FILE *f = fopen(_PATH_PROCNET_ROSE_ROUTE, "r"); + FILE *f = NULL; char buffer[256]; int use; + f=fopen(_PATH_PROCNET_ROSE_ROUTE, "r"); if (f == NULL) { + perror(_PATH_PROCNET_ROSE_ROUTE); printf(_("ROSE not configured in this system.\n")); /* xxx */ return 1; } - printf(_("Kernel ROSE routing table\n")); /* xxx */ - printf(_("Destination Iface Use\n")); /* xxx */ + printf(_("Kernel ROSE routing table\n")); + printf(_("Destination Iface Use\n")); fgets(buffer, 256, f); while (fgets(buffer, 256, f)) { buffer[9] = 0; @@ -1,7 +1,7 @@ /* * lib/sit.c This file contains the SIT HW-type support. * - * Version: $Id: sit.c,v 1.3 1998/11/15 20:12:12 freitag Exp $ + * Version: $Id: sit.c,v 1.4 1999/01/05 20:54:08 philip Exp $ * * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> * Copyright 1993 MicroWalt Corporation @@ -33,6 +33,11 @@ #include "net-support.h" #include "pathnames.h" +#ifndef ARPHRD_SIT +#warning "No definition of ARPHRD_SIT in <net/if_arp.h>, using private value 776" +#define ARPHRD_SIT 776 +#endif + struct hwtype sit_hwtype = { "sit", NULL, /*"IPv6-in-IPv4", */ ARPHRD_SIT, 0, diff --git a/man/en_US/arp.8 b/man/en_US/arp.8 index 6beb0bb..ef1abba 100644 --- a/man/en_US/arp.8 +++ b/man/en_US/arp.8 @@ -1,4 +1,4 @@ -.TH ARP 8 "15 May 1996" "net-tools" "Linux Programmer's Manual" +.TH ARP 8 "5 Jan 1999" "net-tools" "Linux Programmer's Manual" .SH NAME arp \- manipulate the system ARP cache .SH SYNOPSIS @@ -93,10 +93,12 @@ Use the interface hardware address. .TP .B "\-i If, \-\-device If" -Select an Interface. When dumping the ARP cache only entries matching the -Interface will be printed. Setting a permanent or temp ARP entry will be -used on the specified device. If no device is given, the kernels guess the -device from the routing table. For +Select an interface. When dumping the ARP cache only entries matching +the specified interface will be printed. When setting a permanent or +.B temp +ARP entry this interface will be associated with the entry; if this +option is not used, the kernel will guess based on the routing +table. For .B pub entries the specified interface is the interface on which ARP requests will be answered. @@ -118,11 +120,16 @@ the .BR pub lish flag set a .B netmask -may be specified to proxy arp for -entire subnets. Proxy arp for routing entire networks is not a good -protocol, but its sometimes useful so supported. If the +may be specified to proxy arp for entire subnets. This is not good +practice, but is supported by older kernels because it can be +useful. If the .B temp -flag is not supplied entries will be permanent stored into the ARP cache. +flag is not supplied entries will be permanent stored into the ARP +cache. +.br +.B NOTE: +As of kernel 2.2.0 it is no longer possible to set an ARP entry for an +entire subnet. .TP .B "\-f filename, \-\-file filename" Similar to the @@ -1,4 +1,3 @@ - /* * netstat This file contains an implementation of the command * that helps in debugging the networking modules. @@ -7,7 +6,7 @@ * NET-3 Networking Distribution for the LINUX operating * system. * - * Version: $Id: netstat.c,v 1.15 1998/12/11 10:48:52 philip Exp $ + * Version: $Id: netstat.c,v 1.16 1999/01/05 20:53:00 philip Exp $ * * Authors: Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de> * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> @@ -45,7 +44,12 @@ * minor header file misplacement tidy up. *980411 {1.34} Arnaldo Carvalho i18n: catgets -> gnu gettext, substitution * of sprintf for snprintf - *10/1998 Andi Kleen Use new interface primitives. + *10/1998 Andi Kleen Use new interface primitives. + *990101 {1.36} Bernd Eckenfels usage updated to include -s and -C -F, + * fixed netstat -rC output (lib/inet_gr.c) + * removed broken NETLINK Support + * fixed format for /proc/net/udp|tcp|raw + added -w,-t,-u TcpExt support to -s * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General @@ -71,7 +75,7 @@ #include <netinet/in.h> #include <sys/ioctl.h> #include <net/if.h> -#include <net/route.h> +/* #include <net/route.h> realy broken */ #include "net-support.h" #include "pathnames.h" #include "version.h" @@ -81,7 +85,7 @@ #include "interface.h" /* prototypes for statistics.c */ -void parsesnmp(void); +void parsesnmp(int, int, int); void inittab(void); typedef enum { @@ -101,18 +105,19 @@ typedef enum { #define FEATURE_NETSTAT #include "lib/net-features.h" -char *Release = RELEASE, *Version = "netstat 1.35 (1998-12-05)", *Signature = "Fred Baumgarten <dc6iq@insu1.etec.uni-karlsruhe.de> and Alan Cox."; +char *Release = RELEASE, *Version = "netstat 1.36 (1999-01-01)", *Signature = "Fred Baumgarten, Alan Cox, Bernd Eckenfels and Phil Blundell and others."; #define E_READ -1 #define E_IOCTL -3 -int flag_nlp = 0; int flag_int = 0; int flag_rou = 0; int flag_mas = 0; +int flag_sta = 0; int flag_all = 0; +int flag_lst = 0; int flag_cnt = 0; int flag_deb = 0; int flag_not = 0; @@ -185,101 +190,6 @@ FILE *procinfo; INFO_GUTS1(file,name,proc) \ INFO_GUTS3 -#if HAVE_RT_NETLINK && 0 -static int netlink_print(void) -{ - int flag; -#define NL_DEV 1 -#define NL_ADDR 2 -#define NL_MISC 4 - int fd, ret; - struct in_rtmsg buf; - struct aftype *ap; - struct sockaddr *s; - - if ((fd = open(_PATH_DEV_ROUTE, O_RDONLY)) < 0) { - if (errno == ENODEV) - ESYSNOT("netstat", _PATH_DEV_ROUTE); - else - perror(_PATH_DEV_ROUTE); - return (-1); - } - if (flag_ver) { - printf(_("Netlink Kernel Messages")); - if (flag_cnt) - printf(_(" (continous)")); - printf("\n"); - } - do { - if ((ret = read(fd, (char *) &buf, sizeof(buf))) < 0) { - perror("read " _PATH_DEV_ROUTE); - return (-1); - } - if (ret != sizeof(buf)) { - EINTERN("netstat.c", _("netlink message size mismatch")); - return (-1); - } - flag = 0; - /* No NLS, keep this parseable */ - switch (buf.rtmsg_type) { - case RTMSG_NEWROUTE: - printf("NEWROUTE\t"); - flag = NL_DEV | NL_ADDR | NL_MISC; - break; - case RTMSG_DELROUTE: - printf("DELROUTE\t"); - flag = NL_DEV | NL_ADDR | NL_MISC; - break; - case RTMSG_NEWDEVICE: - printf("NEWDEVICE\t"); - flag = NL_DEV | NL_MISC; - break; - case RTMSG_DELDEVICE: - printf("DELDEVICE\t"); - flag = NL_DEV | NL_MISC; - break; - default: - printf("UNKNOWN%lx\t", buf.rtmsg_type); - flag = NL_DEV | NL_ADDR | NL_MISC; - break; - } - - if (flag & NL_ADDR) { - s = &buf.rtmsg_dst; - ap = get_afntype(s->sa_family); - if (ap == NULL) - ap = get_afntype(0); - - printf("%s/%s ", ap->sprint(s, flag_not), ap->name); - - s = &buf.rtmsg_gateway; - ap = get_afntype(s->sa_family); - if (ap == NULL) - ap = get_afntype(0); - - printf("%s/%s ", ap->sprint(s, flag_not), ap->name); - - s = &buf.rtmsg_genmask; - ap = get_afntype(s->sa_family); - if (ap == NULL) - ap = get_afntype(0); - - printf("%s/%s ", ap->sprint(s, 1), ap->name); - } - if (flag & NL_MISC) { - printf("0x%x %d ", buf.rtmsg_flags, buf.rtmsg_metric); - } - if (flag & NL_DEV) { - printf("%s", buf.rtmsg_device); - } - printf("\n"); - } while (flag_cnt); - close(fd); - return (0); -} -#endif - - #if HAVE_AFNETROM static const char *netrom_state[] = { @@ -368,9 +278,9 @@ static const char *tcp_state[] = static void tcp_do_one(int lnr, const char *line) { - unsigned long rxq, txq, time_len, retr; - int num, local_port, rem_port, d, state, uid, timer_run; - char rem_addr[128], local_addr[128], timers[64], buffer[1024]; + unsigned long rxq, txq, time_len, retr, inode; + int num, local_port, rem_port, d, state, uid, timer_run, timeout; + char rem_addr[128], local_addr[128], timers[64], buffer[1024], more[512]; struct aftype *ap; struct passwd *pw; #if HAVE_AFINET6 @@ -385,9 +295,9 @@ static void tcp_do_one(int lnr, const char *line) return; num = sscanf(line, - "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d\n", + "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n", &d, local_addr, &local_port, rem_addr, &rem_port, &state, - &txq, &rxq, &timer_run, &time_len, &retr, &uid); + &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more); if (strlen(local_addr) > 8) { #if HAVE_AFINET6 @@ -445,7 +355,7 @@ static void tcp_do_one(int lnr, const char *line) } strcpy(local_addr, ap->sprint((struct sockaddr *) &localaddr, flag_not)); strcpy(rem_addr, ap->sprint((struct sockaddr *) &remaddr, flag_not)); - if (flag_all || rem_port) { + if (flag_all || (flag_lst && !rem_port) || (!flag_lst && rem_port)) { snprintf(buffer, sizeof(buffer), "%s", get_sname(htons(local_port), "tcp", flag_not)); if ((strlen(local_addr) + strlen(buffer)) > 22) @@ -465,17 +375,18 @@ static void tcp_do_one(int lnr, const char *line) if (flag_opt) switch (timer_run) { case 0: - snprintf(timers, sizeof(timers), _("off (0.00/%ld)"), retr); + snprintf(timers, sizeof(timers), _("off (0.00/%ld/%d)"), retr, timeout); break; case 1: - snprintf(timers, sizeof(timers), _("on (%2.2f/%ld)"), - (double) time_len / 100, retr); + case 2: + snprintf(timers, sizeof(timers), _("on%d (%2.2f/%ld/%d)"), + timer_run,(double) time_len / HZ, retr, timeout); break; default: - snprintf(timers, sizeof(timers), _("unkn-%d (%2.2f/%ld)"), - timer_run, (double) time_len / 100, retr); + snprintf(timers, sizeof(timers), _("unkn-%d (%2.2f/%ld/%d)"), + timer_run, (double) time_len / HZ, retr, timeout); break; } printf("tcp %6ld %6ld %-23s %-23s %-12s", @@ -486,6 +397,7 @@ static void tcp_do_one(int lnr, const char *line) printf("%-10s ", pw->pw_name); else printf("%-10d ", uid); + printf("%-10ld ",inode); } if (flag_opt) printf("%s", timers); @@ -502,8 +414,9 @@ static int tcp_info(void) static void udp_do_one(int lnr, const char *line) { char buffer[8192], local_addr[64], rem_addr[64]; - char *udp_state, timer_queued, timers[64], more[512]; - int num, local_port, rem_port, d, state, timer_run; + char *udp_state, timers[64], more[512]; + int num, local_port, rem_port, d, state, timer_run, uid, timeout; + struct passwd *pw; #if HAVE_AFINET6 struct sockaddr_in6 localaddr, remaddr; char addr6p[8][5]; @@ -513,18 +426,17 @@ static void udp_do_one(int lnr, const char *line) struct sockaddr_in localaddr, remaddr; #endif struct aftype *ap; - unsigned long rxq, txq, time_len, retr; + unsigned long rxq, txq, time_len, retr, inode; if (lnr == 0) return; more[0] = '\0'; - timer_queued = '\0'; num = sscanf(line, - "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %c %512s\n", + "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n", &d, local_addr, &local_port, rem_addr, &rem_port, &state, - &txq, &rxq, &timer_run, &time_len, &retr, &timer_queued, more); + &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more); if (strlen(local_addr) > 8) { #if HAVE_AFINET6 @@ -581,31 +493,31 @@ static void udp_do_one(int lnr, const char *line) break; } - strcpy(local_addr, ap->sprint((struct sockaddr *) &localaddr, flag_not)); - strcpy(rem_addr, ap->sprint((struct sockaddr *) &remaddr, flag_not)); #if HAVE_AFINET6 - if (flag_all || - ((localaddr.sin6_family == AF_INET6) && - ((localaddr.sin6_addr.s6_addr32[0]) || - (localaddr.sin6_addr.s6_addr32[1]) || - (localaddr.sin6_addr.s6_addr32[2]) || - (localaddr.sin6_addr.s6_addr32[3]))) || - ((localaddr.sin6_family == AF_INET) && - ((struct sockaddr_in *) &localaddr)->sin_addr.s_addr)) +#define notnull(A) ((A.sin6_family == AF_INET6) && \ + ((A.sin6_addr.s6_addr32[0]) || \ + (A.sin6_addr.s6_addr32[1]) || \ + (A.sin6_addr.s6_addr32[2]) || \ + (A.sin6_addr.s6_addr32[3]))) || \ + ((A.sin6_family == AF_INET) && \ + ((struct sockaddr_in *) &A)->sin_addr.s_addr)) #else - if (flag_all || localaddr.sin_addr.s_addr) +#define notnull(A) (A.sin_addr.s_addr) #endif + + if (flag_all || (notnull(remaddr) && !flag_lst) || (!notnull(remaddr) && flag_lst)) { + strcpy(local_addr, ap->sprint((struct sockaddr *) &localaddr, flag_not)); snprintf(buffer, sizeof(buffer), "%s", get_sname(htons(local_port), "udp", flag_not)); if ((strlen(local_addr) + strlen(buffer)) > 22) local_addr[22 - strlen(buffer)] = '\0'; - strcat(local_addr, ":"); strcat(local_addr, buffer); + snprintf(buffer, sizeof(buffer), "%s", get_sname(htons(rem_port), "udp", flag_not)); + strcpy(rem_addr, ap->sprint((struct sockaddr *) &remaddr, flag_not)); if ((strlen(rem_addr) + strlen(buffer)) > 22) rem_addr[22 - strlen(buffer)] = '\0'; - strcat(rem_addr, ":"); strcat(rem_addr, buffer); @@ -613,24 +525,29 @@ static void udp_do_one(int lnr, const char *line) if (flag_opt) switch (timer_run) { case 0: - snprintf(timers, sizeof(timers), _("off (0.00/%ld) %c"), retr, timer_queued); + snprintf(timers, sizeof(timers), _("off (0.00/%ld/%d)"), retr, timeout); break; case 1: - snprintf(timers, sizeof(timers), _("on (%2.2f/%ld) %c"), (double) time_len / 100, retr, timer_queued); + case 2: + snprintf(timers, sizeof(timers), _("on%d (%2.2f/%ld/%d)"), timer_run, (double) time_len / 100, retr, timeout); break; default: - snprintf(timers, sizeof(timers), _("unkn-%d (%2.2f/%ld) %c"), timer_run, (double) time_len / 100, - retr, timer_queued); + snprintf(timers, sizeof(timers), _("unkn-%d (%2.2f/%ld/%d)"), timer_run, (double) time_len / 100, + retr, timeout); break; } printf("udp %6ld %6ld %-23s %-23s %-12s", rxq, txq, local_addr, rem_addr, udp_state); - if (flag_exp > 1) - printf("%-10s ", ""); - + if (flag_exp > 1) { + if (!flag_not && ((pw = getpwuid(uid)) != NULL)) + printf("%-10s ", pw->pw_name); + else + printf("%-10d ", uid); + printf("%-10ld ",inode); + } if (flag_opt) printf("%s", timers); printf("\n"); @@ -646,8 +563,9 @@ static int udp_info(void) static void raw_do_one(int lnr, const char *line) { char buffer[8192], local_addr[64], rem_addr[64]; - char *raw_state, timer_queued, timers[64], more[512]; - int num, local_port, rem_port, d, state, timer_run; + char timers[64], more[512]; + int num, local_port, rem_port, d, state, timer_run, uid, timeout; + struct passwd *pw; #if HAVE_AFINET6 struct sockaddr_in6 localaddr, remaddr; char addr6p[8][5]; @@ -657,17 +575,16 @@ static void raw_do_one(int lnr, const char *line) struct sockaddr_in localaddr, remaddr; #endif struct aftype *ap; - unsigned long rxq, txq, time_len, retr; + unsigned long rxq, txq, time_len, retr, inode; if (lnr == 0) return; more[0] = '\0'; - timer_queued = '\0'; num = sscanf(line, - "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %c %512s\n", + "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n", &d, local_addr, &local_port, rem_addr, &rem_port, &state, - &txq, &rxq, &timer_run, &time_len, &retr, &timer_queued, more); + &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more); if (strlen(local_addr) > 8) { #if HAVE_AFINET6 @@ -715,32 +632,20 @@ static void raw_do_one(int lnr, const char *line) fprintf(stderr, _("warning, got bogus raw line.\n")); return; } - raw_state = ""; - strcpy(local_addr, ap->sprint((struct sockaddr *) &localaddr, flag_not)); - strcpy(rem_addr, ap->sprint((struct sockaddr *) &remaddr, flag_not)); -#if HAVE_AFINET6 - if (flag_all || - ((localaddr.sin6_family == AF_INET6) && - ((localaddr.sin6_addr.s6_addr32[0]) || - (localaddr.sin6_addr.s6_addr32[1]) || - (localaddr.sin6_addr.s6_addr32[2]) || - (localaddr.sin6_addr.s6_addr32[3]))) || - ((localaddr.sin6_family == AF_INET) && - ((struct sockaddr_in *) &localaddr)->sin_addr.s_addr)) -#else - if (flag_all || localaddr.sin_addr.s_addr) -#endif + + if (flag_all || (notnull(remaddr) && !flag_lst) || (!notnull(remaddr) && flag_lst)) { snprintf(buffer, sizeof(buffer), "%s", get_sname(htons(local_port), "raw", flag_not)); + strcpy(local_addr, ap->sprint((struct sockaddr *) &localaddr, flag_not)); if ((strlen(local_addr) + strlen(buffer)) > 22) local_addr[22 - strlen(buffer)] = '\0'; - strcat(local_addr, ":"); strcat(local_addr, buffer); + snprintf(buffer, sizeof(buffer), "%s", get_sname(htons(rem_port), "raw", flag_not)); + strcpy(rem_addr, ap->sprint((struct sockaddr *) &remaddr, flag_not)); if ((strlen(rem_addr) + strlen(buffer)) > 22) rem_addr[22 - strlen(buffer)] = '\0'; - strcat(rem_addr, ":"); strcat(rem_addr, buffer); @@ -748,26 +653,31 @@ static void raw_do_one(int lnr, const char *line) if (flag_opt) switch (timer_run) { case 0: - snprintf(timers, sizeof(timers), _("off (0.00/%ld) %c"), retr, timer_queued); + snprintf(timers, sizeof(timers), _("off (0.00/%ld/%d)"), retr, timeout); break; case 1: - snprintf(timers, sizeof(timers), _("on (%2.2f/%ld) %c"), (double) time_len / 100, - retr, timer_queued); + case 2: + snprintf(timers, sizeof(timers), _("on%d (%2.2f/%ld/%d)"), timer_run, (double) time_len / 100, + retr, timeout); break; default: - snprintf(timers, sizeof(timers), _("unkn-%d (%2.2f/%ld) %c"), + snprintf(timers, sizeof(timers), _("unkn-%d (%2.2f/%ld/%d)"), timer_run, (double) time_len / 100, - retr, timer_queued); + retr, timeout); break; } - printf("raw %6ld %6ld %-23s %-23s %-12s", - rxq, txq, local_addr, rem_addr, raw_state); - - if (flag_exp > 1) - printf("%-10s ", ""); + printf("raw %6ld %6ld %-23s %-23s %-12d", + rxq, txq, local_addr, rem_addr, state); + if (flag_exp > 1) { + if (!flag_not && ((pw = getpwuid(uid)) != NULL)) + printf("%-10s ", pw->pw_name); + else + printf("%-10d ", uid); + printf("%-10ld ",inode); + } if (flag_opt) printf("%s", timers); printf("\n"); @@ -813,8 +723,16 @@ static void unix_do_one(int nr, const char *line) strcpy(path, inode); strcpy(inode, "-"); } - if (!flag_all && (state == SS_UNCONNECTED) && (flags & SO_ACCEPTCON)) - return; + + if (!flag_all) { + if ((state == SS_UNCONNECTED) && (flags & SO_ACCEPTCON)) { + if (!flag_lst) + return; + } else { + if (flag_lst) + return; + } + } switch (proto) { case 0: @@ -900,11 +818,15 @@ static void unix_do_one(int nr, const char *line) static int unix_info(void) { - printf(_("Active UNIX domain sockets ")); /* xxx */ + printf(_("Active UNIX domain sockets ")); if (flag_all) - printf(_("(including servers)")); /* xxx */ - else - printf(_("(w/o servers)")); /* xxx */ + printf(_("(servers and established)")); + else { + if (flag_lst) + printf(_("(only servers)")); + else + printf(_("(w/o servers)")); + } printf(_("\nProto RefCnt Flags Type State I-Node Path\n")); /* xxx */ @@ -1176,34 +1098,38 @@ static int iface_info(void) static void version(void) { printf("%s\n%s\n%s\n%s\n", Release, Version, Signature, Features); - exit(1); + exit(E_VERSION); } static void usage(void) { fprintf(stderr, _("usage: netstat [-veenNcCF] [<Af>] -r netstat {-V|--version|-h|--help}\n")); - fprintf(stderr, _(" netstat [-vnNcaeo] [<Socket>]\n")); - fprintf(stderr, _(" netstat { [-veenNac] -i | [-vnNc] -L | [-cnNe] -M }\n\n")); - fprintf(stderr, _(" -r, --route display routing table\n")); /* xxx */ - fprintf(stderr, _(" -L, --netlink display netlink kernel messages\n")); + fprintf(stderr, _(" netstat [-vnNcaeol] [<Socket> ...]\n")); + fprintf(stderr, _(" netstat { [-veenNac] -i | [-cnNe] -M | -s }\n\n")); + + fprintf(stderr, _(" -r, --route display routing table\n")); fprintf(stderr, _(" -i, --interfaces display interface table\n")); + fprintf(stderr, _(" -s, --statistics display networking statistics (like SNMP)\n")); #if HAVE_FW_MASQUERADE fprintf(stderr, _(" -M, --masquerade display masqueraded connections\n\n")); #endif fprintf(stderr, _(" -v, --verbose be verbose\n")); fprintf(stderr, _(" -n, --numeric dont resolve names\n")); + fprintf(stderr, _(" -N, --symbolic resolve hardware names\n")); fprintf(stderr, _(" -e, --extend display other/more informations\n")); fprintf(stderr, _(" -c, --continuous continuous listing\n\n")); - fprintf(stderr, _(" -a, --all, --listening display all\n")); - fprintf(stderr, _(" -o, --timers display timers\n\n")); - fprintf(stderr, _("<Socket>={-t|--tcp} {-u|--udp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom\n")); -#if HAVE_AFINET6 - fprintf(stderr, _("<Af>= -A {inet|inet6|ipx|netrom|ddp|ax25},... --inet --inet6 --ipx --netrom --ddp --ax25\n")); -#else - fprintf(stderr, _("<Af>= -A {inet|ipx|netrom|ddp|ax25},... --inet --ipx --netrom --ddp --ax25\n")); -#endif - exit(1); + fprintf(stderr, _(" -l, --listening display listening server sockets\n")); + fprintf(stderr, _(" -a, --all, --listening display all sockets (default: conected)\n")); + fprintf(stderr, _(" -o, --timers display timers\n")); + fprintf(stderr, _(" -F, --fib display Forwarding Infomation Base (default)\n")); + fprintf(stderr, _(" -C, --cache display routing cache instead of FIB\n\n")); + + fprintf(stderr, _(" <Socket>={-t|--tcp} {-u|--udp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom\n")); + fprintf(stderr, _(" <AF>=Use '-A <af>' or '--<af>' Default: %s\n"), DFLT_AF); + fprintf(stderr, _(" List of possible address families (which support routing):\n")); + print_aflist(1); /* 1 = routeable */ + exit(E_USAGE); } @@ -1227,7 +1153,7 @@ int main {"udp", 0, 0, 'u'}, {"raw", 0, 0, 'w'}, {"unix", 0, 0, 'x'}, - {"listening", 0, 0, 'a'}, + {"listening", 0, 0, 'l'}, {"all", 0, 0, 'a'}, {"timers", 0, 0, 'o'}, {"continuous", 0, 0, 'c'}, @@ -1248,7 +1174,7 @@ int main getroute_init(); /* Set up AF routing support */ afname[0] = '\0'; - while ((i = getopt_long(argc, argv, "MLCFA:acdehinNorstuVv?wx", longopts, &lop)) != EOF) + while ((i = getopt_long(argc, argv, "MCFA:acdehinNorstuVv?wxl", longopts, &lop)) != EOF) switch (i) { case -1: break; @@ -1264,15 +1190,15 @@ int main if (aftrans_opt(optarg)) exit(1); break; - case 'L': - flag_nlp++; - break; case 'M': flag_mas++; break; case 'a': flag_all++; break; + case 'l': + flag_lst++; + break; case 'c': flag_cnt++; break; @@ -1330,15 +1256,13 @@ int main case 'h': usage(); case 's': - inittab(); - parsesnmp(); - exit(0); + flag_sta++; } - if (flag_int + flag_rou + flag_nlp + flag_mas > 1) + if (flag_int + flag_rou + flag_mas + flag_sta > 1) usage(); - if ((flag_inet || flag_inet6) && !(flag_tcp || flag_udp || flag_raw)) + if ((flag_inet || flag_inet6 || flag_sta) && !(flag_tcp || flag_udp || flag_raw)) flag_tcp = flag_udp = flag_raw = 1; if ((flag_tcp || flag_udp || flag_raw) && !(flag_inet || flag_inet6)) @@ -1347,15 +1271,6 @@ int main flag_arg = flag_tcp + flag_udp + flag_raw + flag_unx + flag_ipx + flag_ax25 + flag_netrom; - if (flag_nlp) { -#if HAVE_RT_NETLINK && 0 - i = netlink_print(); -#else - ENOSUPP("netstat.c", "RT_NETLINK"); - i = -1; -#endif - return (i); - } if (flag_mas) { #if HAVE_FW_MASQUERADE && HAVE_AFINET #if MORE_THAN_ONE_MASQ_AF @@ -1374,6 +1289,13 @@ int main #endif return (i); } + + if (flag_sta) { + inittab(); + parsesnmp(flag_raw, flag_tcp, flag_udp); + exit(0); + } + if (flag_rou) { int options = 0; @@ -1410,14 +1332,18 @@ int main if (!flag_arg || flag_tcp || flag_udp || flag_raw) { #if HAVE_AFINET printf(_("Active Internet connections ")); /* xxx */ - if (flag_all) - printf(_("(including servers)")); /* xxx */ - else - printf(_("(w/o servers)")); /* xxx */ + if (flag_all) + printf(_("(servers and established)")); + else { + if (flag_lst) + printf(_("(only servers)")); + else + printf(_("(w/o servers)")); + } printf(_("\nProto Recv-Q Send-Q Local Address Foreign Address State ")); /* xxx */ if (flag_exp > 1) - printf(_(" User ")); /* xxx */ + printf(_(" User Inode ")); if (flag_opt) printf(_(" Timer")); /* xxx */ printf("\n"); @@ -3,7 +3,7 @@ * that maintains the kernel's RARP cache. It is derived * from Fred N. van Kempen's arp command. * - * Version: $Id: rarp.c,v 1.4 1998/11/15 20:08:12 freitag Exp $ + * Version: $Id: rarp.c,v 1.5 1999/01/05 20:53:02 philip Exp $ * * Usage: rarp -d hostname Delete entry * rarp -s hostname ethernet_address Add entry @@ -12,6 +12,7 @@ * * Rewritten: Phil Blundell <Philip.Blundell@pobox.com> 1997-08-03 * gettext instead of catgets: Arnaldo Carvalho de Melo <acme@conectiva.com.br> 1998-06-29 + * 1998-01-01 Bernd Eckenfels reorganised usage() * */ @@ -31,6 +32,8 @@ #include <unistd.h> #include <getopt.h> +#define DFLT_HW "ether" + #include "config.h" #include "intl.h" #include "net-support.h" @@ -170,11 +173,15 @@ static int display_cache(void) static void usage(void) { fprintf(stderr, _("Usage: rarp -a list entries in cache.\n")); - fprintf(stderr, _(" rarp -d hostname delete entry from cache.\n")); - fprintf(stderr, _(" rarp [-t hwtype] -s hostname hwaddr add entry to cache.\n")); - fprintf(stderr, _(" rarp -f add entries from ethers.\n")); - fprintf(stderr, _(" rarp -V display program version.\n")); - exit(-1); + fprintf(stderr, _(" rarp -d <hostname> delete entry from cache.\n")); + fprintf(stderr, _(" rarp [<HW>] -s <hostname> <hwaddr> add entry to cache.\n")); + fprintf(stderr, _(" rarp -f add entries from /etc/ethers.\n")); + fprintf(stderr, _(" rarp -V display program version.\n\n")); + + fprintf(stderr, _(" <HW>=Use '-H <hw>' to specify hardware address type. Default: %s\n"), DFLT_HW); + fprintf(stderr, _(" List of possible hardware types (which support ARP):\n")); + print_hwlist(1); /* 1 = ARPable */ + exit(E_USAGE); } #define MODE_DISPLAY 1 @@ -205,13 +212,11 @@ int main(int argc, char **argv) textdomain("net-tools"); #endif -#if HAVE_HWETHER /* Get a default hardware type. */ - hardware = get_hwtype("ether"); -#endif + hardware = get_hwtype(DFLT_HW); do { - c = getopt_long(argc, argv, "-ht:adsVvf", longopts, NULL); + c = getopt_long(argc, argv, "-ht:aHdsVvf", longopts, NULL); switch (c) { case EOF: break; @@ -219,7 +224,7 @@ int main(int argc, char **argv) usage(); case 'V': fprintf(stderr, version_string); - exit(1); + exit(E_VERSION); break; case 'v': verbose++; @@ -237,6 +242,7 @@ int main(int argc, char **argv) case 'f': mode = MODE_ETHERS; break; + case 'H': case 't': if (optarg) { hardware = get_hwtype(optarg); @@ -2,7 +2,7 @@ * route This file contains an implementation of the command * that manages the IP routing table in the kernel. * - * Version: $Id: route.c,v 1.3 1998/11/15 20:08:17 freitag Exp $ + * Version: $Id: route.c,v 1.4 1999/01/05 20:53:04 philip Exp $ * * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> * @@ -32,13 +32,14 @@ *960426 {1.92} Bernd Eckenfels: FLAG_SYM/-N support *960823 {x.xx} Frank Strauss: INET6 stuff *980629 {1.95} Arnaldo Carvalho de Melo: gettext instead of catgets + *990101 {1.96} Bernd Eckenfels: fixed usage and FLAG_CACHE Output * */ #include <sys/types.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <net/if.h> -#include <net/route.h> +/* #include <net/route.h> realy broken */ #include <netinet/in.h> #include <netdb.h> #include <netinet/in.h> @@ -64,7 +65,7 @@ #define FEATURE_ROUTE #include "lib/net-features.h" /* needs some of the system includes above! */ -char *Release = RELEASE, *Version = "route 1.95 (1998-06-29)"; +char *Release = RELEASE, *Version = "route 1.96 (1999-01-01-)"; int opt_n = 0; /* numerical output flag */ int opt_v = 0; /* debugging output flag */ @@ -75,12 +76,22 @@ struct aftype *ap; /* current address family */ static void usage(void) { - fprintf(stderr, _("Usage: route [-nNvee] [-FC] [Address_families] List kernel routing tables\n")); - fprintf(stderr, _(" route {-V|--version} Display command version and exit.\n")); - fprintf(stderr, _(" route {-h|--help} [Address_family] Usage Syntax for specified AF.\n")); + fprintf(stderr, _("Usage: route [-nNvee] [-FC] [<AF>] List kernel routing tables\n")); fprintf(stderr, _(" route [-v] [-FC] {add|del|flush} ... Modify routing table for AF.\n\n")); - fprintf(stderr, _(" Address_families: inet,inet6,ddp,ipx,netrom,ax25\n")); - fprintf(stderr, _(" specify AF: -A af1,af2.. or --af1 --af2 or af_route\n")); + + fprintf(stderr, _(" route {-h|--help} [<AF>] Detailed usage syntax for specified AF.\n")); + fprintf(stderr, _(" route {-V|--version} Display version/author and exit.\n\n")); + + fprintf(stderr, _(" -v, --verbose be verbose\n")); + fprintf(stderr, _(" -n, --numeric dont resolve names\n")); + fprintf(stderr, _(" -N, --symbolic resolve hardware names\n")); + fprintf(stderr, _(" -e, --extend display other/more informations\n")); + fprintf(stderr, _(" -F, --fib display Forwarding Infomation Base (default)\n")); + fprintf(stderr, _(" -C, --cache display routing cache instead of FIB\n\n")); + + fprintf(stderr, _(" <AF>=Use '-A <af>' or '--<af>' Default: %s\n"), DFLT_AF); + fprintf(stderr, _(" List of possible address families (which support routing):\n")); + print_aflist(1); /* 1 = routeable */ exit(E_USAGE); } diff --git a/statistics.c b/statistics.c index a5876af..2f2a807 100644 --- a/statistics.c +++ b/statistics.c @@ -1,11 +1,10 @@ /* Copyright '97 by Andi Kleen. Subject to the GPL. */ -/* $Id: statistics.c,v 1.9 1998/11/15 20:08:30 freitag Exp $ */ +/* $Id: statistics.c,v 1.10 1999/01/05 20:53:05 philip Exp $ */ /* 19980630 - i18n - Arnaldo Carvalho de Melo <acme@conectiva.com.br> */ /* 19981113 - i18n fixes - Arnaldo Carvalho de Melo <acme@conectiva.com.br> */ - +/* 19990101 - added net/netstat, -t, -u, -w supprt - Bernd Eckenfels */ /* - XXX: rewrite to 2 pass to support /proc/net/netstat too - support -t -u + XXX: add some long-text to TcpExtt */ #include <ctype.h> #include <stdio.h> @@ -22,7 +21,7 @@ #define UFWARN(x) #endif -int print_static; +int print_static,f_raw,f_tcp,f_udp; enum State { number = 0, i_forward, i_inp_icmp, i_outp_icmp, i_rto_alg @@ -105,9 +104,9 @@ struct entry Icmptab[] = {"OutRedirects", N_("redirect: %d"), i_outp_icmp | I_TITLE}, {"OutEchos", N_("echo request: %d"), i_outp_icmp | I_TITLE}, {"OutEchoReps", N_("echo replies: %d"), i_outp_icmp | I_TITLE}, - {"OutTimestamps", N_("timestamp requests: %d"), i_outp_icmp | I_TITLE}, -{"OutTimestampReps", N_("timestamp replies: %d"), i_outp_icmp | I_TITLE}, -{"OutAddrMasks", N_("address mask requests: %d"), i_outp_icmp | I_TITLE}, + {"OutTimestamps", N_("timestamp requests: %d"), i_outp_icmp | I_TITLE}, + {"OutTimestampReps", N_("timestamp replies: %d"), i_outp_icmp | I_TITLE}, + {"OutAddrMasks", N_("address mask requests: %d"), i_outp_icmp | I_TITLE}, {"OutAddrMaskReps", N_("address mask replies: %d"), i_outp_icmp | I_TITLE}, }; @@ -137,6 +136,20 @@ struct entry Udptab[] = {"OutDatagrams", N_("%d packets send"), number}, }; +struct entry Tcpexttab[] = +{ + {"SyncookiesSent", N_("%d SYN cookies sent"), number}, + {"SyncookiesRecv", N_("%d SYN cookies received"), number}, + {"SyncookiesFailed", N_("%d SYN cookies failed"), number}, + /* XXX */ + /* EmbryonicRsts + PruneCalled + RcvPruned + OfoPruned + OutOfWindowIcmps + LockDroppedIcmps */ +}; + struct tabtab { char *title; struct entry *tab; @@ -149,6 +162,7 @@ struct tabtab snmptabs[] = {"Icmp", Icmptab, sizeof(Icmptab)}, {"Tcp", Tcptab, sizeof(Tcptab)}, {"Udp", Udptab, sizeof(Udptab)}, + {"TcpExt", Tcpexttab, sizeof(Tcpexttab)}, {NULL} }; @@ -173,6 +187,7 @@ void printval(struct tabtab *tab, char *title, int val) int type; char buf[512]; + /* printf("key: %s value: %d\n",title,val); */ key.title = title; ent = bsearch(&key, tab->tab, tab->size / sizeof(struct entry), sizeof(struct entry), cmpentries); @@ -225,6 +240,11 @@ struct tabtab *newtable(struct tabtab *tabs, char *title) for (t = tabs; t->title; t++) if (!strcmp(title, t->title)) { + if ( + (((t->tab==Iptab) ||(t->tab==Icmptab)) &&f_raw) || + (((t->tab==Tcptab)||(t->tab==Tcpexttab))&&f_tcp) || + ( (t->tab==Udptab) &&f_udp) + ) printf("%s:\n", _(title)); state = normal; return t; @@ -232,17 +252,11 @@ struct tabtab *newtable(struct tabtab *tabs, char *title) return NULL; } -void parsesnmp() + +void process_fd(FILE *f) { - FILE *f; char buf1[512], buf2[512]; char *sp, *np, *p; - - f = fopen("/proc/net/snmp", "r"); - if (!f) { - perror(_("cannot open /proc/net/snmp")); - return; - } while (fgets(buf1, sizeof buf1, f)) { int endflag; struct tabtab *tab; @@ -275,20 +289,58 @@ void parsesnmp() endflag = 1; *p = '\0'; - if (*sp != '\0') /* XXX */ + /* printf("f: %d %d %d %p %p %p %p %p\n",f_raw, f_tcp, f_udp, Iptab, Icmptab, Tcptab, Tcpexttab, Udptab, tab); */ + + if (*sp != '\0') { /* XXX */ + if ( + (((tab->tab==Iptab) ||(tab->tab==Icmptab)) &&f_raw) || + (((tab->tab==Tcptab)||(tab->tab==Tcpexttab))&&f_tcp) || + ( (tab->tab==Udptab) &&f_udp) + ) printval(tab, sp, strtoul(np, &np, 10)); + } sp = p + 1; } } + return; + +formaterr: + perror(_("error parsing /proc/net/snmp")); + return; +} + + +void parsesnmp(int flag_raw, int flag_tcp, int flag_udp) +{ + FILE *f; + + f_raw = flag_raw; f_tcp = flag_tcp; f_udp = flag_udp; + + f = fopen("/proc/net/snmp", "r"); + if (!f) { + perror(_("cannot open /proc/net/snmp")); + return; + } + process_fd(f); + if (ferror(f)) perror("/proc/net/snmp"); + fclose(f); - return; - formaterr: - perror(_("error parsing /proc/net/snmp")); + f = fopen("/proc/net/netstat", "r"); + + if (f) { + process_fd(f); + + if (ferror(f)) + perror("/proc/net/netstat"); + + fclose(f); + } return; } + void inittab() { |