Messages in this thread Patch in this message | | | Date | Sun, 3 Jan 1999 20:38:05 +0100 | From | Bernd Eckenfels <> | Subject | patch to net-tools 1.49 for 2.0.36/2.2.0 |
| |
Hello,
just prepared a patch to the net-tools which:
- fixes route/netstat -r output of the routing cache - supports more routing flags for netstat/route - compiles better with old glbc2 - a more unified usage output across als tools - prints the supported hardware and address families - removes netlink support from netstat completely (i will provide a new tool to include into the nettols which is based on rtmon.c) - support for -t and -u and -w to netstat -s - support for /proc/net/netstat to netstat -s - support for "netstat -l|--listening" which does only list listening sockets (something which is more often used than listing connected sockets IMHO) As far as i can see from pre2-0-37 and pre 2.2.0 the nettools should be compliant to the proc interface.
The new tools are called net-tools-1.49-1
Greetings Bernd diff -u --recursive net-tools-1.49/Makefile net-tools-1.49-1/Makefile --- net-tools-1.49/Makefile Sun Dec 6 17:16:10 1998 +++ net-tools-1.49-1/Makefile Sun Jan 3 06:39:23 1999 @@ -80,14 +80,14 @@ # Compiler and Linker Options # You may need to uncomment and edit these if you are using libc5 and IPv6. -COPTS = -D_GNU_SOURCE -O2 -Wall -g # -I/usr/inet6/include +COPTS = -D_GNU_SOURCE -O2 -Wall -g # -I/usr/inet6/include LOPTS = RESLIB = # -L/usr/inet6/lib -linet6 # -------- end of user definitions -------- MAINTAINER = Philip.Blundell@pobox.com -RELEASE = 1.49 +RELEASE = 1.49-1 .EXPORT_ALL_VARIABLES: @@ -99,7 +99,7 @@ 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 @@ 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 diff -u --recursive net-tools-1.49/README net-tools-1.49-1/README --- net-tools-1.49/README Fri Dec 11 11:37:51 1998 +++ net-tools-1.49-1/README Sun Jan 3 02:32:05 1999 @@ -77,6 +77,8 @@ The documentation is slimmed down. I think most of it was out of date. +The tools now support the layout of the 2.2.0 /proc files (Bernd Eckenfels). + 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 @@ -85,3 +87,7 @@ Phil Blundell philb@gnu.org 11th December 1998 + +Bernd Eckenfels +net-tools@lina.inka.de +1998-01-02 Only in net-tools-1.49: arp diff -u --recursive net-tools-1.49/arp.c net-tools-1.49-1/arp.c --- net-tools-1.49/arp.c Tue Nov 17 23:00:47 1998 +++ net-tools-1.49-1/arp.c Fri Jan 1 05:32:32 1999 @@ -41,7 +41,7 @@ *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 * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General @@ -597,18 +597,31 @@ 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) Only in net-tools-1.49: config.h Only in net-tools-1.49: config.status Only in net-tools-1.49-1: configure Only in net-tools-1.49: hostname diff -u --recursive net-tools-1.49/hostname.c net-tools-1.49-1/hostname.c --- net-tools-1.49/hostname.c Mon Nov 16 10:17:29 1998 +++ net-tools-1.49-1/hostname.c Fri Jan 1 04:53:33 1999 @@ -180,7 +180,7 @@ 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 @@ 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 */ } Only in net-tools-1.49: ifconfig diff -u --recursive net-tools-1.49/ifconfig.c net-tools-1.49-1/ifconfig.c --- net-tools-1.49/ifconfig.c Sun Dec 6 17:17:44 1998 +++ net-tools-1.49-1/ifconfig.c Fri Jan 1 05:53:41 1999 @@ -18,6 +18,8 @@ * 10/1998 - Andi Kleen. Use interface list primitives. */ +#define DFLT_AF "inet" + #include "config.h" #include <features.h> @@ -418,42 +420,42 @@ 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 @@ } /* 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 */ Only in net-tools-1.49-1/include: linux Only in net-tools-1.49-1/lib: DEADJOE diff -u --recursive net-tools-1.49/lib/Makefile net-tools-1.49-1/lib/Makefile --- net-tools-1.49/lib/Makefile Sun Dec 6 17:16:11 1998 +++ net-tools-1.49-1/lib/Makefile Sun Jan 3 06:40:47 1999 @@ -29,7 +29,7 @@ # 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 diff -u --recursive net-tools-1.49/lib/af.c net-tools-1.49-1/lib/af.c --- net-tools-1.49/lib/af.c Tue Dec 1 10:30:30 1998 +++ net-tools-1.49-1/lib/af.c Fri Jan 1 04:14:29 1999 @@ -291,3 +291,26 @@ 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"); +} diff -u --recursive net-tools-1.49/lib/ash.c net-tools-1.49-1/lib/ash.c --- net-tools-1.49/lib/ash.c Thu Nov 26 11:16:38 1998 +++ net-tools-1.49-1/lib/ash.c Sun Jan 3 05:39:25 1999 @@ -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 -u --recursive net-tools-1.49/lib/ax25_gr.c net-tools-1.49-1/lib/ax25_gr.c --- net-tools-1.49/lib/ax25_gr.c Mon Nov 16 10:17:50 1998 +++ net-tools-1.49-1/lib/ax25_gr.c Fri Jan 1 04:51:58 1999 @@ -43,6 +43,7 @@ int use; if (f == NULL) { + perror(_PATH_PROCNET_AX25_ROUTE); printf(_("AX.25 not configured in this system.\n")); /* xxx */ return 1; } diff -u --recursive net-tools-1.49/lib/econet.c net-tools-1.49-1/lib/econet.c --- net-tools-1.49/lib/econet.c Wed Nov 18 11:32:06 1998 +++ net-tools-1.49-1/lib/econet.c Sun Jan 3 05:27:20 1999 @@ -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 -u --recursive net-tools-1.49/lib/hdlclapb.c net-tools-1.49-1/lib/hdlclapb.c --- net-tools-1.49/lib/hdlclapb.c Mon Nov 16 10:17:56 1998 +++ net-tools-1.49-1/lib/hdlclapb.c Sun Jan 3 05:43:17 1999 @@ -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 -u --recursive net-tools-1.49/lib/hippi.c net-tools-1.49-1/lib/hippi.c --- net-tools-1.49/lib/hippi.c Thu Nov 26 11:16:15 1998 +++ net-tools-1.49-1/lib/hippi.c Sun Jan 3 04:28:56 1999 @@ -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; diff -u --recursive net-tools-1.49/lib/hw.c net-tools-1.49-1/lib/hw.c --- net-tools-1.49/lib/hw.c Mon Nov 16 16:13:48 1998 +++ net-tools-1.49-1/lib/hw.c Fri Jan 1 05:58:34 1999 @@ -214,3 +214,26 @@ } 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"); +} diff -u --recursive net-tools-1.49/lib/inet.c net-tools-1.49-1/lib/inet.c --- net-tools-1.49/lib/inet.c Thu Nov 19 14:01:58 1998 +++ net-tools-1.49-1/lib/inet.c Fri Jan 1 06:40:56 1999 @@ -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 int read_services(void) { struct servent *se; + struct protoent *pe; struct service *item; setservent(1); @@ -333,6 +335,17 @@ } } 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 -u --recursive net-tools-1.49/lib/inet6_gr.c net-tools-1.49-1/lib/inet6_gr.c --- net-tools-1.49/lib/inet6_gr.c Mon Nov 16 10:17:59 1998 +++ net-tools-1.49-1/lib/inet6_gr.c Sun Jan 3 02:42:17 1999 @@ -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 @@ 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 -u --recursive net-tools-1.49/lib/inet6_sr.c net-tools-1.49-1/lib/inet6_sr.c --- net-tools-1.49/lib/inet6_sr.c Mon Nov 16 10:18:00 1998 +++ net-tools-1.49-1/lib/inet6_sr.c Sun Jan 3 02:41:50 1999 @@ -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 -u --recursive net-tools-1.49/lib/inet_gr.c net-tools-1.49-1/lib/inet_gr.c --- net-tools-1.49/lib/inet_gr.c Mon Nov 16 10:18:01 1998 +++ net-tools-1.49-1/lib/inet_gr.c Sun Jan 3 06:13:47 1999 @@ -3,6 +3,7 @@ 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 @@ 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 @@ 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_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 @@ "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 -u --recursive net-tools-1.49/lib/inet_sr.c net-tools-1.49-1/lib/inet_sr.c --- net-tools-1.49/lib/inet_sr.c Thu Nov 19 13:59:24 1998 +++ net-tools-1.49-1/lib/inet_sr.c Sun Jan 3 02:45:54 1999 @@ -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 -u --recursive net-tools-1.49/lib/ipx_gr.c net-tools-1.49-1/lib/ipx_gr.c --- net-tools-1.49/lib/ipx_gr.c Mon Nov 16 10:18:03 1998 +++ net-tools-1.49-1/lib/ipx_gr.c Fri Jan 1 04:58:16 1999 @@ -38,22 +38,24 @@ 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)) { Only in net-tools-1.49/lib: libnet-tools.a diff -u --recursive net-tools-1.49/lib/net-features.h net-tools-1.49-1/lib/net-features.h --- net-tools-1.49/lib/net-features.h Mon Nov 16 10:18:07 1998 +++ net-tools-1.49-1/lib/net-features.h Fri Jan 1 03:21:54 1999 @@ -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) @@ -103,13 +99,6 @@ "-" #endif "RTF_REJECT " - -#if HAVE_RT_NETLINK -"+" -#else -"-" -#endif -"RT_NETLINK " #if HAVE_FW_MASQUERADE "+" diff -u --recursive net-tools-1.49/lib/net-support.h net-tools-1.49-1/lib/net-support.h --- net-tools-1.49/lib/net-support.h Thu Nov 19 13:55:06 1998 +++ net-tools-1.49-1/lib/net-support.h Sun Jan 3 05:57:18 1999 @@ -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 @@ 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 @@ #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 -u --recursive net-tools-1.49/lib/netrom_gr.c net-tools-1.49-1/lib/netrom_gr.c --- net-tools-1.49/lib/netrom_gr.c Mon Nov 16 10:18:12 1998 +++ net-tools-1.49-1/lib/netrom_gr.c Sun Jan 3 03:36:37 1999 @@ -39,12 +39,17 @@ /*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 -u --recursive net-tools-1.49/lib/netrom_sr.c net-tools-1.49-1/lib/netrom_sr.c --- net-tools-1.49/lib/netrom_sr.c Mon Nov 16 10:18:13 1998 +++ net-tools-1.49-1/lib/netrom_sr.c Sun Jan 3 02:42:00 1999 @@ -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> diff -u --recursive net-tools-1.49/lib/proc.c net-tools-1.49-1/lib/proc.c --- net-tools-1.49/lib/proc.c Mon Nov 16 10:18:15 1998 +++ net-tools-1.49-1/lib/proc.c Sun Jan 3 02:22:23 1999 @@ -48,3 +48,27 @@ } 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; +} diff -u --recursive net-tools-1.49/lib/proc.h net-tools-1.49-1/lib/proc.h --- net-tools-1.49/lib/proc.h Mon Nov 16 10:18:17 1998 +++ net-tools-1.49-1/lib/proc.h Sun Jan 3 01:15:24 1999 @@ -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,...); \ No newline at end of file diff -u --recursive net-tools-1.49/lib/rose.c net-tools-1.49-1/lib/rose.c --- net-tools-1.49/lib/rose.c Mon Nov 16 10:18:17 1998 +++ net-tools-1.49-1/lib/rose.c Sun Jan 3 06:06:46 1999 @@ -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 -u --recursive net-tools-1.49/lib/rose_gr.c net-tools-1.49-1/lib/rose_gr.c --- net-tools-1.49/lib/rose_gr.c Mon Nov 16 10:18:18 1998 +++ net-tools-1.49-1/lib/rose_gr.c Fri Jan 1 04:49:17 1999 @@ -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; diff -u --recursive net-tools-1.49/lib/sit.c net-tools-1.49-1/lib/sit.c --- net-tools-1.49/lib/sit.c Mon Nov 16 10:18:18 1998 +++ net-tools-1.49-1/lib/sit.c Sun Jan 3 05:44:16 1999 @@ -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, Only in net-tools-1.49: netstat diff -u --recursive net-tools-1.49/netstat.c net-tools-1.49-1/netstat.c --- net-tools-1.49/netstat.c Fri Dec 11 11:36:43 1998 +++ net-tools-1.49-1/netstat.c Sun Jan 3 02:40:54 1999 @@ -1,4 +1,3 @@ - /* * netstat This file contains an implementation of the command * that helps in debugging the networking modules. @@ -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 @@ #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 @@ 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 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 @@ 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 @@ } 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 @@ 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 @@ printf("%-10s ", pw->pw_name); else printf("%-10d ", uid); + printf("%-10ld ",inode); } if (flag_opt) printf("%s", timers); @@ -502,8 +414,9 @@ 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 @@ 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 @@ 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 @@ 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 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 @@ 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 @@ 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 @@ 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 @@ 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 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 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 @@ {"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 @@ 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 @@ 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 @@ 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 @@ 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 @@ #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 @@ 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"); Only in net-tools-1.49: rarp diff -u --recursive net-tools-1.49/rarp.c net-tools-1.49-1/rarp.c --- net-tools-1.49/rarp.c Mon Nov 16 10:17:34 1998 +++ net-tools-1.49-1/rarp.c Fri Jan 1 05:37:22 1999 @@ -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 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 @@ 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 @@ usage(); case 'V': fprintf(stderr, version_string); - exit(1); + exit(E_VERSION); break; case 'v': verbose++; @@ -237,6 +242,7 @@ case 'f': mode = MODE_ETHERS; break; + case 'H': case 't': if (optarg) { hardware = get_hwtype(optarg); Only in net-tools-1.49: route diff -u --recursive net-tools-1.49/route.c net-tools-1.49-1/route.c --- net-tools-1.49/route.c Mon Nov 16 10:17:35 1998 +++ net-tools-1.49-1/route.c Sun Jan 3 02:40:59 1999 @@ -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 @@ 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 -u --recursive net-tools-1.49/statistics.c net-tools-1.49-1/statistics.c --- net-tools-1.49/statistics.c Mon Nov 16 10:17:38 1998 +++ net-tools-1.49-1/statistics.c Fri Jan 1 15:14:44 1999 @@ -2,10 +2,9 @@ /* $Id: statistics.c,v 1.9 1998/11/15 20:08:30 freitag 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 @@ {"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 @@ {"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 @@ {"Icmp", Icmptab, sizeof(Icmptab)}, {"Tcp", Tcptab, sizeof(Tcptab)}, {"Udp", Udptab, sizeof(Udptab)}, + {"TcpExt", Tcpexttab, sizeof(Tcpexttab)}, {NULL} }; @@ -173,6 +187,7 @@ 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 @@ 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 @@ 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 @@ 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() { Only in net-tools-1.49: version.h | |