Commit db2c3153 authored by Phil Blundell's avatar Phil Blundell

Pile of net-tools goodies. I plan to make a 1.45 release this

weekend - please give it a go and make sure it at least compiles
on your system. :-)
parent b612eddf
Fri Apr 10 22:26:48 1998 Philip Blundell <Philip.Blundell@pobox.com>
* ifconfig.c (ife_print): Bracket Appletalk stuff in #if
HAVE_AFIPX. Add Econet support.
(ife_print): Print `collisions' left aligned with everything
else to make it neater.
(main): Make interface address setting work for Econet.
* interface.h: Add Econet support.
* lib/pathnames.h (_PATH_PROCNET_ROSE_ROUTE): Added.
* netstat.c: Fix `-i' to work with unified interface code. Tidy
up.
* ifconfig.c (if_print): Fix printing of aliased interfaces when
lots are present (patch from Todd R. Eigenschink).
(main): Bracket media stuff with #ifdef IFF_PORTSEL.
* lib/econet.c: New file.
* config.in, lib/Makefile: support Econet.
* sockets.c: Likewise.
Mon Mar 2 20:45:29 1998 Philip Blundell <Philip.Blundell@pobox.com>
* interface.c: New file, contains code shared between ifconfig and
......
......@@ -61,6 +61,7 @@ bool 'Appletalk DDP protocol family' HAVE_AFATALK y
bool 'AX25 (packet radio) protocol family' HAVE_AFAX25 y
bool 'NET/ROM (packet radio) protocol family' HAVE_AFNETROM y
bool 'Rose (packet radio) protocol family' HAVE_AFROSE n
bool 'Econet protocol family' HAVE_AFECONET n
*
*
* Device Hardware types.
......
......@@ -115,7 +115,7 @@ ife_print(struct interface *ptr)
struct hwtype *hw;
int hf;
int can_compress = 0;
static struct aftype *ipxtype=NULL, *ddptype=NULL;
static struct aftype *ipxtype=NULL, *ddptype=NULL, *ectype=NULL;
#if HAVE_AFINET6
FILE *f;
char addr6[40], devname[10];
......@@ -205,6 +205,7 @@ ife_print(struct interface *ptr)
}
#endif
#if HAVE_AFIPX
if (ipxtype==NULL)
ipxtype=get_afntype(AF_IPX);
......@@ -226,6 +227,9 @@ ife_print(struct interface *ptr)
" IPX/Ethernet 802.3 addr:%s\n"),
ipxtype->sprint(&ptr->ipxaddr_e3,1));
}
#endif
#if HAVE_AFTALK
if (ddptype==NULL)
ddptype=get_afntype(AF_APPLETALK);
if (ddptype!=NULL) {
......@@ -234,6 +238,19 @@ ife_print(struct interface *ptr)
" EtherTalk Phase 2 addr:%s\n"),
ddptype->sprint(&ptr->ddpaddr,1));
}
#endif
#if HAVE_AFECONET
if (ectype == NULL)
ectype = get_afntype(AF_ECONET);
if (ectype != NULL) {
if (ptr->has_econet)
printf(NLS_CATGETS(catfd, ifconfigSet, ifconfig_ec,
" econet addr:%s\n"),
ectype->sprint(&ptr->ecaddr,1));
}
#endif
printf(" ");
if (ptr->flags == 0) printf(NLS_CATGETS(catfd, ifconfigSet, ifconfig_noflags,
"[NO FLAGS] "));
......@@ -273,7 +290,7 @@ ife_print(struct interface *ptr)
ptr->stats.tx_packets, ptr->stats.tx_errors,
ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors,
ptr->stats.tx_carrier_errors);
printf(" collisions:%lu ", ptr->stats.collisions);
printf(" Collisions:%lu ", ptr->stats.collisions);
if (can_compress)
printf("compressed:%lu ", ptr->stats.tx_compressed);
printf("\n");
......@@ -313,9 +330,12 @@ if_print(char *ifname)
fgets(buffer, 256, fd);
while (!feof(fd)) {
char *name = buffer;
char *sep;
if (fgets(buffer, 256, fd) == NULL)
break;
buffer[6] = 0;
sep = strrchr(buffer, ':');
if (sep)
*sep = 0;
while (*name == ' ') name++;
if (if_fetch(name, &ife) < 0) {
fprintf(stderr, NLS_CATGETS(catfd, ifconfigSet,
......@@ -508,6 +528,7 @@ main(int argc, char **argv)
continue;
}
#ifdef IFF_PORTSEL
if (!strcmp(*spp, "media") || !strcmp(*spp, "port")) {
if (*++spp == NULL) usage();
if (!strcasecmp(*spp, "auto")) {
......@@ -545,6 +566,7 @@ main(int argc, char **argv)
}
continue;
}
#endif
if (!strcmp(*spp, "trailers")) {
goterr |= clr_flag(ifr.ifr_name, IFF_NOTRAILERS);
......@@ -931,9 +953,27 @@ main(int argc, char **argv)
}
memcpy((char *) &ifr.ifr_addr, (char *) &sa, sizeof(struct sockaddr));
if (ioctl(skfd, SIOCSIFADDR, &ifr) < 0) {
fprintf(stderr, "SIOCSIFADDR: %s\n", strerror(errno));
goterr = 1;
{
int r;
switch (ap->af) {
#ifdef HAVE_AFINET
case AF_INET:
r = ioctl(inet_sock, SIOCSIFADDR, &ifr);
break;
#endif
#ifdef HAVE_AFECONET
case AF_ECONET:
r = ioctl(ec_sock, SIOCSIFADDR, &ifr);
break;
#endif
default:
printf("Don't know how to set addresses for this family.\n");
exit(1);
}
if (r < 0) {
fprintf(stderr, "SIOCSIFADDR: %s\n", strerror(errno));
goterr = 1;
}
}
goterr |= set_flag(ifr.ifr_name, (IFF_UP | IFF_RUNNING));
spp++;
......
......@@ -18,6 +18,11 @@
#if HAVE_AFIPX
#include "ipx.h"
#endif
#if HAVE_AFECONET
#include <linux/if_ec.h>
#endif
#include "net-support.h"
#include "pathnames.h"
#include "version.h"
......@@ -248,6 +253,15 @@ if_fetch(char *ifname, struct interface *ife)
}
#endif
#if HAVE_AFECONET
/* Econet address maybe? */
strcpy(ifr.ifr_name, ifname);
if (ec_sock >= 0 && ioctl(ec_sock, SIOCGIFADDR, &ifr) == 0) {
ife->ecaddr = ifr.ifr_addr;
ife->has_econet = 1;
}
#endif
if_getstats(ifname, ife);
return 0;
}
......@@ -45,6 +45,7 @@ struct interface {
struct sockaddr ipxaddr_e3; /* IPX network address */
struct sockaddr ipxaddr_e2; /* IPX network address */
struct sockaddr ddpaddr; /* Appletalk DDP address */
struct sockaddr ecaddr; /* Econet address */
int has_ip;
int has_ipx_bb;
int has_ipx_sn;
......@@ -52,6 +53,7 @@ struct interface {
int has_ipx_e2;
int has_ax25;
int has_ddp;
int has_econet;
char hwaddr[32]; /* HW address */
struct user_net_device_stats stats; /* statistics */
};
......
......@@ -30,7 +30,7 @@
HWOBJS = hw.o loopback.o slip.o ether.o ax25.o ppp.o arcnet.o tr.o tunnel.o frame.o sit.o rose.o ash.o fddi.o
AFOBJS = unix.o inet.o inet6.o ax25.o ipx.o ddp.o ipx.o netrom.o af.o rose.o
AFOBJS = unix.o inet.o inet6.o ax25.o ipx.o ddp.o ipx.o netrom.o af.o rose.o econet.o
AFGROBJS = inet_gr.o inet6_gr.o ipx_gr.o ddp_gr.o netrom_gr.o ax25_gr.o rose_gr.o getroute.o
AFSROBJS = inet_sr.o inet6_sr.o netrom_sr.o ipx_sr.o setroute.o
ACTOBJS = slip_ac.o ppp_ac.o activate.o
......
......@@ -35,6 +35,7 @@ int flag_ddp = 0;
int flag_netrom = 0;
int flag_inet = 0;
int flag_inet6 = 0;
int flag_econet = 0;
struct aftrans_t {
......@@ -53,6 +54,7 @@ struct aftrans_t {
{"ddp", "ddp", &flag_ddp},
{"unix", "unix", &flag_unx},
{"tcpip", "inet", &flag_inet},
{"econet", "ec", &flag_econet},
{0, 0, 0}
};
......@@ -66,6 +68,7 @@ extern struct aftype ax25_aftype;
extern struct aftype netrom_aftype;
extern struct aftype ipx_aftype;
extern struct aftype ddp_aftype;
extern struct aftype ec_aftype;
static short sVafinit = 0;
......@@ -90,7 +93,10 @@ static struct aftype *aftypes[] = {
#endif
#if HAVE_AFATALK
&ddp_aftype,
#endif
#endif
#if HAVE_AFECONET
&ec_aftype,
#endif
&unspec_aftype,
NULL
};
......@@ -118,6 +124,9 @@ void afinit ()
#endif
#if HAVE_AFATALK
ddp_aftype.title = NLS_CATSAVE (catfd, ddpSet, ddp_ddp, "Appletalk DDP");
#endif
#if HAVE_AFCONET
ec_aftype.title = NLS_CATSAVE (catfd, ecSet, ec_ec, "Econet");
#endif
sVafinit = 1;
}
......
/*
* lib/econet.c This file contains an implementation of the Econet
* support functions for the net-tools.
* (NET-3 base distribution).
*
* Version: lib/econet.c 1.00 1998-04-10
*
* Author: Philip Blundell <philb@gnu.org>
*
* Modified:
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*/
#include "config.h"
#if HAVE_AFECONET
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include "version.h"
#include "net-support.h"
#include "pathnames.h"
#define EXTERN
#include "net-locale.h"
#include <linux/if_ec.h>
/* Display an Econet address */
static char *
ec_print(unsigned char *ptr)
{
static char buff[64];
struct ec_addr *ec = (struct ec_addr *)ptr;
sprintf(buff,"%d.%d", ec->net, ec->station);
return buff;
}
/* Display an Econet socket address */
static char *
ec_sprint(struct sockaddr *sap, int numeric)
{
static char buf[64];
struct sockaddr_ec *sec = (struct sockaddr_ec *)sap;
if (sap->sa_family != AF_ECONET)
return(NLS_CATBUFF (catfd, ecSet, ec_none, "[NONE SET]", buf, 64));
return ec_print((unsigned char *)&sec->addr);
}
static int
ec_input(int type, char *bufp, struct sockaddr *sap)
{
struct sockaddr_ec *sec = (struct sockaddr_ec *)sap;
int net, stn;
switch (sscanf(bufp, "%d.%d", &net, &stn))
{
case 2:
sec->addr.station = stn;
sec->addr.net = net;
return 0;
case 1:
if (sscanf(bufp, "%d", &stn) == 1) {
sec->addr.net = 0;
sec->addr.station = stn;
return 0;
}
}
return -1;
}
struct aftype ec_aftype = {
"ec", NULL, AF_ECONET, 0,
ec_print, ec_sprint, ec_input, NULL,
NULL
};
#endif /* HAVE_AFECONET */
......@@ -38,6 +38,7 @@
# define _PATH_PROCNET_DEV "/proc/net/dev"
# define _PATH_PROCNET_RARP "/proc/net/rarp"
# define _PATH_ETHERS "/etc/ethers"
# define _PATH_PROCNET_ROSE_ROUTE "/proc/net/rose_routes"
/* pathname for the netlink device */
# define _PATH_DEV_ROUTE "/dev/route"
......
......@@ -74,6 +74,8 @@
#include "version.h"
#include "config.h"
#include "net-locale.h"
#include "sockets.h"
#include "interface.h"
/* prototypes for statistics.c */
void parsesnmp(void);
......@@ -104,52 +106,6 @@ char *Release = RELEASE,
#define E_READ -1
#define E_IOCTL -3
/* This is from <linux/netdevice.h>. */
struct net_device_stats
{
unsigned long rx_packets; /* total packets received */
unsigned long tx_packets; /* total packets transmitted */
unsigned long rx_bytes; /* total bytes received */
unsigned long tx_bytes; /* total bytes transmitted */
unsigned long rx_errors; /* bad packets received */
unsigned long tx_errors; /* packet transmit problems */
unsigned long rx_dropped; /* no space in linux buffers */
unsigned long tx_dropped; /* no space available in linux */
unsigned long multicast; /* multicast packets received */
unsigned long collisions;
/* detailed rx_errors */
unsigned long rx_length_errors;
unsigned long rx_over_errors; /* receiver ring buff overflow */
unsigned long rx_crc_errors; /* packet with crc error */
unsigned long rx_frame_errors; /* frame alignment error */
unsigned long rx_fifo_errors; /* fifo overran */
unsigned long rx_missed_errors; /* receiver missed packet */
/* detailed tx_errors */
unsigned long tx_aborted_errors;
unsigned long tx_carrier_errors; /* lost carrier */
unsigned long tx_fifo_errors; /* fifo underran */
unsigned long tx_heartbeat_errors; /* heartbeat failure */
unsigned long tx_window_errors;
};
struct interface {
char name[IFNAMSIZ]; /* interface name */
short flags; /* various flags */
int metric; /* routing metric */
int mtu; /* MTU value */
struct sockaddr addr; /* IP address */
struct sockaddr dstaddr; /* P-P IP address */
struct sockaddr broadaddr; /* IP broadcast address */
struct sockaddr netmask; /* IP network mask */
struct sockaddr hwaddr; /* HW address */
struct net_device_stats stats; /* statistics */
};
int flag_nlp = 0;
int flag_int = 0;
int flag_rou = 0;
......@@ -169,7 +125,6 @@ int flag_exp = 1;
int flag_arg = 0;
int flag_ver = 0;
int skfd;
FILE *procinfo;
#define INFO_GUTS1(file,name,proc) \
......@@ -1159,51 +1114,57 @@ ife_print(struct interface *ptr)
static int
iface_info(void)
{
char buff[1024];
struct interface ife;
struct ifconf ifc;
struct ifreq *ifr;
int i;
char buffer[256];
FILE *fd;
/* Create a channel to the NET kernel. */
if ((skfd = socket(AF_INET,SOCK_DGRAM,0)) < 0) {
perror("socket");
return(E_READ);
}
ifc.ifc_len = sizeof(buff);
ifc.ifc_buf = buff;
if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) {
perror("SIOCGIFCONF");
close(skfd);
return(E_IOCTL);
}
printf(NLS_CATGETS(catfd, netstatSet, netstat_interface, "Kernel Interface table\n"));
printf(NLS_CATGETS(catfd, netstatSet, netstat_header_iface,
"Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flags\n"));
ifr = ifc.ifc_req;
for (i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; ifr++) {
if (if_fetch(ifr->ifr_name, &ife) < 0) {
fprintf(stderr, NLS_CATGETS(catfd, netstatSet, netstat_unkn_iface,
"%s: unknown interface.\n"), ifr->ifr_name);
}
/* Create a channel to the NET kernel. */
if ((skfd = sockets_open()) < 0) {
perror("socket");
NLS_CATCLOSE(catfd)
exit(1);
}
fd = fopen(_PATH_PROCNET_DEV, "r");
fgets(buffer, 256, fd); /* chuck first two lines */
fgets(buffer, 256, fd);
while (!feof(fd)) {
char *name = buffer;
char *sep;
if (fgets(buffer, 256, fd) == NULL)
break;
sep = strrchr(buffer, ':');
if (sep)
*sep = 0;
while (*name == ' ') name++;
if (if_fetch(name, &ife) < 0) {
fprintf(stderr, NLS_CATGETS(catfd, ifconfigSet,
ifconfig_unkn, "%s: unknown interface.\n"),
name);
continue;
}
if (((ife.flags & IFF_UP) == 0) && !flag_all) continue;
ife_print(&ife);
if (((ife.flags & IFF_UP) == 0) && !flag_all) continue;
ife_print(&ife);
}
fclose(fd);
close(skfd);
return(0);
return 0;
}
static void
version(void)
{
printf("%s\n%s\n%s\n%s\n", Release, Version, Signature, Features);
NLS_CATCLOSE(catfd)
exit(1);
printf("%s\n%s\n%s\n%s\n", Release, Version, Signature, Features);
NLS_CATCLOSE(catfd)
exit(1);
}
......
......@@ -25,6 +25,9 @@ int inet6_sock = -1; /* INET6 socket */
#if HAVE_AFATALK
int ddp_sock = -1; /* Appletalk DDP socket */
#endif
#if HAVE_AFECONET
int ec_sock = -1; /* Econet socket */
#endif
int sockets_open(void)
{
......@@ -51,6 +54,10 @@ int sockets_open(void)
#if HAVE_AFATALK
ddp_sock = socket(AF_APPLETALK, SOCK_DGRAM, 0);
#endif
#if HAVE_AFECONET
ec_sock = socket(AF_ECONET, SOCK_DGRAM, 0);
#endif
/*
* Now pick any (existing) useful socket family for generic queries
......@@ -80,6 +87,10 @@ int sockets_open(void)
if (ddp_sock != -1) return ddp_sock;
#endif
#if HAVE_AFECONET
if (ec_sock != -1) return ec_sock;
#endif
/* We have no address families. */
fprintf(stderr, "No usable address families found.\n");
return -1;
......
extern int skfd, ipx_sock, ax25_sock, rose_sock, inet_sock, inet6_sock, ddp_sock;
extern int skfd, ipx_sock, ax25_sock, rose_sock, inet_sock, inet6_sock, ddp_sock, ec_sock;
extern int sockets_open(void);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment