summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arp.c1143
-rw-r--r--hostname.c496
-rw-r--r--ifconfig.c1782
-rw-r--r--include/ipx.h22
-rw-r--r--interface.c708
-rw-r--r--interface.h125
-rw-r--r--lib/Makefile3
-rw-r--r--lib/activate.c83
-rw-r--r--lib/af.c366
-rw-r--r--lib/arcnet.c129
-rw-r--r--lib/ash.c110
-rw-r--r--lib/ax25.c207
-rw-r--r--lib/ax25_gr.c64
-rw-r--r--lib/ddp.c53
-rw-r--r--lib/ddp_gr.c4
-rw-r--r--lib/econet.c87
-rw-r--r--lib/ether.c143
-rw-r--r--lib/fddi.c133
-rw-r--r--lib/frame.c44
-rw-r--r--lib/getargs.c100
-rw-r--r--lib/getroute.c152
-rw-r--r--lib/hdlclapb.c40
-rw-r--r--lib/hippi.c138
-rw-r--r--lib/hw.c217
-rw-r--r--lib/inet.c461
-rw-r--r--lib/inet6.c166
-rw-r--r--lib/inet6_gr.c279
-rw-r--r--lib/inet6_sr.c251
-rw-r--r--lib/inet_gr.c345
-rw-r--r--lib/inet_sr.c428
-rw-r--r--lib/ipx.c219
-rw-r--r--lib/ipx_gr.c74
-rw-r--r--lib/ipx_sr.c19
-rw-r--r--lib/loopback.c62
-rw-r--r--lib/masq_info.c320
-rw-r--r--lib/net-features.h330
-rw-r--r--lib/net-string.c77
-rw-r--r--lib/net-support.h160
-rw-r--r--lib/netrom.c204
-rw-r--r--lib/netrom_gr.c98
-rw-r--r--lib/netrom_sr.c14
-rw-r--r--lib/nstrcmp.c43
-rw-r--r--lib/pathnames.h71
-rw-r--r--lib/ppp.c38
-rw-r--r--lib/ppp_ac.c24
-rw-r--r--lib/proc.c70
-rw-r--r--lib/proc.h4
-rw-r--r--lib/rose.c136
-rw-r--r--lib/rose_gr.c71
-rw-r--r--lib/setroute.c90
-rw-r--r--lib/sit.c29
-rw-r--r--lib/slip.c57
-rw-r--r--lib/slip_ac.c88
-rw-r--r--lib/tr.c136
-rw-r--r--lib/tunnel.c26
-rw-r--r--lib/unix.c90
-rw-r--r--lib/util.c38
-rw-r--r--lib/util.h12
-rw-r--r--netstat.c2266
-rw-r--r--rarp.c420
-rw-r--r--route.c306
-rw-r--r--sockets.c62
-rw-r--r--sockets.h3
-rw-r--r--statistics.c445
64 files changed, 7176 insertions, 7205 deletions
diff --git a/arp.c b/arp.c
index 4350d82..abfc72f 100644
--- a/arp.c
+++ b/arp.c
@@ -1,53 +1,53 @@
/*
- * arp This file contains an implementation of the command
- * that maintains the kernel's ARP cache. It is derived
- * from Berkeley UNIX arp(8), but cleaner and with sup-
- * port for devices other than Ethernet.
+ * arp This file contains an implementation of the command
+ * that maintains the kernel's ARP cache. It is derived
+ * from Berkeley UNIX arp(8), but cleaner and with sup-
+ * port for devices other than Ethernet.
*
- * NET-TOOLS A collection of programs that form the base set of the
- * NET-3 Networking Distribution for the LINUX operating
- * system.
+ * NET-TOOLS A collection of programs that form the base set of the
+ * NET-3 Networking Distribution for the LINUX operating
+ * system.
*
- * Version: arp 1.83 (1998-02-13)
+ * Version: $Id: arp.c,v 1.9 1998/11/15 20:07:31 freitag Exp $
*
- * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
+ * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
*
* Changes:
- * (based on work from Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>)
- * Alan Cox : modified for NET3
- * Andrew Tridgell : proxy arp netmasks
- * Bernd Eckenfels : -n option
- * Bernd Eckenfels : Use only /proc for display
- * {1.60} Bernd Eckenfels : new arpcode (-i) for 1.3.42 but works
- * with 1.2.x, too
- * {1.61} Bernd Eckenfels : more verbose messages
- * {1.62} Bernd Eckenfels : check -t for hw adresses and try to
- * explain EINVAL (jeff)
- *970125 {1.63} Bernd Eckenfels : -a print hardwarename instead of tiltle
- *970201 {1.64} Bernd Eckenfels : net-features.h support
- *970203 {1.65} Bernd Eckenfels : "#define" in "#if",
- * -H|-A additional to -t|-p
- *970214 {1.66} Bernd Eckenfels : Fix optarg required for -H and -A
- *970412 {1.67} Bernd Eckenfels : device=""; is default
- *970514 {1.68} Bernd Eckenfels : -N and -D
- *970517 {1.69} Bernd Eckenfels : usage() fixed
- *970622 {1.70} Bernd Eckenfels : arp -d priv
- *970106 {1.80} Bernd Eckenfels : new syntax without -D and with "dev <If>",
- * ATF_MAGIC, ATF_DONTPUB support.
- * Typo fix (Debian Bug#5728 Giuliano Procida)
- *970803 {1.81} Bernd Eckenfels : removed junk comment line 1
- *970925 {1.82} Bernd Eckenfels : include fix for libc6
- *980213 (1.83) Phil Blundell: set ATF_COM on new entries
+ * (based on work from Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>)
+ * Alan Cox : modified for NET3
+ * Andrew Tridgell : proxy arp netmasks
+ * Bernd Eckenfels : -n option
+ * Bernd Eckenfels : Use only /proc for display
+ * {1.60} Bernd Eckenfels : new arpcode (-i) for 1.3.42 but works
+ * with 1.2.x, too
+ * {1.61} Bernd Eckenfels : more verbose messages
+ * {1.62} Bernd Eckenfels : check -t for hw adresses and try to
+ * explain EINVAL (jeff)
+ *970125 {1.63} Bernd Eckenfels : -a print hardwarename instead of tiltle
+ *970201 {1.64} Bernd Eckenfels : net-features.h support
+ *970203 {1.65} Bernd Eckenfels : "#define" in "#if",
+ * -H|-A additional to -t|-p
+ *970214 {1.66} Bernd Eckenfels : Fix optarg required for -H and -A
+ *970412 {1.67} Bernd Eckenfels : device=""; is default
+ *970514 {1.68} Bernd Eckenfels : -N and -D
+ *970517 {1.69} Bernd Eckenfels : usage() fixed
+ *970622 {1.70} Bernd Eckenfels : arp -d priv
+ *970106 {1.80} Bernd Eckenfels : new syntax without -D and with "dev <If>",
+ * ATF_MAGIC, ATF_DONTPUB support.
+ * Typo fix (Debian Bug#5728 Giuliano Procida)
+ *970803 {1.81} Bernd Eckenfels : removed junk comment line 1
+ *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
*
*
- * 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.
+ * 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 <sys/types.h>
#include <sys/socket.h>
@@ -76,693 +76,690 @@
#define FEATURE_ARP
#include "lib/net-features.h"
-char *Release = RELEASE,
- *Version = "arp 1.84 (1998-06-29)";
-
-int opt_n = 0; /* do not resolve addresses */
-int opt_N = 0; /* use symbolic names */
-int opt_v = 0; /* debugging output flag */
-int opt_D = 0; /* HW-address is devicename */
-int opt_e = 0; /* 0=BSD output, 1=new linux */
-int opt_a = 0; /* all entries, substring match */
-struct aftype *ap; /* current address family */
-struct hwtype *hw; /* current hardware type */
-int sockfd=0; /* active socket descriptor */
-int hw_set = 0; /* flag if hw-type was set (-H) */
-char device[16]=""; /* current device */
+char *Release = RELEASE, *Version = "arp 1.84 (1998-06-29)";
+
+int opt_n = 0; /* do not resolve addresses */
+int opt_N = 0; /* use symbolic names */
+int opt_v = 0; /* debugging output flag */
+int opt_D = 0; /* HW-address is devicename */
+int opt_e = 0; /* 0=BSD output, 1=new linux */
+int opt_a = 0; /* all entries, substring match */
+struct aftype *ap; /* current address family */
+struct hwtype *hw; /* current hardware type */
+int sockfd = 0; /* active socket descriptor */
+int hw_set = 0; /* flag if hw-type was set (-H) */
+char device[16] = ""; /* current device */
static void usage(void);
/* Delete an entry from the ARP cache. */
-static int
-arp_del(char **args)
+static int arp_del(char **args)
{
- char host[128];
- struct arpreq req;
- struct sockaddr sa;
- int flags=0;
- int err;
+ char host[128];
+ struct arpreq req;
+ struct sockaddr sa;
+ int flags = 0;
+ int err;
- memset((char *) &req, 0, sizeof(req));
+ memset((char *) &req, 0, sizeof(req));
- /* Resolve the host name. */
- if (*args == NULL) {
+ /* Resolve the host name. */
+ if (*args == NULL) {
fprintf(stderr, _("arp: need host name\n"));
- return(-1);
- }
- host[(sizeof host)-1] = 0;
- strncpy(host, *args, (sizeof host)-1);
- if (ap->input(0, host, &sa) < 0) {
+ return (-1);
+ }
+ host[(sizeof host) - 1] = 0;
+ strncpy(host, *args, (sizeof host) - 1);
+ if (ap->input(0, host, &sa) < 0) {
ap->herror(host);
- return(-1);
- }
-
- /* If a host has more than one address, use the correct one! */
- memcpy((char *) &req.arp_pa, (char *) &sa, sizeof(struct sockaddr));
-
- if (hw_set)
- req.arp_ha.sa_family=hw->type;
-
- req.arp_flags=ATF_PERM;
- args++;
- while (*args != NULL) {
- if (opt_v) fprintf(stderr,"args=%s\n",*args);
- if (! strcmp(*args, "pub")) {
- flags |= 1;
- args++;
- continue;
+ return (-1);
+ }
+ /* If a host has more than one address, use the correct one! */
+ memcpy((char *) &req.arp_pa, (char *) &sa, sizeof(struct sockaddr));
+
+ if (hw_set)
+ req.arp_ha.sa_family = hw->type;
+
+ req.arp_flags = ATF_PERM;
+ args++;
+ while (*args != NULL) {
+ if (opt_v)
+ fprintf(stderr, "args=%s\n", *args);
+ if (!strcmp(*args, "pub")) {
+ flags |= 1;
+ args++;
+ continue;
}
- if (! strcmp(*args, "priv")) {
- flags |= 2;
- args++;
- continue;
+ if (!strcmp(*args, "priv")) {
+ flags |= 2;
+ args++;
+ continue;
}
- if (! strcmp(*args, "temp")) {
- req.arp_flags &= ~ATF_PERM;
- args++;
- continue;
+ if (!strcmp(*args, "temp")) {
+ req.arp_flags &= ~ATF_PERM;
+ args++;
+ continue;
}
- if (! strcmp(*args, "trail")) {
- req.arp_flags |= ATF_USETRAILERS;
- args++;
- continue;
+ if (!strcmp(*args, "trail")) {
+ req.arp_flags |= ATF_USETRAILERS;
+ args++;
+ continue;
}
- if (! strcmp(*args, "dontpub")) {
+ if (!strcmp(*args, "dontpub")) {
#ifdef HAVE_ATF_DONTPUB
- req.arp_flags |= ATF_DONTPUB;
+ req.arp_flags |= ATF_DONTPUB;
#else
- ENOSUPP("arp", "ATF_DONTPUB");
+ ENOSUPP("arp", "ATF_DONTPUB");
#endif
- args++;
- continue;
+ args++;
+ continue;
}
- if (! strcmp(*args, "auto")) {
+ if (!strcmp(*args, "auto")) {
#ifdef HAVE_ATF_MAGIC
- req.arp_flags |= ATF_MAGIC;
+ req.arp_flags |= ATF_MAGIC;
#else
- ENOSUPP("arp", "ATF_MAGIC");
+ ENOSUPP("arp", "ATF_MAGIC");
#endif
- args++;
- continue;
+ args++;
+ continue;
}
- if (! strcmp(*args, "dev")) {
- if (*++args == NULL) usage();
- strncpy(device,*args,sizeof(device)-1);
- device[sizeof(device)-1]='\0';
- args++;
- continue;
+ if (!strcmp(*args, "dev")) {
+ if (*++args == NULL)
+ usage();
+ strncpy(device, *args, sizeof(device) - 1);
+ device[sizeof(device) - 1] = '\0';
+ args++;
+ continue;
}
- if (! strcmp(*args, "netmask")) {
- if (*++args == NULL) usage();
- if (strcmp(*args,"255.255.255.255") != 0) {
- strcpy(host, *args);
- if (ap->input(0, host, &sa) < 0) {
- ap->herror(host);
- return(-1);
- }
- memcpy((char *) &req.arp_netmask, (char *) &sa,
- sizeof(struct sockaddr));
- req.arp_flags |= ATF_NETMASK;
- }
- args++;
- continue;
- }
- usage();
- }
- if (flags == 0)
- flags = 3;
-
- strcpy(req.arp_dev,device);
-
- err = -1;
-
- /* Call the kernel. */
- if (flags & 2) {
- if (opt_v) fprintf(stderr,"arp: SIOCDARP(nopub)\n");
- if ((err = ioctl(sockfd, SIOCDARP, &req) < 0)) {
- if (errno == ENXIO) {
- if (flags & 1)
- goto nopub;
- printf(_("No ARP entry for %s\n"), host);
- return(-1);
- }
- perror("SIOCDARP(priv)");
- return(-1);
- }
- }
- if ((flags & 1) && (err)) {
-nopub:
- req.arp_flags |= ATF_PUBL;
- if (opt_v) fprintf(stderr,"arp: SIOCDARP(pub)\n");
- if (ioctl(sockfd, SIOCDARP, &req) < 0) {
- if (errno == ENXIO) {
- printf(_("No ARP entry for %s\n"), host);
- return(-1);
+ if (!strcmp(*args, "netmask")) {
+ if (*++args == NULL)
+ usage();
+ if (strcmp(*args, "255.255.255.255") != 0) {
+ strcpy(host, *args);
+ if (ap->input(0, host, &sa) < 0) {
+ ap->herror(host);
+ return (-1);
}
- perror("SIOCDARP(pub)");
- return(-1);
- }
- }
-
- return(0);
+ memcpy((char *) &req.arp_netmask, (char *) &sa,
+ sizeof(struct sockaddr));
+ req.arp_flags |= ATF_NETMASK;
+ }
+ args++;
+ continue;
+ }
+ usage();
+ }
+ if (flags == 0)
+ flags = 3;
+
+ strcpy(req.arp_dev, device);
+
+ err = -1;
+
+ /* Call the kernel. */
+ if (flags & 2) {
+ if (opt_v)
+ fprintf(stderr, "arp: SIOCDARP(nopub)\n");
+ if ((err = ioctl(sockfd, SIOCDARP, &req) < 0)) {
+ if (errno == ENXIO) {
+ if (flags & 1)
+ goto nopub;
+ printf(_("No ARP entry for %s\n"), host);
+ return (-1);
+ }
+ perror("SIOCDARP(priv)");
+ return (-1);
+ }
+ }
+ if ((flags & 1) && (err)) {
+ nopub:
+ req.arp_flags |= ATF_PUBL;
+ if (opt_v)
+ fprintf(stderr, "arp: SIOCDARP(pub)\n");
+ if (ioctl(sockfd, SIOCDARP, &req) < 0) {
+ if (errno == ENXIO) {
+ printf(_("No ARP entry for %s\n"), host);
+ return (-1);
+ }
+ perror("SIOCDARP(pub)");
+ return (-1);
+ }
+ }
+ return (0);
}
/* Get the hardware address to a specified interface name */
-static int
-arp_getdevhw(char *ifname, struct sockaddr *sa, struct hwtype *hw)
+static int arp_getdevhw(char *ifname, struct sockaddr *sa, struct hwtype *hw)
{
- struct ifreq ifr;
- struct hwtype *xhw;
-
- strcpy(ifr.ifr_name, ifname);
- if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) < 0) {
- fprintf(stderr,"arp: cant get HW-Address for `%s': %s.\n", ifname, strerror(errno));
- return(-1);
- }
- if (hw && (ifr.ifr_hwaddr.sa_family!=hw->type)) {
- fprintf(stderr,"arp: protocol type missmatch.\n");
- return(-1);
- }
- memcpy((char *)sa, (char *)&(ifr.ifr_hwaddr), sizeof(struct sockaddr));
-
- if (opt_v) {
- if (!(xhw = get_hwntype(ifr.ifr_hwaddr.sa_family)) || (xhw->sprint==0)) {
- xhw = get_hwntype(-1);
- }
- fprintf(stderr, "arp: device `%s' has HW address %s `%s'.\n",ifname, xhw->name, xhw->sprint(&ifr.ifr_hwaddr));
- }
- return(0);
+ struct ifreq ifr;
+ struct hwtype *xhw;
+
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) < 0) {
+ fprintf(stderr, "arp: cant get HW-Address for `%s': %s.\n", ifname, strerror(errno));
+ return (-1);
+ }
+ if (hw && (ifr.ifr_hwaddr.sa_family != hw->type)) {
+ fprintf(stderr, "arp: protocol type missmatch.\n");
+ return (-1);
+ }
+ memcpy((char *) sa, (char *) &(ifr.ifr_hwaddr), sizeof(struct sockaddr));
+
+ if (opt_v) {
+ if (!(xhw = get_hwntype(ifr.ifr_hwaddr.sa_family)) || (xhw->sprint == 0)) {
+ xhw = get_hwntype(-1);
+ }
+ fprintf(stderr, "arp: device `%s' has HW address %s `%s'.\n", ifname, xhw->name, xhw->sprint(&ifr.ifr_hwaddr));
+ }
+ return (0);
}
/* Set an entry in the ARP cache. */
-static int
-arp_set(char **args)
+static int arp_set(char **args)
{
- char host[128];
- struct arpreq req;
- struct sockaddr sa;
- int flags;
+ char host[128];
+ struct arpreq req;
+ struct sockaddr sa;
+ int flags;
- memset((char *) &req, 0, sizeof(req));
+ memset((char *) &req, 0, sizeof(req));
- /* Resolve the host name. */
- if (*args == NULL) {
+ /* Resolve the host name. */
+ if (*args == NULL) {
fprintf(stderr, _("arp: need host name\n"));
- return(-1);
- }
- host[(sizeof host)-1] = 0;
- strncpy(host, *args++, (sizeof host)-1);
- if (ap->input(0, host, &sa) < 0) {
+ return (-1);
+ }
+ host[(sizeof host) - 1] = 0;
+ strncpy(host, *args++, (sizeof host) - 1);
+ if (ap->input(0, host, &sa) < 0) {
ap->herror(host);
- return(-1);
- }
-
- /* If a host has more than one address, use the correct one! */
- memcpy((char *) &req.arp_pa, (char *) &sa, sizeof(struct sockaddr));
+ return (-1);
+ }
+ /* If a host has more than one address, use the correct one! */
+ memcpy((char *) &req.arp_pa, (char *) &sa, sizeof(struct sockaddr));
- /* Fetch the hardware address. */
- if (*args == NULL) {
+ /* Fetch the hardware address. */
+ if (*args == NULL) {
fprintf(stderr, _("arp: need hardware address\n"));
- return(-1);
- }
-
- if (opt_D) {
- if (arp_getdevhw(*args++, &req.arp_ha, hw_set?hw:NULL) < 0)
- return(-1);
- } else {
- if (hw->input(*args++, &req.arp_ha) < 0) {
- fprintf(stderr, _("arp: invalid hardware address\n"));
- return(-1);
+ return (-1);
}
- }
-
- /* Check out any modifiers. */
- flags = ATF_PERM | ATF_COM;
- while (*args != NULL) {
- if (! strcmp(*args, "temp")) {
- flags &= ~ATF_PERM;
- args++;
- continue;
+ if (opt_D) {
+ if (arp_getdevhw(*args++, &req.arp_ha, hw_set ? hw : NULL) < 0)
+ return (-1);
+ } else {
+ if (hw->input(*args++, &req.arp_ha) < 0) {
+ fprintf(stderr, _("arp: invalid hardware address\n"));
+ return (-1);
}
- if (! strcmp(*args, "pub")) {
- flags |= ATF_PUBL;
- args++;
- continue;
+ }
+
+ /* Check out any modifiers. */
+ flags = ATF_PERM | ATF_COM;
+ while (*args != NULL) {
+ if (!strcmp(*args, "temp")) {
+ flags &= ~ATF_PERM;
+ args++;
+ continue;
}
- if (! strcmp(*args, "priv")) {
- flags &= ~ATF_PUBL;
- args++;
- continue;
+ if (!strcmp(*args, "pub")) {
+ flags |= ATF_PUBL;
+ args++;
+ continue;
}
- if (! strcmp(*args, "trail")) {
- flags |= ATF_USETRAILERS;
- args++;
- continue;
+ if (!strcmp(*args, "priv")) {
+ flags &= ~ATF_PUBL;
+ args++;
+ continue;
+ }
+ if (!strcmp(*args, "trail")) {
+ flags |= ATF_USETRAILERS;
+ args++;
+ continue;
}
- if (! strcmp(*args, "dontpub")) {
+ if (!strcmp(*args, "dontpub")) {
#ifdef HAVE_ATF_DONTPUB
- flags |= ATF_DONTPUB;
+ flags |= ATF_DONTPUB;
#else
- ENOSUPP("arp", "ATF_DONTPUB");
+ ENOSUPP("arp", "ATF_DONTPUB");
#endif
- args++;
- continue;
+ args++;
+ continue;
}
-
- if (! strcmp(*args, "auto")) {
+ if (!strcmp(*args, "auto")) {
#ifdef HAVE_ATF_MAGIC
- flags |= ATF_MAGIC;
+ flags |= ATF_MAGIC;
#else
- ENOSUPP("arp", "ATF_MAGIC");
+ ENOSUPP("arp", "ATF_MAGIC");
#endif
- args++;
- continue;
+ args++;
+ continue;
}
- if (! strcmp(*args, "dev")) {
- if (*++args == NULL) usage();
- strncpy(device,*args,sizeof(device)-1);
- device[sizeof(device)-1]='\0';
- args++;
- continue;
+ if (!strcmp(*args, "dev")) {
+ if (*++args == NULL)
+ usage();
+ strncpy(device, *args, sizeof(device) - 1);
+ device[sizeof(device) - 1] = '\0';
+ args++;
+ continue;
}
-
- if (! strcmp(*args, "netmask")) {
- if (*++args == NULL) usage();
- if (strcmp(*args,"255.255.255.255") != 0) {
- strcpy(host, *args);
- if (ap->input(0, host, &sa) < 0) {
- ap->herror(host);
- return(-1);
- }
- memcpy((char *) &req.arp_netmask, (char *) &sa,
- sizeof(struct sockaddr));
- flags |= ATF_NETMASK;
- }
- args++;
- continue;
+ if (!strcmp(*args, "netmask")) {
+ if (*++args == NULL)
+ usage();
+ if (strcmp(*args, "255.255.255.255") != 0) {
+ strcpy(host, *args);
+ if (ap->input(0, host, &sa) < 0) {
+ ap->herror(host);
+ return (-1);
+ }
+ memcpy((char *) &req.arp_netmask, (char *) &sa,
+ sizeof(struct sockaddr));
+ flags |= ATF_NETMASK;
+ }
+ args++;
+ continue;
}
usage();
- }
+ }
- /* Fill in the remainder of the request. */
- req.arp_flags = flags;
+ /* Fill in the remainder of the request. */
+ req.arp_flags = flags;
- strcpy(req.arp_dev,device);
+ strcpy(req.arp_dev, device);
- /* Call the kernel. */
- if (opt_v) fprintf(stderr,"arp: SIOCSARP()\n");
- if (ioctl(sockfd, SIOCSARP, &req) < 0) {
+ /* Call the kernel. */
+ 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);
+ }
+ return (0);
}
/* Process an EtherFile */
-static int
-arp_file(char *name)
+static int arp_file(char *name)
{
- char buff[1024];
- char *sp, *args[32];
- int linenr, argc;
- FILE *fp;
+ char buff[1024];
+ char *sp, *args[32];
+ int linenr, argc;
+ FILE *fp;
- if ((fp = fopen(name, "r")) == NULL) {
+ if ((fp = fopen(name, "r")) == NULL) {
fprintf(stderr, _("arp: cannot open etherfile %s !\n"), name);
- return(-1);
- }
-
- /* Read the lines in the file. */
- linenr = 0;
- while (fgets(buff, sizeof(buff), fp) != (char *)NULL) {
+ return (-1);
+ }
+ /* Read the lines in the file. */
+ linenr = 0;
+ while (fgets(buff, sizeof(buff), fp) != (char *) NULL) {
linenr++;
- if (opt_v == 1) fprintf(stderr, ">> %s", buff);
- if ((sp = strchr(buff, '\n')) != (char *)NULL) *sp = '\0';
- if (buff[0] == '#' || buff[0] == '\0') continue;
+ if (opt_v == 1)
+ fprintf(stderr, ">> %s", buff);
+ if ((sp = strchr(buff, '\n')) != (char *) NULL)
+ *sp = '\0';
+ if (buff[0] == '#' || buff[0] == '\0')
+ continue;
argc = getargs(buff, args);
if (argc < 2) {
- fprintf(stderr, _("arp: format error on line %u of etherfile %s !\n"),
- linenr, name);
- continue;
+ fprintf(stderr, _("arp: format error on line %u of etherfile %s !\n"),
+ linenr, name);
+ continue;
}
-
if (arp_set(args) != 0)
- fprintf(stderr, _("arp: cannot set entry on line %u of etherfile %s !\n"),
- linenr, name);
- }
+ fprintf(stderr, _("arp: cannot set entry on line %u of etherfile %s !\n"),
+ linenr, name);
+ }
- (void) fclose(fp);
- return(0);
+ (void) fclose(fp);
+ return (0);
}
/* Print the contents of an ARP request block. */
-static void
-arp_disp_2(char *name,int type,int arp_flags,char *hwa,char *mask,char *dev)
+static void arp_disp_2(char *name, int type, int arp_flags, char *hwa, char *mask, char *dev)
{
- static int title = 0;
- struct hwtype *xhw;
- char flags[10];
-
- xhw = get_hwntype(type);
- if (xhw == NULL)
- xhw = get_hwtype(DFLT_HW);
-
- if (title++ == 0) {
- printf(_("Address\t\t\tHWtype\tHWaddress\t Flags Mask\t\t Iface\n"));
- }
- /* Setup the flags. */
- flags[0] = '\0';
- if (arp_flags & ATF_COM) strcat(flags, "C");
- if (arp_flags & ATF_PERM) strcat(flags, "M");
- if (arp_flags & ATF_PUBL) strcat(flags, "P");
+ static int title = 0;
+ struct hwtype *xhw;
+ char flags[10];
+
+ xhw = get_hwntype(type);
+ if (xhw == NULL)
+ xhw = get_hwtype(DFLT_HW);
+
+ if (title++ == 0) {
+ printf(_("Address\t\t\tHWtype\tHWaddress\t Flags Mask\t\t Iface\n"));
+ }
+ /* Setup the flags. */
+ flags[0] = '\0';
+ if (arp_flags & ATF_COM)
+ strcat(flags, "C");
+ if (arp_flags & ATF_PERM)
+ strcat(flags, "M");
+ if (arp_flags & ATF_PUBL)
+ strcat(flags, "P");
#ifdef HAVE_ATF_MAGIC
- if (arp_flags & ATF_MAGIC) strcat(flags, "A");
+ if (arp_flags & ATF_MAGIC)
+ strcat(flags, "A");
#endif
#ifdef HAVE_ATF_DONTPUB
- if (arp_flags & ATF_DONTPUB) strcat(flags, "!");
+ if (arp_flags & ATF_DONTPUB)
+ strcat(flags, "!");
#endif
- if (arp_flags & ATF_USETRAILERS) strcat(flags, "T");
+ if (arp_flags & ATF_USETRAILERS)
+ strcat(flags, "T");
- if (!(arp_flags & ATF_NETMASK)) mask="";
+ if (!(arp_flags & ATF_NETMASK))
+ mask = "";
- printf("%-23.23s\t", name);
+ printf("%-23.23s\t", name);
- if (!(arp_flags & ATF_COM)) {
+ if (!(arp_flags & ATF_COM)) {
if (arp_flags & ATF_PUBL)
- printf("%-8.8s%-20.20s","*","*");
+ printf("%-8.8s%-20.20s", "*", "*");
else
- printf("%-8.8s%-20.20s","","(incomplete)");
- } else {
+ printf("%-8.8s%-20.20s", "", "(incomplete)");
+ } else {
printf("%-8.8s%-20.20s", xhw->name, hwa);
- }
+ }
- printf("%-6.6s%-15.15s %s\n", flags,mask,dev);
+ printf("%-6.6s%-15.15s %s\n", flags, mask, dev);
}
/* Print the contents of an ARP request block. */
-static void
-arp_disp(char *name, char *ip, int type,int arp_flags,char *hwa,char *mask,char *dev)
+static void arp_disp(char *name, char *ip, int type, int arp_flags, char *hwa, char *mask, char *dev)
{
- struct hwtype *xhw;
-
- xhw = get_hwntype(type);
- if (xhw == NULL)
- xhw = get_hwtype(DFLT_HW);
-
+ struct hwtype *xhw;
+ xhw = get_hwntype(type);
+ if (xhw == NULL)
+ xhw = get_hwtype(DFLT_HW);
- printf("%s (%s) at ", name, ip);
+ printf("%s (%s) at ", name, ip);
- if (!(arp_flags & ATF_COM)) {
+ if (!(arp_flags & ATF_COM)) {
if (arp_flags & ATF_PUBL)
- printf("* ");
+ printf("* ");
else
- printf("<incomplete> ");
- } else {
+ printf("<incomplete> ");
+ } else {
printf("%s [%s] ", hwa, xhw->name);
- }
-
- if (arp_flags & ATF_NETMASK)
+ }
+
+ if (arp_flags & ATF_NETMASK)
printf("netmask %s ", mask);
-
- if (arp_flags & ATF_PERM) printf("PERM ");
- if (arp_flags & ATF_PUBL) printf("PUP ");
+
+ if (arp_flags & ATF_PERM)
+ printf("PERM ");
+ if (arp_flags & ATF_PUBL)
+ printf("PUP ");
#ifdef HAVE_ATF_MAGIC
- if (arp_flags & ATF_MAGIC) printf("AUTO ");
+ if (arp_flags & ATF_MAGIC)
+ printf("AUTO ");
#endif
#ifdef HAVE_ATF_DONTPUB
- if (arp_flags & ATF_DONTPUB) printf("DONTPUB ");
+ if (arp_flags & ATF_DONTPUB)
+ printf("DONTPUB ");
#endif
- if (arp_flags & ATF_USETRAILERS) printf("TRAIL ");
+ if (arp_flags & ATF_USETRAILERS)
+ printf("TRAIL ");
- printf("on %s\n", dev);
+ printf("on %s\n", dev);
}
/* Display the contents of the ARP cache in the kernel. */
-static int
-arp_show(char *name)
+static int arp_show(char *name)
{
- char host[100];
- struct sockaddr sa;
- char ip[100];
- char hwa[100];
- char mask[100];
- char line[200];
- char dev[100];
- int type,flags;
- FILE *fp;
- char *hostname;
- int num,entries=0,showed=0;
-
- host[0]='\0';
-
- if (name != NULL) {
- /* Resolve the host name. */
- host[(sizeof host)-1] = 0;
- strncpy(host, name, (sizeof host)-1);
- if (ap->input(0, host, &sa) < 0) {
- ap->herror(host);
- return(-1);
- }
- strcpy(host,ap->sprint(&sa, 1));
- }
-
- /* Open the PROCps kernel table. */
- if ((fp = fopen(_PATH_PROCNET_ARP, "r")) == NULL) {
+ char host[100];
+ struct sockaddr sa;
+ char ip[100];
+ char hwa[100];
+ char mask[100];
+ char line[200];
+ char dev[100];
+ int type, flags;
+ FILE *fp;
+ char *hostname;
+ int num, entries = 0, showed = 0;
+
+ host[0] = '\0';
+
+ if (name != NULL) {
+ /* Resolve the host name. */
+ host[(sizeof host) - 1] = 0;
+ strncpy(host, name, (sizeof host) - 1);
+ if (ap->input(0, host, &sa) < 0) {
+ ap->herror(host);
+ return (-1);
+ }
+ strcpy(host, ap->sprint(&sa, 1));
+ }
+ /* Open the PROCps kernel table. */
+ if ((fp = fopen(_PATH_PROCNET_ARP, "r")) == NULL) {
perror(_PATH_PROCNET_ARP);
- return(-1);
- }
-
- /* Bypass header -- read until newline */
- if (fgets(line, sizeof(line), fp) != (char *)NULL) {
- strcpy(mask,"-");
- strcpy(dev,"-");
+ return (-1);
+ }
+ /* Bypass header -- read until newline */
+ if (fgets(line, sizeof(line), fp) != (char *) NULL) {
+ strcpy(mask, "-");
+ strcpy(dev, "-");
/* Read the ARP cache entries. */
- for(;fgets(line,sizeof(line),fp);)
- {
- num=sscanf(line,"%s 0x%x 0x%x %100s %100s %100s\n",
- ip,&type,&flags,hwa,mask,dev);
- if(num<4)
- break;
-
- entries++;
- /* if the user specified hw-type differs, skip it */
- if (hw_set && (type != hw->type))
- continue;
-
- /* if the user specified address differs, skip it */
- if (host[0] && strcmp(ip,host))
- continue;
-
- /* if the user specified device differs, skip it */
- if (device[0] && strcmp(dev,device))
- continue;
-
- showed++;
- /* This IS ugly but it works -be */
- if (opt_n)
- hostname="?";
- else {
- if (ap->input(0, ip,&sa) < 0)
- hostname=ip;
- else
- hostname = ap->sprint(&sa, opt_n | 0x8000);
- if (strcmp(hostname, ip)==0)
- hostname="?";
- }
+ for (; fgets(line, sizeof(line), fp);) {
+ num = sscanf(line, "%s 0x%x 0x%x %100s %100s %100s\n",
+ ip, &type, &flags, hwa, mask, dev);
+ if (num < 4)
+ break;
+
+ entries++;
+ /* if the user specified hw-type differs, skip it */
+ if (hw_set && (type != hw->type))
+ continue;
+
+ /* if the user specified address differs, skip it */
+ if (host[0] && strcmp(ip, host))
+ continue;
- if (opt_e)
- arp_disp_2(hostname[0]=='?'?ip:hostname,type,flags,hwa,mask,dev);
+ /* if the user specified device differs, skip it */
+ if (device[0] && strcmp(dev, device))
+ continue;
+
+ showed++;
+ /* This IS ugly but it works -be */
+ if (opt_n)
+ hostname = "?";
+ else {
+ if (ap->input(0, ip, &sa) < 0)
+ hostname = ip;
else
- arp_disp(hostname,ip,type,flags,hwa,mask,dev);
+ hostname = ap->sprint(&sa, opt_n | 0x8000);
+ if (strcmp(hostname, ip) == 0)
+ hostname = "?";
+ }
+
+ if (opt_e)
+ arp_disp_2(hostname[0] == '?' ? ip : hostname, type, flags, hwa, mask, dev);
+ else
+ arp_disp(hostname, ip, type, flags, hwa, mask, dev);
+ }
+ }
+ if (opt_v)
+ printf(_("Entries: %d\tSkipped: %d\tFound: %d\n"), entries, entries - showed, showed);
+
+ if (!showed) {
+ if (host[0] && !opt_a)
+ printf("%s (%s) -- no entry\n", name, host);
+ else if (hw_set || host[0] || device[0]) {
+ printf(_("arp: in %d entries no match found.\n"), entries);
}
- }
- if (opt_v)
- printf(_("Entries: %d\tSkipped: %d\tFound: %d\n"),entries,entries-showed,showed);
-
- if (!showed) {
- if (host[0] && !opt_a)
- printf("%s (%s) -- no entry\n", name, host);
- else if (hw_set || host[0] || device[0]) {
- printf(_("arp: in %d entries no match found.\n"),entries);
- }
- }
- (void) fclose(fp);
- return(0);
+ }
+ (void) fclose(fp);
+ return (0);
}
-static void
-version(void)
+static void version(void)
{
- fprintf(stderr, "%s\n%s\n%s\n",Release,Version,Features);
- exit(-1);
+ fprintf(stderr, "%s\n%s\n%s\n", Release, Version, Features);
+ exit(-1);
}
-static void
-usage(void)
+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: 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);
}
-int
-main(int argc, char **argv)
+int main(int argc, char **argv)
{
- int i, lop, what;
- struct option longopts[]=
- {
- {"verbose", 0, 0, 'v'},
- {"version", 0, 0, 'V'},
- {"all", 0, 0, 'a'},
- {"delete", 0, 0, 'd'},
- {"file", 0, 0, 'f'},
- {"numeric", 0, 0, 'n'},
- {"set", 0, 0, 's'},
- {"protocol", 1, 0, 'A'},
- {"hw-type", 1, 0, 'H'},
- {"device", 0, 0, 'i'},
- {"help", 0, 0, 'h'},
- {"use-device", 0, 0, 'D'},
- {"symbolic", 0, 0, 'N'},
- {NULL, 0, 0, 0}
- };
-
+ int i, lop, what;
+ struct option longopts[] =
+ {
+ {"verbose", 0, 0, 'v'},
+ {"version", 0, 0, 'V'},
+ {"all", 0, 0, 'a'},
+ {"delete", 0, 0, 'd'},
+ {"file", 0, 0, 'f'},
+ {"numeric", 0, 0, 'n'},
+ {"set", 0, 0, 's'},
+ {"protocol", 1, 0, 'A'},
+ {"hw-type", 1, 0, 'H'},
+ {"device", 0, 0, 'i'},
+ {"help", 0, 0, 'h'},
+ {"use-device", 0, 0, 'D'},
+ {"symbolic", 0, 0, 'N'},
+ {NULL, 0, 0, 0}
+ };
+
#if I18N
- bindtextdomain("net-tools", "/usr/share/locale");
- textdomain("net-tools");
+ bindtextdomain("net-tools", "/usr/share/locale");
+ textdomain("net-tools");
#endif
- /* Initialize variables... */
- if ((hw = get_hwtype(DFLT_HW)) == NULL) {
+ /* Initialize variables... */
+ if ((hw = get_hwtype(DFLT_HW)) == NULL) {
fprintf(stderr, _("%s: hardware type not supported!\n"), DFLT_HW);
- return(-1);
- }
- if ((ap = get_aftype(DFLT_AF)) == NULL) {
+ return (-1);
+ }
+ if ((ap = get_aftype(DFLT_AF)) == NULL) {
fprintf(stderr, _("%s: address family not supported!\n"), DFLT_AF);
- return(-1);
- }
- what = 0;
+ return (-1);
+ }
+ what = 0;
- /* Fetch the command-line arguments. */
- /* opterr = 0; */
- while ((i = getopt_long(argc, argv, "A:H:adfp:nsei:t:vh?DNV",longopts, &lop)) != EOF) switch(i) {
+ /* Fetch the command-line arguments. */
+ /* opterr = 0; */
+ while ((i = getopt_long(argc, argv, "A:H:adfp:nsei:t:vh?DNV", longopts, &lop)) != EOF)
+ switch (i) {
case 'a':
- what = 1;
- opt_a = 1;
- break;
+ what = 1;
+ opt_a = 1;
+ break;
case 'f':
- what = 2;
- break;
+ what = 2;
+ break;
case 'd':
- what = 3;
- break;
+ what = 3;
+ break;
case 's':
- what = 4;
- break;
+ what = 4;
+ break;
case 'e':
- opt_e = 1;
- break;
+ opt_e = 1;
+ break;
case 'n':
- opt_n = FLAG_NUM;
- break;
+ opt_n = FLAG_NUM;
+ break;
case 'D':
- opt_D = 1;
- break;
+ opt_D = 1;
+ break;
case 'N':
- opt_N = FLAG_SYM;
- fprintf(stderr,"arp: -N not yet supported.\n");
- break;
+ opt_N = FLAG_SYM;
+ fprintf(stderr, "arp: -N not yet supported.\n");
+ break;
case 'v':
- opt_v = 1;
- break;
+ opt_v = 1;
+ break;
case 'A':
case 'p':
- ap = get_aftype(optarg);
- if (ap == NULL) {
- fprintf(stderr, _("arp: %s: unknown address family.\n"),
- optarg);
- exit(-1);
- }
- break;
+ ap = get_aftype(optarg);
+ if (ap == NULL) {
+ fprintf(stderr, _("arp: %s: unknown address family.\n"),
+ optarg);
+ exit(-1);
+ }
+ break;
case 'H':
case 't':
- hw = get_hwtype(optarg);
- if (hw == NULL) {
- fprintf(stderr, _("arp: %s: unknown hardware type.\n"),
- optarg);
- exit(-1);
- }
- hw_set = 1;
- break;
+ hw = get_hwtype(optarg);
+ if (hw == NULL) {
+ fprintf(stderr, _("arp: %s: unknown hardware type.\n"),
+ optarg);
+ exit(-1);
+ }
+ hw_set = 1;
+ break;
case 'i':
- strncpy(device,optarg,sizeof(device)-1);
- device[sizeof(device)-1]='\0';
- break;
+ strncpy(device, optarg, sizeof(device) - 1);
+ device[sizeof(device) - 1] = '\0';
+ break;
case 'V':
- version();
+ version();
case '?':
case 'h':
default:
- usage();
- }
+ usage();
+ }
- if (ap->af != AF_INET) {
+ if (ap->af != AF_INET) {
fprintf(stderr, _("arp: %s: kernel only supports 'inet'.\n"),
- ap->name);
+ ap->name);
exit(-1);
- }
- if (hw->alen <= 0) {
+ }
+ if (hw->alen <= 0) {
fprintf(stderr, _("arp: %s: hardware type without ARP support.\n"),
- hw->name);
+ hw->name);
exit(-1);
- }
- if ((sockfd = socket(AF_INET,SOCK_DGRAM,0)) <0)
- {
- perror("socket");
- exit(-1);
- }
-
- /* Now see what we have to do here... */
- switch(what) {
- case 0:
- opt_e = 1;
- what = arp_show(argv[optind]);
- break;
-
- case 1: /* show an ARP entry in the cache */
- what = arp_show(argv[optind]);
- break;
-
- case 2: /* process an EtherFile */
- what = arp_file(argv[optind]);
- break;
-
- case 3: /* delete an ARP entry from the cache */
- what = arp_del(&argv[optind]);
- break;
-
- case 4: /* set an ARP entry in the cache */
- what = arp_set(&argv[optind]);
- break;
-
- default:
- usage();
- }
+ }
+ if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ perror("socket");
+ exit(-1);
+ }
+ /* Now see what we have to do here... */
+ switch (what) {
+ case 0:
+ opt_e = 1;
+ what = arp_show(argv[optind]);
+ break;
+
+ case 1: /* show an ARP entry in the cache */
+ what = arp_show(argv[optind]);
+ break;
+
+ case 2: /* process an EtherFile */
+ what = arp_file(argv[optind]);
+ break;
+
+ case 3: /* delete an ARP entry from the cache */
+ what = arp_del(&argv[optind]);
+ break;
+
+ case 4: /* set an ARP entry in the cache */
+ what = arp_set(&argv[optind]);
+ break;
+
+ default:
+ usage();
+ }
- exit(what);
+ exit(what);
}
diff --git a/hostname.c b/hostname.c
index cdf0f7c..b566b18 100644
--- a/hostname.c
+++ b/hostname.c
@@ -1,32 +1,32 @@
/*
- * hostname This file contains an implementation of the command
- * that maintains the hostname and the domainname. It
- * is also used to show the FQDN and the IP-Addresses.
+ * hostname This file contains an implementation of the command
+ * that maintains the hostname and the domainname. It
+ * is also used to show the FQDN and the IP-Addresses.
*
- * Usage: hostname [-d|-f|-s|-a|-i|-y]
- * hostname [-h|-V]
- * hostname {name|-F file}
- * dnsdmoainname
- * nisdomainname {name|-F file}
+ * Usage: hostname [-d|-f|-s|-a|-i|-y]
+ * hostname [-h|-V]
+ * hostname {name|-F file}
+ * dnsdmoainname
+ * nisdomainname {name|-F file}
*
- * Version: hostname 1.96 (1996-02-18)
+ * Version: hostname 1.96 (1996-02-18)
*
- * Author: Peter Tobias <tobias@et-inf.fho-emden.de>
+ * Author: Peter Tobias <tobias@et-inf.fho-emden.de>
*
* Changes:
- * {1.90} Peter Tobias : Added -a and -i options.
- * {1.91} Bernd Eckenfels : -v,-V rewritten, long_opts
- * (major rewrite), usage.
- *960120 {1.95} Bernd Eckenfels : -y/nisdomainname - support for get/
- * setdomainname added
- *960218 {1.96} Bernd Eckenfels : netinet/in.h added
+ * {1.90} Peter Tobias : Added -a and -i options.
+ * {1.91} Bernd Eckenfels : -v,-V rewritten, long_opts
+ * (major rewrite), usage.
+ *960120 {1.95} Bernd Eckenfels : -y/nisdomainname - support for get/
+ * setdomainname added
+ *960218 {1.96} Bernd Eckenfels : netinet/in.h added
*980629 {1.97} Arnaldo Carvalho de Melo : gettext instead of catgets for i18n
*
- * 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.
+ * 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 <stdio.h>
#include <unistd.h>
@@ -41,284 +41,284 @@
#include "version.h"
#include "../intl.h"
-char *Release = RELEASE,
- *Version = "hostname 1.97 (1998-06-29)";
-
+char *Release = RELEASE, *Version = "hostname 1.97 (1998-06-29)";
+
static char *program_name;
-static int opt_v;
+static int opt_v;
static void sethname(char *);
static void setdname(char *);
static void showhname(char *, int);
static void usage(void);
static void version(void);
-static void setfilename(char *,int);
+static void setfilename(char *, int);
#define SETHOST 1
#define SETDOMAIN 2
static void sethname(char *hname)
{
- if (opt_v)
- fprintf(stderr,_("Setting hostname to `%s'\n"),
- hname);
- if(sethostname(hname, strlen(hname))) {
- switch(errno) {
- case EPERM:
- fprintf(stderr,_("%s: you must be root to change the host name\n"), program_name);
- break;
- case EINVAL:
- fprintf(stderr,_("%s: name too long\n"), program_name);
- break;
- default:
- }
- exit(1);
- };
+ if (opt_v)
+ fprintf(stderr, _("Setting hostname to `%s'\n"),
+ hname);
+ if (sethostname(hname, strlen(hname))) {
+ switch (errno) {
+ case EPERM:
+ fprintf(stderr, _("%s: you must be root to change the host name\n"), program_name);
+ break;
+ case EINVAL:
+ fprintf(stderr, _("%s: name too long\n"), program_name);
+ break;
+ default:
+ }
+ exit(1);
+ };
}
static void setdname(char *dname)
{
- if (opt_v)
- fprintf(stderr,_("Setting domainname to `%s'\n"),
- dname);
- if(setdomainname(dname, strlen(dname))) {
- switch(errno) {
- case EPERM:
- fprintf(stderr,_("%s: you must be root to change the domain name\n"), program_name);
- break;
- case EINVAL:
- fprintf(stderr,_("%s: name too long\n"), program_name);
- break;
- default:
- }
- exit(1);
- };
+ if (opt_v)
+ fprintf(stderr, _("Setting domainname to `%s'\n"),
+ dname);
+ if (setdomainname(dname, strlen(dname))) {
+ switch (errno) {
+ case EPERM:
+ fprintf(stderr, _("%s: you must be root to change the domain name\n"), program_name);
+ break;
+ case EINVAL:
+ fprintf(stderr, _("%s: name too long\n"), program_name);
+ break;
+ default:
+ }
+ exit(1);
+ };
}
static void showhname(char *hname, int c)
{
- struct hostent *hp;
- register char *p,**alias;
- struct in_addr **ip;
-
- if (opt_v)
- fprintf(stderr,_("Resolving `%s' ...\n"),hname);
- if (!(hp = gethostbyname(hname))) {
- herror(program_name);
- exit(1);
- }
+ struct hostent *hp;
+ register char *p, **alias;
+ struct in_addr **ip;
- if (opt_v) {
- fprintf(stderr,_("Result: h_name=`%s'\n"),
- hp->h_name);
-
- alias=hp->h_aliases;
- while(alias[0])
- fprintf(stderr,_("Result: h_aliases=`%s'\n"),
- *alias++);
-
- ip=(struct in_addr **)hp->h_addr_list;
- while(ip[0])
- fprintf(stderr,_("Result: h_addr_list=`%s'\n"),
- inet_ntoa(**ip++));
- }
+ if (opt_v)
+ fprintf(stderr, _("Resolving `%s' ...\n"), hname);
+ if (!(hp = gethostbyname(hname))) {
+ herror(program_name);
+ exit(1);
+ }
+ if (opt_v) {
+ fprintf(stderr, _("Result: h_name=`%s'\n"),
+ hp->h_name);
- if (!(p = strchr(hp->h_name, '.')) && (c == 'd')) return;
+ alias = hp->h_aliases;
+ while (alias[0])
+ fprintf(stderr, _("Result: h_aliases=`%s'\n"),
+ *alias++);
- switch(c) {
- case 'a':
- while (hp->h_aliases[0])
- printf("%s ", *hp->h_aliases++);
- printf("\n");
- break;
- case 'i':
- while (hp->h_addr_list[0])
- printf("%s ", inet_ntoa(*(struct in_addr *) * hp->h_addr_list++));
- printf("\n");
- break;
- case 'd':
- printf("%s\n", ++p);
- break;
- case 'f':
- printf("%s\n", hp->h_name);
- break;
- case 's':
- if (p != NULL) *p = '\0';
- printf("%s\n", hp->h_name);
- break;
- default:
- }
+ ip = (struct in_addr **) hp->h_addr_list;
+ while (ip[0])
+ fprintf(stderr, _("Result: h_addr_list=`%s'\n"),
+ inet_ntoa(**ip++));
+ }
+ if (!(p = strchr(hp->h_name, '.')) && (c == 'd'))
+ return;
+
+ switch (c) {
+ case 'a':
+ while (hp->h_aliases[0])
+ printf("%s ", *hp->h_aliases++);
+ printf("\n");
+ break;
+ case 'i':
+ while (hp->h_addr_list[0])
+ printf("%s ", inet_ntoa(*(struct in_addr *) *hp->h_addr_list++));
+ printf("\n");
+ break;
+ case 'd':
+ printf("%s\n", ++p);
+ break;
+ case 'f':
+ printf("%s\n", hp->h_name);
+ break;
+ case 's':
+ if (p != NULL)
+ *p = '\0';
+ printf("%s\n", hp->h_name);
+ break;
+ default:
+ }
}
-static void setfilename(char * name,int what)
-{
- register FILE *fd;
- register char *p;
- char fline[MAXHOSTNAMELEN];
+static void setfilename(char *name, int what)
+{
+ register FILE *fd;
+ register char *p;
+ char fline[MAXHOSTNAMELEN];
- if ((fd = fopen(name, "r")) != NULL) {
+ if ((fd = fopen(name, "r")) != NULL) {
while (fgets(fline, sizeof(fline), fd) != NULL) {
- if ((p = index(fline, '\n')) != NULL)
- *p = '\0';
- if (opt_v) fprintf(stderr, ">> %s\n", fline);
- if (fline[0] == '#')
- continue;
- if (what == SETHOST) {
- sethname(fline);
- } else {
- setdname(fline);
- }
+ if ((p = index(fline, '\n')) != NULL)
+ *p = '\0';
+ if (opt_v)
+ fprintf(stderr, ">> %s\n", fline);
+ if (fline[0] == '#')
+ continue;
+ if (what == SETHOST) {
+ sethname(fline);
+ } else {
+ setdname(fline);
+ }
}
(void) fclose(fd);
- } else {
- fprintf(stderr,_("%s: can't open `%s'\n"),
- program_name, optarg);
+ } else {
+ fprintf(stderr, _("%s: can't open `%s'\n"),
+ program_name, optarg);
exit(1);
- }
+ }
}
static void version(void)
{
- fprintf(stderr,"%s\n%s\n",Release,Version);
- exit(-1);
+ fprintf(stderr, "%s\n%s\n", Release, Version);
+ exit(-1);
}
static void usage(void)
{
- fprintf(stderr,_("Usage: hostname [-v] {hostname|-F file} set hostname (from file)\n"));
- fprintf(stderr,_(" domainname [-v] {nisdomain|-F file} set NIS domainname (from file)\n"));
- fprintf(stderr,_(" hostname [-v] [-d|-f|-s|-a|-i|-y] display formated name\n"));
- fprintf(stderr,_(" hostname [-v] display hostname\n\n"));
- fprintf(stderr,_(" hostname -V|--version|-h|--help print info and exit\n\n"));
- fprintf(stderr,_(" dnsdomainname=hostname -d, {yp,nis,}domainname=hostname -y\n\n"));
- fprintf(stderr,_(" -s, --short short host name\n"));
- fprintf(stderr,_(" -a, --alias alias names\n"));
- fprintf(stderr,_(" -i, --ip-address addresses for the hostname\n"));
- fprintf(stderr,_(" -f, --fqdn, --long long host name (FQDN)\n"));
- fprintf(stderr,_(" -d, --domain DNS domain name\n"));
- fprintf(stderr,_(" -y, --yp, --nis NIS/YP domainname\n"));
- fprintf(stderr,_(" -F, --file read hostname or nis domainname from given File\n\n"));
- fprintf(stderr,_(" This comand can get or set the hostname or the NIS domainname. You can\n"));
- fprintf(stderr,_(" also get the DNS domain or the FQDN (fully qualified domain name).\n"));
- 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);
+ fprintf(stderr, _("Usage: hostname [-v] {hostname|-F file} set hostname (from file)\n"));
+ fprintf(stderr, _(" domainname [-v] {nisdomain|-F file} set NIS domainname (from file)\n"));
+ fprintf(stderr, _(" hostname [-v] [-d|-f|-s|-a|-i|-y] display formated name\n"));
+ fprintf(stderr, _(" hostname [-v] display hostname\n\n"));
+ fprintf(stderr, _(" hostname -V|--version|-h|--help print info and exit\n\n"));
+ fprintf(stderr, _(" dnsdomainname=hostname -d, {yp,nis,}domainname=hostname -y\n\n"));
+ fprintf(stderr, _(" -s, --short short host name\n"));
+ fprintf(stderr, _(" -a, --alias alias names\n"));
+ fprintf(stderr, _(" -i, --ip-address addresses for the hostname\n"));
+ fprintf(stderr, _(" -f, --fqdn, --long long host name (FQDN)\n"));
+ fprintf(stderr, _(" -d, --domain DNS domain name\n"));
+ fprintf(stderr, _(" -y, --yp, --nis NIS/YP domainname\n"));
+ fprintf(stderr, _(" -F, --file read hostname or nis domainname from given File\n\n"));
+ fprintf(stderr, _(" This comand can get or set the hostname or the NIS domainname. You can\n"));
+ fprintf(stderr, _(" also get the DNS domain or the FQDN (fully qualified domain name).\n"));
+ 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);
}
int main(int argc, char **argv)
{
- int c;
- char type='\0';
- int option_index = 0;
- int what = 0;
- char myname[MAXHOSTNAMELEN+1] = { 0 };
- char *file=NULL;
+ int c;
+ char type = '\0';
+ int option_index = 0;
+ int what = 0;
+ char myname[MAXHOSTNAMELEN + 1] =
+ {0};
+ char *file = NULL;
- static const struct option long_options[] =
- {
- {"domain", no_argument, 0, 'd'},
- {"file", required_argument, 0, 'F'},
- {"fqdn", no_argument, 0, 'f'},
- {"help", no_argument, 0, 'h'},
- {"long", no_argument, 0, 'f'},
- {"short", no_argument, 0, 's'},
- {"version", no_argument, 0, 'V'},
- {"verbose", no_argument, 0, 'v'},
- {"alias", no_argument, 0, 'a'},
- {"ip-address", no_argument, 0, 'i'},
- {"nis", no_argument, 0, 'y'},
- {"yp", no_argument, 0, 'y'},
- {0, 0, 0, 0}
- };
+ static const struct option long_options[] =
+ {
+ {"domain", no_argument, 0, 'd'},
+ {"file", required_argument, 0, 'F'},
+ {"fqdn", no_argument, 0, 'f'},
+ {"help", no_argument, 0, 'h'},
+ {"long", no_argument, 0, 'f'},
+ {"short", no_argument, 0, 's'},
+ {"version", no_argument, 0, 'V'},
+ {"verbose", no_argument, 0, 'v'},
+ {"alias", no_argument, 0, 'a'},
+ {"ip-address", no_argument, 0, 'i'},
+ {"nis", no_argument, 0, 'y'},
+ {"yp", no_argument, 0, 'y'},
+ {0, 0, 0, 0}
+ };
#if I18N
- bindtextdomain("net-tools", "/usr/share/locale");
- textdomain("net-tools");
+ bindtextdomain("net-tools", "/usr/share/locale");
+ textdomain("net-tools");
#endif
- program_name = (rindex(argv[0], '/')) ? rindex(argv[0], '/') + 1 : argv[0];
+ program_name = (rindex(argv[0], '/')) ? rindex(argv[0], '/') + 1 : argv[0];
+
+ if (!strcmp(program_name, "ypdomainname") ||
+ !strcmp(program_name, "domainname") ||
+ !strcmp(program_name, "nisdomainname"))
+ what = 3;
+ if (!strcmp(program_name, "dnsdomainname"))
+ what = 2;
- if (!strcmp(program_name,"ypdomainname") ||
- !strcmp(program_name,"domainname") ||
- !strcmp(program_name,"nisdomainname"))
- what = 3;
- if (!strcmp(program_name,"dnsdomainname"))
- what = 2;
-
- while((c = getopt_long(argc, argv, "adfF:h?isVvy", long_options, &option_index)) != EOF)
- switch(c)
- {
- case 'd':
- what = 2;
- break;
- case 'a':
- case 'f':
- case 'i':
- case 's':
- what = 1;
- type=c;
- break;
- case 'y':
- what = 3;
- break;
- case 'F':
- file=optarg;
- break;
- case 'v':
- opt_v++;
- break;
- case 'V':
- version();
- case '?':
- case 'h':
- default:
- usage();
+ while ((c = getopt_long(argc, argv, "adfF:h?isVvy", long_options, &option_index)) != EOF)
+ switch (c) {
+ case 'd':
+ what = 2;
+ break;
+ case 'a':
+ case 'f':
+ case 'i':
+ case 's':
+ what = 1;
+ type = c;
+ break;
+ case 'y':
+ what = 3;
+ break;
+ case 'F':
+ file = optarg;
+ break;
+ case 'v':
+ opt_v++;
+ break;
+ case 'V':
+ version();
+ case '?':
+ case 'h':
+ default:
+ usage();
};
- switch(what) {
- case 2:
- if (file || (optind < argc)) {
- fprintf(stderr,_("%s: You can't change the DNS domain name with this command\n"), program_name);
- fprintf(stderr,_("\nUnless you are using bind or NIS for host lookups you can change the DNS\n"));
- fprintf(stderr,_("domain name (which is part of the FQDN) in the /etc/hosts file.\n"));
- exit(1);
- }
- type='d';
- /* NOBREAK */
- case 0:
- if (file) {
- setfilename(file,SETHOST);
- break;
- }
- if (optind < argc) {
- sethname(argv[optind]);
- break;
- }
- case 1:
- gethostname(myname, sizeof(myname));
- if (opt_v)
- fprintf(stderr,_("gethostname()=`%s'\n"),myname);
- if (!type)
- printf("%s\n",myname);
- else
- showhname(myname,type);
- break;
- case 3:
- if (file) {
- setfilename(file,SETDOMAIN);
- break;
- }
- if (optind < argc) {
- setdname(argv[optind]);
- break;
- }
- getdomainname(myname,sizeof(myname));
- if (opt_v)
- fprintf(stderr,_("getdomainname()=`%s'\n"),myname);
- printf("%s\n",myname);
- break;
+ switch (what) {
+ case 2:
+ if (file || (optind < argc)) {
+ fprintf(stderr, _("%s: You can't change the DNS domain name with this command\n"), program_name);
+ fprintf(stderr, _("\nUnless you are using bind or NIS for host lookups you can change the DNS\n"));
+ fprintf(stderr, _("domain name (which is part of the FQDN) in the /etc/hosts file.\n"));
+ exit(1);
}
- exit(0);
+ type = 'd';
+ /* NOBREAK */
+ case 0:
+ if (file) {
+ setfilename(file, SETHOST);
+ break;
+ }
+ if (optind < argc) {
+ sethname(argv[optind]);
+ break;
+ }
+ case 1:
+ gethostname(myname, sizeof(myname));
+ if (opt_v)
+ fprintf(stderr, _("gethostname()=`%s'\n"), myname);
+ if (!type)
+ printf("%s\n", myname);
+ else
+ showhname(myname, type);
+ break;
+ case 3:
+ if (file) {
+ setfilename(file, SETDOMAIN);
+ break;
+ }
+ if (optind < argc) {
+ setdname(argv[optind]);
+ break;
+ }
+ getdomainname(myname, sizeof(myname));
+ if (opt_v)
+ fprintf(stderr, _("getdomainname()=`%s'\n"), myname);
+ printf("%s\n", myname);
+ break;
+ }
+ exit(0);
}
diff --git a/ifconfig.c b/ifconfig.c
index 1d1f467..efebfca 100644
--- a/ifconfig.c
+++ b/ifconfig.c
@@ -1,21 +1,21 @@
/*
- * ifconfig This file contains an implementation of the command
- * that either displays or sets the characteristics of
- * one or more of the system's networking interfaces.
+ * ifconfig This file contains an implementation of the command
+ * that either displays or sets the characteristics of
+ * one or more of the system's networking interfaces.
*
- * Version: ifconfig 1.34 (1998-06-30)
+ * Version: $Id: ifconfig.c,v 1.18 1998/11/15 20:07:42 freitag Exp $
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* and others. Copyright 1993 MicroWalt Corporation
*
- * 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.
+ * 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.
* {1.34} - 19980630 - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
* - gettext instead of catgets for i18n
- * 10/1998 - Andi Kleen. Use interface list primitives.
+ * 10/1998 - Andi Kleen. Use interface list primitives.
*/
#include "config.h"
@@ -47,21 +47,21 @@
#ifndef _LINUX_IN6_H
/*
- * This is in linux/include/net/ipv6.h.
+ * This is in linux/include/net/ipv6.h.
*/
struct in6_ifreq {
- struct in6_addr ifr6_addr;
- __u32 ifr6_prefixlen;
- unsigned int ifr6_ifindex;
+ struct in6_addr ifr6_addr;
+ __u32 ifr6_prefixlen;
+ unsigned int ifr6_ifindex;
};
#endif
-
+
#define IPV6_ADDR_ANY 0x0000U
-#define IPV6_ADDR_UNICAST 0x0001U
-#define IPV6_ADDR_MULTICAST 0x0002U
+#define IPV6_ADDR_UNICAST 0x0001U
+#define IPV6_ADDR_MULTICAST 0x0002U
#define IPV6_ADDR_ANYCAST 0x0004U
#define IPV6_ADDR_LOOPBACK 0x0010U
@@ -73,21 +73,22 @@ struct in6_ifreq {
#define IPV6_ADDR_SCOPE_MASK 0x00f0U
#define IPV6_ADDR_MAPPED 0x1000U
-#define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */
+#define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */
-#endif /* HAVE_AFINET6 */
+#endif /* HAVE_AFINET6 */
#ifdef IFF_PORTSEL
-static const char *if_port_text[][4] = {
+static const char *if_port_text[][4] =
+{
/* Keep in step with <linux/netdevice.h> */
- { "unknown", NULL , NULL, NULL },
- { "10base2", "bnc", "coax", NULL },
- { "10baseT", "utp", "tpe", NULL },
- { "AUI", "thick", "db15", NULL },
- { "100baseT", NULL, NULL, NULL },
- { "100baseTX", NULL, NULL, NULL },
- { "100baseFX", NULL, NULL, NULL },
- { NULL, NULL, NULL, NULL },
+ {"unknown", NULL, NULL, NULL},
+ {"10base2", "bnc", "coax", NULL},
+ {"10baseT", "utp", "tpe", NULL},
+ {"AUI", "thick", "db15", NULL},
+ {"100baseT", NULL, NULL, NULL},
+ {"100baseTX", NULL, NULL, NULL},
+ {"100baseFX", NULL, NULL, NULL},
+ {NULL, NULL, NULL, NULL},
};
#endif
@@ -105,242 +106,266 @@ static const char *if_port_text[][4] = {
#include "interface.h"
#include "sockets.h"
-char *Release = RELEASE,
- *Version = "ifconfig 1.36 (1998-10-31)";
+char *Release = RELEASE, *Version = "ifconfig 1.36 (1998-10-31)";
-int opt_a = 0; /* show all interfaces */
-int opt_i = 0; /* show the statistics */
-int opt_v = 0; /* debugging output flag */
+int opt_a = 0; /* show all interfaces */
+int opt_i = 0; /* show the statistics */
+int opt_v = 0; /* debugging output flag */
-int addr_family = 0; /* currently selected AF */
+int addr_family = 0; /* currently selected AF */
-static void
-ife_print(struct interface *ptr)
+static void ife_print(struct interface *ptr)
{
- struct aftype *ap;
- struct hwtype *hw;
- int hf;
- int can_compress = 0;
+ struct aftype *ap;
+ struct hwtype *hw;
+ int hf;
+ int can_compress = 0;
#if HAVE_AFIPX
- static struct aftype *ipxtype=NULL;
+ static struct aftype *ipxtype = NULL;
#endif
#if HAVE_AFECONET
- static struct aftype *ectype = NULL;
+ static struct aftype *ectype = NULL;
#endif
#if HAVE_AFATALK
- static struct aftype *ddptype = NULL;
+ static struct aftype *ddptype = NULL;
#endif
#if HAVE_AFINET6
- FILE *f;
- char addr6[40], devname[20];
- struct sockaddr_in6 sap;
- int plen, scope, dad_status, if_idx;
- extern struct aftype inet6_aftype;
- char addr6p[8][5];
-
- if (!strncmp(ptr->name, "sit", 3))
- ptr->addr.sa_family = AF_INET6; /* fix this up properly one day */
+ FILE *f;
+ char addr6[40], devname[20];
+ struct sockaddr_in6 sap;
+ int plen, scope, dad_status, if_idx;
+ extern struct aftype inet6_aftype;
+ char addr6p[8][5];
+
+ if (!strncmp(ptr->name, "sit", 3))
+ ptr->addr.sa_family = AF_INET6; /* fix this up properly one day */
#endif
- ap = get_afntype(ptr->addr.sa_family);
- if (ap == NULL) ap = get_afntype(0);
-
- hf=ptr->type;
-
- if (strncmp(ptr->name, "lo", 2) == 0)
- hf=255;
-
- if (hf==ARPHRD_CSLIP || hf==ARPHRD_CSLIP6)
- can_compress = 1;
-
- hw = get_hwntype(hf);
- if (hw == NULL) hw = get_hwntype(-1);
-
- printf(_("%-8.8s Link encap:%s "), ptr->name, hw->title);
- /* Don't print the hardware address for ATM or Ash if it's null. */
- if (hw->sprint != NULL && ((strncmp(ptr->name, "atm", 3) &&
- strncmp(ptr->name, "ash", 3)) ||
- (ptr->hwaddr[0] || ptr->hwaddr[1] || ptr->hwaddr[2] || ptr->hwaddr[3] ||
- ptr->hwaddr[4] || ptr->hwaddr[5])))
- printf(_("HWaddr %s "), hw->print(ptr->hwaddr));
+ ap = get_afntype(ptr->addr.sa_family);
+ if (ap == NULL)
+ ap = get_afntype(0);
+
+ hf = ptr->type;
+
+ if (strncmp(ptr->name, "lo", 2) == 0)
+ hf = 255;
+
+ if (hf == ARPHRD_CSLIP || hf == ARPHRD_CSLIP6)
+ can_compress = 1;
+
+ hw = get_hwntype(hf);
+ if (hw == NULL)
+ hw = get_hwntype(-1);
+
+ printf(_("%-8.8s Link encap:%s "), ptr->name, hw->title);
+ /* Don't print the hardware address for ATM or Ash if it's null. */
+ if (hw->sprint != NULL && ((strncmp(ptr->name, "atm", 3) &&
+ strncmp(ptr->name, "ash", 3)) ||
+ (ptr->hwaddr[0] || ptr->hwaddr[1] || ptr->hwaddr[2] || ptr->hwaddr[3] ||
+ ptr->hwaddr[4] || ptr->hwaddr[5])))
+ printf(_("HWaddr %s "), hw->print(ptr->hwaddr));
#ifdef IFF_PORTSEL
- if (ptr->flags & IFF_PORTSEL)
- printf(_("Media:%s%s"), if_port_text[ptr->map.port][0],
- (ptr->flags & IFF_AUTOMEDIA)?_("(auto)"):"");
+ if (ptr->flags & IFF_PORTSEL)
+ printf(_("Media:%s%s"), if_port_text[ptr->map.port][0],
+ (ptr->flags & IFF_AUTOMEDIA) ? _("(auto)") : "");
#endif
- printf("\n");
-#if HAVE_AFINET6
- if (ap->af != AF_INET6) {
+ printf("\n");
+#if HAVE_AFINET6
+ if (ap->af != AF_INET6) {
#endif
- printf(_(" %s addr:%s "), ap->name,
- ap->sprint(&ptr->addr, 1));
- if (ptr->flags & IFF_POINTOPOINT) {
- printf(_(" P-t-P:%s "), ap->sprint(&ptr->dstaddr, 1));
- }
- if (ptr->flags & IFF_BROADCAST) {
- printf(_(" Bcast:%s "), ap->sprint(&ptr->broadaddr, 1));
- }
- printf(_(" Mask:%s\n"), ap->sprint(&ptr->netmask, 1));
+ printf(_(" %s addr:%s "), ap->name,
+ ap->sprint(&ptr->addr, 1));
+ if (ptr->flags & IFF_POINTOPOINT) {
+ printf(_(" P-t-P:%s "), ap->sprint(&ptr->dstaddr, 1));
+ }
+ if (ptr->flags & IFF_BROADCAST) {
+ printf(_(" Bcast:%s "), ap->sprint(&ptr->broadaddr, 1));
+ }
+ printf(_(" Mask:%s\n"), ap->sprint(&ptr->netmask, 1));
#if HAVE_AFINET6
- }
- /* FIXME: should be integrated into interface.c. */
-
- if ((f = fopen(_PATH_PROCNET_IFINET6, "r")) != NULL) {
- while(fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n",
- addr6p[0], addr6p[1], addr6p[2], addr6p[3],
- addr6p[4], addr6p[5], addr6p[6], addr6p[7],
- &if_idx, &plen, &scope, &dad_status, devname) != EOF) {
- if (!strcmp(devname, ptr->name)) {
- sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s",
- addr6p[0], addr6p[1], addr6p[2], addr6p[3],
- addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
- inet6_aftype.input(1, addr6, (struct sockaddr *)&sap);
- printf(_(" inet6 addr: %s/%d"),
- inet6_aftype.sprint((struct sockaddr *)&sap, 1), plen);
- printf(_(" Scope:"));
- switch (scope) {
- case 0: printf(_("Global")); break;
- case IPV6_ADDR_LINKLOCAL: printf(_("Link")); break;
- case IPV6_ADDR_SITELOCAL: printf(_("Site")); break;
- case IPV6_ADDR_COMPATv4: printf(_("Compat")); break;
- case IPV6_ADDR_LOOPBACK: printf(_("Host")); break;
- default: printf(_("Unknown"));
+ }
+ /* FIXME: should be integrated into interface.c. */
+
+ if ((f = fopen(_PATH_PROCNET_IFINET6, "r")) != NULL) {
+ while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n",
+ addr6p[0], addr6p[1], addr6p[2], addr6p[3],
+ addr6p[4], addr6p[5], addr6p[6], addr6p[7],
+ &if_idx, &plen, &scope, &dad_status, devname) != EOF) {
+ if (!strcmp(devname, ptr->name)) {
+ sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s",
+ addr6p[0], addr6p[1], addr6p[2], addr6p[3],
+ addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
+ inet6_aftype.input(1, addr6, (struct sockaddr *) &sap);
+ printf(_(" inet6 addr: %s/%d"),
+ inet6_aftype.sprint((struct sockaddr *) &sap, 1), plen);
+ printf(_(" Scope:"));
+ switch (scope) {
+ case 0:
+ printf(_("Global"));
+ break;
+ case IPV6_ADDR_LINKLOCAL:
+ printf(_("Link"));
+ break;
+ case IPV6_ADDR_SITELOCAL:
+ printf(_("Site"));
+ break;
+ case IPV6_ADDR_COMPATv4:
+ printf(_("Compat"));
+ break;
+ case IPV6_ADDR_LOOPBACK:
+ printf(_("Host"));
+ break;
+ default:
+ printf(_("Unknown"));
+ }
+ printf("\n");
+ }
}
- printf("\n");
- }
+ fclose(f);
}
- fclose(f);
- }
#endif
-
+
#if HAVE_AFIPX
- if (ipxtype==NULL)
- ipxtype=get_afntype(AF_IPX);
-
- if (ipxtype!=NULL) {
- if(ptr->has_ipx_bb)
- printf(_(" IPX/Ethernet II addr:%s\n"),
- ipxtype->sprint(&ptr->ipxaddr_bb,1));
- if(ptr->has_ipx_sn)
- printf(_(" IPX/Ethernet SNAP addr:%s\n"),
- ipxtype->sprint(&ptr->ipxaddr_sn,1));
- if(ptr->has_ipx_e2)
- printf(_(" IPX/Ethernet 802.2 addr:%s\n"),
- ipxtype->sprint(&ptr->ipxaddr_e2,1));
- if(ptr->has_ipx_e3)
- printf(_(" IPX/Ethernet 802.3 addr:%s\n"),
- ipxtype->sprint(&ptr->ipxaddr_e3,1));
- }
+ if (ipxtype == NULL)
+ ipxtype = get_afntype(AF_IPX);
+
+ if (ipxtype != NULL) {
+ if (ptr->has_ipx_bb)
+ printf(_(" IPX/Ethernet II addr:%s\n"),
+ ipxtype->sprint(&ptr->ipxaddr_bb, 1));
+ if (ptr->has_ipx_sn)
+ printf(_(" IPX/Ethernet SNAP addr:%s\n"),
+ ipxtype->sprint(&ptr->ipxaddr_sn, 1));
+ if (ptr->has_ipx_e2)
+ printf(_(" IPX/Ethernet 802.2 addr:%s\n"),
+ ipxtype->sprint(&ptr->ipxaddr_e2, 1));
+ if (ptr->has_ipx_e3)
+ printf(_(" IPX/Ethernet 802.3 addr:%s\n"),
+ ipxtype->sprint(&ptr->ipxaddr_e3, 1));
+ }
#endif
#if HAVE_AFATALK
- if (ddptype==NULL)
- ddptype=get_afntype(AF_APPLETALK);
- if (ddptype!=NULL) {
- if (ptr->has_ddp)
- printf(_(" EtherTalk Phase 2 addr:%s\n"), ddptype->sprint(&ptr->ddpaddr,1));
- }
+ if (ddptype == NULL)
+ ddptype = get_afntype(AF_APPLETALK);
+ if (ddptype != NULL) {
+ if (ptr->has_ddp)
+ printf(_(" 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(_(" econet addr:%s\n"), ectype->sprint(&ptr->ecaddr,1));
- }
+ if (ectype == NULL)
+ ectype = get_afntype(AF_ECONET);
+ if (ectype != NULL) {
+ if (ptr->has_econet)
+ printf(_(" econet addr:%s\n"), ectype->sprint(&ptr->ecaddr, 1));
+ }
#endif
- printf(" ");
- if (ptr->flags == 0) printf(_("[NO FLAGS] "));
- if (ptr->flags & IFF_UP) printf(_("UP "));
- if (ptr->flags & IFF_BROADCAST) printf(_("BROADCAST "));
- if (ptr->flags & IFF_DEBUG) printf(_("DEBUG "));
- if (ptr->flags & IFF_LOOPBACK) printf(_("LOOPBACK "));
- if (ptr->flags & IFF_POINTOPOINT) printf(_("POINTOPOINT "));
- if (ptr->flags & IFF_NOTRAILERS) printf(_("NOTRAILERS "));
- if (ptr->flags & IFF_RUNNING) printf(_("RUNNING "));
- if (ptr->flags & IFF_NOARP) printf(_("NOARP "));
- if (ptr->flags & IFF_PROMISC) printf(_("PROMISC "));
- if (ptr->flags & IFF_ALLMULTI) printf(_("ALLMULTI "));
- if (ptr->flags & IFF_SLAVE) printf(_("SLAVE "));
- if (ptr->flags & IFF_MASTER) printf(_("MASTER "));
- if (ptr->flags & IFF_MULTICAST) printf(_("MULTICAST "));
+ printf(" ");
+ if (ptr->flags == 0)
+ printf(_("[NO FLAGS] "));
+ if (ptr->flags & IFF_UP)
+ printf(_("UP "));
+ if (ptr->flags & IFF_BROADCAST)
+ printf(_("BROADCAST "));
+ if (ptr->flags & IFF_DEBUG)
+ printf(_("DEBUG "));
+ if (ptr->flags & IFF_LOOPBACK)
+ printf(_("LOOPBACK "));
+ if (ptr->flags & IFF_POINTOPOINT)
+ printf(_("POINTOPOINT "));
+ if (ptr->flags & IFF_NOTRAILERS)
+ printf(_("NOTRAILERS "));
+ if (ptr->flags & IFF_RUNNING)
+ printf(_("RUNNING "));
+ if (ptr->flags & IFF_NOARP)
+ printf(_("NOARP "));
+ if (ptr->flags & IFF_PROMISC)
+ printf(_("PROMISC "));
+ if (ptr->flags & IFF_ALLMULTI)
+ printf(_("ALLMULTI "));
+ if (ptr->flags & IFF_SLAVE)
+ printf(_("SLAVE "));
+ if (ptr->flags & IFF_MASTER)
+ printf(_("MASTER "));
+ if (ptr->flags & IFF_MULTICAST)
+ printf(_("MULTICAST "));
#ifdef HAVE_DYNAMIC
- if (ptr->flags & IFF_DYNAMIC) printf(_("DYNAMIC "));
-#endif
+ if (ptr->flags & IFF_DYNAMIC)
+ printf(_("DYNAMIC "));
+#endif
- printf(_(" MTU:%d Metric:%d"),
- ptr->mtu, ptr->metric?ptr->metric:1);
+ printf(_(" MTU:%d Metric:%d"),
+ ptr->mtu, ptr->metric ? ptr->metric : 1);
#ifdef SIOCSKEEPALIVE
- if (ptr->outfill || ptr->keepalive)
- printf(_(" Outfill:%d Keepalive:%d"),
- ptr->outfill, ptr->keepalive);
+ if (ptr->outfill || ptr->keepalive)
+ printf(_(" Outfill:%d Keepalive:%d"),
+ ptr->outfill, ptr->keepalive);
#endif
- printf("\n");
-
- /* If needed, display the interface statistics. */
-
- if (ptr->statistics_valid) {
- /* XXX: statistics are currently only printed for the original address,
- * not for the aliases, although strictly speaking they're shared
- * by all addresses.
- */
- printf(" ");
-
- printf(_("RX packets:%lu errors:%lu dropped:%lu overruns:%lu frame:%lu\n"),
- ptr->stats.rx_packets, ptr->stats.rx_errors,
- ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors,
- ptr->stats.rx_frame_errors);
- if (can_compress)
- printf(_(" compressed:%lu\n"), ptr->stats.rx_compressed);
-
- printf(" ");
-
- printf(_("TX packets:%lu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n"),
- 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);
- if (can_compress)
- printf(_("compressed:%lu "), ptr->stats.tx_compressed);
- if (ptr->tx_queue_len != -1)
- printf(_("txqueuelen:%d "), ptr->tx_queue_len);
- printf("\n");
- }
-
- if ((ptr->map.irq || ptr->map.mem_start || ptr->map.dma ||
- ptr->map.base_addr)) {
- printf(" ");
- if (ptr->map.irq)
- printf(_("Interrupt:%d "), ptr->map.irq);
- if (ptr->map.base_addr>=0x100) /* Only print devices using it for
- I/O maps */
- printf(_("Base address:0x%x "), ptr->map.base_addr);
- if (ptr->map.mem_start) {
- printf(_("Memory:%lx-%lx "), ptr->map.mem_start,ptr->map.mem_end);
+ printf("\n");
+
+ /* If needed, display the interface statistics. */
+
+ if (ptr->statistics_valid) {
+ /* XXX: statistics are currently only printed for the original address,
+ * not for the aliases, although strictly speaking they're shared
+ * by all addresses.
+ */
+ printf(" ");
+
+ printf(_("RX packets:%lu errors:%lu dropped:%lu overruns:%lu frame:%lu\n"),
+ ptr->stats.rx_packets, ptr->stats.rx_errors,
+ ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors,
+ ptr->stats.rx_frame_errors);
+ if (can_compress)
+ printf(_(" compressed:%lu\n"), ptr->stats.rx_compressed);
+
+ printf(" ");
+
+ printf(_("TX packets:%lu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n"),
+ 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);
+ if (can_compress)
+ printf(_("compressed:%lu "), ptr->stats.tx_compressed);
+ if (ptr->tx_queue_len != -1)
+ printf(_("txqueuelen:%d "), ptr->tx_queue_len);
+ printf("\n");
+ }
+ if ((ptr->map.irq || ptr->map.mem_start || ptr->map.dma ||
+ ptr->map.base_addr)) {
+ printf(" ");
+ if (ptr->map.irq)
+ printf(_("Interrupt:%d "), ptr->map.irq);
+ if (ptr->map.base_addr >= 0x100) /* Only print devices using it for
+ I/O maps */
+ printf(_("Base address:0x%x "), ptr->map.base_addr);
+ if (ptr->map.mem_start) {
+ printf(_("Memory:%lx-%lx "), ptr->map.mem_start, ptr->map.mem_end);
+ }
+ if (ptr->map.dma)
+ printf(_("DMA chan:%x "), ptr->map.dma);
+ printf("\n");
}
- if (ptr->map.dma)
- printf(_("DMA chan:%x "), ptr->map.dma);
printf("\n");
- }
-
- printf("\n");
}
static int do_if_print(struct interface *ife, void *cookie)
{
- int *opt_a = (int *)cookie;
+ int *opt_a = (int *) cookie;
if (if_fetch(ife->name, ife) < 0) {
- fprintf (stderr, _("%s: error fetching interface information: %s\n\n"),
- ife->name, strerror(errno));
+ fprintf(stderr, _("%s: error fetching interface information: %s\n\n"),
+ ife->name, strerror(errno));
return -1;
}
if (!(ife->flags & IFF_UP) && !(*opt_a))
return 0;
- ife_print(ife);
+ ife_print(ife);
return 0;
}
@@ -348,760 +373,745 @@ static void if_print(char *ifname)
{
struct interface *ife;
- if (!ifname) {
- for_all_interfaces(do_if_print, &opt_a);
+ if (!ifname) {
+ for_all_interfaces(do_if_print, &opt_a);
} else {
- ife = lookup_interface(ifname);
+ ife = lookup_interface(ifname);
if (!ife)
- fprintf(stderr, _("%s: interface not found.\n"), ifname);
+ fprintf(stderr, _("%s: interface not found.\n"), ifname);
else if (if_fetch(ifname, ife) < 0)
fprintf(stderr, _("%s: error fetching interface information: %s"),
- ifname, strerror(errno));
- else
+ ifname, strerror(errno));
+ else
ife_print(ife);
}
}
/* Set a certain interface flag. */
-static int
-set_flag(char *ifname, short flag)
+static int set_flag(char *ifname, short flag)
{
- struct ifreq ifr;
-
- strcpy(ifr.ifr_name, ifname);
- if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) {
- fprintf(stderr, _("%s: unknown interface.\n"), ifname);
- return(-1);
- }
- strcpy(ifr.ifr_name, ifname);
- ifr.ifr_flags |= flag;
- if (ioctl(skfd, SIOCSIFFLAGS, &ifr) < 0) {
- perror("SIOCSIFFLAGS");
- return -1;
- }
- return(0);
+ struct ifreq ifr;
+
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) {
+ fprintf(stderr, _("%s: unknown interface.\n"), ifname);
+ return (-1);
+ }
+ strcpy(ifr.ifr_name, ifname);
+ ifr.ifr_flags |= flag;
+ if (ioctl(skfd, SIOCSIFFLAGS, &ifr) < 0) {
+ perror("SIOCSIFFLAGS");
+ return -1;
+ }
+ return (0);
}
/* Clear a certain interface flag. */
-static int
-clr_flag(char *ifname, short flag)
+static int clr_flag(char *ifname, short flag)
{
- struct ifreq ifr;
-
- strcpy(ifr.ifr_name, ifname);
- if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) {
- fprintf(stderr, _("%s: unknown interface.\n"), ifname);
- return -1;
- }
- strcpy(ifr.ifr_name, ifname);
- ifr.ifr_flags &= ~flag;
- if (ioctl(skfd, SIOCSIFFLAGS, &ifr) < 0) {
- perror("SIOCSIFFLAGS");
- return -1;
- }
- return(0);
+ struct ifreq ifr;
+
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) {
+ fprintf(stderr, _("%s: unknown interface.\n"), ifname);
+ return -1;
+ }
+ strcpy(ifr.ifr_name, ifname);
+ ifr.ifr_flags &= ~flag;
+ if (ioctl(skfd, SIOCSIFFLAGS, &ifr) < 0) {
+ perror("SIOCSIFFLAGS");
+ return -1;
+ }
+ return (0);
}
-static void
-usage(void)
+static void usage(void)
{
- fprintf(stderr, _("Usage: ifconfig [-a] [-i] [-v] interface\n"));
- fprintf(stderr, _(" [[family] 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 */
+ fprintf(stderr, _("Usage: ifconfig [-a] [-i] [-v] interface\n"));
+ fprintf(stderr, _(" [[family] 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"));
+ /* 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 [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"));
#endif
- fprintf(stderr, _(" [hw class address]\n"));
- fprintf(stderr, _(" [metric NN] [mtu NN]\n"));
+ 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, _(" [[-]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"));
#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"));
+ exit(1);
}
-static void
-version(void)
+static void version(void)
{
- fprintf(stderr,"%s\n%s\n",Release,Version);
- exit(1);
+ fprintf(stderr, "%s\n%s\n", Release, Version);
+ exit(1);
}
-static int
-set_netmask(int skfd, struct ifreq *ifr, struct sockaddr *sa)
+static int set_netmask(int skfd, struct ifreq *ifr, struct sockaddr *sa)
{
- int err = 0;
+ int err = 0;
- memcpy((char *) &ifr->ifr_netmask, (char *) sa,
- sizeof(struct sockaddr));
- if (ioctl(skfd, SIOCSIFNETMASK, ifr) < 0) {
- fprintf(stderr, "SIOCSIFNETMASK: %s\n",
- strerror(errno));
- err = 1;
- }
- return 0;
+ memcpy((char *) &ifr->ifr_netmask, (char *) sa,
+ sizeof(struct sockaddr));
+ if (ioctl(skfd, SIOCSIFNETMASK, ifr) < 0) {
+ fprintf(stderr, "SIOCSIFNETMASK: %s\n",
+ strerror(errno));
+ err = 1;
+ }
+ return 0;
}
-int
-main(int argc, char **argv)
+int main(int argc, char **argv)
{
- struct sockaddr sa;
- char host[128];
- struct aftype *ap;
- struct hwtype *hw;
- struct ifreq ifr;
- int goterr = 0, didnetmask = 0;
- char **spp;
- int fd;
+ struct sockaddr sa;
+ char host[128];
+ struct aftype *ap;
+ struct hwtype *hw;
+ struct ifreq ifr;
+ int goterr = 0, didnetmask = 0;
+ char **spp;
+ int fd;
#if HAVE_AFINET6
- extern struct aftype inet6_aftype;
- struct sockaddr_in6 sa6;
- struct in6_ifreq ifr6;
- unsigned long prefix_len;
- char *cp;
+ extern struct aftype inet6_aftype;
+ struct sockaddr_in6 sa6;
+ struct in6_ifreq ifr6;
+ unsigned long prefix_len;
+ char *cp;
#endif
-
+
#if I18N
- bindtextdomain("net-tools", "/usr/share/locale");
- textdomain("net-tools");
+ bindtextdomain("net-tools", "/usr/share/locale");
+ textdomain("net-tools");
#endif
- /* Create a channel to the NET kernel. */
- if ((skfd = sockets_open(0)) < 0) {
- perror("socket");
- exit(1);
- }
-
- /* Find any options. */
- argc--; argv++;
- while (argc && *argv[0] == '-') {
- if (!strcmp(*argv, "-a")) opt_a = 1;
-
- if (!strcmp(*argv, "-v")) opt_v = 1;
-
- if (!strcmp(*argv, "-V") || !strcmp(*argv, "-version") ||
- !strcmp(*argv, "--version")) version();
-
- if (!strcmp(*argv, "-?") || !strcmp(*argv, "-h") ||
- !strcmp(*argv, "-help") || !strcmp(*argv, "--help")) usage();
-
- argv++;
- argc--;
- }
-
- /* Do we have to show the current setup? */
- if (argc == 0) {
- if_print((char *)NULL);
- (void) close(skfd);
- exit(0);
- }
-
- /* No. Fetch the interface name. */
- spp = argv;
- strncpy(ifr.ifr_name, *spp++, IFNAMSIZ);
- if (*spp == (char *)NULL) {
- if_print(ifr.ifr_name);
- (void) close(skfd);
- exit(0);
- }
-
- /* The next argument is either an address family name, or an option. */
- if ((ap = get_aftype(*spp)) == NULL)
- ap = get_aftype("inet");
- else {
- /* XXX: should print the current setup if no args left, but only
- for this family */
- spp++;
- }
- addr_family = ap->af;
-
- if (sockets_open(addr_family) < 0) {
- perror("family socket");
- exit(1);
- }
-
- /* Process the remaining arguments. */
- while (*spp != (char *)NULL) {
- if (!strcmp(*spp, "arp")) {
- goterr |= clr_flag(ifr.ifr_name, IFF_NOARP);
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "-arp")) {
- goterr |= set_flag(ifr.ifr_name, IFF_NOARP);
- spp++;
- continue;
+ /* Create a channel to the NET kernel. */
+ if ((skfd = sockets_open(0)) < 0) {
+ perror("socket");
+ exit(1);
}
+ /* Find any options. */
+ argc--;
+ argv++;
+ while (argc && *argv[0] == '-') {
+ if (!strcmp(*argv, "-a"))
+ opt_a = 1;
-#ifdef IFF_PORTSEL
- if (!strcmp(*spp, "media") || !strcmp(*spp, "port")) {
- if (*++spp == NULL) usage();
- if (!strcasecmp(*spp, "auto")) {
- goterr |= set_flag(ifr.ifr_name, IFF_AUTOMEDIA);
- } else {
- int i, j, newport;
- char *endp;
- newport = strtol(*spp, &endp, 10);
- if (*endp != 0) {
- newport = -1;
- for (i = 0; if_port_text[i][0] && newport == -1; i++) {
- for (j = 0; if_port_text[i][j]; j++) {
- if (!strcasecmp(*spp, if_port_text[i][j])) {
- newport = i;
- break;
- }
- }
- }
- }
- spp++;
- if (newport == -1) {
- fprintf(stderr, _("Unknown media type.\n"));
- goterr = 1;
- } else {
- if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
- goterr = 1;
- continue;
- }
- ifr.ifr_map.port = newport;
- if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) {
- perror("SIOCSIFMAP");
- goterr = 1;
- }
- }
- }
- continue;
- }
-#endif
-
- if (!strcmp(*spp, "trailers")) {
- goterr |= clr_flag(ifr.ifr_name, IFF_NOTRAILERS);
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "-trailers")) {
- goterr |= set_flag(ifr.ifr_name, IFF_NOTRAILERS);
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "promisc")) {
- goterr |= set_flag(ifr.ifr_name, IFF_PROMISC);
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "-promisc")) {
- goterr |= clr_flag(ifr.ifr_name, IFF_PROMISC);
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "multicast")) {
- goterr |= set_flag(ifr.ifr_name, IFF_MULTICAST);
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "-multicast")) {
- goterr |= clr_flag(ifr.ifr_name, IFF_MULTICAST);
- spp++;
- continue;
- }
+ if (!strcmp(*argv, "-v"))
+ opt_v = 1;
- if (!strcmp(*spp, "allmulti")) {
- goterr |= set_flag(ifr.ifr_name, IFF_ALLMULTI);
- spp++;
- continue;
- }
+ if (!strcmp(*argv, "-V") || !strcmp(*argv, "-version") ||
+ !strcmp(*argv, "--version"))
+ version();
- if (!strcmp(*spp, "-allmulti")) {
- goterr |= clr_flag(ifr.ifr_name, IFF_ALLMULTI);
- spp++;
- continue;
+ if (!strcmp(*argv, "-?") || !strcmp(*argv, "-h") ||
+ !strcmp(*argv, "-help") || !strcmp(*argv, "--help"))
+ usage();
+
+ argv++;
+ argc--;
}
- if (!strcmp(*spp, "up")) {
- goterr |= set_flag(ifr.ifr_name, (IFF_UP | IFF_RUNNING));
- spp++;
- continue;
+ /* Do we have to show the current setup? */
+ if (argc == 0) {
+ if_print((char *) NULL);
+ (void) close(skfd);
+ exit(0);
+ }
+ /* No. Fetch the interface name. */
+ spp = argv;
+ strncpy(ifr.ifr_name, *spp++, IFNAMSIZ);
+ if (*spp == (char *) NULL) {
+ if_print(ifr.ifr_name);
+ (void) close(skfd);
+ exit(0);
}
+ /* The next argument is either an address family name, or an option. */
+ if ((ap = get_aftype(*spp)) == NULL)
+ ap = get_aftype("inet");
+ else {
+ /* XXX: should print the current setup if no args left, but only
+ for this family */
+ spp++;
+ }
+ addr_family = ap->af;
- if (!strcmp(*spp, "down")) {
- goterr |= clr_flag(ifr.ifr_name, IFF_UP);
- spp++;
- continue;
+ if (sockets_open(addr_family) < 0) {
+ perror("family socket");
+ exit(1);
}
+ /* Process the remaining arguments. */
+ while (*spp != (char *) NULL) {
+ if (!strcmp(*spp, "arp")) {
+ goterr |= clr_flag(ifr.ifr_name, IFF_NOARP);
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "-arp")) {
+ goterr |= set_flag(ifr.ifr_name, IFF_NOARP);
+ spp++;
+ continue;
+ }
+#ifdef IFF_PORTSEL
+ if (!strcmp(*spp, "media") || !strcmp(*spp, "port")) {
+ if (*++spp == NULL)
+ usage();
+ if (!strcasecmp(*spp, "auto")) {
+ goterr |= set_flag(ifr.ifr_name, IFF_AUTOMEDIA);
+ } else {
+ int i, j, newport;
+ char *endp;
+ newport = strtol(*spp, &endp, 10);
+ if (*endp != 0) {
+ newport = -1;
+ for (i = 0; if_port_text[i][0] && newport == -1; i++) {
+ for (j = 0; if_port_text[i][j]; j++) {
+ if (!strcasecmp(*spp, if_port_text[i][j])) {
+ newport = i;
+ break;
+ }
+ }
+ }
+ }
+ spp++;
+ if (newport == -1) {
+ fprintf(stderr, _("Unknown media type.\n"));
+ goterr = 1;
+ } else {
+ if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
+ goterr = 1;
+ continue;
+ }
+ ifr.ifr_map.port = newport;
+ if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) {
+ perror("SIOCSIFMAP");
+ goterr = 1;
+ }
+ }
+ }
+ continue;
+ }
+#endif
+ if (!strcmp(*spp, "trailers")) {
+ goterr |= clr_flag(ifr.ifr_name, IFF_NOTRAILERS);
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "-trailers")) {
+ goterr |= set_flag(ifr.ifr_name, IFF_NOTRAILERS);
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "promisc")) {
+ goterr |= set_flag(ifr.ifr_name, IFF_PROMISC);
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "-promisc")) {
+ goterr |= clr_flag(ifr.ifr_name, IFF_PROMISC);
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "multicast")) {
+ goterr |= set_flag(ifr.ifr_name, IFF_MULTICAST);
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "-multicast")) {
+ goterr |= clr_flag(ifr.ifr_name, IFF_MULTICAST);
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "allmulti")) {
+ goterr |= set_flag(ifr.ifr_name, IFF_ALLMULTI);
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "-allmulti")) {
+ goterr |= clr_flag(ifr.ifr_name, IFF_ALLMULTI);
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "up")) {
+ goterr |= set_flag(ifr.ifr_name, (IFF_UP | IFF_RUNNING));
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "down")) {
+ goterr |= clr_flag(ifr.ifr_name, IFF_UP);
+ spp++;
+ continue;
+ }
#ifdef HAVE_DYNAMIC
- if (!strcmp(*spp, "dynamic")) {
- goterr |= set_flag(ifr.ifr_name, IFF_DYNAMIC);
- spp++;
- continue;
+ if (!strcmp(*spp, "dynamic")) {
+ goterr |= set_flag(ifr.ifr_name, IFF_DYNAMIC);
+ spp++;
+ continue;
}
if (!strcmp(*spp, "-dynamic")) {
- goterr |= clr_flag(ifr.ifr_name, IFF_DYNAMIC);
- spp++;
- continue;
+ goterr |= clr_flag(ifr.ifr_name, IFF_DYNAMIC);
+ spp++;
+ continue;
}
#endif
- if (!strcmp(*spp, "metric")) {
- if (*++spp == NULL) usage();
- ifr.ifr_metric = atoi(*spp);
- if (ioctl(skfd, SIOCSIFMETRIC, &ifr) < 0) {
- fprintf(stderr, "SIOCSIFMETRIC: %s\n", strerror(errno));
- goterr = 1;
- }
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "mtu")) {
- if (*++spp == NULL) usage();
- ifr.ifr_mtu = atoi(*spp);
- if (ioctl(skfd, SIOCSIFMTU, &ifr) < 0) {
- fprintf(stderr, "SIOCSIFMTU: %s\n", strerror(errno));
- goterr = 1;
- }
- spp++;
- continue;
- }
-
+ if (!strcmp(*spp, "metric")) {
+ if (*++spp == NULL)
+ usage();
+ ifr.ifr_metric = atoi(*spp);
+ if (ioctl(skfd, SIOCSIFMETRIC, &ifr) < 0) {
+ fprintf(stderr, "SIOCSIFMETRIC: %s\n", strerror(errno));
+ goterr = 1;
+ }
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "mtu")) {
+ if (*++spp == NULL)
+ usage();
+ ifr.ifr_mtu = atoi(*spp);
+ if (ioctl(skfd, SIOCSIFMTU, &ifr) < 0) {
+ fprintf(stderr, "SIOCSIFMTU: %s\n", strerror(errno));
+ goterr = 1;
+ }
+ spp++;
+ continue;
+ }
#ifdef SIOCSKEEPALIVE
- if (!strcmp(*spp, "keepalive")) {
- if (*++spp == NULL) usage();
- ifr.ifr_data = (caddr_t)atoi(*spp);
- if (ioctl(skfd, SIOCSKEEPALIVE, &ifr) < 0) {
- fprintf(stderr, "SIOCSKEEPALIVE: %s\n", strerror(errno));
- goterr = 1;
- }
- spp++;
- continue;
- }
+ if (!strcmp(*spp, "keepalive")) {
+ if (*++spp == NULL)
+ usage();
+ ifr.ifr_data = (caddr_t) atoi(*spp);
+ if (ioctl(skfd, SIOCSKEEPALIVE, &ifr) < 0) {
+ fprintf(stderr, "SIOCSKEEPALIVE: %s\n", strerror(errno));
+ goterr = 1;
+ }
+ spp++;
+ continue;
+ }
#endif
#ifdef SIOCSOUTFILL
- if (!strcmp(*spp, "outfill")) {
- if (*++spp == NULL) usage();
- ifr.ifr_data = (caddr_t)atoi(*spp);
- if (ioctl(skfd, SIOCSOUTFILL, &ifr) < 0) {
- fprintf(stderr, "SIOCSOUTFILL: %s\n", strerror(errno));
- goterr = 1;
- }
- spp++;
- continue;
- }
+ if (!strcmp(*spp, "outfill")) {
+ if (*++spp == NULL)
+ usage();
+ ifr.ifr_data = (caddr_t) atoi(*spp);
+ if (ioctl(skfd, SIOCSOUTFILL, &ifr) < 0) {
+ fprintf(stderr, "SIOCSOUTFILL: %s\n", strerror(errno));
+ goterr = 1;
+ }
+ spp++;
+ continue;
+ }
#endif
-
- if (!strcmp(*spp, "-broadcast")) {
- goterr |= clr_flag(ifr.ifr_name, IFF_BROADCAST);
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "broadcast")) {
- if (*++spp != NULL ) {
- host[(sizeof host)-1] = 0;
- strncpy(host, *spp, (sizeof host)-1);
- if (ap->input(0, host, &sa) < 0) {
- ap->herror(host);
- goterr = 1;
- spp++;
- continue;
+
+ if (!strcmp(*spp, "-broadcast")) {
+ goterr |= clr_flag(ifr.ifr_name, IFF_BROADCAST);
+ spp++;
+ continue;
}
- memcpy((char *) &ifr.ifr_broadaddr, (char *) &sa,
- sizeof(struct sockaddr));
- if (ioctl(ap->fd, SIOCSIFBRDADDR, &ifr) < 0) {
- fprintf(stderr, "SIOCSIFBRDADDR: %s\n",
- strerror(errno));
- goterr = 1;
+ if (!strcmp(*spp, "broadcast")) {
+ if (*++spp != NULL) {
+ host[(sizeof host) - 1] = 0;
+ strncpy(host, *spp, (sizeof host) - 1);
+ if (ap->input(0, host, &sa) < 0) {
+ ap->herror(host);
+ goterr = 1;
+ spp++;
+ continue;
+ }
+ memcpy((char *) &ifr.ifr_broadaddr, (char *) &sa,
+ sizeof(struct sockaddr));
+ if (ioctl(ap->fd, SIOCSIFBRDADDR, &ifr) < 0) {
+ fprintf(stderr, "SIOCSIFBRDADDR: %s\n",
+ strerror(errno));
+ goterr = 1;
+ }
+ spp++;
+ }
+ goterr |= set_flag(ifr.ifr_name, IFF_BROADCAST);
+ continue;
+ }
+ if (!strcmp(*spp, "dstaddr")) {
+ if (*++spp == NULL)
+ usage();
+ host[(sizeof host) - 1] = 0;
+ strncpy(host, *spp, (sizeof host) - 1);
+ if (ap->input(0, host, &sa) < 0) {
+ ap->herror(host);
+ goterr = 1;
+ spp++;
+ continue;
+ }
+ memcpy((char *) &ifr.ifr_dstaddr, (char *) &sa,
+ sizeof(struct sockaddr));
+ if (ioctl(ap->fd, SIOCSIFDSTADDR, &ifr) < 0) {
+ fprintf(stderr, "SIOCSIFDSTADDR: %s\n",
+ strerror(errno));
+ goterr = 1;
+ }
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "netmask")) {
+ if (*++spp == NULL || didnetmask)
+ usage();
+ host[(sizeof host) - 1] = 0;
+ strncpy(host, *spp, (sizeof host) - 1);
+ if (ap->input(0, host, &sa) < 0) {
+ ap->herror(host);
+ goterr = 1;
+ spp++;
+ continue;
+ }
+ didnetmask++;
+ goterr = set_netmask(ap->fd, &ifr, &sa);
+ spp++;
+ continue;
}
- spp++;
- }
- goterr |= set_flag(ifr.ifr_name, IFF_BROADCAST);
- continue;
- }
-
- if (!strcmp(*spp, "dstaddr")) {
- if (*++spp == NULL) usage();
- host[(sizeof host)-1] = 0;
- strncpy(host, *spp, (sizeof host)-1);
- if (ap->input(0, host, &sa) < 0) {
- ap->herror(host);
- goterr = 1;
- spp++;
- continue;
- }
- memcpy((char *) &ifr.ifr_dstaddr, (char *) &sa,
- sizeof(struct sockaddr));
- if (ioctl(ap->fd, SIOCSIFDSTADDR, &ifr) < 0) {
- fprintf(stderr, "SIOCSIFDSTADDR: %s\n",
- strerror(errno));
- goterr = 1;
- }
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "netmask")) {
- if (*++spp == NULL || didnetmask) usage();
- host[(sizeof host)-1] = 0;
- strncpy(host, *spp, (sizeof host)-1);
- if (ap->input(0, host, &sa) < 0) {
- ap->herror(host);
- goterr = 1;
- spp++;
- continue;
- }
- didnetmask++;
- goterr = set_netmask(ap->fd, &ifr, &sa);
- spp++;
- continue;
- }
-
#ifdef HAVE_TXQUEUELEN
- if (!strcmp(*spp, "txqueuelen")) {
- if (*++spp == NULL) usage();
- ifr.ifr_qlen = strtoul(*spp, NULL, 0);
- if (ioctl(skfd, SIOCSIFTXQLEN, &ifr) < 0) {
- fprintf(stderr, "SIOCSIFTXQLEN: %s\n", strerror(errno));
- goterr = 1;
- }
- spp++;
- continue;
- }
+ if (!strcmp(*spp, "txqueuelen")) {
+ if (*++spp == NULL)
+ usage();
+ ifr.ifr_qlen = strtoul(*spp, NULL, 0);
+ if (ioctl(skfd, SIOCSIFTXQLEN, &ifr) < 0) {
+ fprintf(stderr, "SIOCSIFTXQLEN: %s\n", strerror(errno));
+ goterr = 1;
+ }
+ spp++;
+ continue;
+ }
#endif
- if (!strcmp(*spp, "mem_start")) {
- if (*++spp == NULL) usage();
- if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
- goterr = 1;
- continue;
- }
- ifr.ifr_map.mem_start = strtoul(*spp, NULL, 0);
- if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) {
- fprintf(stderr, "SIOCSIFMAP: %s\n", strerror(errno));
- goterr = 1;
- }
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "io_addr")) {
- if (*++spp == NULL) usage();
- if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
- goterr = 1;
- continue;
- }
- ifr.ifr_map.base_addr = strtol(*spp, NULL, 0);
- if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) {
- fprintf(stderr, "SIOCSIFMAP: %s\n", strerror(errno));
- goterr = 1;
- }
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "irq")) {
- if (*++spp == NULL) usage();
- if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
- goterr = 1;
- continue;
- }
- ifr.ifr_map.irq = atoi(*spp);
- if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) {
- fprintf(stderr, "SIOCSIFMAP: %s\n", strerror(errno));
- goterr = 1;
- }
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "-pointopoint")) {
- goterr |= clr_flag(ifr.ifr_name, IFF_POINTOPOINT);
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "pointopoint")) {
- if (*(spp+1) != NULL) {
- spp++;
- host[(sizeof host)-1] = 0;
- strncpy(host, *spp, (sizeof host)-1);
- if (ap->input(0, host, &sa)) {
- ap->herror(host);
- goterr = 1;
- spp++;
- continue;
+ if (!strcmp(*spp, "mem_start")) {
+ if (*++spp == NULL)
+ usage();
+ if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
+ goterr = 1;
+ continue;
+ }
+ ifr.ifr_map.mem_start = strtoul(*spp, NULL, 0);
+ if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) {
+ fprintf(stderr, "SIOCSIFMAP: %s\n", strerror(errno));
+ goterr = 1;
+ }
+ spp++;
+ continue;
}
- memcpy((char *) &ifr.ifr_dstaddr, (char *) &sa,
- sizeof(struct sockaddr));
- if (ioctl(skfd, SIOCSIFDSTADDR, &ifr) < 0) {
- fprintf(stderr, "SIOCSIFDSTADDR: %s\n",
- strerror(errno));
- goterr = 1;
+ if (!strcmp(*spp, "io_addr")) {
+ if (*++spp == NULL)
+ usage();
+ if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
+ goterr = 1;
+ continue;
+ }
+ ifr.ifr_map.base_addr = strtol(*spp, NULL, 0);
+ if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) {
+ fprintf(stderr, "SIOCSIFMAP: %s\n", strerror(errno));
+ goterr = 1;
+ }
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "irq")) {
+ if (*++spp == NULL)
+ usage();
+ if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) {
+ goterr = 1;
+ continue;
+ }
+ ifr.ifr_map.irq = atoi(*spp);
+ if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) {
+ fprintf(stderr, "SIOCSIFMAP: %s\n", strerror(errno));
+ goterr = 1;
+ }
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "-pointopoint")) {
+ goterr |= clr_flag(ifr.ifr_name, IFF_POINTOPOINT);
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "pointopoint")) {
+ if (*(spp + 1) != NULL) {
+ spp++;
+ host[(sizeof host) - 1] = 0;
+ strncpy(host, *spp, (sizeof host) - 1);
+ if (ap->input(0, host, &sa)) {
+ ap->herror(host);
+ goterr = 1;
+ spp++;
+ continue;
+ }
+ memcpy((char *) &ifr.ifr_dstaddr, (char *) &sa,
+ sizeof(struct sockaddr));
+ if (ioctl(skfd, SIOCSIFDSTADDR, &ifr) < 0) {
+ fprintf(stderr, "SIOCSIFDSTADDR: %s\n",
+ strerror(errno));
+ goterr = 1;
+ }
+ }
+ goterr |= set_flag(ifr.ifr_name, IFF_POINTOPOINT);
+ spp++;
+ continue;
+ };
+
+ if (!strcmp(*spp, "hw")) {
+ if (*++spp == NULL)
+ usage();
+ if ((hw = get_hwtype(*spp)) == NULL)
+ usage();
+ if (*++spp == NULL)
+ usage();
+ host[(sizeof host) - 1] = 0;
+ strncpy(host, *spp, (sizeof host) - 1);
+ if (hw->input(host, &sa) < 0) {
+ fprintf(stderr, _("%s: invalid %s address.\n"), host, hw->name);
+ goterr = 1;
+ spp++;
+ continue;
+ }
+ memcpy((char *) &ifr.ifr_hwaddr, (char *) &sa,
+ sizeof(struct sockaddr));
+ if (ioctl(skfd, SIOCSIFHWADDR, &ifr) < 0) {
+ fprintf(stderr, "SIOCSIFHWADDR: %s\n",
+ strerror(errno));
+ goterr = 1;
+ }
+ spp++;
+ continue;
}
- }
- goterr |= set_flag(ifr.ifr_name, IFF_POINTOPOINT);
- spp++;
- continue;
- };
-
- if (!strcmp(*spp, "hw")) {
- if (*++spp == NULL) usage();
- if ((hw = get_hwtype(*spp)) == NULL) usage();
- if (*++spp == NULL) usage();
- host[(sizeof host)-1] = 0;
- strncpy(host, *spp, (sizeof host)-1);
- if (hw->input(host, &sa) < 0) {
- fprintf(stderr, _("%s: invalid %s address.\n"), host, hw->name);
- goterr = 1;
- spp++;
- continue;
- }
- memcpy((char *) &ifr.ifr_hwaddr, (char *) &sa,
- sizeof(struct sockaddr));
- if (ioctl(skfd, SIOCSIFHWADDR, &ifr) < 0) {
- fprintf(stderr, "SIOCSIFHWADDR: %s\n",
- strerror(errno));
- goterr = 1;
- }
- spp++;
- continue;
- }
-
#if HAVE_AFINET6
- if (!strcmp(*spp, "add")) {
- if (*++spp == NULL) usage();
- if ((cp = strchr(*spp, '/'))) {
- prefix_len = atol(cp+1);
- if ((prefix_len < 0) || (prefix_len > 128)) usage();
- *cp = 0;
- } else {
- prefix_len = 0;
- }
- host[(sizeof host)-1] = 0;
- strncpy(host, *spp, (sizeof host)-1);
- if (inet6_aftype.input(1, host, (struct sockaddr *)&sa6) < 0) {
- inet6_aftype.herror(host);
- goterr = 1;
- spp++;
- continue;
- }
- memcpy((char *) &ifr6.ifr6_addr, (char *) &sa6.sin6_addr,
- sizeof(struct in6_addr));
-
- fd = get_socket_for_af(AF_INET6);
- if (fd < 0) {
- fprintf(stderr, _("No support for INET6 on this system.\n"));
- goterr = 1;
- spp++;
- continue;
- }
-
- if (ioctl(fd, SIOGIFINDEX, &ifr) < 0) {
- perror("SIOGIFINDEX");
- goterr = 1;
- spp++;
- continue;
- }
-
- ifr6.ifr6_ifindex = ifr.ifr_ifindex;
- ifr6.ifr6_prefixlen = prefix_len;
- if (ioctl(fd, SIOCSIFADDR, &ifr6) < 0) {
- perror("SIOCSIFADDR");
- goterr = 1;
- }
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "del")) {
- if (*++spp == NULL) usage();
- if ((cp = strchr(*spp, '/'))) {
- prefix_len = atol(cp+1);
- if ((prefix_len < 0) || (prefix_len > 128)) usage();
- *cp = 0;
- } else {
- prefix_len = 0;
- }
- host[(sizeof host)-1] = 0;
- strncpy(host, *spp, (sizeof host)-1);
- if (inet6_aftype.input(1, host, (struct sockaddr *)&sa6) < 0) {
- inet6_aftype.herror(host);
- goterr = 1;
- spp++;
- continue;
- }
- memcpy((char *) &ifr6.ifr6_addr, (char *) &sa6.sin6_addr,
- sizeof(struct in6_addr));
-
- fd = get_socket_for_af(AF_INET6);
- if (fd < 0) {
- fprintf(stderr, _("No support for INET6 on this system.\n"));
- goterr = 1;
- spp++;
- continue;
- }
-
- if (ioctl(fd, SIOGIFINDEX, &ifr) < 0) {
- perror("SIOGIFINDEX");
- goterr = 1;
- spp++;
- continue;
- }
-
- ifr6.ifr6_ifindex = ifr.ifr_ifindex;
- ifr6.ifr6_prefixlen = prefix_len;
+ if (!strcmp(*spp, "add")) {
+ if (*++spp == NULL)
+ usage();
+ if ((cp = strchr(*spp, '/'))) {
+ prefix_len = atol(cp + 1);
+ if ((prefix_len < 0) || (prefix_len > 128))
+ usage();
+ *cp = 0;
+ } else {
+ prefix_len = 0;
+ }
+ host[(sizeof host) - 1] = 0;
+ strncpy(host, *spp, (sizeof host) - 1);
+ if (inet6_aftype.input(1, host, (struct sockaddr *) &sa6) < 0) {
+ inet6_aftype.herror(host);
+ goterr = 1;
+ spp++;
+ continue;
+ }
+ memcpy((char *) &ifr6.ifr6_addr, (char *) &sa6.sin6_addr,
+ sizeof(struct in6_addr));
+
+ fd = get_socket_for_af(AF_INET6);
+ if (fd < 0) {
+ fprintf(stderr, _("No support for INET6 on this system.\n"));
+ goterr = 1;
+ spp++;
+ continue;
+ }
+ if (ioctl(fd, SIOGIFINDEX, &ifr) < 0) {
+ perror("SIOGIFINDEX");
+ goterr = 1;
+ spp++;
+ continue;
+ }
+ ifr6.ifr6_ifindex = ifr.ifr_ifindex;
+ ifr6.ifr6_prefixlen = prefix_len;
+ if (ioctl(fd, SIOCSIFADDR, &ifr6) < 0) {
+ perror("SIOCSIFADDR");
+ goterr = 1;
+ }
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "del")) {
+ if (*++spp == NULL)
+ usage();
+ if ((cp = strchr(*spp, '/'))) {
+ prefix_len = atol(cp + 1);
+ if ((prefix_len < 0) || (prefix_len > 128))
+ usage();
+ *cp = 0;
+ } else {
+ prefix_len = 0;
+ }
+ host[(sizeof host) - 1] = 0;
+ strncpy(host, *spp, (sizeof host) - 1);
+ if (inet6_aftype.input(1, host, (struct sockaddr *) &sa6) < 0) {
+ inet6_aftype.herror(host);
+ goterr = 1;
+ spp++;
+ continue;
+ }
+ memcpy((char *) &ifr6.ifr6_addr, (char *) &sa6.sin6_addr,
+ sizeof(struct in6_addr));
+
+ fd = get_socket_for_af(AF_INET6);
+ if (fd < 0) {
+ fprintf(stderr, _("No support for INET6 on this system.\n"));
+ goterr = 1;
+ spp++;
+ continue;
+ }
+ if (ioctl(fd, SIOGIFINDEX, &ifr) < 0) {
+ perror("SIOGIFINDEX");
+ goterr = 1;
+ spp++;
+ continue;
+ }
+ ifr6.ifr6_ifindex = ifr.ifr_ifindex;
+ ifr6.ifr6_prefixlen = prefix_len;
#ifdef SIOCDIFADDR
- if (ioctl(fd, SIOCDIFADDR, &ifr6) < 0) {
- fprintf(stderr, "SIOCDIFADDR: %s\n",
- strerror(errno));
- goterr = 1;
- }
+ if (ioctl(fd, SIOCDIFADDR, &ifr6) < 0) {
+ fprintf(stderr, "SIOCDIFADDR: %s\n",
+ strerror(errno));
+ goterr = 1;
+ }
#else
- fprintf(stderr, _("Address deletion not supported on this system.\n"));
+ fprintf(stderr, _("Address deletion not supported on this system.\n"));
#endif
- spp++;
- continue;
- }
-
- if (!strcmp(*spp, "tunnel")) {
- if (*++spp == NULL) usage();
- if ((cp = strchr(*spp, '/'))) {
- prefix_len = atol(cp+1);
- if ((prefix_len < 0) || (prefix_len > 128)) usage();
- *cp = 0;
- } else {
- prefix_len = 0;
- }
- host[(sizeof host)-1] = 0;
- strncpy(host, *spp, (sizeof host)-1);
- if (inet6_aftype.input(1, host, (struct sockaddr *)&sa6) < 0) {
- inet6_aftype.herror(host);
- goterr = 1;
- spp++;
- continue;
- }
- memcpy((char *) &ifr6.ifr6_addr, (char *) &sa6.sin6_addr,
- sizeof(struct in6_addr));
-
- fd = get_socket_for_af(AF_INET6);
- if (fd < 0) {
- fprintf(stderr, _("No support for INET6 on this system.\n"));
- goterr = 1;
- spp++;
- continue;
- }
+ spp++;
+ continue;
+ }
+ if (!strcmp(*spp, "tunnel")) {
+ if (*++spp == NULL)
+ usage();
+ if ((cp = strchr(*spp, '/'))) {
+ prefix_len = atol(cp + 1);
+ if ((prefix_len < 0) || (prefix_len > 128))
+ usage();
+ *cp = 0;
+ } else {
+ prefix_len = 0;
+ }
+ host[(sizeof host) - 1] = 0;
+ strncpy(host, *spp, (sizeof host) - 1);
+ if (inet6_aftype.input(1, host, (struct sockaddr *) &sa6) < 0) {
+ inet6_aftype.herror(host);
+ goterr = 1;
+ spp++;
+ continue;
+ }
+ memcpy((char *) &ifr6.ifr6_addr, (char *) &sa6.sin6_addr,
+ sizeof(struct in6_addr));
+
+ fd = get_socket_for_af(AF_INET6);
+ if (fd < 0) {
+ fprintf(stderr, _("No support for INET6 on this system.\n"));
+ goterr = 1;
+ spp++;
+ continue;
+ }
+ if (ioctl(fd, SIOGIFINDEX, &ifr) < 0) {
+ perror("SIOGIFINDEX");
+ goterr = 1;
+ spp++;
+ continue;
+ }
+ ifr6.ifr6_ifindex = ifr.ifr_ifindex;
+ ifr6.ifr6_prefixlen = prefix_len;
- if (ioctl(fd, SIOGIFINDEX, &ifr) < 0) {
- perror("SIOGIFINDEX");
- goterr = 1;
- spp++;
- continue;
- }
-
- ifr6.ifr6_ifindex = ifr.ifr_ifindex;
- ifr6.ifr6_prefixlen = prefix_len;
-
- if (ioctl(fd, SIOCSIFDSTADDR, &ifr6) < 0) {
- fprintf(stderr, "SIOCSIFDSTADDR: %s\n",
- strerror(errno));
- goterr = 1;
- }
- spp++;
- continue;
- }
+ if (ioctl(fd, SIOCSIFDSTADDR, &ifr6) < 0) {
+ fprintf(stderr, "SIOCSIFDSTADDR: %s\n",
+ strerror(errno));
+ goterr = 1;
+ }
+ spp++;
+ continue;
+ }
#endif
-
- /* If the next argument is a valid hostname, assume OK. */
- host[(sizeof host)-1] = '\0';
- strncpy(host, *spp, (sizeof host)-1);
-
- /* FIXME: sa is too small for INET6 addresses, inet6 should use that too,
- broadcast is unexpected */
- if (ap->getmask) {
- switch (ap->getmask(host, &sa, NULL)) {
- case -1: usage(); break;
- case 1:
- if (didnetmask) usage();
-
- goterr = set_netmask(skfd, &ifr, &sa);
- didnetmask++;
- break;
- }
- }
-
- if (ap->input(0, host, &sa) < 0) {
- ap->herror(host);
- usage();
- }
- memcpy((char *) &ifr.ifr_addr, (char *) &sa, sizeof(struct sockaddr));
- {
- int r = 0; /* to shut gcc up */
- switch (ap->af) {
-#if HAVE_AFINET
- case AF_INET:
- fd = get_socket_for_af(AF_INET);
- if (fd < 0) {
- fprintf(stderr, _("No support for INET on this system.\n"));
- exit(1);
+ /* If the next argument is a valid hostname, assume OK. */
+ host[(sizeof host) - 1] = '\0';
+ strncpy(host, *spp, (sizeof host) - 1);
+
+ /* FIXME: sa is too small for INET6 addresses, inet6 should use that too,
+ broadcast is unexpected */
+ if (ap->getmask) {
+ switch (ap->getmask(host, &sa, NULL)) {
+ case -1:
+ usage();
+ break;
+ case 1:
+ if (didnetmask)
+ usage();
+
+ goterr = set_netmask(skfd, &ifr, &sa);
+ didnetmask++;
+ break;
+ }
}
- r = ioctl(fd, SIOCSIFADDR, &ifr);
- break;
+ if (ap->input(0, host, &sa) < 0) {
+ ap->herror(host);
+ usage();
+ }
+ memcpy((char *) &ifr.ifr_addr, (char *) &sa, sizeof(struct sockaddr));
+ {
+ int r = 0; /* to shut gcc up */
+ switch (ap->af) {
+#if HAVE_AFINET
+ case AF_INET:
+ fd = get_socket_for_af(AF_INET);
+ if (fd < 0) {
+ fprintf(stderr, _("No support for INET on this system.\n"));
+ exit(1);
+ }
+ r = ioctl(fd, SIOCSIFADDR, &ifr);
+ break;
#endif
#if HAVE_AFECONET
- case AF_ECONET:
- fd = get_socket_for_af(AF_ECONET);
- if (fd < 0) {
- fprintf(stderr, _("No support for ECONET on this system.\n"));
- exit(1);
- }
- r = ioctl(fd, SIOCSIFADDR, &ifr);
- break;
+ case AF_ECONET:
+ fd = get_socket_for_af(AF_ECONET);
+ if (fd < 0) {
+ fprintf(stderr, _("No support for ECONET on this system.\n"));
+ exit(1);
+ }
+ r = ioctl(fd, SIOCSIFADDR, &ifr);
+ break;
#endif
- default:
- fprintf(stderr,
+ default:
+ fprintf(stderr,
_("Don't know how to set addresses for this family.\n"));
- exit(1);
- }
- if (r < 0) {
- perror("SIOCSIFADDR");
- goterr = 1;
- }
+ exit(1);
+ }
+ if (r < 0) {
+ perror("SIOCSIFADDR");
+ goterr = 1;
+ }
+ }
+ goterr |= set_flag(ifr.ifr_name, (IFF_UP | IFF_RUNNING));
+ spp++;
}
- goterr |= set_flag(ifr.ifr_name, (IFF_UP | IFF_RUNNING));
- spp++;
- }
- return(goterr);
+ return (goterr);
}
diff --git a/include/ipx.h b/include/ipx.h
index 0b63141..1f1e94b 100644
--- a/include/ipx.h
+++ b/include/ipx.h
@@ -1,24 +1,24 @@
+
/* Sanitised ipx.h for net-tools. */
-#ifndef _IPX_H_
+#ifndef _IPX_H_
#define _IPX_H_
#define IPX_NODE_LEN 6
#define IPX_MTU 576
-struct sockaddr_ipx
- {
-#if LINUX_VERSION_CODE > 131328 /* 2.1.0 or later */
- sa_family_t sipx_family;
+struct sockaddr_ipx {
+#if LINUX_VERSION_CODE > 131328 /* 2.1.0 or later */
+ sa_family_t sipx_family;
#else
short sipx_family;
#endif
- unsigned short sipx_port;
- unsigned long sipx_network;
- unsigned char sipx_node[IPX_NODE_LEN];
- unsigned char sipx_type;
- unsigned char sipx_zero; /* 16 byte fill */
- };
+ unsigned short sipx_port;
+ unsigned long sipx_network;
+ unsigned char sipx_node[IPX_NODE_LEN];
+ unsigned char sipx_type;
+ unsigned char sipx_zero; /* 16 byte fill */
+};
#define IPX_FRAME_NONE 0
#define IPX_FRAME_SNAP 1
diff --git a/interface.c b/interface.c
index 59e3582..6709fab 100644
--- a/interface.c
+++ b/interface.c
@@ -1,10 +1,10 @@
/* Code to manipulate interface information, shared between ifconfig and
netstat.
- 10/1998 partly rewriten by Andi Kleen to support interface list.
- I don't claim that the list operations are efficient @).
+ 10/1998 partly rewriten by Andi Kleen to support an interface list.
+ I don't claim that the list operations are efficient @).
- $Id: interface.c,v 1.9 1998/11/15 18:58:40 freitag Exp $
+ $Id: interface.c,v 1.10 1998/11/15 20:07:52 freitag Exp $
*/
#include "config.h"
@@ -48,431 +48,427 @@
#include "util.h"
#include "intl.h"
-int procnetdev_vsn = 1;
+int procnetdev_vsn = 1;
static struct interface *int_list;
void add_interface(struct interface *n)
{
- struct interface *ife, **pp;
+ struct interface *ife, **pp;
- pp = &int_list;
- for (ife = int_list; ife; pp = &ife->next, ife = ife->next) {
- if (nstrcmp(ife->name, n->name) > 0)
- break;
- }
- n->next = (*pp);
- (*pp) = n;
-}
-
-struct interface *lookup_interface(char *name)
-{
- struct interface *ife;
- if (!int_list && (if_readlist()) < 0)
- return NULL;
- for (ife = int_list; ife; ife = ife->next) {
- if (!strcmp(ife->name,name))
- break;
- }
- return ife;
+ pp = &int_list;
+ for (ife = int_list; ife; pp = &ife->next, ife = ife->next) {
+ if (nstrcmp(ife->name, n->name) > 0)
+ break;
+ }
+ n->next = (*pp);
+ (*pp) = n;
}
-int
-for_all_interfaces(int (*doit)(struct interface *, void *), void *cookie)
-{
- struct interface *ife;
+struct interface *lookup_interface(char *name)
+{
+ struct interface *ife;
+ if (!int_list && (if_readlist()) < 0)
+ return NULL;
+ for (ife = int_list; ife; ife = ife->next) {
+ if (!strcmp(ife->name, name))
+ break;
+ }
+ return ife;
+}
- if (!int_list && (if_readlist() < 0))
- return -1;
- for (ife = int_list; ife; ife = ife->next) {
- int err = doit(ife, cookie);
- if (err)
- return err;
- }
- return 0;
+int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie)
+{
+ struct interface *ife;
+
+ if (!int_list && (if_readlist() < 0))
+ return -1;
+ for (ife = int_list; ife; ife = ife->next) {
+ int err = doit(ife, cookie);
+ if (err)
+ return err;
+ }
+ return 0;
}
static int if_readconf(void)
{
- int numreqs = 30;
- struct ifconf ifc;
- struct ifreq *ifr;
- int n, err = -1;
- int skfd;
-
- /* SIOCGIFCONF seems to only work properly on AF_INET sockets
- currently */
- skfd = get_socket_for_af(AF_INET);
- if (skfd < 0) {
- fprintf(stderr, _("warning: no inet socket available: %s\n"),
- strerror(errno));
- return -1;
+ int numreqs = 30;
+ struct ifconf ifc;
+ struct ifreq *ifr;
+ int n, err = -1;
+ int skfd;
+
+ /* SIOCGIFCONF seems to only work properly on AF_INET sockets
+ currently */
+ skfd = get_socket_for_af(AF_INET);
+ if (skfd < 0) {
+ fprintf(stderr, _("warning: no inet socket available: %s\n"),
+ strerror(errno));
+ return -1;
+ }
+ ifc.ifc_buf = NULL;
+ for (;;) {
+ ifc.ifc_len = sizeof(struct ifreq) * numreqs;
+ ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len);
+
+ if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) {
+ perror("SIOCGIFCONF");
+ goto out;
}
-
- ifc.ifc_buf = NULL;
- for (;;) {
- ifc.ifc_len = sizeof(struct ifreq) * numreqs;
- ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len);
-
- if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) {
- perror("SIOCGIFCONF");
- goto out;
- }
-
- if (ifc.ifc_len == sizeof(struct ifreq)*numreqs) {
- /* assume it overflowed and try again */
- numreqs += 10;
- continue;
- }
- break;
+ if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) {
+ /* assume it overflowed and try again */
+ numreqs += 10;
+ continue;
}
+ break;
+ }
- for (ifr = ifc.ifc_req,n = 0; n < ifc.ifc_len;
- n += sizeof(struct ifreq), ifr++) {
- struct interface *ife;
-
- ife = lookup_interface(ifr->ifr_name);
- if (ife)
- continue;
-
- new(ife);
- strcpy(ife->name, ifr->ifr_name);
- add_interface(ife);
- }
- err = 0;
+ for (ifr = ifc.ifc_req, n = 0; n < ifc.ifc_len;
+ n += sizeof(struct ifreq), ifr++) {
+ struct interface *ife;
+
+ ife = lookup_interface(ifr->ifr_name);
+ if (ife)
+ continue;
+
+ new(ife);
+ strcpy(ife->name, ifr->ifr_name);
+ add_interface(ife);
+ }
+ err = 0;
-out:
- free(ifc.ifc_buf);
- return err;
+ out:
+ free(ifc.ifc_buf);
+ return err;
}
static char *get_name(char *name, char *p)
{
- while (isspace(*p)) p++;
- while (*p) {
- if (isspace(*p))
- break;
- if (*p == ':') { /* could be an alias */
- char *dot = p, *dotname = name;
- *name++ = *p++;
- while (isdigit(*p))
- *name++ = *p++;
- if (*p != ':') { /* it wasn't, backup */
- p = dot;
- name = dotname;
- }
- if (*p == '\0') return NULL;
- p++;
- break;
- }
- *name++ = *p++;
+ while (isspace(*p))
+ p++;
+ while (*p) {
+ if (isspace(*p))
+ break;
+ if (*p == ':') { /* could be an alias */
+ char *dot = p, *dotname = name;
+ *name++ = *p++;
+ while (isdigit(*p))
+ *name++ = *p++;
+ if (*p != ':') { /* it wasn't, backup */
+ p = dot;
+ name = dotname;
+ }
+ if (*p == '\0')
+ return NULL;
+ p++;
+ break;
}
- *name++ = '\0';
- return p;
-}
+ *name++ = *p++;
+ }
+ *name++ = '\0';
+ return p;
+}
static int procnetdev_version(char *buf)
{
- if (strstr(buf,"compressed"))
- return 3;
- if (strstr(buf,"bytes"))
- return 2;
- return 1;
+ if (strstr(buf, "compressed"))
+ return 3;
+ if (strstr(buf, "bytes"))
+ return 2;
+ return 1;
}
static int get_dev_fields(char *bp, struct interface *ife)
- {
- switch (procnetdev_vsn) {
- case 3:
- sscanf(bp,
- "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
- &ife->stats.rx_bytes,
- &ife->stats.rx_packets,
- &ife->stats.rx_errors,
- &ife->stats.rx_dropped,
- &ife->stats.rx_fifo_errors,
- &ife->stats.rx_frame_errors,
- &ife->stats.rx_compressed,
- &ife->stats.rx_multicast,
-
- &ife->stats.tx_bytes,
- &ife->stats.tx_packets,
- &ife->stats.tx_errors,
- &ife->stats.tx_dropped,
- &ife->stats.tx_fifo_errors,
- &ife->stats.collisions,
- &ife->stats.tx_carrier_errors,
- &ife->stats.tx_compressed);
- break;
- case 2:
- sscanf(bp, "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
- &ife->stats.rx_bytes,
- &ife->stats.rx_packets,
- &ife->stats.rx_errors,
- &ife->stats.rx_dropped,
- &ife->stats.rx_fifo_errors,
- &ife->stats.rx_frame_errors,
-
- &ife->stats.tx_bytes,
- &ife->stats.tx_packets,
- &ife->stats.tx_errors,
- &ife->stats.tx_dropped,
- &ife->stats.tx_fifo_errors,
- &ife->stats.collisions,
- &ife->stats.tx_carrier_errors);
- ife->stats.rx_multicast = 0;
- break;
- case 1:
- sscanf(bp, "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
- &ife->stats.rx_packets,
- &ife->stats.rx_errors,
- &ife->stats.rx_dropped,
- &ife->stats.rx_fifo_errors,
- &ife->stats.rx_frame_errors,
-
- &ife->stats.tx_packets,
- &ife->stats.tx_errors,
- &ife->stats.tx_dropped,
- &ife->stats.tx_fifo_errors,
- &ife->stats.collisions,
- &ife->stats.tx_carrier_errors);
- ife->stats.rx_bytes = 0;
- ife->stats.tx_bytes = 0;
- ife->stats.rx_multicast = 0;
- break;
- }
- return 0;
+{
+ switch (procnetdev_vsn) {
+ case 3:
+ sscanf(bp,
+ "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
+ &ife->stats.rx_bytes,
+ &ife->stats.rx_packets,
+ &ife->stats.rx_errors,
+ &ife->stats.rx_dropped,
+ &ife->stats.rx_fifo_errors,
+ &ife->stats.rx_frame_errors,
+ &ife->stats.rx_compressed,
+ &ife->stats.rx_multicast,
+
+ &ife->stats.tx_bytes,
+ &ife->stats.tx_packets,
+ &ife->stats.tx_errors,
+ &ife->stats.tx_dropped,
+ &ife->stats.tx_fifo_errors,
+ &ife->stats.collisions,
+ &ife->stats.tx_carrier_errors,
+ &ife->stats.tx_compressed);
+ break;
+ case 2:
+ sscanf(bp, "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
+ &ife->stats.rx_bytes,
+ &ife->stats.rx_packets,
+ &ife->stats.rx_errors,
+ &ife->stats.rx_dropped,
+ &ife->stats.rx_fifo_errors,
+ &ife->stats.rx_frame_errors,
+
+ &ife->stats.tx_bytes,
+ &ife->stats.tx_packets,
+ &ife->stats.tx_errors,
+ &ife->stats.tx_dropped,
+ &ife->stats.tx_fifo_errors,
+ &ife->stats.collisions,
+ &ife->stats.tx_carrier_errors);
+ ife->stats.rx_multicast = 0;
+ break;
+ case 1:
+ sscanf(bp, "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
+ &ife->stats.rx_packets,
+ &ife->stats.rx_errors,
+ &ife->stats.rx_dropped,
+ &ife->stats.rx_fifo_errors,
+ &ife->stats.rx_frame_errors,
+
+ &ife->stats.tx_packets,
+ &ife->stats.tx_errors,
+ &ife->stats.tx_dropped,
+ &ife->stats.tx_fifo_errors,
+ &ife->stats.collisions,
+ &ife->stats.tx_carrier_errors);
+ ife->stats.rx_bytes = 0;
+ ife->stats.tx_bytes = 0;
+ ife->stats.rx_multicast = 0;
+ break;
+ }
+ return 0;
}
-int if_readlist(void)
+int if_readlist(void)
{
- FILE *fh;
- char buf[512];
- struct interface *ife;
- int err;
-
- fh = fopen(_PATH_PROCNET_DEV,"r");
- if (!fh) {
- perror(_PATH_PROCNET_DEV);
- return -1;
- }
-
- fgets(buf,sizeof buf,fh); /* eat line */
- fgets(buf,sizeof buf,fh);
-
-#if 0 /* pretty, but can't cope with missing fields */
- fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh,
- "face", "", /* parsed separately */
- "bytes", "%lu",
- "packets", "%lu",
- "errs", "%lu",
- "drop", "%lu",
- "fifo", "%lu",
- "frame", "%lu",
- "compressed", "%lu",
- "multicast", "%lu",
- "bytes", "%lu",
- "packets", "%lu",
- "errs", "%lu",
- "drop", "%lu",
- "fifo", "%lu",
- "colls", "%lu",
- "carrier", "%lu",
- "compressed", "%lu",
- NULL);
- if (!fmt)
- return -1;
+ FILE *fh;
+ char buf[512];
+ struct interface *ife;
+ int err;
+
+ fh = fopen(_PATH_PROCNET_DEV, "r");
+ if (!fh) {
+ perror(_PATH_PROCNET_DEV);
+ return -1;
+ }
+ fgets(buf, sizeof buf, fh); /* eat line */
+ fgets(buf, sizeof buf, fh);
+
+#if 0 /* pretty, but can't cope with missing fields */
+ fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh,
+ "face", "", /* parsed separately */
+ "bytes", "%lu",
+ "packets", "%lu",
+ "errs", "%lu",
+ "drop", "%lu",
+ "fifo", "%lu",
+ "frame", "%lu",
+ "compressed", "%lu",
+ "multicast", "%lu",
+ "bytes", "%lu",
+ "packets", "%lu",
+ "errs", "%lu",
+ "drop", "%lu",
+ "fifo", "%lu",
+ "colls", "%lu",
+ "carrier", "%lu",
+ "compressed", "%lu",
+ NULL);
+ if (!fmt)
+ return -1;
#else
- procnetdev_vsn = procnetdev_version(buf);
-#endif
+ procnetdev_vsn = procnetdev_version(buf);
+#endif
- err = 0;
- while (fgets(buf,sizeof buf,fh)) {
- char *s;
+ err = 0;
+ while (fgets(buf, sizeof buf, fh)) {
+ char *s;
- new(ife);
-
- s = get_name(ife->name, buf);
- get_dev_fields(s, ife);
- ife->statistics_valid = 1;
+ new(ife);
- add_interface(ife);
- }
- if (ferror(fh)) {
- perror(_PATH_PROCNET_DEV);
- err = -1;
- }
-
- if (!err)
- err = if_readconf();
+ s = get_name(ife->name, buf);
+ get_dev_fields(s, ife);
+ ife->statistics_valid = 1;
+
+ add_interface(ife);
+ }
+ if (ferror(fh)) {
+ perror(_PATH_PROCNET_DEV);
+ err = -1;
+ }
+ if (!err)
+ err = if_readconf();
#if 0
- free(fmt);
+ free(fmt);
#endif
- return err;
-}
+ return err;
+}
/* Support for fetching an IPX address */
#if HAVE_AFIPX
static int ipx_getaddr(int sock, int ft, struct ifreq *ifr)
{
- ((struct sockaddr_ipx *)&ifr->ifr_addr)->sipx_type=ft;
- return ioctl(sock, SIOCGIFADDR, ifr);
+ ((struct sockaddr_ipx *) &ifr->ifr_addr)->sipx_type = ft;
+ return ioctl(sock, SIOCGIFADDR, ifr);
}
#endif
/* Fetch the interface configuration from the kernel. */
-int
-if_fetch(char *ifname, struct interface *ife)
+int if_fetch(char *ifname, struct interface *ife)
{
- struct ifreq ifr;
- int fd;
-
- strcpy(ifr.ifr_name, ifname);
- if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) return(-1);
- ife->flags = ifr.ifr_flags;
-
- strcpy(ifr.ifr_name, ifname);
- if (ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0)
- memset(ife->hwaddr, 0, 32);
- else
- memcpy(ife->hwaddr,ifr.ifr_hwaddr.sa_data,8);
-
- ife->type=ifr.ifr_hwaddr.sa_family;
-
- strcpy(ifr.ifr_name, ifname);
- if (ioctl(skfd, SIOCGIFMETRIC, &ifr) < 0)
- ife->metric = 0;
- else
- ife->metric = ifr.ifr_metric;
-
- strcpy(ifr.ifr_name, ifname);
- if (ioctl(skfd, SIOCGIFMTU, &ifr) < 0)
- ife->mtu = 0;
- else
- ife->mtu = ifr.ifr_mtu;
-
- if (ife->type==ARPHRD_SLIP || ife->type==ARPHRD_CSLIP ||
- ife->type==ARPHRD_SLIP6 || ife->type==ARPHRD_CSLIP6 ||
- ife->type==ARPHRD_ADAPT) {
-#ifdef SIOCGOUTFILL
+ struct ifreq ifr;
+ int fd;
+
strcpy(ifr.ifr_name, ifname);
- if (ioctl(skfd, SIOCGOUTFILL, &ifr) < 0)
- ife->outfill = 0;
- else
- ife->outfill = (unsigned int)ifr.ifr_data;
-#endif
-#ifdef SIOCGKEEPALIVE
+ if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0)
+ return (-1);
+ ife->flags = ifr.ifr_flags;
+
strcpy(ifr.ifr_name, ifname);
- if (ioctl(skfd, SIOCGKEEPALIVE, &ifr) < 0)
- ife->keepalive = 0;
+ if (ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0)
+ memset(ife->hwaddr, 0, 32);
else
- ife->keepalive = (unsigned int)ifr.ifr_data;
-#endif
- }
+ memcpy(ife->hwaddr, ifr.ifr_hwaddr.sa_data, 8);
- strcpy(ifr.ifr_name, ifname);
- if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0)
- memset(&ife->map, 0, sizeof(struct ifmap));
- else
- memcpy(&ife->map,&ifr.ifr_map,sizeof(struct ifmap));
+ ife->type = ifr.ifr_hwaddr.sa_family;
- strcpy(ifr.ifr_name, ifname);
- if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0)
- memset(&ife->map, 0, sizeof(struct ifmap));
- else
- ife->map = ifr.ifr_map;
-
-#ifdef HAVE_TXQUEUELEN
- strcpy(ifr.ifr_name, ifname);
- if (ioctl(skfd, SIOCGIFTXQLEN, &ifr) < 0)
- ife->tx_queue_len = -1; /* unknown value */
- else
- ife->tx_queue_len = ifr.ifr_qlen;
-#else
- ife->tx_queue_len = -1; /* unknown value */
-#endif
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(skfd, SIOCGIFMETRIC, &ifr) < 0)
+ ife->metric = 0;
+ else
+ ife->metric = ifr.ifr_metric;
-#if HAVE_AFINET
- fd = get_socket_for_af(AF_INET);
- if (fd >= 0) {
strcpy(ifr.ifr_name, ifname);
- if (ioctl(fd, SIOCGIFDSTADDR, &ifr) < 0)
- memset(&ife->dstaddr, 0, sizeof(struct sockaddr));
- else
- ife->dstaddr = ifr.ifr_dstaddr;
+ if (ioctl(skfd, SIOCGIFMTU, &ifr) < 0)
+ ife->mtu = 0;
+ else
+ ife->mtu = ifr.ifr_mtu;
+ if (ife->type == ARPHRD_SLIP || ife->type == ARPHRD_CSLIP ||
+ ife->type == ARPHRD_SLIP6 || ife->type == ARPHRD_CSLIP6 ||
+ ife->type == ARPHRD_ADAPT) {
+#ifdef SIOCGOUTFILL
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(skfd, SIOCGOUTFILL, &ifr) < 0)
+ ife->outfill = 0;
+ else
+ ife->outfill = (unsigned int) ifr.ifr_data;
+#endif
+#ifdef SIOCGKEEPALIVE
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(skfd, SIOCGKEEPALIVE, &ifr) < 0)
+ ife->keepalive = 0;
+ else
+ ife->keepalive = (unsigned int) ifr.ifr_data;
+#endif
+ }
strcpy(ifr.ifr_name, ifname);
- if (ioctl(fd, SIOCGIFBRDADDR, &ifr) < 0)
- memset(&ife->broadaddr, 0, sizeof(struct sockaddr));
- else
- ife->broadaddr = ifr.ifr_broadaddr;
+ if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0)
+ memset(&ife->map, 0, sizeof(struct ifmap));
+ else
+ memcpy(&ife->map, &ifr.ifr_map, sizeof(struct ifmap));
strcpy(ifr.ifr_name, ifname);
- if (ioctl(fd, SIOCGIFNETMASK, &ifr) < 0)
- memset(&ife->netmask, 0, sizeof(struct sockaddr));
- else
- ife->netmask = ifr.ifr_netmask;
+ if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0)
+ memset(&ife->map, 0, sizeof(struct ifmap));
+ else
+ ife->map = ifr.ifr_map;
+#ifdef HAVE_TXQUEUELEN
strcpy(ifr.ifr_name, ifname);
- if (ioctl(fd, SIOCGIFADDR, &ifr) < 0)
- memset(&ife->addr, 0, sizeof(struct sockaddr));
- else
- ife->addr = ifr.ifr_addr;
- }
+ if (ioctl(skfd, SIOCGIFTXQLEN, &ifr) < 0)
+ ife->tx_queue_len = -1; /* unknown value */
+ else
+ ife->tx_queue_len = ifr.ifr_qlen;
+#else
+ ife->tx_queue_len = -1; /* unknown value */
#endif
-
-#if HAVE_AFATALK
- /* DDP address maybe ? */
- fd = get_socket_for_af(AF_APPLETALK);
- if (fd >= 0) {
- strcpy(ifr.ifr_name, ifname);
- if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
- ife->ddpaddr=ifr.ifr_addr;
- ife->has_ddp=1;
+
+#if HAVE_AFINET
+ fd = get_socket_for_af(AF_INET);
+ if (fd >= 0) {
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(fd, SIOCGIFDSTADDR, &ifr) < 0)
+ memset(&ife->dstaddr, 0, sizeof(struct sockaddr));
+ else
+ ife->dstaddr = ifr.ifr_dstaddr;
+
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(fd, SIOCGIFBRDADDR, &ifr) < 0)
+ memset(&ife->broadaddr, 0, sizeof(struct sockaddr));
+ else
+ ife->broadaddr = ifr.ifr_broadaddr;
+
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(fd, SIOCGIFNETMASK, &ifr) < 0)
+ memset(&ife->netmask, 0, sizeof(struct sockaddr));
+ else
+ ife->netmask = ifr.ifr_netmask;
+
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(fd, SIOCGIFADDR, &ifr) < 0)
+ memset(&ife->addr, 0, sizeof(struct sockaddr));
+ else
+ ife->addr = ifr.ifr_addr;
}
- }
#endif
-#if HAVE_AFIPX
- /* Look for IPX addresses with all framing types */
- fd = get_socket_for_af(AF_IPX);
- if (fd >= 0) {
- strcpy(ifr.ifr_name, ifname);
- if (!ipx_getaddr(fd, IPX_FRAME_ETHERII, &ifr)) {
- ife->has_ipx_bb=1;
- ife->ipxaddr_bb=ifr.ifr_addr;
- }
- strcpy(ifr.ifr_name, ifname);
- if (!ipx_getaddr(fd, IPX_FRAME_SNAP, &ifr)) {
- ife->has_ipx_sn=1;
- ife->ipxaddr_sn=ifr.ifr_addr;
- }
- strcpy(ifr.ifr_name, ifname);
- if(!ipx_getaddr(fd, IPX_FRAME_8023, &ifr)) {
- ife->has_ipx_e3=1;
- ife->ipxaddr_e3=ifr.ifr_addr;
+#if HAVE_AFATALK
+ /* DDP address maybe ? */
+ fd = get_socket_for_af(AF_APPLETALK);
+ if (fd >= 0) {
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
+ ife->ddpaddr = ifr.ifr_addr;
+ ife->has_ddp = 1;
+ }
}
- strcpy(ifr.ifr_name, ifname);
- if(!ipx_getaddr(fd, IPX_FRAME_8022, &ifr)) {
- ife->has_ipx_e2=1;
- ife->ipxaddr_e2=ifr.ifr_addr;
+#endif
+
+#if HAVE_AFIPX
+ /* Look for IPX addresses with all framing types */
+ fd = get_socket_for_af(AF_IPX);
+ if (fd >= 0) {
+ strcpy(ifr.ifr_name, ifname);
+ if (!ipx_getaddr(fd, IPX_FRAME_ETHERII, &ifr)) {
+ ife->has_ipx_bb = 1;
+ ife->ipxaddr_bb = ifr.ifr_addr;
+ }
+ strcpy(ifr.ifr_name, ifname);
+ if (!ipx_getaddr(fd, IPX_FRAME_SNAP, &ifr)) {
+ ife->has_ipx_sn = 1;
+ ife->ipxaddr_sn = ifr.ifr_addr;
+ }
+ strcpy(ifr.ifr_name, ifname);
+ if (!ipx_getaddr(fd, IPX_FRAME_8023, &ifr)) {
+ ife->has_ipx_e3 = 1;
+ ife->ipxaddr_e3 = ifr.ifr_addr;
+ }
+ strcpy(ifr.ifr_name, ifname);
+ if (!ipx_getaddr(fd, IPX_FRAME_8022, &ifr)) {
+ ife->has_ipx_e2 = 1;
+ ife->ipxaddr_e2 = ifr.ifr_addr;
+ }
}
- }
#endif
#if HAVE_AFECONET
- /* Econet address maybe? */
- fd = get_socket_for_af(AF_ECONET);
- if (fd >= 0) {
- strcpy(ifr.ifr_name, ifname);
- if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
- ife->ecaddr = ifr.ifr_addr;
- ife->has_econet = 1;
+ /* Econet address maybe? */
+ fd = get_socket_for_af(AF_ECONET);
+ if (fd >= 0) {
+ strcpy(ifr.ifr_name, ifname);
+ if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
+ ife->ecaddr = ifr.ifr_addr;
+ ife->has_econet = 1;
+ }
}
- }
#endif
- return 0;
+ return 0;
}
diff --git a/interface.h b/interface.h
index 06009ce..5fd2cc3 100644
--- a/interface.h
+++ b/interface.h
@@ -1,78 +1,77 @@
-struct user_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 rx_multicast; /* multicast packets received */
- unsigned long rx_compressed;
- unsigned long tx_compressed;
- unsigned long collisions;
+struct user_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 rx_multicast; /* multicast packets received */
+ unsigned long rx_compressed;
+ unsigned long tx_compressed;
+ 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; /* recved pkt with crc error */
- unsigned long rx_frame_errors; /* recv'd frame alignment error */
- unsigned long rx_fifo_errors; /* recv'r fifo overrun */
- unsigned long rx_missed_errors; /* receiver missed packet */
- /* detailed tx_errors */
- unsigned long tx_aborted_errors;
- unsigned long tx_carrier_errors;
- unsigned long tx_fifo_errors;
- unsigned long tx_heartbeat_errors;
- unsigned long tx_window_errors;
+ /* detailed rx_errors: */
+ unsigned long rx_length_errors;
+ unsigned long rx_over_errors; /* receiver ring buff overflow */
+ unsigned long rx_crc_errors; /* recved pkt with crc error */
+ unsigned long rx_frame_errors; /* recv'd frame alignment error */
+ unsigned long rx_fifo_errors; /* recv'r fifo overrun */
+ unsigned long rx_missed_errors; /* receiver missed packet */
+ /* detailed tx_errors */
+ unsigned long tx_aborted_errors;
+ unsigned long tx_carrier_errors;
+ unsigned long tx_fifo_errors;
+ unsigned long tx_heartbeat_errors;
+ unsigned long tx_window_errors;
};
struct interface {
- struct interface *next;
+ struct interface *next;
- char name[IFNAMSIZ]; /* interface name */
- short type; /* if type */
- short flags; /* various flags */
- int metric; /* routing metric */
- int mtu; /* MTU value */
- int tx_queue_len; /* transmit queue length */
- struct ifmap map; /* hardware setup */
- 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 ipxaddr_bb; /* IPX network address */
- struct sockaddr ipxaddr_sn; /* IPX network address */
- 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;
- int has_ipx_e3;
- int has_ipx_e2;
- int has_ax25;
- int has_ddp;
- int has_econet;
- char hwaddr[32]; /* HW address */
- int statistics_valid;
- struct user_net_device_stats stats; /* statistics */
- int keepalive; /* keepalive value for SLIP */
- int outfill; /* outfill value for SLIP */
+ char name[IFNAMSIZ]; /* interface name */
+ short type; /* if type */
+ short flags; /* various flags */
+ int metric; /* routing metric */
+ int mtu; /* MTU value */
+ int tx_queue_len; /* transmit queue length */
+ struct ifmap map; /* hardware setup */
+ 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 ipxaddr_bb; /* IPX network address */
+ struct sockaddr ipxaddr_sn; /* IPX network address */
+ 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;
+ int has_ipx_e3;
+ int has_ipx_e2;
+ int has_ax25;
+ int has_ddp;
+ int has_econet;
+ char hwaddr[32]; /* HW address */
+ int statistics_valid;
+ struct user_net_device_stats stats; /* statistics */
+ int keepalive; /* keepalive value for SLIP */
+ int outfill; /* outfill value for SLIP */
};
extern int if_fetch(char *ifname, struct interface *ife);
-extern int for_all_interfaces(int (*)(struct interface *, void *), void *);
+extern int for_all_interfaces(int (*)(struct interface *, void *), void *);
extern struct interface *lookup_interface(char *name);
extern int if_readlist(void);
-/* Define for poor glibc2.0 users, the feature check is done at runtime */
+/* Define for poor glibc2.0 users, the feature check is done at runtime */
#if !defined(SIOCSIFTXQLEN)
-#define SIOCSIFTXQLEN 0x8943
-#define SIOCGIFTXQLEN 0x8942
+#define SIOCSIFTXQLEN 0x8943
+#define SIOCGIFTXQLEN 0x8942
#endif
#if !defined(ifr_qlen)
@@ -83,5 +82,5 @@ extern int if_readlist(void);
#define HAVE_DYNAMIC
#ifndef IFF_DYNAMIC
-#define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses*/
+#define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses */
#endif
diff --git a/lib/Makefile b/lib/Makefile
index 97e736d..f36b6af 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -22,9 +22,8 @@ AFGROBJS = inet_gr.o inet6_gr.o ipx_gr.o ddp_gr.o netrom_gr.o ax25_gr.o rose_gr.
AFSROBJS = inet_sr.o inet6_sr.o netrom_sr.o ipx_sr.o setroute.o
ACTOBJS = slip_ac.o ppp_ac.o activate.o
VARIA = getargs.o masq_info.o proc.o util.o nstrcmp.o
-NLSMISC = net-string.o
-OBJS = $(NLSMISC) $(VARIA) $(AFOBJS) $(HWOBJS) \
+OBJS = $(VARIA) $(AFOBJS) $(HWOBJS) \
$(AFGROBJS) $(AFSROBJS) $(ACTOBJS)
diff --git a/lib/activate.c b/lib/activate.c
index 07c5521..ae8ade2 100644
--- a/lib/activate.c
+++ b/lib/activate.c
@@ -1,27 +1,27 @@
/*
- * lib/activate.c This file contains a small interface function to
- * use the HW specific activate routines for line
- * disciplines
+ * lib/activate.c This file contains a small interface function to
+ * use the HW specific activate routines for line
+ * disciplines
*
- * NET-LIB A collection of functions used from the base set of the
- * NET-3 Networking Distribution for the LINUX operating
- * system. (net-tools, net-drivers)
+ * NET-LIB A collection of functions used from the base set of the
+ * NET-3 Networking Distribution for the LINUX operating
+ * system. (net-tools, net-drivers)
*
- * Version: lib/activate.c 0.01 (1996-03-22)
+ * Version: $Id: activate.c,v 1.3 1998/11/15 20:08:55 freitag Exp $
*
- * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de>
- * Copyright 1996 Bernd Eckenfels, Germany
+ * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de>
+ * Copyright 1996 Bernd Eckenfels, Germany
*
* Modifications:
*
- *960322 {0.01} Bernd Eckenfels: creation
+ *960322 {0.01} Bernd Eckenfels: creation
*980411 {0.01i} Arnaldo Carvalho: i18n: now uses gettext
*
- * 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.
+ * 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 <stdio.h>
#include <string.h>
@@ -31,12 +31,12 @@
#include "config.h"
#include "intl.h"
-extern struct hwtype slip_hwtype;
-extern struct hwtype cslip_hwtype;
-extern struct hwtype slip6_hwtype;
-extern struct hwtype cslip6_hwtype;
-extern struct hwtype adaptive_hwtype;
-extern struct hwtype ppp_hwtype;
+extern struct hwtype slip_hwtype;
+extern struct hwtype cslip_hwtype;
+extern struct hwtype slip6_hwtype;
+extern struct hwtype cslip6_hwtype;
+extern struct hwtype adaptive_hwtype;
+extern struct hwtype ppp_hwtype;
extern int SLIP_activate(int fd);
extern int CSLIP_activate(int fd);
@@ -45,34 +45,33 @@ extern int CSLIP6_activate(int fd);
extern int ADAPTIVE_activate(int fd);
extern int PPP_activate(int fd);
-void
-activate_init(void)
+void activate_init(void)
{
#if HAVE_HWSLIP
- slip_hwtype.activate = SLIP_activate;
- cslip_hwtype.activate = CSLIP_activate;
- slip6_hwtype.activate = SLIP6_activate;
- cslip6_hwtype.activate = CSLIP6_activate;
- adaptive_hwtype.activate = ADAPTIVE_activate;
+ slip_hwtype.activate = SLIP_activate;
+ cslip_hwtype.activate = CSLIP_activate;
+ slip6_hwtype.activate = SLIP6_activate;
+ cslip6_hwtype.activate = CSLIP6_activate;
+ adaptive_hwtype.activate = ADAPTIVE_activate;
#endif
#if HAVE_HWPPP
- ppp_hwtype.activate = PPP_activate;
+ ppp_hwtype.activate = PPP_activate;
#endif
}
int activate_ld(const char *hwname, int fd)
{
- struct hwtype *hw;
-
- hw = get_hwtype(hwname);
-
- if (!hw) {
- fprintf(stderr,_("Hardware type `%s' not supported.\n"),hwname);
- return(E_NOSUPP);
- }
- if (!hw->activate) {
- fprintf(stderr,_("Cannot change line discipline to `%s'.\n"),hw->name);
- return(E_OPTERR);
- }
- return(hw->activate(fd));
+ struct hwtype *hw;
+
+ hw = get_hwtype(hwname);
+
+ if (!hw) {
+ fprintf(stderr, _("Hardware type `%s' not supported.\n"), hwname);
+ return (E_NOSUPP);
+ }
+ if (!hw->activate) {
+ fprintf(stderr, _("Cannot change line discipline to `%s'.\n"), hw->name);
+ return (E_OPTERR);
+ }
+ return (hw->activate(fd));
}
diff --git a/lib/af.c b/lib/af.c
index c9b79e9..c373aa2 100644
--- a/lib/af.c
+++ b/lib/af.c
@@ -1,17 +1,17 @@
/*
- * lib/af.c This file contains the top-level part of the protocol
- * support functions module for the NET-2 base distribution.
+ * lib/af.c This file contains the top-level part of the protocol
+ * support functions module for the NET-2 base distribution.
*
- * Version: lib/af.c 1.13 (1996-02-21)
+ * Version: $Id: af.c,v 1.6 1998/11/15 20:08:59 freitag Exp $
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
- * 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.
+ * 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 <sys/types.h>
#include <sys/socket.h>
@@ -38,231 +38,257 @@ int flag_econet = 0;
struct aftrans_t {
- char *alias;
- char *name;
- int *flag;
-} aftrans[]={
- {"ax25", "ax25", &flag_ax25},
- {"ip", "inet", &flag_inet},
- {"ip6", "inet6", &flag_inet6},
- {"ipx", "ipx", &flag_ipx},
- {"appletalk", "ddp", &flag_ddp},
- {"netrom", "netrom", &flag_netrom},
- {"inet", "inet", &flag_inet},
- {"inet6", "inet6", &flag_inet6},
- {"ddp", "ddp", &flag_ddp},
- {"unix", "unix", &flag_unx},
- {"tcpip", "inet", &flag_inet},
- {"econet", "ec", &flag_econet},
- {0, 0, 0}
+ char *alias;
+ char *name;
+ int *flag;
+} aftrans[] = {
+
+ {
+ "ax25", "ax25", &flag_ax25
+ },
+ {
+ "ip", "inet", &flag_inet
+ },
+ {
+ "ip6", "inet6", &flag_inet6
+ },
+ {
+ "ipx", "ipx", &flag_ipx
+ },
+ {
+ "appletalk", "ddp", &flag_ddp
+ },
+ {
+ "netrom", "netrom", &flag_netrom
+ },
+ {
+ "inet", "inet", &flag_inet
+ },
+ {
+ "inet6", "inet6", &flag_inet6
+ },
+ {
+ "ddp", "ddp", &flag_ddp
+ },
+ {
+ "unix", "unix", &flag_unx
+ },
+ {
+ "tcpip", "inet", &flag_inet
+ },
+ {
+ "econet", "ec", &flag_econet
+ },
+ {
+ 0, 0, 0
+ }
};
-char afname[256]="";
+char afname[256] = "";
-extern struct aftype unspec_aftype;
-extern struct aftype unix_aftype;
-extern struct aftype inet_aftype;
-extern struct aftype inet6_aftype;
-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;
+extern struct aftype unspec_aftype;
+extern struct aftype unix_aftype;
+extern struct aftype inet_aftype;
+extern struct aftype inet6_aftype;
+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;
-struct aftype *aftypes[] = {
+struct aftype *aftypes[] =
+{
#if HAVE_AFUNIX
- &unix_aftype,
+ &unix_aftype,
#endif
#if HAVE_AFINET
- &inet_aftype,
+ &inet_aftype,
#endif
#if HAVE_AFINET6
- &inet6_aftype,
+ &inet6_aftype,
#endif
#if HAVE_AFAX25
- &ax25_aftype,
+ &ax25_aftype,
#endif
#if HAVE_AFNETROM
- &netrom_aftype,
+ &netrom_aftype,
#endif
#if HAVE_AFIPX
- &ipx_aftype,
+ &ipx_aftype,
#endif
#if HAVE_AFATALK
- &ddp_aftype,
+ &ddp_aftype,
#endif
#if HAVE_AFECONET
- &ec_aftype,
+ &ec_aftype,
#endif
- &unspec_aftype,
- NULL
+ &unspec_aftype,
+ NULL
};
-void afinit ()
+void afinit()
{
- unspec_aftype.title = _("UNSPEC");
+ unspec_aftype.title = _("UNSPEC");
#if HAVE_AFINET
- unix_aftype.title = _("UNIX Domain");
+ unix_aftype.title = _("UNIX Domain");
#endif
#if HAVE_AFINET
- inet_aftype.title = _("DARPA Internet");
+ inet_aftype.title = _("DARPA Internet");
#endif
#if HAVE_AFINET6
- inet6_aftype.title = _("IPv6");
+ inet6_aftype.title = _("IPv6");
#endif
#if HAVE_AFAX25
- ax25_aftype.title = _("AMPR AX.25");
+ ax25_aftype.title = _("AMPR AX.25");
#endif
#if HAVE_AFNETROM
- netrom_aftype.title = _("AMPR NET/ROM");
+ netrom_aftype.title = _("AMPR NET/ROM");
#endif
#if HAVE_AFIPX
- ipx_aftype.title = _("IPX");
+ ipx_aftype.title = _("IPX");
#endif
#if HAVE_AFATALK
- ddp_aftype.title = _("Appletalk DDP");
+ ddp_aftype.title = _("Appletalk DDP");
#endif
#if HAVE_AFECONET
- ec_aftype.title = _("Econet");
+ ec_aftype.title = _("Econet");
#endif
- sVafinit = 1;
+ sVafinit = 1;
}
-/* set the default AF list from the program name or a constant value */
-void
-aftrans_def(char *tool, char *argv0, char *dflt)
+/* set the default AF list from the program name or a constant value */
+void aftrans_def(char *tool, char *argv0, char *dflt)
{
- char *tmp;
- char *buf;
-
- strcpy(afname, dflt);
-
- if (!(tmp = strrchr(argv0, '/')))
- tmp = argv0; /* no slash?! */
- else
- tmp++;
-
- if (!(buf = strdup(tmp)))
- return;
-
- if (strlen(tool) >= strlen(tmp)) {
- free(buf);
- return;
- }
- tmp = buf+(strlen(tmp)-strlen(tool));
-
- if (strcmp(tmp, tool)!=0) {
- free(buf);
- return;
- }
-
- *tmp = '\0';
- if ((tmp = strchr(buf,'_')))
- *tmp = '\0';
-
- afname[0]='\0';
- if (aftrans_opt(buf))
- strcpy(afname, buf);
-
- free(buf);
+ char *tmp;
+ char *buf;
+
+ strcpy(afname, dflt);
+
+ if (!(tmp = strrchr(argv0, '/')))
+ tmp = argv0; /* no slash?! */
+ else
+ tmp++;
+
+ if (!(buf = strdup(tmp)))
+ return;
+
+ if (strlen(tool) >= strlen(tmp)) {
+ free(buf);
+ return;
+ }
+ tmp = buf + (strlen(tmp) - strlen(tool));
+
+ if (strcmp(tmp, tool) != 0) {
+ free(buf);
+ return;
+ }
+ *tmp = '\0';
+ if ((tmp = strchr(buf, '_')))
+ *tmp = '\0';
+
+ afname[0] = '\0';
+ if (aftrans_opt(buf))
+ strcpy(afname, buf);
+
+ free(buf);
}
/* Check our protocol family table for this family. */
-struct aftype *
-get_aftype(const char *name)
+struct aftype *get_aftype(const char *name)
{
- struct aftype **afp;
-
- if (!sVafinit)
- afinit ();
-
- afp = aftypes;
- while (*afp != NULL) {
- if (!strcmp((*afp)->name, name)) return(*afp);
+ struct aftype **afp;
+
+ if (!sVafinit)
+ afinit();
+
+ afp = aftypes;
+ while (*afp != NULL) {
+ if (!strcmp((*afp)->name, name))
+ return (*afp);
afp++;
- }
- if (index(name,','))
- fprintf(stderr,_("Please don't supply more than one address family.\n"));
- return(NULL);
+ }
+ if (index(name, ','))
+ fprintf(stderr, _("Please don't supply more than one address family.\n"));
+ return (NULL);
}
/* Check our protocol family table for this family. */
-struct aftype *
-get_afntype(int af)
+struct aftype *get_afntype(int af)
{
- struct aftype **afp;
-
- if (!sVafinit)
- afinit ();
-
- afp = aftypes;
- while (*afp != NULL) {
- if ((*afp)->af == af) return(*afp);
+ struct aftype **afp;
+
+ if (!sVafinit)
+ afinit();
+
+ afp = aftypes;
+ while (*afp != NULL) {
+ if ((*afp)->af == af)
+ return (*afp);
afp++;
- }
- return(NULL);
+ }
+ return (NULL);
}
/* Check our protocol family table for this family and return its socket */
-int
-get_socket_for_af(int af)
+int get_socket_for_af(int af)
{
- struct aftype **afp;
-
- if (!sVafinit)
- afinit ();
-
- afp = aftypes;
- while (*afp != NULL) {
- if ((*afp)->af == af) return (*afp)->fd;
+ struct aftype **afp;
+
+ if (!sVafinit)
+ afinit();
+
+ afp = aftypes;
+ while (*afp != NULL) {
+ if ((*afp)->af == af)
+ return (*afp)->fd;
afp++;
- }
- return -1;
+ }
+ return -1;
}
int aftrans_opt(const char *arg)
{
- struct aftrans_t *paft;
- char *tmp1, *tmp2;
- char buf[256];
-
- strncpy(buf,arg,sizeof(buf));
- buf[sizeof(buf)-1]='\0';
-
- tmp1=buf;
-
- while(tmp1) {
-
- tmp2=index(tmp1,',');
-
- if (tmp2)
- *(tmp2++)='\0';
-
- paft=aftrans;
- for(paft=aftrans;paft->alias;paft++) {
- if (strcmp(tmp1,paft->alias))
- continue;
- if (strlen(paft->name)+strlen(afname)+1 >= sizeof(afname)) {
- fprintf(stderr,_("Too much address family arguments.\n"));
- return(0);
- }
- if (paft->flag)
- (*paft->flag)++;
- if (afname[0])
- strcat(afname,",");
- strcat(afname,paft->name);
- break;
- }
- if (!paft->alias) {
- fprintf(stderr,_("Unknown address family `%s'.\n"),tmp1);
- return(1);
- }
- tmp1=tmp2;
+ struct aftrans_t *paft;
+ char *tmp1, *tmp2;
+ char buf[256];
+
+ strncpy(buf, arg, sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+
+ tmp1 = buf;
+
+ while (tmp1) {
+
+ tmp2 = index(tmp1, ',');
+
+ if (tmp2)
+ *(tmp2++) = '\0';
+
+ paft = aftrans;
+ for (paft = aftrans; paft->alias; paft++) {
+ if (strcmp(tmp1, paft->alias))
+ continue;
+ if (strlen(paft->name) + strlen(afname) + 1 >= sizeof(afname)) {
+ fprintf(stderr, _("Too much address family arguments.\n"));
+ return (0);
+ }
+ if (paft->flag)
+ (*paft->flag)++;
+ if (afname[0])
+ strcat(afname, ",");
+ strcat(afname, paft->name);
+ break;
+ }
+ if (!paft->alias) {
+ fprintf(stderr, _("Unknown address family `%s'.\n"), tmp1);
+ return (1);
}
+ tmp1 = tmp2;
+ }
- return(0);
+ return (0);
}
diff --git a/lib/arcnet.c b/lib/arcnet.c
index 7804211..8b8a870 100644
--- a/lib/arcnet.c
+++ b/lib/arcnet.c
@@ -1,17 +1,17 @@
/*
- * lib/arcnet.c This file contains an implementation of the "ARCnet"
- * support functions for the NET-2 base distribution.
+ * lib/arcnet.c This file contains an implementation of the "ARCnet"
+ * support functions for the NET-2 base distribution.
*
- * Version: @(#)arcnet.c 1.10 10/07/93
+ * Version: $Id: arcnet.c,v 1.3 1998/11/15 20:09:06 freitag Exp $
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
- * 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.
+ * 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"
@@ -34,103 +34,106 @@ extern struct hwtype arcnet_hwtype;
/* Display an ARCnet address in readable format. */
-static char *
-pr_arcnet(unsigned char *ptr)
+static char *pr_arcnet(unsigned char *ptr)
{
- static char buff[64];
+ static char buff[64];
- snprintf(buff, sizeof(buff), "%02X",(ptr[0] & 0377));
- return(buff);
+ snprintf(buff, sizeof(buff), "%02X", (ptr[0] & 0377));
+ return (buff);
}
/* Display an ARCnet socket address. */
-static char *
-pr_sarcnet(struct sockaddr *sap)
+static char *pr_sarcnet(struct sockaddr *sap)
{
- static char buf[64];
+ static char buf[64];
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return strncpy (buf, _("[NONE SET]"), sizeof (buf));
- return(pr_arcnet(sap->sa_data));
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return strncpy(buf, _("[NONE SET]"), sizeof(buf));
+ return (pr_arcnet(sap->sa_data));
}
/* Input an ARCnet address and convert to binary. */
-static int
-in_arcnet(char *bufp, struct sockaddr *sap)
+static int in_arcnet(char *bufp, struct sockaddr *sap)
{
- unsigned char *ptr;
- char c, *orig;
- int i, val;
+ unsigned char *ptr;
+ char c, *orig;
+ int i, val;
- sap->sa_family = arcnet_hwtype.type;
- ptr = sap->sa_data;
+ sap->sa_family = arcnet_hwtype.type;
+ ptr = sap->sa_data;
- i = 0;
- orig = bufp;
- while((*bufp != '\0') && (i < 1)) {
+ i = 0;
+ orig = bufp;
+ while ((*bufp != '\0') && (i < 1)) {
val = 0;
c = *bufp++;
- if (isdigit(c)) val = c - '0';
- else if (c >= 'a' && c <= 'f') val = c - 'a' + 10;
- else if (c >= 'A' && c <= 'F') val = c - 'A' + 10;
- else {
+ if (isdigit(c))
+ val = c - '0';
+ else if (c >= 'a' && c <= 'f')
+ val = c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ val = c - 'A' + 10;
+ else {
#ifdef DEBUG
- fprintf(stderr, _("in_arcnet(%s): invalid arcnet address!\n"), orig);
+ fprintf(stderr, _("in_arcnet(%s): invalid arcnet address!\n"), orig);
#endif
- errno = EINVAL;
- return(-1);
+ errno = EINVAL;
+ return (-1);
}
val <<= 4;
c = *bufp++;
- if (isdigit(c)) val |= c - '0';
- else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10;
- else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10;
- else {
+ if (isdigit(c))
+ val |= c - '0';
+ else if (c >= 'a' && c <= 'f')
+ val |= c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ val |= c - 'A' + 10;
+ else {
#ifdef DEBUG
- fprintf(stderr, _("in_arcnet(%s): invalid arcnet address!\n"), orig);
+ fprintf(stderr, _("in_arcnet(%s): invalid arcnet address!\n"), orig);
#endif
- errno = EINVAL;
- return(-1);
+ errno = EINVAL;
+ return (-1);
}
*ptr++ = (unsigned char) (val & 0377);
i++;
/* We might get a semicolon here - not required. */
if (*bufp == ':') {
- if (i == ETH_ALEN) {
+ if (i == ETH_ALEN) {
#ifdef DEBUG
- fprintf(stderr, _("in_arcnet(%s): trailing : ignored!\n"),
- orig)
+ fprintf(stderr, _("in_arcnet(%s): trailing : ignored!\n"),
+ orig)
#endif
- ; /* nothing */
- }
- bufp++;
+ ; /* nothing */
+ }
+ bufp++;
}
- }
+ }
- /* That's it. Any trailing junk? */
- if ((i == ETH_ALEN) && (*bufp != '\0')) {
+ /* That's it. Any trailing junk? */
+ if ((i == ETH_ALEN) && (*bufp != '\0')) {
#ifdef DEBUG
fprintf(stderr, _("in_arcnet(%s): trailing junk!\n"), orig);
errno = EINVAL;
- return(-1);
+ return (-1);
#endif
- }
-
+ }
#ifdef DEBUG
- fprintf(stderr, "in_arcnet(%s): %s\n", orig, pr_arcnet(sap->sa_data));
+ fprintf(stderr, "in_arcnet(%s): %s\n", orig, pr_arcnet(sap->sa_data));
#endif
- return(0);
+ return (0);
}
-struct hwtype arcnet_hwtype = {
- "arcnet", NULL, /*"2.5Mbps ARCnet",*/ ARPHRD_ARCNET, 1,
- pr_arcnet, pr_sarcnet, in_arcnet, NULL
+struct hwtype arcnet_hwtype =
+{
+ "arcnet", NULL, /*"2.5Mbps ARCnet", */ ARPHRD_ARCNET, 1,
+ pr_arcnet, pr_sarcnet, in_arcnet, NULL
};
-#endif /* HAVE_HWARC */
+#endif /* HAVE_HWARC */
diff --git a/lib/ash.c b/lib/ash.c
index 80eafeb..8542c27 100644
--- a/lib/ash.c
+++ b/lib/ash.c
@@ -1,6 +1,7 @@
/*
- * lib/ash.c This file contains an implementation of the Ash
- * support functions for the NET-2 base distribution.
+ * lib/ash.c This file contains an implementation of the Ash
+ * support functions for the NET-2 base distribution.
+ * $Id: ash.c,v 1.6 1998/11/15 20:09:16 freitag Exp $
*/
#include "config.h"
@@ -29,77 +30,76 @@
extern struct hwtype ash_hwtype;
/* Display an Ash address in readable format. */
-static char *
-pr_ash(unsigned char *ptr)
+static char *pr_ash(unsigned char *ptr)
{
- static char buff[128];
- char *p = buff;
- unsigned int i = 0;
-
- p[0] = '['; p++;
- while (ptr[i] != 0xc9 && ptr[i] != 0xff && (i < ASH_ALEN))
- sprintf (p++, "%1x", ptr[i++]);
- *(p++) = ']';
- *p = 0;
-
- return buff;
+ static char buff[128];
+ char *p = buff;
+ unsigned int i = 0;
+
+ p[0] = '[';
+ p++;
+ while (ptr[i] != 0xc9 && ptr[i] != 0xff && (i < ASH_ALEN))
+ sprintf(p++, "%1x", ptr[i++]);
+ *(p++) = ']';
+ *p = 0;
+
+ return buff;
}
/* Display an Ash socket address. */
-static char *
-pr_sash(struct sockaddr *sap)
+static char *pr_sash(struct sockaddr *sap)
{
- static char buf[64];
+ static char buf[64];
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return strncpy (buf, "[NONE SET]", 64);
- return pr_ash (sap->sa_data);
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return strncpy(buf, "[NONE SET]", 64);
+ return pr_ash(sap->sa_data);
}
-static unsigned char hamming[16] =
-{
- 0x15, 0x02, 0x49, 0x5e, 0x64, 0x73, 0x38, 0x2f,
- 0xd0, 0xc7, 0x8c, 0x9b, 0xa1, 0xb6, 0xfd, 0xea
+static unsigned char hamming[16] =
+{
+ 0x15, 0x02, 0x49, 0x5e, 0x64, 0x73, 0x38, 0x2f,
+ 0xd0, 0xc7, 0x8c, 0x9b, 0xa1, 0xb6, 0xfd, 0xea
};
-static int
-in_ash(char *bufp, struct sockaddr *sap)
+static int in_ash(char *bufp, struct sockaddr *sap)
{
- unsigned char *ptr;
- unsigned int i = 0;
-
- sap->sa_family = ash_hwtype.type;
- ptr = sap->sa_data;
-
- while (bufp && i < ASH_ALEN) {
- char *next;
- int hop = strtol (bufp, &next, 16);
- ptr[i++] = hamming[hop];
- switch (*next) {
- case ':':
- bufp = next + 1;
- break;
- case 0:
- bufp = NULL;
- break;
- default:
- fprintf (stderr, _("Malformed Ash address"));
- memset (ptr, 0xc9, ASH_ALEN);
- return -1;
+ unsigned char *ptr;
+ unsigned int i = 0;
+
+ sap->sa_family = ash_hwtype.type;
+ ptr = sap->sa_data;
+
+ while (bufp && i < ASH_ALEN) {
+ char *next;
+ int hop = strtol(bufp, &next, 16);
+ ptr[i++] = hamming[hop];
+ switch (*next) {
+ case ':':
+ bufp = next + 1;
+ break;
+ case 0:
+ bufp = NULL;
+ break;
+ default:
+ fprintf(stderr, _("Malformed Ash address"));
+ memset(ptr, 0xc9, ASH_ALEN);
+ return -1;
+ }
}
- }
- while (i < ASH_ALEN)
- ptr[i++] = 0xc9;
+ while (i < ASH_ALEN)
+ ptr[i++] = 0xc9;
- return 0;
+ return 0;
}
-struct hwtype ash_hwtype = {
- "ash", NULL, ARPHRD_ASH, ASH_ALEN,
- pr_ash, pr_sash, in_ash, NULL
+struct hwtype ash_hwtype =
+{
+ "ash", NULL, ARPHRD_ASH, ASH_ALEN,
+ pr_ash, pr_sash, in_ash, NULL
};
#endif
diff --git a/lib/ax25.c b/lib/ax25.c
index 0260a0f..ba5e1ad 100644
--- a/lib/ax25.c
+++ b/lib/ax25.c
@@ -1,22 +1,22 @@
/*
- * lib/ax25.c This file contains an implementation of the "AX.25"
- * support functions for the NET-2 base distribution.
+ * lib/ax25.c This file contains an implementation of the "AX.25"
+ * support functions.
*
- * Version: @(#)ax25.c 1.20 12/16/93
+ * Version: $Id: ax25.c,v 1.6 1998/11/15 20:09:19 freitag Exp $
*
- * NOTE: I will redo this module as soon as I got the libax25.a
- * library sorted out. This library contains some useful
- * and often used address conversion functions, database
- * lookup stuff, and more of the like.
+ * NOTE: I will redo this module as soon as I got the libax25.a
+ * library sorted out. This library contains some useful
+ * and often used address conversion functions, database
+ * lookup stuff, and more of the like.
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
- * 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.
+ * 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"
@@ -44,164 +44,165 @@
static char AX25_errmsg[128];
-
extern struct aftype ax25_aftype;
-
-static char *
-AX25_print(unsigned char *ptr)
+static char *AX25_print(unsigned char *ptr)
{
- static char buff[8];
- int i;
+ static char buff[8];
+ int i;
- for (i = 0; i < 6; i++) {
+ for (i = 0; i < 6; i++) {
buff[i] = ((ptr[i] & 0377) >> 1);
- if (buff[i] == ' ') buff[i] = '\0';
- }
- buff[6] = '\0';
- i = ((ptr[6] & 0x1E) >> 1);
- if (i != 0) sprintf(&buff[strlen(buff)], "-%d", i);
- return(buff);
+ if (buff[i] == ' ')
+ buff[i] = '\0';
+ }
+ buff[6] = '\0';
+ i = ((ptr[6] & 0x1E) >> 1);
+ if (i != 0)
+ sprintf(&buff[strlen(buff)], "-%d", i);
+ return (buff);
}
/* Display an AX.25 socket address. */
static char *
-AX25_sprint(struct sockaddr *sap, int numeric)
+ AX25_sprint(struct sockaddr *sap, int numeric)
{
- static char buf[64];
+ static char buf[64];
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return strncpy (buf, _("[NONE SET]"), sizeof (buf));
- return(AX25_print(((struct sockaddr_ax25 *)sap)->sax25_call.ax25_call));
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return strncpy(buf, _("[NONE SET]"), sizeof(buf));
+ return (AX25_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call));
}
-static int
-AX25_input(int type, char *bufp, struct sockaddr *sap)
+static int AX25_input(int type, char *bufp, struct sockaddr *sap)
{
- unsigned char *ptr;
- char *orig, c;
- int i;
+ unsigned char *ptr;
+ char *orig, c;
+ int i;
- sap->sa_family = ax25_aftype.af;
- ptr = ((struct sockaddr_ax25 *)sap)->sax25_call.ax25_call;
+ sap->sa_family = ax25_aftype.af;
+ ptr = ((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call;
- /* First, scan and convert the basic callsign. */
- orig = bufp;
- i = 0;
- while((*bufp != '\0') && (*bufp != '-') && (i < 6)) {
+ /* First, scan and convert the basic callsign. */
+ orig = bufp;
+ i = 0;
+ while ((*bufp != '\0') && (*bufp != '-') && (i < 6)) {
c = *bufp++;
- if (islower(c)) c = toupper(c);
- if (! (isupper(c) || isdigit(c))) {
- strcpy(AX25_errmsg, _("Invalid callsign"));
+ if (islower(c))
+ c = toupper(c);
+ if (!(isupper(c) || isdigit(c))) {
+ strncpy(AX25_errmsg, _("Invalid callsign"), sizeof(AX25_errmsg)-2);
+ AX25_errmsg[sizeof(AX25_errmsg)-1]=0;
#ifdef DEBUG
- fprintf(stderr, "ax25_input(%s): %s !\n", AX25_errmsg, orig);
+ fprintf(stderr, "ax25_input(%s): %s !\n", AX25_errmsg, orig);
#endif
- errno = EINVAL;
- return(-1);
+ errno = EINVAL;
+ return (-1);
}
*ptr++ = (unsigned char) ((c << 1) & 0xFE);
i++;
- }
+ }
- /* Callsign too long? */
- if ((i == 6) && (*bufp != '-') && (*bufp != '\0')) {
+ /* Callsign too long? */
+ if ((i == 6) && (*bufp != '-') && (*bufp != '\0')) {
strcpy(AX25_errmsg, _("Callsign too long"));
#ifdef DEBUG
fprintf(stderr, "ax25_input(%s): %s !\n", AX25_errmsg, orig);
#endif
errno = E2BIG;
- return(-1);
- }
-
- /* Nope, fill out the address bytes with blanks. */
- while (i++ < sizeof(ax25_address)-1) {
+ return (-1);
+ }
+ /* Nope, fill out the address bytes with blanks. */
+ while (i++ < sizeof(ax25_address) - 1) {
*ptr++ = (unsigned char) ((' ' << 1) & 0xFE);
- }
+ }
- /* See if we need to add an SSID field. */
- if (*bufp == '-') {
+ /* See if we need to add an SSID field. */
+ if (*bufp == '-') {
i = atoi(++bufp);
*ptr = (unsigned char) ((i << 1) & 0xFE);
- } else {
+ } else {
*ptr = (unsigned char) '\0';
- }
+ }
- /* All done. */
+ /* All done. */
#ifdef DEBUG
- fprintf(stderr, "ax25_input(%s): ", orig);
- for (i = 0; i < sizeof(ax25_address); i++)
+ fprintf(stderr, "ax25_input(%s): ", orig);
+ for (i = 0; i < sizeof(ax25_address); i++)
fprintf(stderr, "%02X ", sap->sa_data[i] & 0377);
- fprintf(stderr, "\n");
+ fprintf(stderr, "\n");
#endif
- return(0);
+ return (0);
}
/* Display an error message. */
-static void
-AX25_herror(char *text)
+static void AX25_herror(char *text)
{
- if (text == NULL) fprintf(stderr, "%s\n", AX25_errmsg);
- else fprintf(stderr, "%s: %s\n", text, AX25_errmsg);
+ if (text == NULL)
+ fprintf(stderr, "%s\n", AX25_errmsg);
+ else
+ fprintf(stderr, "%s: %s\n", text, AX25_errmsg);
}
-static char *
-AX25_hprint(struct sockaddr *sap)
+static char *AX25_hprint(struct sockaddr *sap)
{
- static char buf[64];
+ static char buf[64];
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return strncpy (buf, _("[NONE SET]"), sizeof (buf));
- return(AX25_print(((struct sockaddr_ax25 *)sap)->sax25_call.ax25_call));
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return strncpy(buf, _("[NONE SET]"), sizeof(buf));
+ return (AX25_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call));
}
-static int
-AX25_hinput(char *bufp, struct sockaddr *sap)
+static int AX25_hinput(char *bufp, struct sockaddr *sap)
{
- if (AX25_input(0, bufp, sap) < 0) return(-1);
- sap->sa_family = ARPHRD_AX25;
- return(0);
+ if (AX25_input(0, bufp, sap) < 0)
+ return (-1);
+ sap->sa_family = ARPHRD_AX25;
+ return (0);
}
#if 0
/* Set the line discipline of a terminal line. */
-static int
-KISS_set_disc(int fd, int disc)
+static int KISS_set_disc(int fd, int disc)
{
- if (ioctl(fd, TIOCSETD, &disc) < 0) {
+ if (ioctl(fd, TIOCSETD, &disc) < 0) {
fprintf(stderr, "KISS_set_disc(%d): %s\n", disc, strerror(errno));
- return(-errno);
- }
- return(0);
+ return (-errno);
+ }
+ return (0);
}
/* Start the KISS encapsulation on the file descriptor. */
-static int
-KISS_init(int fd)
+static int KISS_init(int fd)
{
- if (KISS_set_disc(fd, N_SLIP) < 0) return(-1);
- if (ioctl(fd, SIOCSIFENCAP, 4) <0) return(-1);
- return(0);
+ if (KISS_set_disc(fd, N_SLIP) < 0)
+ return (-1);
+ if (ioctl(fd, SIOCSIFENCAP, 4) < 0)
+ return (-1);
+ return (0);
}
#endif
-struct hwtype ax25_hwtype = {
- "ax25", NULL, /*"AMPR AX.25",*/ ARPHRD_AX25, 7,
- AX25_print, AX25_hprint, AX25_hinput, NULL
+struct hwtype ax25_hwtype =
+{
+ "ax25", NULL, /*"AMPR AX.25", */ ARPHRD_AX25, 7,
+ AX25_print, AX25_hprint, AX25_hinput, NULL
};
-struct aftype ax25_aftype = {
- "ax25", NULL, /*"AMPR AX.25",*/ AF_AX25, 7,
- AX25_print, AX25_sprint, AX25_input, AX25_herror,
- NULL, NULL, NULL,
- -1,
- "/proc/net/ax25"
+struct aftype ax25_aftype =
+{
+ "ax25", NULL, /*"AMPR AX.25", */ AF_AX25, 7,
+ AX25_print, AX25_sprint, AX25_input, AX25_herror,
+ NULL, NULL, NULL,
+ -1,
+ "/proc/net/ax25"
};
-#endif /* HAVE_xxAX25 */
+#endif /* HAVE_xxAX25 */
diff --git a/lib/ax25_gr.c b/lib/ax25_gr.c
index 6ecf59e..69f0793 100644
--- a/lib/ax25_gr.c
+++ b/lib/ax25_gr.c
@@ -1,18 +1,18 @@
/*
- * lib/ax25_gr.c This file contains an implementation of the "AX.25"
- * route print support functions.
+ * lib/ax25_gr.c This file contains an implementation of the "AX.25"
+ * route print support functions.
*
- * Version: lib/ax25_gr.c 1.01 (1996-02-15)
+ * Version: $Id: ax25_gr.c,v 1.3 1998/11/15 20:09:22 freitag Exp $
*
- * Author: Bernd Eckenfels, <ecki@lina.inka.de>
- * Copyright 1999 Bernd Eckenfels, Germany
- * base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK>
+ * Author: Bernd Eckenfels, <ecki@lina.inka.de>
+ * Copyright 1999 Bernd Eckenfels, Germany
+ * base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK>
*
- * 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.
+ * 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"
@@ -38,28 +38,26 @@
int AX25_rprint(int options)
{
- FILE *f=fopen(_PATH_PROCNET_AX25_ROUTE, "r");
- char buffer[256];
- int use;
+ FILE *f = fopen(_PATH_PROCNET_AX25_ROUTE, "r");
+ char buffer[256];
+ int use;
- if(f==NULL)
- {
- printf(_("AX.25 not configured in this system.\n")); /* xxx */
- return 1;
- }
- printf(_("Kernel AX.25 routing table\n")); /* xxx */
- printf(_("Destination Iface Use\n")); /* xxx */
- fgets(buffer,256,f);
- while(fgets(buffer,256,f))
- {
- buffer[9]=0;
- buffer[14]=0;
- use=atoi(buffer+15);
- printf("%-9s %-5s %5d\n",
- buffer,buffer+10,use);
- }
- fclose(f);
- return 0;
+ if (f == NULL) {
+ printf(_("AX.25 not configured in this system.\n")); /* xxx */
+ return 1;
+ }
+ printf(_("Kernel AX.25 routing table\n")); /* xxx */
+ printf(_("Destination Iface Use\n")); /* xxx */
+ fgets(buffer, 256, f);
+ while (fgets(buffer, 256, f)) {
+ buffer[9] = 0;
+ buffer[14] = 0;
+ use = atoi(buffer + 15);
+ printf("%-9s %-5s %5d\n",
+ buffer, buffer + 10, use);
+ }
+ fclose(f);
+ return 0;
}
-#endif /* HAVE_AFAX25 */
+#endif /* HAVE_AFAX25 */
diff --git a/lib/ddp.c b/lib/ddp.c
index 81f4eb3..d26eb70 100644
--- a/lib/ddp.c
+++ b/lib/ddp.c
@@ -1,14 +1,16 @@
/*
- * DDP protocol output functions.
- * [Not yet input]
+ * DDP protocol output functions.
+ * [Not yet input]
*
- * Alan Cox <Alan.Cox@linux.org>
+ * Alan Cox <Alan.Cox@linux.org>
*
- * 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.
+ * $Id: ddp.c,v 1.4 1998/11/15 20:09:25 freitag Exp $
+ *
+ * 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"
@@ -29,34 +31,33 @@
#include "intl.h"
/* Display a ddp domain address. */
-static char *
-ddp_print(unsigned char *ptr)
+static char *ddp_print(unsigned char *ptr)
{
- static char buff[64];
- struct sockaddr_at *sat=(struct sockaddr_at *)(ptr-2);
- sprintf(buff,"%d/%d",(int) ntohs(sat->sat_addr.s_net), (int)sat->sat_addr.s_node);
- return(buff);
+ static char buff[64];
+ struct sockaddr_at *sat = (struct sockaddr_at *) (ptr - 2);
+ sprintf(buff, "%d/%d", (int) ntohs(sat->sat_addr.s_net), (int) sat->sat_addr.s_node);
+ return (buff);
}
/* Display a ddp domain address. */
-static char *
-ddp_sprint(struct sockaddr *sap, int numeric)
+static char *ddp_sprint(struct sockaddr *sap, int numeric)
{
- static char buf[64];
+ static char buf[64];
- if (sap->sa_family != AF_APPLETALK)
- return strncpy (buf, _("[NONE SET]"), sizeof (buf));
- return(ddp_print(sap->sa_data));
+ if (sap->sa_family != AF_APPLETALK)
+ return strncpy(buf, _("[NONE SET]"), sizeof(buf));
+ return (ddp_print(sap->sa_data));
}
-struct aftype ddp_aftype = {
- "ddp", NULL, /*"Appletalk DDP",*/ AF_APPLETALK, 0,
- ddp_print, ddp_sprint, NULL, NULL,
- NULL/*DDP_rprint*/, NULL, NULL,
- -1,
- "/proc/net/appletalk"
+struct aftype ddp_aftype =
+{
+ "ddp", NULL, /*"Appletalk DDP", */ AF_APPLETALK, 0,
+ ddp_print, ddp_sprint, NULL, NULL,
+ NULL /*DDP_rprint */ , NULL, NULL,
+ -1,
+ "/proc/net/appletalk"
};
#endif
diff --git a/lib/ddp_gr.c b/lib/ddp_gr.c
index 317fab3..94169f0 100644
--- a/lib/ddp_gr.c
+++ b/lib/ddp_gr.c
@@ -18,7 +18,7 @@
int DDP_rprint(int options)
{
- fprintf(stderr, _("Routing table for `ddp' not yet supported.\n"));
- return(1);
+ fprintf(stderr, _("Routing table for `ddp' not yet supported.\n"));
+ return (1);
}
#endif
diff --git a/lib/econet.c b/lib/econet.c
index faf0246..41cbdac 100644
--- a/lib/econet.c
+++ b/lib/econet.c
@@ -1,19 +1,19 @@
/*
- * lib/econet.c This file contains an implementation of the Econet
- * support functions for the net-tools.
- * (NET-3 base distribution).
+ * 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
+ * Version: $Id: econet.c,v 1.4 1998/11/15 20:09:30 freitag Exp $
*
- * Author: Philip Blundell <philb@gnu.org>
+ * 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.
+ * 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"
@@ -33,54 +33,53 @@
/* Display an Econet address */
static char *
-ec_print(unsigned char *ptr)
+ 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;
+ 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)
+ ec_sprint(struct sockaddr *sap, int numeric)
{
- struct sockaddr_ec *sec = (struct sockaddr_ec *)sap;
+ struct sockaddr_ec *sec = (struct sockaddr_ec *) sap;
- if (sap->sa_family != AF_ECONET)
- return _("[NONE SET]");
+ if (sap->sa_family != AF_ECONET)
+ return _("[NONE SET]");
- return ec_print((unsigned char *)&sec->addr);
+ return ec_print((unsigned char *) &sec->addr);
}
-static int
-ec_input(int type, char *bufp, struct sockaddr *sap)
+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;
+ 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;
+ return -1;
}
-struct aftype ec_aftype = {
- "ec", NULL, AF_ECONET, 0,
- ec_print, ec_sprint, ec_input, NULL,
- NULL, NULL, NULL,
- -1,
- NULL
+struct aftype ec_aftype =
+{
+ "ec", NULL, AF_ECONET, 0,
+ ec_print, ec_sprint, ec_input, NULL,
+ NULL, NULL, NULL,
+ -1,
+ NULL
};
-#endif /* HAVE_AFECONET */
+#endif /* HAVE_AFECONET */
diff --git a/lib/ether.c b/lib/ether.c
index 7991706..56f8dc1 100644
--- a/lib/ether.c
+++ b/lib/ether.c
@@ -1,17 +1,17 @@
/*
- * lib/ether.c This file contains an implementation of the "Ethernet"
- * support functions for the NET-2 base distribution.
+ * lib/ether.c This file contains an implementation of the "Ethernet"
+ * support functions.
*
- * Version: @(#)ether.c 1.10 10/07/93
+ * Version: $Id: ether.c,v 1.4 1998/11/15 20:09:33 freitag Exp $
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
- * 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.
+ * 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"
@@ -34,109 +34,114 @@ extern struct hwtype ether_hwtype;
/* Display an Ethernet address in readable format. */
-static char *
-pr_ether(unsigned char *ptr)
+static char *pr_ether(unsigned char *ptr)
{
- static char buff[64];
+ static char buff[64];
- snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X",
- (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
- (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
- );
- return(buff);
+ snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X",
+ (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
+ (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
+ );
+ return (buff);
}
/* Display an Ethernet socket address. */
-static char *
-pr_sether(struct sockaddr *sap)
+static char *pr_sether(struct sockaddr *sap)
{
- static char buf[64];
+ static char buf[64];
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return strncpy (buf, _("[NONE SET]"), sizeof (buf));
- return(pr_ether(sap->sa_data));
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return strncpy(buf, _("[NONE SET]"), sizeof(buf));
+ return (pr_ether(sap->sa_data));
}
/* Input an Ethernet address and convert to binary. */
-static int
-in_ether(char *bufp, struct sockaddr *sap)
+static int in_ether(char *bufp, struct sockaddr *sap)
{
- unsigned char *ptr;
- char c, *orig;
- int i;
- unsigned val;
+ unsigned char *ptr;
+ char c, *orig;
+ int i;
+ unsigned val;
- sap->sa_family = ether_hwtype.type;
- ptr = sap->sa_data;
+ sap->sa_family = ether_hwtype.type;
+ ptr = sap->sa_data;
- i = 0;
- orig = bufp;
- while((*bufp != '\0') && (i < ETH_ALEN)) {
+ i = 0;
+ orig = bufp;
+ while ((*bufp != '\0') && (i < ETH_ALEN)) {
val = 0;
c = *bufp++;
- if (isdigit(c)) val = c - '0';
- else if (c >= 'a' && c <= 'f') val = c - 'a' + 10;
- else if (c >= 'A' && c <= 'F') val = c - 'A' + 10;
- else {
+ if (isdigit(c))
+ val = c - '0';
+ else if (c >= 'a' && c <= 'f')
+ val = c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ val = c - 'A' + 10;
+ else {
#ifdef DEBUG
- fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig);
+ fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig);
#endif
- errno = EINVAL;
- return(-1);
+ errno = EINVAL;
+ return (-1);
}
val <<= 4;
c = *bufp;
- if (isdigit(c)) val |= c - '0';
- else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10;
- else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10;
- else if (c == ':' || c == 0) val >>= 4;
- else {
+ if (isdigit(c))
+ val |= c - '0';
+ else if (c >= 'a' && c <= 'f')
+ val |= c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ val |= c - 'A' + 10;
+ else if (c == ':' || c == 0)
+ val >>= 4;
+ else {
#ifdef DEBUG
- fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig);
+ fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig);
#endif
- errno = EINVAL;
- return(-1);
+ errno = EINVAL;
+ return (-1);
}
- if (c != 0) bufp++;
+ if (c != 0)
+ bufp++;
*ptr++ = (unsigned char) (val & 0377);
i++;
/* We might get a semicolon here - not required. */
if (*bufp == ':') {
- if (i == ETH_ALEN) {
+ if (i == ETH_ALEN) {
#ifdef DEBUG
- fprintf(stderr, _("in_ether(%s): trailing : ignored!\n"),
- orig)
+ fprintf(stderr, _("in_ether(%s): trailing : ignored!\n"),
+ orig)
#endif
- ; /* nothing */
- }
- bufp++;
+ ; /* nothing */
+ }
+ bufp++;
}
- }
+ }
- /* That's it. Any trailing junk? */
- if ((i == ETH_ALEN) && (*bufp != '\0')) {
+ /* That's it. Any trailing junk? */
+ if ((i == ETH_ALEN) && (*bufp != '\0')) {
#ifdef DEBUG
fprintf(stderr, _("in_ether(%s): trailing junk!\n"), orig);
errno = EINVAL;
- return(-1);
+ return (-1);
#endif
- }
-
+ }
#ifdef DEBUG
- fprintf(stderr, "in_ether(%s): %s\n", orig, pr_ether(sap->sa_data));
+ fprintf(stderr, "in_ether(%s): %s\n", orig, pr_ether(sap->sa_data));
#endif
- return(0);
+ return (0);
}
-struct hwtype ether_hwtype = {
- "ether", NULL, /*"10Mbps Ethernet",*/ ARPHRD_ETHER, ETH_ALEN,
- pr_ether, pr_sether, in_ether, NULL
+struct hwtype ether_hwtype =
+{
+ "ether", NULL, /*"10Mbps Ethernet", */ ARPHRD_ETHER, ETH_ALEN,
+ pr_ether, pr_sether, in_ether, NULL
};
-#endif /* HAVE_HWETHER */
+#endif /* HAVE_HWETHER */
diff --git a/lib/fddi.c b/lib/fddi.c
index 614bd6a..fadb8bd 100644
--- a/lib/fddi.c
+++ b/lib/fddi.c
@@ -1,18 +1,18 @@
/*
- * lib/fddi.c This file contains an implementation of the "FDDI"
- * support functions for the NET-2 base distribution.
+ * lib/fddi.c This file contains an implementation of the "FDDI"
+ * support functions.
*
- * Version: @(#)fddi.c 1.01 07/01/1998
+ * Version: $Id: fddi.c,v 1.4 1998/11/15 20:09:35 freitag Exp $
*
- * Author: Lawrence V. Stefani, <stefani@lkg.dec.com>
+ * Author: Lawrence V. Stefani, <stefani@lkg.dec.com>
*
* 1998-07-01 - Arnaldo Carvalho de Melo <acme@conectiva.com.br> GNU gettext
*
- * 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.
+ * 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"
@@ -45,106 +45,109 @@ extern struct hwtype fddi_hwtype;
/* Display an FDDI address in readable format. */
-static char *
-pr_fddi(unsigned char *ptr)
+static char *pr_fddi(unsigned char *ptr)
{
- static char buff[64];
+ static char buff[64];
- snprintf(buff, sizeof(buff), "%02X-%02X-%02X-%02X-%02X-%02X",
- (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
- (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
- );
- return(buff);
+ snprintf(buff, sizeof(buff), "%02X-%02X-%02X-%02X-%02X-%02X",
+ (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
+ (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
+ );
+ return (buff);
}
/* Display an FDDI socket address. */
-static char *
-pr_sfddi(struct sockaddr *sap)
+static char *pr_sfddi(struct sockaddr *sap)
{
- static char buf[64];
+ static char buf[64];
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return strncpy (buf, _("[NONE SET]"), sizeof (buf));
- return(pr_fddi(sap->sa_data));
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return strncpy(buf, _("[NONE SET]"), sizeof(buf));
+ return (pr_fddi(sap->sa_data));
}
/* Input an FDDI address and convert to binary. */
-static int
-in_fddi(char *bufp, struct sockaddr *sap)
+static int in_fddi(char *bufp, struct sockaddr *sap)
{
- unsigned char *ptr;
- char c, *orig;
- int i, val;
+ unsigned char *ptr;
+ char c, *orig;
+ int i, val;
- sap->sa_family = fddi_hwtype.type;
- ptr = sap->sa_data;
+ sap->sa_family = fddi_hwtype.type;
+ ptr = sap->sa_data;
- i = 0;
- orig = bufp;
- while((*bufp != '\0') && (i < FDDI_K_ALEN)) {
+ i = 0;
+ orig = bufp;
+ while ((*bufp != '\0') && (i < FDDI_K_ALEN)) {
val = 0;
c = *bufp++;
- if (isdigit(c)) val = c - '0';
- else if (c >= 'a' && c <= 'f') val = c - 'a' + 10;
- else if (c >= 'A' && c <= 'F') val = c - 'A' + 10;
- else {
+ if (isdigit(c))
+ val = c - '0';
+ else if (c >= 'a' && c <= 'f')
+ val = c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ val = c - 'A' + 10;
+ else {
#ifdef DEBUG
- fprintf(stderr, _("in_fddi(%s): invalid fddi address!\n"), orig);
+ fprintf(stderr, _("in_fddi(%s): invalid fddi address!\n"), orig);
#endif
- errno = EINVAL;
- return(-1);
+ errno = EINVAL;
+ return (-1);
}
val <<= 4;
c = *bufp++;
- if (isdigit(c)) val |= c - '0';
- else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10;
- else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10;
- else {
+ if (isdigit(c))
+ val |= c - '0';
+ else if (c >= 'a' && c <= 'f')
+ val |= c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ val |= c - 'A' + 10;
+ else {
#ifdef DEBUG
- fprintf(stderr, _("in_fddi(%s): invalid fddi address!\n"), orig);
+ fprintf(stderr, _("in_fddi(%s): invalid fddi address!\n"), orig);
#endif
- errno = EINVAL;
- return(-1);
+ errno = EINVAL;
+ return (-1);
}
*ptr++ = (unsigned char) (val & 0377);
i++;
/* We might get a semicolon here - not required. */
if (*bufp == ':') {
- if (i == FDDI_K_ALEN) {
+ if (i == FDDI_K_ALEN) {
#ifdef DEBUG
- fprintf(stderr, _("in_fddi(%s): trailing : ignored!\n"),
- orig)
+ fprintf(stderr, _("in_fddi(%s): trailing : ignored!\n"),
+ orig)
#endif
- ; /* nothing */
- }
- bufp++;
+ ; /* nothing */
+ }
+ bufp++;
}
- }
+ }
- /* That's it. Any trailing junk? */
- if ((i == FDDI_K_ALEN) && (*bufp != '\0')) {
+ /* That's it. Any trailing junk? */
+ if ((i == FDDI_K_ALEN) && (*bufp != '\0')) {
#ifdef DEBUG
fprintf(stderr, _("in_fddi(%s): trailing junk!\n"), orig);
errno = EINVAL;
- return(-1);
+ return (-1);
#endif
- }
-
+ }
#ifdef DEBUG
- fprintf(stderr, "in_fddi(%s): %s\n", orig, pr_fddi(sap->sa_data));
+ fprintf(stderr, "in_fddi(%s): %s\n", orig, pr_fddi(sap->sa_data));
#endif
- return(0);
+ return (0);
}
-struct hwtype fddi_hwtype = {
- "fddi", NULL, /*"Fiber Distributed Data Interface (FDDI)",*/ ARPHRD_FDDI, FDDI_K_ALEN,
- pr_fddi, pr_sfddi, in_fddi, NULL
+struct hwtype fddi_hwtype =
+{
+ "fddi", NULL, /*"Fiber Distributed Data Interface (FDDI)", */ ARPHRD_FDDI, FDDI_K_ALEN,
+ pr_fddi, pr_sfddi, in_fddi, NULL
};
-#endif /* HAVE_HWFDDI */
+#endif /* HAVE_HWFDDI */
diff --git a/lib/frame.c b/lib/frame.c
index e24e06e..1cfd88e 100644
--- a/lib/frame.c
+++ b/lib/frame.c
@@ -1,22 +1,22 @@
/*
- * lib/frame.c This file contains the Frame Relay support.
+ * lib/frame.c This file contains the Frame Relay support.
*
- * Version: lib/frame.c 0.01 (1996-03-23)
+ * Version: $Id: frame.c,v 1.3 1998/11/15 20:09:39 freitag Exp $
*
- * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
+ * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
*
- * Author: Mike McLagan <mike.mclagan@linux.org>
+ * Author: Mike McLagan <mike.mclagan@linux.org>
*
* Changes:
*
- *962303 {0.01} Mike McLagan : creation
- *960413 {0.02} Bernd Eckenfels : included in net-lib
+ *962303 {0.01} Mike McLagan : creation
+ *960413 {0.02} Bernd Eckenfels : included in net-lib
*
- * 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.
+ * 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"
@@ -39,19 +39,21 @@
char *pr_dlci(unsigned char *ptr)
{
- static char buf[12];
+ static char buf[12];
- snprintf(buf, sizeof(buf), "%i", *(short *)ptr);
- return(buf);
+ snprintf(buf, sizeof(buf), "%i", *(short *) ptr);
+ return (buf);
}
-struct hwtype dlci_hwtype = {
- "dlci", NULL, /*"Frame Relay DLCI",*/ ARPHRD_DLCI, 3,
- pr_dlci, NULL, NULL, NULL
+struct hwtype dlci_hwtype =
+{
+ "dlci", NULL, /*"Frame Relay DLCI", */ ARPHRD_DLCI, 3,
+ pr_dlci, NULL, NULL, NULL
};
-struct hwtype frad_hwtype = {
- "frad", NULL, /*"Frame Relay Access Device",*/ ARPHRD_FRAD, 0,
- NULL, NULL, NULL, NULL
+struct hwtype frad_hwtype =
+{
+ "frad", NULL, /*"Frame Relay Access Device", */ ARPHRD_FRAD, 0,
+ NULL, NULL, NULL, NULL
};
-#endif /* HAVE_HWFR */
+#endif /* HAVE_HWFR */
diff --git a/lib/getargs.c b/lib/getargs.c
index cebd91b..4170097 100644
--- a/lib/getargs.c
+++ b/lib/getargs.c
@@ -1,16 +1,16 @@
/*
- * lib/getargs.c General argument parser.
+ * lib/getargs.c General argument parser.
*
- * Version: @(#)getargs.c 4.0.1 04/05/94
+ * Version: $Id: getargs.c,v 1.3 1998/11/15 20:09:43 freitag Exp $
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993,1994 MicroWalt Corporation
+ * Copyright 1993,1994 MicroWalt Corporation
*
- * 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.
+ * 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"
#include <sys/types.h>
@@ -27,61 +27,65 @@
/* Split the input string into multiple fields. */
-int
-getargs(char *string, char *arguments[])
+int getargs(char *string, char *arguments[])
{
- char temp[1024];
- char *sp, *ptr;
- int i, argc;
- char want;
+ int len = strlen(string);
+ char temp[len+1];
+ char *sp, *ptr;
+ int i, argc;
+ char want;
- /*
- * Copy the string into a buffer. We may have to modify
- * the original string because of all the quoting...
- */
- sp = string; i = 0;
- strcpy(temp, string);
- ptr = temp;
-
- /*
- * Look for delimiters ("); if present whatever
- * they enclose will be considered one argument.
- */
- while (*ptr != '\0' && i < 31) {
+ /*
+ * Copy the string into a buffer. We may have to modify
+ * the original string because of all the quoting...
+ */
+ sp = string;
+ i = 0;
+ strcpy(temp, string);
+ ptr = temp;
+
+ /*
+ * Look for delimiters ("); if present whatever
+ * they enclose will be considered one argument.
+ */
+ while (*ptr != '\0' && i < 31) {
/* Ignore leading whitespace on input string. */
- while (*ptr == ' ' || *ptr == '\t') ptr++;
+ while (*ptr == ' ' || *ptr == '\t')
+ ptr++;
/* Set string pointer. */
arguments[i++] = sp;
/* Check for any delimiters. */
if (*ptr == '"' || *ptr == '\'') {
- /*
- * Copy the string up to any whitespace OR the next
- * delimiter. If the delimiter was escaped, skip it
- * as it if was not there.
- */
- want = *ptr++;
- while(*ptr != '\0') {
- if (*ptr == want && *(ptr - 1) != '\\') {
- ptr++;
- break;
- }
- *sp++ = *ptr++;
+ /*
+ * Copy the string up to any whitespace OR the next
+ * delimiter. If the delimiter was escaped, skip it
+ * as it if was not there.
+ */
+ want = *ptr++;
+ while (*ptr != '\0') {
+ if (*ptr == want && *(ptr - 1) != '\\') {
+ ptr++;
+ break;
}
+ *sp++ = *ptr++;
+ }
} else {
- /* Just copy the string up to any whitespace. */
- while(*ptr != '\0' && *ptr != ' ' && *ptr != '\t')
- *sp++ = *ptr++;
+ /* Just copy the string up to any whitespace. */
+ while (*ptr != '\0' && *ptr != ' ' && *ptr != '\t')
+ *sp++ = *ptr++;
}
*sp++ = '\0';
/* Skip trailing whitespace. */
if (*ptr != '\0') {
- while(*ptr == ' ' || *ptr == '\t') ptr++;
+ while (*ptr == ' ' || *ptr == '\t')
+ ptr++;
}
- }
- argc = i;
- while (i < 32) arguments[i++] = (char *)NULL;
- return(argc);
+ }
+ argc = i;
+ while (i < 32)
+ arguments[i++] = (char *) NULL;
+ return (argc);
}
diff --git a/lib/getroute.c b/lib/getroute.c
index d6d282e..f4b91e7 100644
--- a/lib/getroute.c
+++ b/lib/getroute.c
@@ -1,33 +1,33 @@
/*
- * lib/getroute.c This file contains a small interface function to
- * use the AF specific print routine for the routing
- * table.
+ * lib/getroute.c This file contains a small interface function to
+ * use the AF specific print routine for the routing
+ * table.
*
- * NET-LIB A collection of functions used from the base set of the
- * NET-3 Networking Distribution for the LINUX operating
- * system. (net-tools, net-drivers)
+ * NET-LIB A collection of functions used from the base set of the
+ * NET-3 Networking Distribution for the LINUX operating
+ * system. (net-tools, net-drivers)
*
- * Version: lib/getroute.c 1.03 (1996-04-13)
+ * Version: $Id: getroute.c,v 1.3 1998/11/15 20:09:47 freitag Exp $
*
- * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de>
- * Copyright 1999 Bernd Eckenfels, Germany
+ * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de>
+ * Copyright 1999 Bernd Eckenfels, Germany
*
* Modifications:
*
- *951020 {0.10} Bernd Eckenfels: creation
- *960202 {0.90} Bernd Eckenfels: rewrite to use getaftype.
- *960204 {0.91} Bernd Eckenfels: takes constant list of AFs
- *960206 {1.01} Bernd Eckenfels: route_init will enable routing
- * support in the AF handlers
- *960221 {1.02} Bernd Eckenfels: renamed from route_info to getroute.c
- *960413 {1.03} Bernd Eckenfels: new RTACTION support
+ *951020 {0.10} Bernd Eckenfels: creation
+ *960202 {0.90} Bernd Eckenfels: rewrite to use getaftype.
+ *960204 {0.91} Bernd Eckenfels: takes constant list of AFs
+ *960206 {1.01} Bernd Eckenfels: route_init will enable routing
+ * support in the AF handlers
+ *960221 {1.02} Bernd Eckenfels: renamed from route_info to getroute.c
+ *960413 {1.03} Bernd Eckenfels: new RTACTION support
*980701 {1.04} Arnaldo C. Melo: GNU gettext instead of catgets
*
- * 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.
+ * 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 <stdio.h>
#include <string.h>
@@ -37,81 +37,77 @@
#include "config.h"
#include "intl.h"
-extern struct aftype unspec_aftype;
-extern struct aftype unix_aftype;
-extern struct aftype inet_aftype;
-extern struct aftype inet6_aftype;
-extern struct aftype ax25_aftype;
-extern struct aftype netrom_aftype;
-extern struct aftype ipx_aftype;
-extern struct aftype ddp_aftype;
+extern struct aftype unspec_aftype;
+extern struct aftype unix_aftype;
+extern struct aftype inet_aftype;
+extern struct aftype inet6_aftype;
+extern struct aftype ax25_aftype;
+extern struct aftype netrom_aftype;
+extern struct aftype ipx_aftype;
+extern struct aftype ddp_aftype;
-void
-getroute_init(void)
+void getroute_init(void)
{
#if HAVE_AFINET
- inet_aftype.rprint = INET_rprint;
+ inet_aftype.rprint = INET_rprint;
#endif
#if HAVE_AFINET6
- inet6_aftype.rprint = INET6_rprint;
+ inet6_aftype.rprint = INET6_rprint;
#endif
#if HAVE_AFNETROM
- netrom_aftype.rprint = NETROM_rprint;
+ netrom_aftype.rprint = NETROM_rprint;
#endif
#if HAVE_AFAX25
- ax25_aftype.rprint = AX25_rprint;
+ ax25_aftype.rprint = AX25_rprint;
#endif
#if HAVE_AFIPX
- ipx_aftype.rprint = IPX_rprint;
+ ipx_aftype.rprint = IPX_rprint;
#endif
#if HAVE_AFATALK
- ddp_aftype.rprint = DDP_rprint;
+ ddp_aftype.rprint = DDP_rprint;
#endif
}
-int
-route_info(const char *afname, int options)
+int route_info(const char *afname, int options)
{
- struct aftype *ap;
- char *tmp1,*tmp2;
- int found=E_NOTFOUND,rc;
- char buf[256];
-
- strncpy(buf,afname,sizeof(buf));
- buf[sizeof(buf)-1]='\0';
-
- tmp1=buf;
-
- while(tmp1) {
-
- ap=NULL;
-
- if ((tmp2=index(tmp1,',')))
- *tmp2++='\0';
-
+ struct aftype *ap;
+ char *tmp1, *tmp2;
+ int found = E_NOTFOUND, rc;
+ char buf[256];
+
+ strncpy(buf, afname, sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+
+ tmp1 = buf;
+
+ while (tmp1) {
+
+ ap = NULL;
+
+ if ((tmp2 = index(tmp1, ',')))
+ *tmp2++ = '\0';
+
if (!tmp1[0]) {
- tmp1=tmp2;
- continue;
+ tmp1 = tmp2;
+ continue;
}
-
- ap = get_aftype(tmp1);
-
- if (!ap) {
- fprintf(stderr,_("Address family `%s' not supported.\n"),tmp1);
- return(E_OPTERR);
- }
- tmp1=tmp2;
-
- if (!ap->rprint) {
- fprintf(stderr,_("No routing for address family `%s'.\n"),ap->name);
- return(E_OPTERR);
- }
-
- found = 0;
-
+ ap = get_aftype(tmp1);
+
+ if (!ap) {
+ fprintf(stderr, _("Address family `%s' not supported.\n"), tmp1);
+ return (E_OPTERR);
+ }
+ tmp1 = tmp2;
+
+ if (!ap->rprint) {
+ fprintf(stderr, _("No routing for address family `%s'.\n"), ap->name);
+ return (E_OPTERR);
+ }
+ found = 0;
+
if ((rc = ap->rprint(options)))
- return(rc);
-
- }
- return(found);
+ return (rc);
+
+ }
+ return (found);
}
diff --git a/lib/hdlclapb.c b/lib/hdlclapb.c
index c5a0ce7..4cac136 100644
--- a/lib/hdlclapb.c
+++ b/lib/hdlclapb.c
@@ -1,21 +1,21 @@
/*
* lib/hdlclapb.c
- * This file contains the HDLC/LAPB support for the NET-2 base
- * distribution.
+ * This file contains the HDLC/LAPB support for the NET-2 base
+ * distribution.
*
- * Version: @(#)hdlclapb.c 0.10 22/04/1998
+ * Version: $Id: hdlclapb.c,v 1.3 1998/11/15 20:09:55 freitag Exp $
*
- * Original Author:
- * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Original Author:
+ * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
- * Modified by Alan Cox, May 94 to cover NET-3
+ * Modified by Alan Cox, May 94 to cover NET-3
*
- * 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.
+ * 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"
@@ -36,13 +36,15 @@
#include "net-support.h"
#include "pathnames.h"
-struct hwtype hdlc_hwtype = {
- "hdlc", NULL, /*"(Cisco) HDLC",*/ ARPHRD_HDLC, 0,
- NULL, NULL, NULL, NULL,
+struct hwtype hdlc_hwtype =
+{
+ "hdlc", NULL, /*"(Cisco) HDLC", */ ARPHRD_HDLC, 0,
+ NULL, NULL, NULL, NULL,
};
-struct hwtype lapb_hwtype = {
- "lapb", NULL, /*"LAPB",*/ ARPHRD_LAPB, 0,
- NULL, NULL, NULL, NULL,
+struct hwtype lapb_hwtype =
+{
+ "lapb", NULL, /*"LAPB", */ ARPHRD_LAPB, 0,
+ NULL, NULL, NULL, NULL,
};
-#endif /* HAVE_HWHDLCLAPB */
+#endif /* HAVE_HWHDLCLAPB */
diff --git a/lib/hippi.c b/lib/hippi.c
index ce58462..0086a76 100644
--- a/lib/hippi.c
+++ b/lib/hippi.c
@@ -1,19 +1,19 @@
/*
- * lib/hippi.c This file contains an implementation of the "HIPPI"
- * support functions for the NET-2 base distribution.
+ * lib/hippi.c This file contains an implementation of the "HIPPI"
+ * support functions for the NET-2 base distribution.
*
- * Version: @(#)hippi.c 1.0 06/06/97
+ * Version: $Id$
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
- * Modified for HIPPI by Jes Sorensen, <Jes.Sorensen@cern.ch>
+ * Modified for HIPPI by Jes Sorensen, <Jes.Sorensen@cern.ch>
*
- * 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.
+ * 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"
@@ -36,114 +36,118 @@
#include "intl.h"
/*
- * HIPPI magic constants.
+ * HIPPI magic constants.
*/
-#define HIPPI_ALEN 6 /* Bytes in one HIPPI hw-addr */
+#define HIPPI_ALEN 6 /* Bytes in one HIPPI hw-addr */
extern struct hwtype hippi_hwtype;
/* Display an HIPPI address in readable format. */
-static char *
-pr_hippi(unsigned char *ptr)
+static char *pr_hippi(unsigned char *ptr)
{
- static char buff[64];
+ static char buff[64];
- sprintf(buff, "%02X:%02X:%02X:%02X:%02X:%02X",
- (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
- (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
- );
- return(buff);
+ sprintf(buff, "%02X:%02X:%02X:%02X:%02X:%02X",
+ (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
+ (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
+ );
+ return (buff);
}
/* Display an HIPPI socket address. */
static char *
-pr_shippi(struct sockaddr *sap)
+ pr_shippi(struct sockaddr *sap)
{
- static char buf[64];
+ static char buf[64];
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return(strncpy(buf, _("[NONE SET]"), 64));
- return(pr_hippi(sap->sa_data));
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return (strncpy(buf, _("[NONE SET]"), 64));
+ return (pr_hippi(sap->sa_data));
}
/* Input an HIPPI address and convert to binary. */
-static int
-in_hippi(char *bufp, struct sockaddr *sap)
+static int in_hippi(char *bufp, struct sockaddr *sap)
{
- unsigned char *ptr;
- char c, *orig;
- int i, val;
+ unsigned char *ptr;
+ char c, *orig;
+ int i, val;
- sap->sa_family = hippi_hwtype.type;
- ptr = sap->sa_data;
+ sap->sa_family = hippi_hwtype.type;
+ ptr = sap->sa_data;
- i = 0;
- orig = bufp;
- while((*bufp != '\0') && (i < HIPPI_ALEN)) {
+ i = 0;
+ orig = bufp;
+ while ((*bufp != '\0') && (i < HIPPI_ALEN)) {
val = 0;
c = *bufp++;
- if (isdigit(c)) val = c - '0';
- else if (c >= 'a' && c <= 'f') val = c - 'a' + 10;
- else if (c >= 'A' && c <= 'F') val = c - 'A' + 10;
- else {
+ if (isdigit(c))
+ val = c - '0';
+ else if (c >= 'a' && c <= 'f')
+ val = c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ val = c - 'A' + 10;
+ else {
#ifdef DEBUG
- fprintf(stderr, _("in_hippi(%s): invalid hippi address!\n"), orig);
+ fprintf(stderr, _("in_hippi(%s): invalid hippi address!\n"), orig);
#endif
- errno = EINVAL;
- return(-1);
+ errno = EINVAL;
+ return (-1);
}
val <<= 4;
c = *bufp++;
- if (isdigit(c)) val |= c - '0';
- else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10;
- else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10;
- else {
+ if (isdigit(c))
+ val |= c - '0';
+ else if (c >= 'a' && c <= 'f')
+ val |= c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ val |= c - 'A' + 10;
+ else {
#ifdef DEBUG
- fprintf(stderr, _("in_hippi(%s): invalid hippi address!\n"), orig);
+ fprintf(stderr, _("in_hippi(%s): invalid hippi address!\n"), orig);
#endif
- errno = EINVAL;
- return(-1);
+ errno = EINVAL;
+ return (-1);
}
*ptr++ = (unsigned char) (val & 0377);
i++;
/* We might get a semicolon here - not required. */
if (*bufp == ':') {
- if (i == HIPPI_ALEN) {
+ if (i == HIPPI_ALEN) {
#ifdef DEBUG
- fprintf(stderr, _("in_hippi(%s): trailing : ignored!\n"), orig)
+ fprintf(stderr, _("in_hippi(%s): trailing : ignored!\n"), orig)
#endif
- ; /* nothing */
- }
- bufp++;
+ ; /* nothing */
+ }
+ bufp++;
}
- }
+ }
- /* That's it. Any trailing junk? */
- if ((i == HIPPI_ALEN) && (*bufp != '\0')) {
+ /* That's it. Any trailing junk? */
+ if ((i == HIPPI_ALEN) && (*bufp != '\0')) {
#ifdef DEBUG
fprintf(stderr, _("in_hippi(%s): trailing junk!\n"), orig);
errno = EINVAL;
- return(-1);
+ return (-1);
#endif
- }
-
+ }
#ifdef DEBUG
- fprintf(stderr, "in_hippi(%s): %s\n", orig, pr_hippi(sap->sa_data));
+ fprintf(stderr, "in_hippi(%s): %s\n", orig, pr_hippi(sap->sa_data));
#endif
- return(0);
+ return (0);
}
-struct hwtype hippi_hwtype = {
- "hippi", NULL, /*"HIPPI",*/ ARPHRD_HIPPI, HIPPI_ALEN,
- pr_hippi, pr_shippi, in_hippi, NULL
+struct hwtype hippi_hwtype =
+{
+ "hippi", NULL, /*"HIPPI", */ ARPHRD_HIPPI, HIPPI_ALEN,
+ pr_hippi, pr_shippi, in_hippi, NULL
};
-#endif /* HAVE_HWHIPPI */
+#endif /* HAVE_HWHIPPI */
diff --git a/lib/hw.c b/lib/hw.c
index a96ed8a..b73b213 100644
--- a/lib/hw.c
+++ b/lib/hw.c
@@ -1,21 +1,21 @@
/*
- * lib/hw.c This file contains the top-level part of the hardware
- * support functions module for the NET-2 base distribution.
+ * lib/hw.c This file contains the top-level part of the hardware
+ * support functions module.
*
- * Version: lib/hw.c 1.21 (1998-07-01)
+ * Version: $Id: hw.c,v 1.8 1998/11/15 20:10:13 freitag Exp $
*
- * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
+ * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
*980701 {1.21} Arnaldo C. Melo GNU gettext instead of catgets
*
- * 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.
+ * 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 <sys/types.h>
#include <sys/socket.h>
@@ -30,186 +30,187 @@
#include "pathnames.h"
#include "intl.h"
-extern struct hwtype unspec_hwtype;
-extern struct hwtype loop_hwtype;
+extern struct hwtype unspec_hwtype;
+extern struct hwtype loop_hwtype;
-extern struct hwtype slip_hwtype;
-extern struct hwtype cslip_hwtype;
-extern struct hwtype slip6_hwtype;
-extern struct hwtype cslip6_hwtype;
-extern struct hwtype adaptive_hwtype;
+extern struct hwtype slip_hwtype;
+extern struct hwtype cslip_hwtype;
+extern struct hwtype slip6_hwtype;
+extern struct hwtype cslip6_hwtype;
+extern struct hwtype adaptive_hwtype;
-extern struct hwtype ether_hwtype;
-extern struct hwtype fddi_hwtype;
-extern struct hwtype hippi_hwtype;
-extern struct hwtype tr_hwtype;
+extern struct hwtype ether_hwtype;
+extern struct hwtype fddi_hwtype;
+extern struct hwtype hippi_hwtype;
+extern struct hwtype tr_hwtype;
-extern struct hwtype ax25_hwtype;
-extern struct hwtype rose_hwtype;
-extern struct hwtype netrom_hwtype;
-extern struct hwtype tunnel_hwtype;
+extern struct hwtype ax25_hwtype;
+extern struct hwtype rose_hwtype;
+extern struct hwtype netrom_hwtype;
+extern struct hwtype tunnel_hwtype;
-extern struct hwtype ash_hwtype;
+extern struct hwtype ash_hwtype;
-extern struct hwtype ppp_hwtype;
+extern struct hwtype ppp_hwtype;
-extern struct hwtype arcnet_hwtype;
+extern struct hwtype arcnet_hwtype;
-extern struct hwtype dlci_hwtype;
-extern struct hwtype frad_hwtype;
+extern struct hwtype dlci_hwtype;
+extern struct hwtype frad_hwtype;
-extern struct hwtype hdlc_hwtype;
-extern struct hwtype lapb_hwtype;
+extern struct hwtype hdlc_hwtype;
+extern struct hwtype lapb_hwtype;
-extern struct hwtype sit_hwtype;
+extern struct hwtype sit_hwtype;
-static struct hwtype *hwtypes[] = {
+static struct hwtype *hwtypes[] =
+{
- &loop_hwtype,
+ &loop_hwtype,
#if HAVE_HWSLIP
- &slip_hwtype,
- &cslip_hwtype,
- &slip6_hwtype,
- &cslip6_hwtype,
- &adaptive_hwtype,
+ &slip_hwtype,
+ &cslip_hwtype,
+ &slip6_hwtype,
+ &cslip6_hwtype,
+ &adaptive_hwtype,
#endif
#if HAVE_HWASH
- &ash_hwtype,
+ &ash_hwtype,
#endif
#if HAVE_HWETHER
- &ether_hwtype,
+ &ether_hwtype,
#endif
#if HAVE_HWTR
- &tr_hwtype,
+ &tr_hwtype,
#endif
#if HAVE_HWAX25
- &ax25_hwtype,
+ &ax25_hwtype,
#endif
#if HAVE_HWNETROM
- &netrom_hwtype,
+ &netrom_hwtype,
#endif
#if HAVE_HWTUNNEL
- &tunnel_hwtype,
+ &tunnel_hwtype,
#endif
#if HAVE_HWPPP
- &ppp_hwtype,
-#endif
+ &ppp_hwtype,
+#endif
#if HAVE_HWHDLCLAPB
- &hdlc_hwtype,
- &lapb_hwtype,
+ &hdlc_hwtype,
+ &lapb_hwtype,
#endif
#if HAVE_HWARC
- &arcnet_hwtype,
-#endif
+ &arcnet_hwtype,
+#endif
#if HAVE_HWFR
- &dlci_hwtype,
- &frad_hwtype,
+ &dlci_hwtype,
+ &frad_hwtype,
#endif
#if HAVE_HWSIT
- &sit_hwtype,
+ &sit_hwtype,
#endif
#if HAVE_HWROSE
- &rose_hwtype,
+ &rose_hwtype,
#endif
#if HAVE_HWFDDI
- &fddi_hwtype,
+ &fddi_hwtype,
#endif
#if HAVE_HWHIPPI
- &hippi_hwtype,
+ &hippi_hwtype,
#endif
- &unspec_hwtype,
- NULL
+ &unspec_hwtype,
+ NULL
};
static short sVhwinit = 0;
-void hwinit ()
+void hwinit()
{
- loop_hwtype.title = _("Local Loopback");
- unspec_hwtype.title = _("UNSPEC");
+ loop_hwtype.title = _("Local Loopback");
+ unspec_hwtype.title = _("UNSPEC");
#if HAVE_HWSLIP
- slip_hwtype.title = _("Serial Line IP");
- cslip_hwtype.title = _("VJ Serial Line IP");
- slip6_hwtype.title = _("6-bit Serial Line IP");
- cslip6_hwtype.title = _("VJ 6-bit Serial Line IP");
- adaptive_hwtype.title = _("Adaptive Serial Line IP");
+ slip_hwtype.title = _("Serial Line IP");
+ cslip_hwtype.title = _("VJ Serial Line IP");
+ slip6_hwtype.title = _("6-bit Serial Line IP");
+ cslip6_hwtype.title = _("VJ 6-bit Serial Line IP");
+ adaptive_hwtype.title = _("Adaptive Serial Line IP");
#endif
#if HAVE_HWETHER
- ether_hwtype.title = _("Ethernet");
+ ether_hwtype.title = _("Ethernet");
#endif
#if HAVE_HWASH
- ash_hwtype.title = _("Ash");
+ ash_hwtype.title = _("Ash");
#endif
#if HAVE_HWFDDI
- fddi_hwtype.title = _("Fiber Distributed Data Interface");
+ fddi_hwtype.title = _("Fiber Distributed Data Interface");
#endif
#if HAVE_HWHIPPI
- hippi_hwtype.title = _("HIPPI");
+ hippi_hwtype.title = _("HIPPI");
#endif
#if HAVE_HWAX25
- ax25_hwtype.title = _("AMPR AX.25");
+ ax25_hwtype.title = _("AMPR AX.25");
#endif
#if HAVE_HWROSE
- rose_hwtype.title = _("AMPR ROSE");
+ rose_hwtype.title = _("AMPR ROSE");
#endif
#if HAVE_HWNETROM
- netrom_hwtype.title = _("AMPR NET/ROM");
+ netrom_hwtype.title = _("AMPR NET/ROM");
#endif
#if HAVE_HWTUNNEL
- tunnel_hwtype.title = _("IPIP Tunnel");
+ tunnel_hwtype.title = _("IPIP Tunnel");
#endif
#if HAVE_HWPPP
- ppp_hwtype.title = _("Point-to-Point Protocol");
-#endif
+ ppp_hwtype.title = _("Point-to-Point Protocol");
+#endif
#if HAVE_HWHDLCLAPB
- hdlc_hwtype.title = _("(Cisco)-HDLC");
- lapb_hwtype.title = _("LAPB");
+ hdlc_hwtype.title = _("(Cisco)-HDLC");
+ lapb_hwtype.title = _("LAPB");
#endif
#if HAVE_HWARC
- arcnet_hwtype.title = _("1.5Mbps ARCnet");
+ arcnet_hwtype.title = _("1.5Mbps ARCnet");
#endif
#if HAVE_HWFR
- dlci_hwtype.title = _("Frame Relay DLCI");
- frad_hwtype.title = _("Frame Relay Access Device");
+ dlci_hwtype.title = _("Frame Relay DLCI");
+ frad_hwtype.title = _("Frame Relay Access Device");
#endif
#if HAVE_HWSIT
- sit_hwtype.title = _("IPv6-in-IPv4");
+ sit_hwtype.title = _("IPv6-in-IPv4");
#endif
- sVhwinit = 1;
+ sVhwinit = 1;
}
/* Check our hardware type table for this type. */
-struct hwtype *
-get_hwtype(const char *name)
+struct hwtype *get_hwtype(const char *name)
{
- struct hwtype **hwp;
-
- if (!sVhwinit)
- hwinit();
-
- hwp = hwtypes;
- while (*hwp != NULL) {
- if (!strcmp((*hwp)->name, name)) return(*hwp);
+ struct hwtype **hwp;
+
+ if (!sVhwinit)
+ hwinit();
+
+ hwp = hwtypes;
+ while (*hwp != NULL) {
+ if (!strcmp((*hwp)->name, name))
+ return (*hwp);
hwp++;
- }
- return(NULL);
+ }
+ return (NULL);
}
/* Check our hardware type table for this type. */
-struct hwtype *
-get_hwntype(int type)
+struct hwtype *get_hwntype(int type)
{
- struct hwtype **hwp;
+ struct hwtype **hwp;
- if (!sVhwinit)
- hwinit();
+ if (!sVhwinit)
+ hwinit();
- hwp = hwtypes;
- while (*hwp != NULL) {
- if ((*hwp)->type == type) return(*hwp);
+ hwp = hwtypes;
+ while (*hwp != NULL) {
+ if ((*hwp)->type == type)
+ return (*hwp);
hwp++;
- }
- return(NULL);
+ }
+ return (NULL);
}
diff --git a/lib/inet.c b/lib/inet.c
index e35c504..149a275 100644
--- a/lib/inet.c
+++ b/lib/inet.c
@@ -1,26 +1,26 @@
/*
- * lib/inet.c This file contains an implementation of the "INET"
- * support functions for the net-tools.
- * (NET-3 base distribution).
+ * lib/inet.c This file contains an implementation of the "INET"
+ * support functions for the net-tools.
+ * (NET-3 base distribution).
*
- * Version: lib/inet.c 1.26 1996-03-29
+ * Version: $Id: inet.c,v 1.5 1998/11/15 20:10:27 freitag Exp $
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
* Modified:
- *960113 {1.21} Bernd Eckenfels : rresolve cache bug.
- *960128 {1.22} Bernd Eckenfels : endian bug in print
+ *960113 {1.21} Bernd Eckenfels : rresolve cache bug.
+ *960128 {1.22} Bernd Eckenfels : endian bug in print
*960203 {1.23} Bernd Eckenfels : net-features support
- *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
+ *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
*
- * 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.
+ * 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"
@@ -43,342 +43,329 @@
#include "pathnames.h"
#include "intl.h"
-extern int h_errno; /* some netdb.h versions don't export this */
+extern int h_errno; /* some netdb.h versions don't export this */
struct addr {
- struct sockaddr_in addr;
- char *name;
- struct addr *next;
+ struct sockaddr_in addr;
+ char *name;
+ struct addr *next;
};
struct service {
- int number;
- char *name;
- struct service *next;
+ int number;
+ char *name;
+ struct service *next;
};
-static struct service *tcp_name = NULL,
- *udp_name = NULL,
- *raw_name = NULL;
+static struct service *tcp_name = NULL, *udp_name = NULL, *raw_name = NULL;
-static struct addr *INET_nn = NULL; /* addr-to-name cache */
+static struct addr *INET_nn = NULL; /* addr-to-name cache */
-static int
-INET_resolve(char *name, struct sockaddr_in *sin)
+static int INET_resolve(char *name, struct sockaddr_in *sin)
{
- struct hostent *hp;
- struct netent *np;
+ struct hostent *hp;
+ struct netent *np;
- /* Grmpf. -FvK */
- sin->sin_family = AF_INET;
- sin->sin_port = 0;
+ /* Grmpf. -FvK */
+ sin->sin_family = AF_INET;
+ sin->sin_port = 0;
- /* Default is special, meaning 0.0.0.0. */
- if (!strcmp(name, "default")) {
+ /* Default is special, meaning 0.0.0.0. */
+ if (!strcmp(name, "default")) {
sin->sin_addr.s_addr = INADDR_ANY;
- return(1);
- }
-
- /* Look to see if it's a dotted quad. */
- if (inet_aton(name, &sin->sin_addr)) {
- return 0;
- }
-
- /* Try the NETWORKS database to see if this is a known network. */
- if ((np = getnetbyname(name)) != (struct netent *)NULL) {
- sin->sin_addr.s_addr = htonl(np->n_net);
- strcpy(name, np->n_name);
- return 1;
- }
-
+ return (1);
+ }
+ /* Look to see if it's a dotted quad. */
+ if (inet_aton(name, &sin->sin_addr)) {
+ return 0;
+ }
+ /* Try the NETWORKS database to see if this is a known network. */
+ if ((np = getnetbyname(name)) != (struct netent *) NULL) {
+ sin->sin_addr.s_addr = htonl(np->n_net);
+ strcpy(name, np->n_name);
+ return 1;
+ }
#ifdef DEBUG
- res_init();
- _res.options |= RES_DEBUG;
+ res_init();
+ _res.options |= RES_DEBUG;
#endif
- if ((hp = gethostbyname(name)) == (struct hostent *)NULL) {
- errno = h_errno;
- return -1;
- }
- memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0], hp->h_length);
- strcpy(name, hp->h_name);
- return 0;
+ if ((hp = gethostbyname(name)) == (struct hostent *) NULL) {
+ errno = h_errno;
+ return -1;
+ }
+ memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0], hp->h_length);
+ strcpy(name, hp->h_name);
+ return 0;
}
-static int
-INET_rresolve(char *name, struct sockaddr_in *sin, int numeric)
+static int INET_rresolve(char *name, struct sockaddr_in *sin, int numeric)
{
- struct hostent *ent;
- struct netent *np;
- struct addr *pn;
- unsigned long ad, host_ad;
+ struct hostent *ent;
+ struct netent *np;
+ struct addr *pn;
+ unsigned long ad, host_ad;
- /* Grmpf. -FvK */
- if (sin->sin_family != AF_INET) {
+ /* Grmpf. -FvK */
+ if (sin->sin_family != AF_INET) {
#ifdef DEBUG
fprintf(stderr, _("rresolve: unsupport address family %d !\n"), sin->sin_family);
#endif
errno = EAFNOSUPPORT;
- return(-1);
- }
-
- ad = (unsigned long) sin->sin_addr.s_addr;
- if (ad == INADDR_ANY) {
+ return (-1);
+ }
+ ad = (unsigned long) sin->sin_addr.s_addr;
+ if (ad == INADDR_ANY) {
if ((numeric & 0x7FFF) == 0) {
- if (numeric & 0x8000) strcpy(name, "default");
- else strcpy(name, "*");
- return(0);
+ if (numeric & 0x8000)
+ strcpy(name, "default");
+ else
+ strcpy(name, "*");
+ return (0);
}
- }
- if (numeric & 0x7FFF) {
- strcpy(name,inet_ntoa (sin->sin_addr));
- return(0);
- }
-
+ }
+ if (numeric & 0x7FFF) {
+ strcpy(name, inet_ntoa(sin->sin_addr));
+ return (0);
+ }
#if 0
- INET_nn = NULL;
+ INET_nn = NULL;
#endif
- pn = INET_nn;
- while (pn != NULL) {
+ pn = INET_nn;
+ while (pn != NULL) {
if (pn->addr.sin_addr.s_addr == ad) {
- strcpy(name, pn->name);
- return(0);
+ strcpy(name, pn->name);
+ return (0);
}
pn = pn->next;
- }
+ }
- host_ad = ntohl(ad);
- np = NULL;
- ent = NULL;
- if ((host_ad & 0xFF) != 0) {
+ host_ad = ntohl(ad);
+ np = NULL;
+ ent = NULL;
+ if ((host_ad & 0xFF) != 0) {
ent = gethostbyaddr((char *) &ad, 4, AF_INET);
if (ent != NULL)
- strcpy(name, ent->h_name);
- } else {
+ strcpy(name, ent->h_name);
+ } else {
np = getnetbyaddr(host_ad, AF_INET);
if (np != NULL) {
- strcpy(name, np->n_name);
+ strcpy(name, np->n_name);
}
- }
- if ((ent == NULL) && (np == NULL)) {
- strcpy(name,inet_ntoa (sin->sin_addr));
- }
- pn = (struct addr *)malloc(sizeof(struct addr));
- pn->addr = *sin;
- pn->next = INET_nn;
- pn->name = (char *) malloc(strlen(name) + 1);
- strcpy(pn->name, name);
- INET_nn = pn;
-
- return(0);
+ }
+ if ((ent == NULL) && (np == NULL)) {
+ strcpy(name, inet_ntoa(sin->sin_addr));
+ }
+ pn = (struct addr *) malloc(sizeof(struct addr));
+ pn->addr = *sin;
+ pn->next = INET_nn;
+ pn->name = (char *) malloc(strlen(name) + 1);
+ strcpy(pn->name, name);
+ INET_nn = pn;
+
+ return (0);
}
-static void
-INET_reserror(char *text)
+static void INET_reserror(char *text)
{
- herror(text);
+ herror(text);
}
/* Display an Internet socket address. */
-static char *
-INET_print(unsigned char *ptr)
+static char *INET_print(unsigned char *ptr)
{
- return(inet_ntoa((*(struct in_addr *) ptr)));
+ return (inet_ntoa((*(struct in_addr *) ptr)));
}
/* Display an Internet socket address. */
-static char *
-INET_sprint(struct sockaddr *sap, int numeric)
+static char *INET_sprint(struct sockaddr *sap, int numeric)
{
- static char buff[128];
+ static char buff[128];
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return strncpy (buff, _("[NONE SET]"), sizeof(buff));
- if (INET_rresolve(buff, (struct sockaddr_in *) sap, numeric) != 0)
- return(NULL);
- return(buff);
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return strncpy(buff, _("[NONE SET]"), sizeof(buff));
+ if (INET_rresolve(buff, (struct sockaddr_in *) sap, numeric) != 0)
+ return (NULL);
+ return (buff);
}
-static int
-INET_getsock(char *bufp, struct sockaddr *sap)
+static int INET_getsock(char *bufp, struct sockaddr *sap)
{
- char *sp = bufp,*bp;
- unsigned int i;
- unsigned val;
- struct sockaddr_in *sin;
-
- sin = (struct sockaddr_in *) sap;
- sin->sin_family = AF_INET;
- sin->sin_port = 0;
-
- val = 0;
- bp=(char *)&val;
- for (i = 0; i < sizeof(sin->sin_addr.s_addr); i++) {
+ char *sp = bufp, *bp;
+ unsigned int i;
+ unsigned val;
+ struct sockaddr_in *sin;
+
+ sin = (struct sockaddr_in *) sap;
+ sin->sin_family = AF_INET;
+ sin->sin_port = 0;
+
+ val = 0;
+ bp = (char *) &val;
+ for (i = 0; i < sizeof(sin->sin_addr.s_addr); i++) {
*sp = toupper(*sp);
-
- if ((*sp >= 'A') && (*sp <= 'F'))
- bp[i] |= (int) (*sp - 'A') + 10;
+
+ if ((*sp >= 'A') && (*sp <= 'F'))
+ bp[i] |= (int) (*sp - 'A') + 10;
else if ((*sp >= '0') && (*sp <= '9'))
- bp[i] |= (int) (*sp - '0');
+ bp[i] |= (int) (*sp - '0');
else
- return(-1);
+ return (-1);
bp[i] <<= 4;
sp++;
*sp = toupper(*sp);
-
- if ((*sp >= 'A') && (*sp <= 'F'))
- bp[i] |= (int) (*sp - 'A') + 10;
+
+ if ((*sp >= 'A') && (*sp <= 'F'))
+ bp[i] |= (int) (*sp - 'A') + 10;
else if ((*sp >= '0') && (*sp <= '9'))
- bp[i] |= (int) (*sp - '0');
+ bp[i] |= (int) (*sp - '0');
else
- return(-1);
-
+ return (-1);
+
sp++;
}
- sin->sin_addr.s_addr = htonl (val);
+ sin->sin_addr.s_addr = htonl(val);
- return(sp-bufp);
+ return (sp - bufp);
}
-static int
-INET_input(int type, char *bufp, struct sockaddr *sap)
+static int INET_input(int type, char *bufp, struct sockaddr *sap)
{
- switch(type) {
- case 1:
- return(INET_getsock(bufp,sap));
- default:
- return(INET_resolve(bufp, (struct sockaddr_in *) sap));
- }
+ switch (type) {
+ case 1:
+ return (INET_getsock(bufp, sap));
+ default:
+ return (INET_resolve(bufp, (struct sockaddr_in *) sap));
+ }
}
static int INET_getnetmask(char *adr, struct sockaddr *m, char *name)
-{
- struct sockaddr_in *mask = (struct sockaddr_in *)m;
- char *slash, *end;
- int prefix;
-
- if ((slash = strchr(adr, '/')) == NULL)
- return 0;
-
- *slash++ = '\0';
- prefix = strtoul(slash,&end,0);
- if (*end != '\0')
- return -1;
-
- if (name) {
- sprintf(name, "/%d", prefix);
- }
-
- mask->sin_family = AF_INET;
- mask->sin_addr.s_addr = htonl(~(0xffffffffU >> prefix));
- return 1;
-}
+{
+ struct sockaddr_in *mask = (struct sockaddr_in *) m;
+ char *slash, *end;
+ int prefix;
+
+ if ((slash = strchr(adr, '/')) == NULL)
+ return 0;
+
+ *slash++ = '\0';
+ prefix = strtoul(slash, &end, 0);
+ if (*end != '\0')
+ return -1;
+
+ if (name) {
+ sprintf(name, "/%d", prefix);
+ }
+ mask->sin_family = AF_INET;
+ mask->sin_addr.s_addr = htonl(~(0xffffffffU >> prefix));
+ return 1;
+}
-struct aftype inet_aftype = {
- "inet", NULL, /*"DARPA Internet",*/ AF_INET, sizeof(unsigned long),
- INET_print, INET_sprint, INET_input, INET_reserror,
- NULL/*INET_rprint*/, NULL/*INET_rinput*/,
- INET_getnetmask,
- -1,
- NULL
+struct aftype inet_aftype =
+{
+ "inet", NULL, /*"DARPA Internet", */ AF_INET, sizeof(unsigned long),
+ INET_print, INET_sprint, INET_input, INET_reserror,
+ NULL /*INET_rprint */ , NULL /*INET_rinput */ ,
+ INET_getnetmask,
+ -1,
+ NULL
};
-#endif /* HAVE_AFINET || HAVE_AFINET6 */
+#endif /* HAVE_AFINET || HAVE_AFINET6 */
#if HAVE_AFINET || HAVE_AFINET6
-static void
-add2list(struct service **namebase, struct service *item)
+static void add2list(struct service **namebase, struct service *item)
{
- if (*namebase == NULL) {
+ if (*namebase == NULL) {
*namebase = item;
item->next = NULL;
- } else {
+ } else {
item->next = *namebase;
*namebase = item;
- }
+ }
}
-static struct service *
-searchlist(struct service *servicebase, int number)
+static struct service *searchlist(struct service *servicebase, int number)
{
- struct service *item;
+ struct service *item;
- for(item = servicebase; item != NULL; item = item->next) {
- if (item->number == number) return(item);
- }
- return(NULL);
+ for (item = servicebase; item != NULL; item = item->next) {
+ if (item->number == number)
+ return (item);
+ }
+ return (NULL);
}
-static int
-read_services(void)
+static int read_services(void)
{
- struct servent *se;
- struct service *item;
+ struct servent *se;
+ struct service *item;
- setservent(1);
- while((se=getservent())) {
+ setservent(1);
+ while ((se = getservent())) {
/* Allocate a service entry. */
item = (struct service *) malloc(sizeof(struct service));
- if (item == NULL) perror("netstat");
+ if (item == NULL)
+ perror("netstat");
item->name = strdup(se->s_name);
item->number = se->s_port;
/* Fill it in. */
- if (! strcmp(se->s_proto, "tcp")) {
- add2list(&tcp_name,item);
- } else if (! strcmp(se->s_proto, "udp")) {
- add2list(&udp_name,item);
- } else if (! strcmp(se->s_proto, "raw")) {
- add2list(&raw_name,item);
+ if (!strcmp(se->s_proto, "tcp")) {
+ add2list(&tcp_name, item);
+ } else if (!strcmp(se->s_proto, "udp")) {
+ add2list(&udp_name, item);
+ } else if (!strcmp(se->s_proto, "raw")) {
+ add2list(&raw_name, item);
}
- }
- endservent();
- return(0);
+ }
+ endservent();
+ return (0);
}
-char *
-get_sname(int socknumber, char *proto, int numeric)
+char *get_sname(int socknumber, char *proto, int numeric)
{
- static char buffer[64], init=0;
- struct service *item;
+ static char buffer[64], init = 0;
+ struct service *item;
- if (socknumber == 0) return("*");
- if (numeric) {
+ if (socknumber == 0)
+ return ("*");
+ if (numeric) {
sprintf(buffer, "%d", ntohs(socknumber));
- return(buffer);
- }
- if (!init) {
- (void)read_services();
- init=1;
- }
- buffer[0]='\0';
- if (! strcmp(proto, "tcp")) {
+ return (buffer);
+ }
+ if (!init) {
+ (void) read_services();
+ init = 1;
+ }
+ buffer[0] = '\0';
+ if (!strcmp(proto, "tcp")) {
if ((item = searchlist(tcp_name, socknumber)) != NULL)
- sprintf(buffer, "%s", item->name);
- } else if (! strcmp(proto, "udp")) {
+ sprintf(buffer, "%s", item->name);
+ } else if (!strcmp(proto, "udp")) {
if ((item = searchlist(udp_name, socknumber)) != NULL)
- sprintf(buffer, "%s", item->name);
- } else if (! strcmp(proto, "raw")) {
+ sprintf(buffer, "%s", item->name);
+ } else if (!strcmp(proto, "raw")) {
if ((item = searchlist(raw_name, socknumber)) != NULL)
- sprintf(buffer, "%s", item->name);
+ sprintf(buffer, "%s", item->name);
- }
- if (!buffer[0])
- sprintf(buffer, "%d", ntohs(socknumber));
- return(buffer);
+ }
+ if (!buffer[0])
+ sprintf(buffer, "%d", ntohs(socknumber));
+ return (buffer);
}
-#endif /* HAVE_AFINET || HAVE_AFINET6 */
+#endif /* HAVE_AFINET || HAVE_AFINET6 */
diff --git a/lib/inet6.c b/lib/inet6.c
index 564de85..7c11528 100644
--- a/lib/inet6.c
+++ b/lib/inet6.c
@@ -1,22 +1,22 @@
/*
- * lib/inet6.c This file contains an implementation of the "INET6"
- * support functions for the net-tools.
- * (most of it copied from lib/inet.c 1.26).
+ * lib/inet6.c This file contains an implementation of the "INET6"
+ * support functions for the net-tools.
+ * (most of it copied from lib/inet.c 1.26).
*
- * Version: lib/inet6.c 0.02 1998-07-01
+ * Version: $Id: inet6.c,v 1.4 1998/11/15 20:10:37 freitag Exp $
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
* Modified:
- *960808 {0.01} Frank Strauss : adapted for IPv6 support
+ *960808 {0.01} Frank Strauss : adapted for IPv6 support
*980701 {0.02} Arnaldo C. Melo: GNU gettext instead of catgets
*
- * 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.
+ * 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"
@@ -40,126 +40,116 @@
#include "pathnames.h"
#include "intl.h"
-extern int h_errno; /* some netdb.h versions don't export this */
+extern int h_errno; /* some netdb.h versions don't export this */
-static int
-INET6_resolve(char *name, struct sockaddr_in6 *sin6)
+static int INET6_resolve(char *name, struct sockaddr_in6 *sin6)
{
- struct addrinfo req, *ai;
- int s;
+ struct addrinfo req, *ai;
+ int s;
- req.ai_family = AF_INET6;
- if ((s = getaddrinfo(name, NULL, &req, &ai))) {
- fprintf(stderr, "getaddrinfo: %s: %s\n", name, gai_strerror(s));
- return -1;
- }
+ req.ai_family = AF_INET6;
+ if ((s = getaddrinfo(name, NULL, &req, &ai))) {
+ fprintf(stderr, "getaddrinfo: %s: %s\n", name, gai_strerror(s));
+ return -1;
+ }
+ memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6));
- memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6));
+ freeaddrinfo(ai);
- freeaddrinfo(ai);
-
- return(0);
+ return (0);
}
-static int
-INET6_rresolve(char *name, struct sockaddr_in6 *sin6, int numeric)
+static int INET6_rresolve(char *name, struct sockaddr_in6 *sin6, int numeric)
{
- int s;
+ int s;
- /* Grmpf. -FvK */
- if (sin6->sin6_family != AF_INET6) {
+ /* Grmpf. -FvK */
+ if (sin6->sin6_family != AF_INET6) {
#ifdef DEBUG
fprintf(stderr, _("rresolve: unsupport address family %d !\n"),
- sin6->sin6_family);
+ sin6->sin6_family);
#endif
errno = EAFNOSUPPORT;
- return(-1);
- }
-
- if (numeric & 0x7FFF) {
- inet_ntop(AF_INET6, &sin6->sin6_addr, name, 80);
- return(0);
- }
-
- if ((s = getnameinfo((struct sockaddr *)sin6, sizeof(struct sockaddr_in6),
- name, 255 /* !! */, NULL, 0, 0))) {
- fprintf(stderr, "getnameinfo: %s\n", gai_strerror(s));
- return -1;
- }
-
- return(0);
+ return (-1);
+ }
+ if (numeric & 0x7FFF) {
+ inet_ntop(AF_INET6, &sin6->sin6_addr, name, 80);
+ return (0);
+ }
+ if ((s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6),
+ name, 255 /* !! */ , NULL, 0, 0))) {
+ fprintf(stderr, "getnameinfo: %s\n", gai_strerror(s));
+ return -1;
+ }
+ return (0);
}
-static void
-INET6_reserror(char *text)
+static void INET6_reserror(char *text)
{
- herror(text);
+ herror(text);
}
/* Display an Internet socket address. */
-static char *
-INET6_print(unsigned char *ptr)
+static char *INET6_print(unsigned char *ptr)
{
- static char name[80];
+ static char name[80];
- inet_ntop(AF_INET6, (struct in6_addr *)ptr, name, 80);
- return name;
+ inet_ntop(AF_INET6, (struct in6_addr *) ptr, name, 80);
+ return name;
}
/* Display an Internet socket address. */
/* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */
-static char *
-INET6_sprint(struct sockaddr *sap, int numeric)
+static char *INET6_sprint(struct sockaddr *sap, int numeric)
{
- static char buff[128];
+ static char buff[128];
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return strncpy (buff, _("[NONE SET]"), sizeof (buff));
- if (INET6_rresolve(buff, (struct sockaddr_in6 *) sap, numeric) != 0)
- return(NULL);
- return(buff);
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return strncpy(buff, _("[NONE SET]"), sizeof(buff));
+ if (INET6_rresolve(buff, (struct sockaddr_in6 *) sap, numeric) != 0)
+ return (NULL);
+ return (buff);
}
-static int
-INET6_getsock(char *bufp, struct sockaddr *sap)
+static int INET6_getsock(char *bufp, struct sockaddr *sap)
{
- struct sockaddr_in6 *sin6;
-
- sin6 = (struct sockaddr_in6 *) sap;
- sin6->sin6_family = AF_INET6;
- sin6->sin6_port = 0;
+ struct sockaddr_in6 *sin6;
+
+ sin6 = (struct sockaddr_in6 *) sap;
+ sin6->sin6_family = AF_INET6;
+ sin6->sin6_port = 0;
- if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0)
- return(-1);
+ if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0)
+ return (-1);
- return 16; /* ?;) */
+ return 16; /* ?;) */
}
-static int
-INET6_input(int type, char *bufp, struct sockaddr *sap)
+static int INET6_input(int type, char *bufp, struct sockaddr *sap)
{
- switch(type) {
- case 1:
- return(INET6_getsock(bufp, sap));
- default:
- return(INET6_resolve(bufp, (struct sockaddr_in6 *) sap));
- }
+ switch (type) {
+ case 1:
+ return (INET6_getsock(bufp, sap));
+ default:
+ return (INET6_resolve(bufp, (struct sockaddr_in6 *) sap));
+ }
}
-struct aftype inet6_aftype = {
- "inet6", NULL, /*"IPv6",*/ AF_INET6, sizeof(struct in6_addr),
- INET6_print, INET6_sprint, INET6_input, INET6_reserror,
- INET6_rprint, INET6_rinput, NULL,
+struct aftype inet6_aftype =
+{
+ "inet6", NULL, /*"IPv6", */ AF_INET6, sizeof(struct in6_addr),
+ INET6_print, INET6_sprint, INET6_input, INET6_reserror,
+ INET6_rprint, INET6_rinput, NULL,
- -1,
- "/proc/net/if_inet6"
+ -1,
+ "/proc/net/if_inet6"
};
-#endif /* HAVE_AFINET6 */
+#endif /* HAVE_AFINET6 */
diff --git a/lib/inet6_gr.c b/lib/inet6_gr.c
index f54cc7d..42f8839 100644
--- a/lib/inet6_gr.c
+++ b/lib/inet6_gr.c
@@ -1,8 +1,8 @@
/*
- Modifications:
- 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets,
- snprintf instead of sprintf
-*/
+ Modifications:
+ 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets,
+ snprintf instead of sprintf
+ */
#include "config.h"
@@ -24,7 +24,7 @@
#include <stdio.h>
#include <unistd.h>
#ifndef __GLIBC__
-#include <netinet6/ipv6_route.h> /* glibc doesn't have this */
+#include <netinet6/ipv6_route.h> /* glibc doesn't have this */
#endif
#include "version.h"
#include "net-support.h"
@@ -34,11 +34,11 @@
/* this is from linux/include/net/ndisc.h */
/*
- * Neighbor Cache Entry States (7.3.2.)
+ * Neighbor Cache Entry States (7.3.2.)
*/
/*
- * The lsb is set for states that have a timer associated
+ * The lsb is set for states that have a timer associated
*/
#define NUD_NONE 0x00
@@ -47,45 +47,43 @@
#define NUD_STALE 0x30
#define NUD_DELAY 0x41
#define NUD_PROBE 0x51
-#define NUD_FAILED 0x60 /* neighbour discovery failed */
+#define NUD_FAILED 0x60 /* neighbour discovery failed */
#define NUD_IN_TIMER 0x01
#define NDISC_QUEUE_LEN 3
#define NCF_NOARP 0x0100 /* no ARP needed on this device */
-#define NCF_SUBNET 0x0200 /* NC entry for subnet */
+#define NCF_SUBNET 0x0200 /* NC entry for subnet */
#define NCF_INVALID 0x0400
-#define NCF_DELAY_EXPIRED 0x0800 /* time to move to PROBE */
-#define NCF_ROUTER 0x1000 /* neighbour is a router */
-#define NCF_HHVALID 0x2000 /* Hardware header is valid */
+#define NCF_DELAY_EXPIRED 0x0800 /* time to move to PROBE */
+#define NCF_ROUTER 0x1000 /* neighbour is a router */
+#define NCF_HHVALID 0x2000 /* Hardware header is valid */
-extern struct aftype inet6_aftype;
+extern struct aftype inet6_aftype;
int rprint_fib6(int ext, int numeric)
{
- char buff[4096], iface[16], flags[16];
- char addr6[128], naddr6[128];
- 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");
- return 1;
- }
+ char buff[4096], iface[16], flags[16];
+ char addr6[128], naddr6[128];
+ 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];
- printf(_("Kernel IPv6 routing table\n"));
+ if (!fp) {
+ ESYSNOT("getroute", "INET6 FIB");
+ return 1;
+ }
+ printf(_("Kernel IPv6 routing table\n"));
- printf(_("Destination "
- "Next Hop "
- "Flags Metric Ref Use Iface\n"));
+ printf(_("Destination "
+ "Next Hop "
+ "Flags Metric Ref Use Iface\n"));
- while (fgets(buff, 1023, fp))
- {
+ while (fgets(buff, 1023, fp)) {
num = sscanf(buff, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %4s%4s%4s%4s%4s%4s%4s%4s %02x %4s%4s%4s%4s%4s%4s%4s%4s %08x %08x %08x %08x %s\n",
addr6p[0], addr6p[1], addr6p[2], addr6p[3],
addr6p[4], addr6p[5], addr6p[6], addr6p[7],
@@ -97,168 +95,179 @@ int rprint_fib6(int ext, int numeric)
naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7],
&metric, &use, &refcnt, &iflags, iface);
#if 0
- if (num < 23) continue;
+ if (num < 23)
+ continue;
#endif
- if (!(iflags & RTF_UP)) continue;
+ if (!(iflags & RTF_UP))
+ continue;
/* Fetch and resolve the target address. */
snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
- addr6p[0], addr6p[1], addr6p[2], addr6p[3],
- addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
- inet6_aftype.input(1, addr6, (struct sockaddr *)&saddr6);
+ addr6p[0], addr6p[1], addr6p[2], addr6p[3],
+ addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
+ inet6_aftype.input(1, addr6, (struct sockaddr *) &saddr6);
snprintf(addr6, sizeof(addr6), "%s/%d",
- inet6_aftype.sprint((struct sockaddr *)&saddr6, 1),
- prefix_len);
-
+ inet6_aftype.sprint((struct sockaddr *) &saddr6, 1),
+ prefix_len);
+
/* Fetch and resolve the nexthop address. */
snprintf(naddr6, sizeof(naddr6), "%s:%s:%s:%s:%s:%s:%s:%s",
- naddr6p[0], naddr6p[1], naddr6p[2], naddr6p[3],
- naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7]);
- inet6_aftype.input(1, naddr6, (struct sockaddr *)&snaddr6);
+ naddr6p[0], naddr6p[1], naddr6p[2], naddr6p[3],
+ naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7]);
+ inet6_aftype.input(1, naddr6, (struct sockaddr *) &snaddr6);
snprintf(naddr6, sizeof(naddr6), "%s",
- inet6_aftype.sprint((struct sockaddr *)&snaddr6, 1));
-
+ inet6_aftype.sprint((struct sockaddr *) &snaddr6, 1));
+
/* Decode the flags. */
strcpy(flags, "U");
- if (iflags & RTF_GATEWAY) strcat(flags, "G");
- if (iflags & RTF_HOST) strcat(flags, "H");
- if (iflags & RTF_DEFAULT) strcat(flags, "D");
- if (iflags & RTF_ADDRCONF) strcat(flags, "A");
- if (iflags & RTF_CACHE) strcat(flags, "C");
-
+ if (iflags & RTF_GATEWAY)
+ strcat(flags, "G");
+ if (iflags & RTF_HOST)
+ strcat(flags, "H");
+ if (iflags & RTF_DEFAULT)
+ strcat(flags, "D");
+ if (iflags & RTF_ADDRCONF)
+ strcat(flags, "A");
+ if (iflags & RTF_CACHE)
+ strcat(flags, "C");
+
/* Print the info. */
printf("%-43s %-39s %-5s %-6d %-2d %7d %-8s\n",
addr6, naddr6, flags, metric, refcnt, use, iface);
- }
+ }
- (void) fclose(fp);
- return(0);
+ (void) fclose(fp);
+ return (0);
}
int rprint_cache6(int ext, int numeric)
{
- char buff[4096], iface[16], flags[16];
- char addr6[128], haddr[20], statestr[20];
- struct sockaddr_in6 saddr6;
- int type, num, refcnt, prefix_len, location,state,gc;
- long tstamp, expire, ndflags,reachable,stale,delete;
- FILE *fp=fopen(_PATH_PROCNET_NDISC, "r");
- char addr6p[8][5], haddrp[6][3];
-
- if (!fp) {
- ESYSNOT("nd_print","ND Table");
- return 1;
- }
+ char buff[4096], iface[16], flags[16];
+ char addr6[128], haddr[20], statestr[20];
+ struct sockaddr_in6 saddr6;
+ int type, num, refcnt, prefix_len, location, state, gc;
+ long tstamp, expire, ndflags, reachable, stale, delete;
+ FILE *fp = fopen(_PATH_PROCNET_NDISC, "r");
+ char addr6p[8][5], haddrp[6][3];
- printf(_("Kernel IPv6 Neighbour Cache\n"));
+ if (!fp) {
+ ESYSNOT("nd_print", "ND Table");
+ return 1;
+ }
+ printf(_("Kernel IPv6 Neighbour Cache\n"));
- if (ext == 2)
- printf(_("Neighbour "
- "HW Address "
- "Iface Flags Ref State\n"));
- else
- printf(_("Neighbour "
- "HW Address "
- "Iface Flags Ref State Stale(sec) Delete(sec)\n"));
+ if (ext == 2)
+ printf(_("Neighbour "
+ "HW Address "
+ "Iface Flags Ref State\n"));
+ else
+ printf(_("Neighbour "
+ "HW Address "
+ "Iface Flags Ref State Stale(sec) Delete(sec)\n"));
- while (fgets(buff, 1023, fp))
- {
+ while (fgets(buff, 1023, fp)) {
num = sscanf(buff, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %08lx %08lx %08lx %04x %04x %04lx %8s %2s%2s%2s%2s%2s%2s\n",
addr6p[0], addr6p[1], addr6p[2], addr6p[3],
addr6p[4], addr6p[5], addr6p[6], addr6p[7],
&location, &prefix_len, &type, &state, &expire, &tstamp, &reachable, &gc, &refcnt,
&ndflags, iface,
- haddrp[0], haddrp[1], haddrp[2], haddrp[3], haddrp[4], haddrp[5]);
+ haddrp[0], haddrp[1], haddrp[2], haddrp[3], haddrp[4], haddrp[5]);
/* Fetch and resolve the nexthop address. */
snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
- addr6p[0], addr6p[1], addr6p[2], addr6p[3],
- addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
- inet6_aftype.input(1, addr6, (struct sockaddr *)&saddr6);
+ addr6p[0], addr6p[1], addr6p[2], addr6p[3],
+ addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
+ inet6_aftype.input(1, addr6, (struct sockaddr *) &saddr6);
snprintf(addr6, sizeof(addr6), "%s/%d",
- inet6_aftype.sprint((struct sockaddr *)&saddr6, numeric),
- prefix_len);
-
+ inet6_aftype.sprint((struct sockaddr *) &saddr6, numeric),
+ prefix_len);
+
/* Fetch the hardware address. */
snprintf(haddr, sizeof(haddr), "%s:%s:%s:%s:%s:%s",
- haddrp[0],haddrp[1],haddrp[2], haddrp[3],haddrp[4],haddrp[5]);
-
+ haddrp[0], haddrp[1], haddrp[2], haddrp[3], haddrp[4], haddrp[5]);
+
/* Decode the flags. */
flags[0] = '\0';
- if (ndflags & NCF_NOARP) strcat(flags, "N");
- if (ndflags & NCF_SUBNET) strcat(flags, "S");
- if (ndflags & NCF_INVALID) strcat(flags, "I");
- if (ndflags & NCF_DELAY_EXPIRED) strcat(flags, "D");
- if (ndflags & NCF_ROUTER) strcat(flags, "R");
- if (ndflags & NCF_HHVALID) strcat(flags, "H");
+ if (ndflags & NCF_NOARP)
+ strcat(flags, "N");
+ if (ndflags & NCF_SUBNET)
+ strcat(flags, "S");
+ if (ndflags & NCF_INVALID)
+ strcat(flags, "I");
+ if (ndflags & NCF_DELAY_EXPIRED)
+ strcat(flags, "D");
+ if (ndflags & NCF_ROUTER)
+ strcat(flags, "R");
+ if (ndflags & NCF_HHVALID)
+ strcat(flags, "H");
/* Decode the state */
switch (state) {
case NUD_NONE:
- strcpy(statestr,"NONE");
- break;
+ strcpy(statestr, "NONE");
+ break;
case NUD_INCOMPLETE:
- strcpy(statestr,"INCOMPLETE");
- break;
+ strcpy(statestr, "INCOMPLETE");
+ break;
case NUD_REACHABLE:
- strcpy(statestr,"REACHABLE");
- break;
+ strcpy(statestr, "REACHABLE");
+ break;
case NUD_STALE:
- strcpy(statestr,"STALE");
- break;
+ strcpy(statestr, "STALE");
+ break;
case NUD_DELAY:
- strcpy(statestr,"DELAY");
- break;
+ strcpy(statestr, "DELAY");
+ break;
case NUD_PROBE:
- strcpy(statestr,"PROBE");
- break;
+ strcpy(statestr, "PROBE");
+ break;
case NUD_FAILED:
- strcpy(statestr,"FAILED");
- break;
+ strcpy(statestr, "FAILED");
+ break;
case NUD_IN_TIMER:
- strcpy(statestr,"IN TIMER");
- break;
+ strcpy(statestr, "IN TIMER");
+ break;
default:
- snprintf(statestr,sizeof (statestr),"UNKNOWN %02x",state);
- break;
+ snprintf(statestr, sizeof(statestr), "UNKNOWN %02x", state);
+ break;
}
-
+
/* Print the info. */
printf("%-43s %-17s %-8s %-5s %-3d %-16s",
addr6, haddr, iface, flags, refcnt, statestr);
- stale=0;
- if (state==NUD_REACHABLE)
- stale = reachable > tstamp?reachable - tstamp:0;
- delete = gc > tstamp?gc - tstamp:0;
- if (ext!=2){
- printf(" %-9ld ",stale/HZ);
- if (refcnt)
- printf(" * ");
- else
- printf(" %-7ld ",delete/HZ);
+ stale = 0;
+ if (state == NUD_REACHABLE)
+ stale = reachable > tstamp ? reachable - tstamp : 0;
+ delete = gc > tstamp ? gc - tstamp : 0;
+ if (ext != 2) {
+ printf(" %-9ld ", stale / HZ);
+ if (refcnt)
+ printf(" * ");
+ else
+ printf(" %-7ld ", delete / HZ);
}
printf("\n");
- }
+ }
- (void) fclose(fp);
- return(0);
+ (void) fclose(fp);
+ return (0);
}
int INET6_rprint(int options)
{
- int ext = options & FLAG_EXT;
- int numeric = options & (FLAG_NUM|FLAG_SYM);
- int rc = E_INTERN;
-
- if (options & FLAG_FIB)
- if ((rc = rprint_fib6(ext,numeric)))
- return(rc);
-
- if (options & FLAG_CACHE)
- if ((rc = rprint_cache6(ext,numeric)))
- return(rc);
- return(rc);
+ int ext = options & FLAG_EXT;
+ int numeric = options & (FLAG_NUM | FLAG_SYM);
+ int rc = E_INTERN;
+
+ if (options & FLAG_FIB)
+ if ((rc = rprint_fib6(ext, numeric)))
+ return (rc);
+
+ if (options & FLAG_CACHE)
+ if ((rc = rprint_cache6(ext, numeric)))
+ return (rc);
+ return (rc);
}
-#endif /* HAVE_AFINET6 */
+#endif /* HAVE_AFINET6 */
diff --git a/lib/inet6_sr.c b/lib/inet6_sr.c
index 988d46d..7aa0c4d 100644
--- a/lib/inet6_sr.c
+++ b/lib/inet6_sr.c
@@ -1,7 +1,7 @@
/*
- Modifications:
- 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets
-*/
+ Modifications:
+ 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets
+ */
#include "config.h"
@@ -24,8 +24,8 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
-#ifndef __GLIBC__
-#include <netinet6/ipv6_route.h> /* glibc does not have this */
+#ifndef __GLIBC__
+#include <netinet6/ipv6_route.h> /* glibc does not have this */
#endif
#include "version.h"
#include "net-support.h"
@@ -33,158 +33,155 @@
#include "intl.h"
#include "net-features.h"
-extern struct aftype inet6_aftype;
+extern struct aftype inet6_aftype;
static int skfd = -1;
static int usage(void)
{
- fprintf(stderr,_("Usage: inet6_route [-vF] del Target\n"));
- fprintf(stderr,_(" inet6_route [-vF] add Target [gw Gw] [metric M] [[dev] If]\n"));
- fprintf(stderr,_(" inet6_route [-FC] flush NOT supported\n"));
- return(E_USAGE);
+ fprintf(stderr, _("Usage: inet6_route [-vF] del Target\n"));
+ fprintf(stderr, _(" inet6_route [-vF] add Target [gw Gw] [metric M] [[dev] If]\n"));
+ fprintf(stderr, _(" inet6_route [-FC] flush NOT supported\n"));
+ return (E_USAGE);
}
static int INET6_setroute(int action, int options, char **args)
{
- struct in6_rtmsg rt;
- struct ifreq ifr;
- struct sockaddr_in6 sa6;
- char target[128], gateway[128] = "NONE";
- int metric, prefix_len;
- char *devname = NULL;
- char *cp;
-
- if (*args == NULL)
- return(usage());
-
- strcpy(target, *args++);
- if ((cp = strchr(target, '/'))) {
- prefix_len = atol(cp+1);
- if ((prefix_len < 0) || (prefix_len > 128)) usage();
- *cp = 0;
- } else {
- prefix_len = 128;
- }
-
- /* Clean out the RTREQ structure. */
- memset((char *) &rt, 0, sizeof(struct in6_rtmsg));
-
- if (inet6_aftype.input(1, target, (struct sockaddr *)&sa6) < 0) {
+ struct in6_rtmsg rt;
+ struct ifreq ifr;
+ struct sockaddr_in6 sa6;
+ char target[128], gateway[128] = "NONE";
+ int metric, prefix_len;
+ char *devname = NULL;
+ char *cp;
+
+ if (*args == NULL)
+ return (usage());
+
+ strcpy(target, *args++);
+ if ((cp = strchr(target, '/'))) {
+ prefix_len = atol(cp + 1);
+ if ((prefix_len < 0) || (prefix_len > 128))
+ usage();
+ *cp = 0;
+ } else {
+ prefix_len = 128;
+ }
+
+ /* Clean out the RTREQ structure. */
+ memset((char *) &rt, 0, sizeof(struct in6_rtmsg));
+
+ if (inet6_aftype.input(1, target, (struct sockaddr *) &sa6) < 0) {
inet6_aftype.herror(target);
return (1);
- }
- memcpy(&rt.rtmsg_dst, sa6.sin6_addr.s6_addr, sizeof(struct in6_addr));
-
- /* Fill in the other fields. */
- rt.rtmsg_flags = RTF_UP;
- if (prefix_len == 128)
+ }
+ memcpy(&rt.rtmsg_dst, sa6.sin6_addr.s6_addr, sizeof(struct in6_addr));
+
+ /* Fill in the other fields. */
+ rt.rtmsg_flags = RTF_UP;
+ if (prefix_len == 128)
rt.rtmsg_flags |= RTF_HOST;
- rt.rtmsg_metric = 1;
- rt.rtmsg_dst_len = prefix_len;
-
- while (*args) {
+ rt.rtmsg_metric = 1;
+ rt.rtmsg_dst_len = prefix_len;
+
+ while (*args) {
if (!strcmp(*args, "metric")) {
- args++;
- if (!*args || !isdigit(**args))
- return(usage());
- metric = atoi(*args);
- rt.rtmsg_metric = metric;
- args++;
- continue;
+ args++;
+ if (!*args || !isdigit(**args))
+ return (usage());
+ metric = atoi(*args);
+ rt.rtmsg_metric = metric;
+ args++;
+ continue;
}
- if (!strcmp(*args,"gw") || !strcmp(*args,"gateway")) {
- args++;
- if (!*args)
- return(usage());
- if (rt.rtmsg_flags & RTF_GATEWAY)
- return(usage());
- strcpy(gateway, *args);
- if (inet6_aftype.input(1, gateway,
- (struct sockaddr *)&sa6) < 0) {
- inet6_aftype.herror(gateway);
- return (E_LOOKUP);
- }
- memcpy(&rt.rtmsg_gateway, sa6.sin6_addr.s6_addr,
- sizeof(struct in6_addr));
- rt.rtmsg_flags |= RTF_GATEWAY;
- args++;
- continue;
+ if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) {
+ args++;
+ if (!*args)
+ return (usage());
+ if (rt.rtmsg_flags & RTF_GATEWAY)
+ return (usage());
+ strcpy(gateway, *args);
+ if (inet6_aftype.input(1, gateway,
+ (struct sockaddr *) &sa6) < 0) {
+ inet6_aftype.herror(gateway);
+ return (E_LOOKUP);
+ }
+ memcpy(&rt.rtmsg_gateway, sa6.sin6_addr.s6_addr,
+ sizeof(struct in6_addr));
+ rt.rtmsg_flags |= RTF_GATEWAY;
+ args++;
+ continue;
}
- if (!strcmp(*args,"mod")) {
- args++;
- rt.rtmsg_flags |= RTF_MODIFIED;
- continue;
+ if (!strcmp(*args, "mod")) {
+ args++;
+ rt.rtmsg_flags |= RTF_MODIFIED;
+ continue;
}
- if (!strcmp(*args,"dyn")) {
- args++;
- rt.rtmsg_flags |= RTF_DYNAMIC;
- continue;
+ if (!strcmp(*args, "dyn")) {
+ args++;
+ rt.rtmsg_flags |= RTF_DYNAMIC;
+ continue;
}
- if (!strcmp(*args,"device") || !strcmp(*args,"dev")) {
- args++;
- if (!*args)
- return(usage());
- } else
- if (args[1])
- return(usage());
+ if (!strcmp(*args, "device") || !strcmp(*args, "dev")) {
+ args++;
+ if (!*args)
+ return (usage());
+ } else if (args[1])
+ return (usage());
devname = *args;
args++;
- }
-
- /* Create a socket to the INET6 kernel. */
- if ((skfd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
- perror("socket");
- return(E_SOCK);
- }
-
- if (devname) {
- memset(&ifr, 0, sizeof(ifr));
- strcpy(ifr.ifr_name, devname);
-
- if (ioctl(skfd, SIOGIFINDEX, &ifr) < 0) {
- perror("SIOGIFINDEX");
- return(E_SOCK);
- }
-
- rt.rtmsg_ifindex = ifr.ifr_ifindex;
- }
- else
- rt.rtmsg_ifindex = 0;
-
- /* Tell the kernel to accept this route. */
- if (action==RTACTION_DEL) {
+ }
+
+ /* Create a socket to the INET6 kernel. */
+ if ((skfd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
+ perror("socket");
+ return (E_SOCK);
+ }
+ if (devname) {
+ memset(&ifr, 0, sizeof(ifr));
+ strcpy(ifr.ifr_name, devname);
+
+ if (ioctl(skfd, SIOGIFINDEX, &ifr) < 0) {
+ perror("SIOGIFINDEX");
+ return (E_SOCK);
+ }
+ rt.rtmsg_ifindex = ifr.ifr_ifindex;
+ } else
+ rt.rtmsg_ifindex = 0;
+
+ /* Tell the kernel to accept this route. */
+ if (action == RTACTION_DEL) {
if (ioctl(skfd, SIOCDELRT, &rt) < 0) {
- perror("SIOCDELRT");
- close(skfd);
- return(E_SOCK);
+ perror("SIOCDELRT");
+ close(skfd);
+ return (E_SOCK);
}
- } else {
+ } else {
if (ioctl(skfd, SIOCADDRT, &rt) < 0) {
- perror("SIOCADDRT");
- close(skfd);
- return(E_SOCK);
+ perror("SIOCADDRT");
+ close(skfd);
+ return (E_SOCK);
}
- }
+ }
- /* Close the socket. */
- (void) close(skfd);
- return(0);
+ /* Close the socket. */
+ (void) close(skfd);
+ return (0);
}
int INET6_rinput(int action, int options, char **args)
{
- if (action == RTACTION_FLUSH) {
- fprintf(stderr,_("Flushing `inet6' routing table not supported\n"));
- return(usage());
- }
- if ((*args == NULL) || (action == RTACTION_HELP))
- return(usage());
-
- return(INET6_setroute(action, options, args));
+ if (action == RTACTION_FLUSH) {
+ fprintf(stderr, _("Flushing `inet6' routing table not supported\n"));
+ return (usage());
+ }
+ if ((*args == NULL) || (action == RTACTION_HELP))
+ return (usage());
+
+ return (INET6_setroute(action, options, args));
}
-#endif /* HAVE_AFINET6 */
+#endif /* HAVE_AFINET6 */
diff --git a/lib/inet_gr.c b/lib/inet_gr.c
index 5de96ef..3d09348 100644
--- a/lib/inet_gr.c
+++ b/lib/inet_gr.c
@@ -1,7 +1,9 @@
/*
- Modifications:
- 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets
-*/
+ $Id: inet_gr.c,v 1.9 1998/11/15 20:10:48 freitag Exp $
+
+ Modifications:
+ 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets
+ */
#include "config.h"
@@ -27,268 +29,279 @@
#include "net-features.h"
#include "proc.h"
-extern struct aftype inet_aftype;
+extern struct aftype inet_aftype;
int rprint_fib(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;
- FILE *fp=fopen(_PATH_PROCNET_ROUTE, "r");
- char *fmt;
+ 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;
+ FILE *fp = fopen(_PATH_PROCNET_ROUTE, "r");
+ char *fmt;
- if (!fp) {
- ESYSNOT("getroute","INET FIB");
+ if (!fp) {
+ ESYSNOT("getroute", "INET FIB");
return 1;
- }
-
- printf(_("Kernel IP routing table\n"));
+ }
+ printf(_("Kernel IP routing table\n"));
- if (ext == 1)
+ if (ext == 1)
printf(_("Destination Gateway Genmask "
"Flags Metric Ref Use Iface\n"));
- if (ext == 2)
+ if (ext == 2)
printf(_("Destination Gateway Genmask "
"Flags MSS Window irtt Iface\n"));
- if (ext >= 3)
+ if (ext >= 3)
printf(_("Destination Gateway Genmask "
"Flags Metric Ref Use Iface "
"MSS Window irtt\n"));
- irtt=0;
- window=0;
- mss=0;
+ irtt = 0;
+ window = 0;
+ mss = 0;
- fmt = proc_gen_fmt(_PATH_PROCNET_ROUTE, 0, fp,
- "Iface", "%16s",
- "Destination", "%128s",
- "Gateway", "%128s",
- "Flags", "%X",
- "RefCnt", "%d",
- "Use", "%d",
- "Metric", "%d",
- "Mask", "%128s",
- "MTU", "%d",
- "Window", "%d",
- "IRTT", "%d",
- NULL);
- /* "%16s %128s %128s %X %d %d %d %128s %d %d %d\n" */
+ fmt = proc_gen_fmt(_PATH_PROCNET_ROUTE, 0, fp,
+ "Iface", "%16s",
+ "Destination", "%128s",
+ "Gateway", "%128s",
+ "Flags", "%X",
+ "RefCnt", "%d",
+ "Use", "%d",
+ "Metric", "%d",
+ "Mask", "%128s",
+ "MTU", "%d",
+ "Window", "%d",
+ "IRTT", "%d",
+ NULL);
+ /* "%16s %128s %128s %X %d %d %d %128s %d %d %d\n" */
- if (!fmt)
- return 1;
+ if (!fmt)
+ return 1;
- while (fgets(buff, 1023, fp))
- {
- num = sscanf(buff, fmt,
- iface, net_addr, gate_addr,
- &iflags, &refcnt, &use, &metric, mask_addr,
- &mss,&window,&irtt);
- if (num < 10 || !(iflags & RTF_UP)) continue;
+ while (fgets(buff, 1023, fp)) {
+ num = sscanf(buff, fmt,
+ iface, net_addr, gate_addr,
+ &iflags, &refcnt, &use, &metric, mask_addr,
+ &mss, &window, &irtt);
+ if (num < 10 || !(iflags & RTF_UP))
+ continue;
/* Fetch and resolve the target address. */
- (void)inet_aftype.input(1, net_addr, &snet);
+ (void) inet_aftype.input(1, net_addr, &snet);
strcpy(net_addr, inet_aftype.sprint(&snet, (numeric | 0x8000)));
net_addr[15] = '\0';
-
+
/* Fetch and resolve the gateway address. */
- (void)inet_aftype.input(1, gate_addr, &sgate);
+ (void) inet_aftype.input(1, gate_addr, &sgate);
strcpy(gate_addr, inet_aftype.sprint(&sgate, numeric));
gate_addr[15] = '\0';
/* Fetch and resolve the genmask. */
- (void)inet_aftype.input(1, mask_addr, &smask);
+ (void) inet_aftype.input(1, mask_addr, &smask);
strcpy(mask_addr, inet_aftype.sprint(&smask, 1));
mask_addr[15] = '\0';
/* Decode the flags. */
strcpy(flags, "U");
- if (iflags & RTF_GATEWAY) strcat(flags, "G");
+ if (iflags & RTF_GATEWAY)
+ strcat(flags, "G");
#if HAVE_RTF_REJECT
- if (iflags & RTF_REJECT) strcpy(flags,"!");
+ 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");
+ 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");
/* 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
+ 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,
- metric, refcnt, use, iface);
+ printf("%-15s %-15s %-15s %-5s %-6d %-2d %7d %s\n",
+ net_addr, gate_addr, mask_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
+ 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,
- mss, window, irtt, iface);
+ printf("%-15s %-15s %-15s %-5s %5d %-5d %6d %s\n",
+ net_addr, gate_addr, mask_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
+ 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 %d\n",
- net_addr, gate_addr, mask_addr, flags,
- metric, refcnt, use, iface, mss, window, irtt);
+ printf("%-15s %-15s %-15s %-5s %-6d %-3d %6d %-6.6s %-5d %-6d %d\n",
+ net_addr, gate_addr, mask_addr, flags,
+ metric, refcnt, use, iface, mss, window, irtt);
}
- }
+ }
- free(fmt);
- (void) fclose(fp);
- return(0);
+ free(fmt);
+ (void) fclose(fp);
+ return (0);
}
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[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;
- FILE *fp=fopen(_PATH_PROCNET_RTCACHE, "r");
+ FILE *fp = fopen(_PATH_PROCNET_RTCACHE, "r");
- if (!fp) {
- ESYSNOT("getroute","INET CACHE");
+ if (!fp) {
+ ESYSNOT("getroute", "INET CACHE");
return 1;
- }
-
- if (ext == 1)
+ }
+ if (ext == 1)
printf(_("Destination Gateway Source "
"Flags Metric Ref Use Iface\n"));
- if (ext == 2)
+ if (ext == 2)
printf(_("Destination Gateway Source "
"Flags MSS Window irtt Iface\n"));
- if (ext >= 3)
+ if (ext >= 3)
printf(_("Destination Gateway Source "
"Flags Metric Ref Use Iface "
"MSS Window irtt HH Arp\n"));
- fmt = proc_gen_fmt(_PATH_PROCNET_ROUTE, 0, fp,
- "Iface", "%16s",
- "Destination", "%128s",
- "Gateway", "%128s",
- "Flags", "%X",
- "RefCnt", "%d",
- "Use", "%d",
- "Metric", "%d",
- "Mask", "%128s",
- "MTU", "%d",
- "Window", "%d",
- "IRTT", "%d",
- NULL);
- /* "%16s %128s %128s %X %d %d %d %128s %d %d %d %d %d\n" */
+ fmt = proc_gen_fmt(_PATH_PROCNET_ROUTE, 0, fp,
+ "Iface", "%16s",
+ "Destination", "%128s",
+ "Gateway", "%128s",
+ "Flags", "%X",
+ "RefCnt", "%d",
+ "Use", "%d",
+ "Metric", "%d",
+ "Mask", "%128s",
+ "MTU", "%d",
+ "Window", "%d",
+ "IRTT", "%d",
+ NULL);
+ /* "%16s %128s %128s %X %d %d %d %128s %d %d %d %d %d\n" */
- irtt=0;
- window=0;
- mss=0;
- hh=0;
- arp=0;
- while (fgets(buff, 1023, fp))
- {
+ irtt = 0;
+ window = 0;
+ mss = 0;
+ hh = 0;
+ arp = 0;
+ while (fgets(buff, 1023, fp)) {
num = sscanf(buff, fmt,
- iface, net_addr, gate_addr,
- &iflags, &refcnt, &use, &metric, mask_addr,
- &mss,&window,&irtt,&hh,&arp);
- if (num < 12) continue;
+ iface, net_addr, gate_addr,
+ &iflags, &refcnt, &use, &metric, mask_addr,
+ &mss, &window, &irtt, &hh, &arp);
+ if (num < 12)
+ continue;
/* Fetch and resolve the target address. */
- (void)inet_aftype.input(1, net_addr, &snet);
+ (void) inet_aftype.input(1, net_addr, &snet);
strcpy(net_addr, inet_aftype.sprint(&snet, (numeric | 0x8000)));
net_addr[15] = '\0';
/* Fetch and resolve the gateway address. */
- (void)inet_aftype.input(1, gate_addr, &sgate);
+ (void) inet_aftype.input(1, gate_addr, &sgate);
strcpy(gate_addr, inet_aftype.sprint(&sgate, numeric));
gate_addr[15] = '\0';
/* Fetch and resolve the genmask. */
- (void)inet_aftype.input(1, mask_addr, &smask);
+ (void) inet_aftype.input(1, mask_addr, &smask);
strcpy(mask_addr, inet_aftype.sprint(&smask, 1));
mask_addr[15] = '\0';
/* Decode the flags. */
flags[0] = '\0';
- if (iflags & RTF_UP) strcat(flags, "U");
- if (iflags & RTF_GATEWAY) strcat(flags, "G");
+ if (iflags & RTF_UP)
+ strcat(flags, "U");
+ if (iflags & RTF_GATEWAY)
+ strcat(flags, "G");
#if HAVE_RTF_REJECT
- if (iflags & RTF_REJECT) strcpy(flags,"!");
+ 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");
+ 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");
/* 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
+ 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,
- metric, refcnt, use, iface);
+ printf("%-15s %-15s %-15s %-5s %-6d %-2d %7d %s\n",
+ net_addr, gate_addr, mask_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
+ 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,
- mss, window, irtt, iface);
+ printf("%-15s %-15s %-15s %-5s %5d %-5d %6d %s\n",
+ net_addr, gate_addr, mask_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
+ 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,
- metric, refcnt, use, iface, mss, window, irtt, hh, arp);
+ printf("%-15s %-15s %-15s %-5s %-6d %-3d %6d %-6.6s %-5d %-6d %-6d %-3d %d\n",
+ net_addr, gate_addr, mask_addr, flags,
+ metric, refcnt, use, iface, mss, window, irtt, hh, arp);
}
- }
+ }
- free(fmt);
- (void) fclose(fp);
- return(0);
+ free(fmt);
+ (void) fclose(fp);
+ return (0);
}
int INET_rprint(int options)
{
- int ext = options & FLAG_EXT;
- int numeric = options & (FLAG_NUM|FLAG_SYM);
- int rc = E_INTERN;
-
- if (options & FLAG_FIB)
- if ((rc = rprint_fib(ext,numeric)))
- return(rc);
- if (options & FLAG_CACHE)
- rc = rprint_cache(ext,numeric);
-
- return(rc);
+ int ext = options & FLAG_EXT;
+ int numeric = options & (FLAG_NUM | FLAG_SYM);
+ int rc = E_INTERN;
+
+ if (options & FLAG_FIB)
+ if ((rc = rprint_fib(ext, numeric)))
+ return (rc);
+ if (options & FLAG_CACHE)
+ rc = rprint_cache(ext, numeric);
+
+ return (rc);
}
-#endif /* HAVE_AFINET */
+#endif /* HAVE_AFINET */
diff --git a/lib/inet_sr.c b/lib/inet_sr.c
index 51516ae..6636e3a 100644
--- a/lib/inet_sr.c
+++ b/lib/inet_sr.c
@@ -1,7 +1,7 @@
/*
- Modifications:
- 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets
-*/
+ Modifications:
+ 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets
+ */
#include "config.h"
@@ -37,294 +37,286 @@
#define full_mask(x) (((struct sockaddr_in *)&(x))->sin_addr.s_addr)
#endif
-extern struct aftype inet_aftype;
+extern struct aftype inet_aftype;
static int skfd = -1;
static int usage(void)
{
- fprintf(stderr,_("Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]\n"));
- fprintf(stderr,_(" inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]\n"));
- fprintf(stderr,_(" [netmask N] [mss Mss] [window W] [irtt I]\n"));
- fprintf(stderr,_(" [mod] [dyn] [reinstate] [[dev] If]\n"));
- fprintf(stderr,_(" inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject\n"));
- fprintf(stderr,_(" inet_route [-FC] flush NOT supported\n"));
- return(E_USAGE);
+ fprintf(stderr, _("Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]\n"));
+ fprintf(stderr, _(" inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]\n"));
+ fprintf(stderr, _(" [netmask N] [mss Mss] [window W] [irtt I]\n"));
+ fprintf(stderr, _(" [mod] [dyn] [reinstate] [[dev] If]\n"));
+ fprintf(stderr, _(" inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject\n"));
+ fprintf(stderr, _(" inet_route [-FC] flush NOT supported\n"));
+ return (E_USAGE);
}
static int INET_setroute(int action, int options, char **args)
{
- struct rtentry rt;
- char target[128], gateway[128] = "NONE", netmask[128] = "default";
- int xflag, isnet;
+ struct rtentry rt;
+ char target[128], gateway[128] = "NONE", netmask[128] = "default";
+ int xflag, isnet;
- xflag = 0;
+ xflag = 0;
- if (!strcmp(*args, "#net")) {
+ if (!strcmp(*args, "#net")) {
xflag = 1;
args++;
- } else if (!strcmp(*args, "#host")) {
+ } else if (!strcmp(*args, "#host")) {
xflag = 2;
args++;
- }
-
- if (*args == NULL)
- return(usage());
+ }
+ if (*args == NULL)
+ return (usage());
- target[(sizeof target)-1] = 0;
- strncpy(target, *args++, (sizeof target)-1);
+ target[(sizeof target) - 1] = 0;
+ strncpy(target, *args++, (sizeof target) - 1);
- /* Clean out the RTREQ structure. */
- memset((char *) &rt, 0, sizeof(struct rtentry));
+ /* Clean out the RTREQ structure. */
+ memset((char *) &rt, 0, sizeof(struct rtentry));
- /* Special hack for /prefix syntax */
- {
- union {
- struct sockaddr_in m;
- struct sockaddr d;
- } mask;
- int n;
+ /* Special hack for /prefix syntax */
+ {
+ union {
+ struct sockaddr_in m;
+ struct sockaddr d;
+ } mask;
+ int n;
- n = inet_aftype.getmask(target, &mask.d, netmask);
- if (n < 0)
- return usage();
- else if (n)
- rt.rt_genmask = full_mask(mask.d);
- }
-
- if ((isnet = inet_aftype.input(0, target, &rt.rt_dst)) < 0) {
+ n = inet_aftype.getmask(target, &mask.d, netmask);
+ if (n < 0)
+ return usage();
+ else if (n)
+ rt.rt_genmask = full_mask(mask.d);
+ }
+
+ if ((isnet = inet_aftype.input(0, target, &rt.rt_dst)) < 0) {
inet_aftype.herror(target);
return (1);
- }
- switch (xflag) {
- case 1:
- isnet = 1;
- break;
+ }
+ switch (xflag) {
+ case 1:
+ isnet = 1;
+ break;
- case 2:
- isnet = 0;
- break;
+ case 2:
+ isnet = 0;
+ break;
- default:
- break;
- }
+ default:
+ break;
+ }
- /* Fill in the other fields. */
- rt.rt_flags = (RTF_UP | RTF_HOST);
- if (isnet)
+ /* Fill in the other fields. */
+ rt.rt_flags = (RTF_UP | RTF_HOST);
+ if (isnet)
rt.rt_flags &= ~RTF_HOST;
- while (*args) {
+ while (*args) {
if (!strcmp(*args, "metric")) {
- int metric;
+ int metric;
- args++;
- if (!*args || !isdigit(**args))
- return(usage());
- metric = atoi(*args);
+ args++;
+ if (!*args || !isdigit(**args))
+ return (usage());
+ metric = atoi(*args);
#if HAVE_NEW_ADDRT
- rt.rt_metric = metric + 1;
+ rt.rt_metric = metric + 1;
#else
- ENOSUPP("inet_setroute","NEW_ADDRT (metric)");
+ ENOSUPP("inet_setroute", "NEW_ADDRT (metric)");
#endif
- args++;
- continue;
+ args++;
+ continue;
}
if (!strcmp(*args, "netmask")) {
- struct sockaddr mask;
+ struct sockaddr mask;
- args++;
- if (!*args || mask_in_addr(rt))
- return(usage());
- netmask[(sizeof netmask)-1] = 0;
- strncpy(netmask, *args, (sizeof netmask)-1);
- if ((isnet = inet_aftype.input(0, netmask, &mask)) < 0) {
- inet_aftype.herror(netmask);
- return (E_LOOKUP);
- }
- rt.rt_genmask = full_mask(mask);
- args++;
- continue;
+ args++;
+ if (!*args || mask_in_addr(rt))
+ return (usage());
+ netmask[(sizeof netmask) - 1] = 0;
+ strncpy(netmask, *args, (sizeof netmask) - 1);
+ if ((isnet = inet_aftype.input(0, netmask, &mask)) < 0) {
+ inet_aftype.herror(netmask);
+ return (E_LOOKUP);
+ }
+ rt.rt_genmask = full_mask(mask);
+ args++;
+ continue;
}
- if (!strcmp(*args,"gw") || !strcmp(*args,"gateway")) {
- args++;
- if (!*args)
- return(usage());
- if (rt.rt_flags & RTF_GATEWAY)
- return(usage());
- gateway[(sizeof gateway)-1] = 0;
- strncpy(gateway, *args, (sizeof gateway)-1);
- if ((isnet = inet_aftype.input(0, gateway, &rt.rt_gateway)) < 0) {
- inet_aftype.herror(gateway);
- return (E_LOOKUP);
- }
- if (isnet) {
- fprintf(stderr, _("route: %s: cannot use a NETWORK as gateway!\n"),
- gateway);
- return (E_OPTERR);
- }
- rt.rt_flags |= RTF_GATEWAY;
- args++;
- continue;
+ if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) {
+ args++;
+ if (!*args)
+ return (usage());
+ if (rt.rt_flags & RTF_GATEWAY)
+ return (usage());
+ gateway[(sizeof gateway) - 1] = 0;
+ strncpy(gateway, *args, (sizeof gateway) - 1);
+ if ((isnet = inet_aftype.input(0, gateway, &rt.rt_gateway)) < 0) {
+ inet_aftype.herror(gateway);
+ return (E_LOOKUP);
+ }
+ if (isnet) {
+ fprintf(stderr, _("route: %s: cannot use a NETWORK as gateway!\n"),
+ gateway);
+ return (E_OPTERR);
+ }
+ rt.rt_flags |= RTF_GATEWAY;
+ args++;
+ continue;
}
- if (!strcmp(*args,"mss")) {
- args++;
- rt.rt_flags |= RTF_MSS;
- if(!*args)
- return(usage());
- rt.rt_mss = atoi(*args);
- args++;
- if(rt.rt_mss<64||rt.rt_mss>32768)
- {
- fprintf(stderr, _("route: Invalid MSS.\n"));
- return(E_OPTERR);
- }
- continue;
+ if (!strcmp(*args, "mss")) {
+ args++;
+ rt.rt_flags |= RTF_MSS;
+ if (!*args)
+ return (usage());
+ rt.rt_mss = atoi(*args);
+ args++;
+ if (rt.rt_mss < 64 || rt.rt_mss > 32768) {
+ fprintf(stderr, _("route: Invalid MSS.\n"));
+ return (E_OPTERR);
+ }
+ continue;
}
- if (!strcmp(*args,"window")) {
- args++;
- if(!*args)
- return(usage());
- rt.rt_flags |= RTF_WINDOW;
- rt.rt_window = atoi(*args);
- args++;
- if(rt.rt_window<128)
- {
- fprintf(stderr, _("route: Invalid window.\n"));
- return(E_OPTERR);
- }
- continue;
+ if (!strcmp(*args, "window")) {
+ args++;
+ if (!*args)
+ return (usage());
+ rt.rt_flags |= RTF_WINDOW;
+ rt.rt_window = atoi(*args);
+ args++;
+ if (rt.rt_window < 128) {
+ fprintf(stderr, _("route: Invalid window.\n"));
+ return (E_OPTERR);
+ }
+ continue;
}
- if (!strcmp(*args,"irtt")) {
- args++;
- if(!*args)
- return(usage());
- args++;
+ if (!strcmp(*args, "irtt")) {
+ args++;
+ if (!*args)
+ return (usage());
+ args++;
#if HAVE_RTF_IRTT
- rt.rt_flags |= RTF_IRTT;
- rt.rt_irtt = atoi(*(args-1));
- rt.rt_irtt*=(HZ/100); /* FIXME */
-#if 0 /* FIXME: do we need to check anything of this? */
- if(rt.rt_irtt<1||rt.rt_irtt> (120*HZ))
- {
- fprintf(stderr, _("route: Invalid initial rtt.\n"));
- return(E_OPTERR);
- }
+ rt.rt_flags |= RTF_IRTT;
+ rt.rt_irtt = atoi(*(args - 1));
+ rt.rt_irtt *= (HZ / 100); /* FIXME */
+#if 0 /* FIXME: do we need to check anything of this? */
+ if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) {
+ fprintf(stderr, _("route: Invalid initial rtt.\n"));
+ return (E_OPTERR);
+ }
#endif
#else
- ENOSUPP("inet_setroute","RTF_IRTT");
+ ENOSUPP("inet_setroute", "RTF_IRTT");
#endif
- continue;
+ continue;
}
- if (!strcmp(*args,"reject")) {
- args++;
+ if (!strcmp(*args, "reject")) {
+ args++;
#if HAVE_RTF_REJECT
- rt.rt_flags |= RTF_REJECT;
+ rt.rt_flags |= RTF_REJECT;
#else
- ENOSUPP("inet_setroute","RTF_REJECT");
+ ENOSUPP("inet_setroute", "RTF_REJECT");
#endif
- continue;
+ continue;
}
- if (!strcmp(*args,"mod")) {
- args++;
- rt.rt_flags |= RTF_MODIFIED;
- continue;
+ if (!strcmp(*args, "mod")) {
+ args++;
+ rt.rt_flags |= RTF_MODIFIED;
+ continue;
}
- if (!strcmp(*args,"dyn")) {
- args++;
- rt.rt_flags |= RTF_DYNAMIC;
- continue;
+ if (!strcmp(*args, "dyn")) {
+ args++;
+ rt.rt_flags |= RTF_DYNAMIC;
+ continue;
}
- if (!strcmp(*args,"reinstate")) {
- args++;
- rt.rt_flags |= RTF_REINSTATE;
- continue;
+ if (!strcmp(*args, "reinstate")) {
+ args++;
+ rt.rt_flags |= RTF_REINSTATE;
+ continue;
}
-
- if (!strcmp(*args,"device") || !strcmp(*args,"dev")) {
- args++;
- if (rt.rt_dev || *args == NULL)
- return usage();
- rt.rt_dev = *args++;
- continue;
+ if (!strcmp(*args, "device") || !strcmp(*args, "dev")) {
+ args++;
+ if (rt.rt_dev || *args == NULL)
+ return usage();
+ rt.rt_dev = *args++;
+ continue;
}
-
- /* nothing matches */
- if (!rt.rt_dev) {
- rt.rt_dev = *args++;
- if (*args)
- return usage(); /* must be last to catch typos */
+ /* nothing matches */
+ if (!rt.rt_dev) {
+ rt.rt_dev = *args++;
+ if (*args)
+ return usage(); /* must be last to catch typos */
} else
- return usage();
- }
+ return usage();
+ }
#if HAVE_RTF_REJECT
- if ((rt.rt_flags & RTF_REJECT) && !rt.rt_dev)
- rt.rt_dev="lo";
+ if ((rt.rt_flags & RTF_REJECT) && !rt.rt_dev)
+ rt.rt_dev = "lo";
#endif
-
- /* sanity checks.. */
- if (mask_in_addr(rt)) {
+
+ /* sanity checks.. */
+ if (mask_in_addr(rt)) {
__u32 mask = ~ntohl(mask_in_addr(rt));
if ((rt.rt_flags & RTF_HOST) && mask != 0xffffffff) {
- fprintf(stderr, _("route: netmask %.8x doesn't make sense with host route\n"), mask);
- return(E_OPTERR);
+ fprintf(stderr, _("route: netmask %.8x doesn't make sense with host route\n"), mask);
+ return (E_OPTERR);
}
- if (mask & (mask+1)) {
- fprintf(stderr, _("route: bogus netmask %s\n"), netmask);
- return(E_OPTERR);
+ if (mask & (mask + 1)) {
+ fprintf(stderr, _("route: bogus netmask %s\n"), netmask);
+ return (E_OPTERR);
}
mask = ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr;
if (mask & ~mask_in_addr(rt)) {
- fprintf(stderr, _("route: netmask doesn't match route address\n"));
- return(E_OPTERR);
+ fprintf(stderr, _("route: netmask doesn't match route address\n"));
+ return (E_OPTERR);
}
- }
-
- /* Fill out netmask if still unset */
- if ((action==RTACTION_ADD) && rt.rt_flags & RTF_HOST)
+ }
+ /* Fill out netmask if still unset */
+ if ((action == RTACTION_ADD) && rt.rt_flags & RTF_HOST)
mask_in_addr(rt) = 0xffffffff;
- /* Create a socket to the INET kernel. */
- if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ /* Create a socket to the INET kernel. */
+ if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("socket");
- return(E_SOCK);
- }
-
- /* Tell the kernel to accept this route. */
- if (action==RTACTION_DEL) {
+ return (E_SOCK);
+ }
+ /* Tell the kernel to accept this route. */
+ if (action == RTACTION_DEL) {
if (ioctl(skfd, SIOCDELRT, &rt) < 0) {
- perror("SIOCDELRT");
- close(skfd);
- return(E_SOCK);
+ perror("SIOCDELRT");
+ close(skfd);
+ return (E_SOCK);
}
- } else {
+ } else {
if (ioctl(skfd, SIOCADDRT, &rt) < 0) {
- perror("SIOCADDRT");
- close(skfd);
- return(E_SOCK);
+ perror("SIOCADDRT");
+ close(skfd);
+ return (E_SOCK);
}
- }
+ }
- /* Close the socket. */
- (void) close(skfd);
- return(0);
+ /* Close the socket. */
+ (void) close(skfd);
+ return (0);
}
int INET_rinput(int action, int options, char **args)
{
- if (action == RTACTION_FLUSH) {
- fprintf(stderr,_("Flushing `inet' routing table not supported\n"));
- return(usage());
- }
- if (options & FLAG_CACHE) {
- fprintf(stderr,_("Modifying `inet' routing cache not supported\n"));
- return(usage());
- }
- if ((*args == NULL) || (action == RTACTION_HELP))
- return(usage());
-
- return(INET_setroute(action, options, args));
+ if (action == RTACTION_FLUSH) {
+ fprintf(stderr, _("Flushing `inet' routing table not supported\n"));
+ return (usage());
+ }
+ if (options & FLAG_CACHE) {
+ fprintf(stderr, _("Modifying `inet' routing cache not supported\n"));
+ return (usage());
+ }
+ if ((*args == NULL) || (action == RTACTION_HELP))
+ return (usage());
+
+ return (INET_setroute(action, options, args));
}
-#endif /* HAVE_AFINET */
+#endif /* HAVE_AFINET */
diff --git a/lib/ipx.c b/lib/ipx.c
index 09bbb3c..668883e 100644
--- a/lib/ipx.c
+++ b/lib/ipx.c
@@ -1,14 +1,14 @@
/*
- * IPX protocol output functions.
- * [Not yet input]
+ * IPX protocol output functions.
+ * [Not yet input]
*
- * Alan Cox <Alan.Cox@linux.org>
+ * Alan Cox <Alan.Cox@linux.org>
*
- * 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.
+ * 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.
* Modifications:
* 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets,
* snprintf instead of sprintf
@@ -41,142 +41,139 @@
#endif
/* Display a ipx domain address. */
-static char *
-IPX_print(unsigned char *ptr)
+static char *IPX_print(unsigned char *ptr)
{
- static char buff[64];
- struct sockaddr_ipx *sipx=(struct sockaddr_ipx *)(ptr-2);
- int t;
-
-
- for(t=IPX_NODE_LEN;t;t--)
- if (sipx->sipx_node[t-1])
- break;
-
- if (t && ntohl(sipx->sipx_network))
- snprintf(buff,sizeof(buff),"%08lX:%02X%02X%02X%02X%02X%02X",
- (long int)ntohl(sipx->sipx_network),
- (int)sipx->sipx_node[0],(int)sipx->sipx_node[1],
- (int)sipx->sipx_node[2],(int)sipx->sipx_node[3],
- (int)sipx->sipx_node[4],(int)sipx->sipx_node[5]);
- else if (!t && ntohl(sipx->sipx_network))
- snprintf(buff,sizeof(buff),"%08lX", (long int)ntohl(sipx->sipx_network));
- else if (t && !ntohl(sipx->sipx_network))
- snprintf(buff,sizeof(buff),"%02X%02X%02X%02X%02X%02X",
- (int)sipx->sipx_node[0],(int)sipx->sipx_node[1],
- (int)sipx->sipx_node[2],(int)sipx->sipx_node[3],
- (int)sipx->sipx_node[4],(int)sipx->sipx_node[5]);
- else
- buff[0] = '\0';
- return(buff);
+ static char buff[64];
+ struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) (ptr - 2);
+ int t;
+
+
+ for (t = IPX_NODE_LEN; t; t--)
+ if (sipx->sipx_node[t - 1])
+ break;
+
+ if (t && ntohl(sipx->sipx_network))
+ snprintf(buff, sizeof(buff), "%08lX:%02X%02X%02X%02X%02X%02X",
+ (long int) ntohl(sipx->sipx_network),
+ (int) sipx->sipx_node[0], (int) sipx->sipx_node[1],
+ (int) sipx->sipx_node[2], (int) sipx->sipx_node[3],
+ (int) sipx->sipx_node[4], (int) sipx->sipx_node[5]);
+ else if (!t && ntohl(sipx->sipx_network))
+ snprintf(buff, sizeof(buff), "%08lX", (long int) ntohl(sipx->sipx_network));
+ else if (t && !ntohl(sipx->sipx_network))
+ snprintf(buff, sizeof(buff), "%02X%02X%02X%02X%02X%02X",
+ (int) sipx->sipx_node[0], (int) sipx->sipx_node[1],
+ (int) sipx->sipx_node[2], (int) sipx->sipx_node[3],
+ (int) sipx->sipx_node[4], (int) sipx->sipx_node[5]);
+ else
+ buff[0] = '\0';
+ return (buff);
}
/* Display a ipx domain address. */
-static char *
-IPX_sprint(struct sockaddr *sap, int numeric)
+static char *IPX_sprint(struct sockaddr *sap, int numeric)
{
- static char buf[64];
+ static char buf[64];
- if (sap->sa_family != AF_IPX)
- return strncpy (buf, _("[NONE SET]"), sizeof (buf));
- return(IPX_print(sap->sa_data));
+ if (sap->sa_family != AF_IPX)
+ return strncpy(buf, _("[NONE SET]"), sizeof(buf));
+ return (IPX_print(sap->sa_data));
}
-static int
-IPX_getsock(char *bufp, struct sockaddr *sap)
+static int IPX_getsock(char *bufp, struct sockaddr *sap)
{
- char *sp = bufp,*bp;
- unsigned int i;
- unsigned char val;
- struct sockaddr_ipx *sipx=(struct sockaddr_ipx *) sap;
-
- sipx->sipx_port = 0;
-
- val = 0;
- bp=(char *)sipx->sipx_node;
- for (i = 0; i < sizeof(sipx->sipx_node); i++) {
+ char *sp = bufp, *bp;
+ unsigned int i;
+ unsigned char val;
+ struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) sap;
+
+ sipx->sipx_port = 0;
+
+ val = 0;
+ bp = (char *) sipx->sipx_node;
+ for (i = 0; i < sizeof(sipx->sipx_node); i++) {
*sp = toupper(*sp);
-
- if ((*sp >= 'A') && (*sp <= 'F'))
- bp[i] |= (int) (*sp - 'A') + 10;
+
+ if ((*sp >= 'A') && (*sp <= 'F'))
+ bp[i] |= (int) (*sp - 'A') + 10;
else if ((*sp >= '0') && (*sp <= '9'))
- bp[i] |= (int) (*sp - '0');
+ bp[i] |= (int) (*sp - '0');
else
- return(-1);
+ return (-1);
bp[i] <<= 4;
sp++;
*sp = toupper(*sp);
-
- if ((*sp >= 'A') && (*sp <= 'F'))
- bp[i] |= (int) (*sp - 'A') + 10;
+
+ if ((*sp >= 'A') && (*sp <= 'F'))
+ bp[i] |= (int) (*sp - 'A') + 10;
else if ((*sp >= '0') && (*sp <= '9'))
- bp[i] |= (int) (*sp - '0');
+ bp[i] |= (int) (*sp - '0');
else
- return(-1);
-
+ return (-1);
+
sp++;
}
if ((memcmp(sipx->sipx_node, "\0\0\0\0\0\0\0\0", IPX_NODE_LEN) == 0) ||
- (memcmp(sipx->sipx_node, "\377\377\377\377\377\377", IPX_NODE_LEN) == 0))
- return(-1);
-
- return(0);
+ (memcmp(sipx->sipx_node, "\377\377\377\377\377\377", IPX_NODE_LEN) == 0))
+ return (-1);
+
+ return (0);
}
-/* XXX define type which makes verbose format checks AF_input*/
+/* XXX define type which makes verbose format checks AF_input */
-static int
-IPX_input(int type, char *bufp, struct sockaddr *sap)
+static int IPX_input(int type, char *bufp, struct sockaddr *sap)
{
- struct sockaddr_ipx *sai=(struct sockaddr_ipx *)sap;
- unsigned long netnum;
- char *ep;
- int nbo;
-
- sai->sipx_family = AF_IPX;
- sai->sipx_network = htonl(0);
- sai->sipx_node[0] = sai->sipx_node[1] = sai->sipx_node[2] =
- sai->sipx_node[3] = sai->sipx_node[4] = sai->sipx_node[5] = '\0';
- sai->sipx_port = 0;
-
- if (type & 4)
- nbo = 1;
- else
- nbo = 0;
-
- type &= 3;
- if (type <= 1) {
- netnum = strtoul(bufp,&ep,16);
+ struct sockaddr_ipx *sai = (struct sockaddr_ipx *) sap;
+ unsigned long netnum;
+ char *ep;
+ int nbo;
+
+ sai->sipx_family = AF_IPX;
+ sai->sipx_network = htonl(0);
+ sai->sipx_node[0] = sai->sipx_node[1] = sai->sipx_node[2] =
+ sai->sipx_node[3] = sai->sipx_node[4] = sai->sipx_node[5] = '\0';
+ sai->sipx_port = 0;
+
+ if (type & 4)
+ nbo = 1;
+ else
+ nbo = 0;
+
+ type &= 3;
+ if (type <= 1) {
+ netnum = strtoul(bufp, &ep, 16);
if ((netnum == 0xffffffffL) || (netnum == 0L))
- return(-1);
+ return (-1);
if (nbo)
- sai->sipx_network = netnum;
+ sai->sipx_network = netnum;
else
- sai->sipx_network = htonl(netnum);
- }
- if (type == 1) {
- if (*ep != '\0')
- return(-2);
- return(0);
- }
- if (type == 0) {
- if (*ep != ':')
- return(-3);
- bufp=ep+1;
- }
- return(IPX_getsock(bufp,sap));
+ sai->sipx_network = htonl(netnum);
+ }
+ if (type == 1) {
+ if (*ep != '\0')
+ return (-2);
+ return (0);
+ }
+ if (type == 0) {
+ if (*ep != ':')
+ return (-3);
+ bufp = ep + 1;
+ }
+ return (IPX_getsock(bufp, sap));
}
-struct aftype ipx_aftype = {
- "ipx", NULL, /*"IPX",*/ AF_IPX, 0,
- IPX_print, IPX_sprint, IPX_input, NULL,
- NULL/*IPX_rprint*/, NULL, NULL,
- -1,
- "/proc/net/ipx"
+struct aftype ipx_aftype =
+{
+ "ipx", NULL, /*"IPX", */ AF_IPX, 0,
+ IPX_print, IPX_sprint, IPX_input, NULL,
+ NULL /*IPX_rprint */ , NULL, NULL,
+ -1,
+ "/proc/net/ipx"
};
#endif
diff --git a/lib/ipx_gr.c b/lib/ipx_gr.c
index 1bacaa2..757720a 100644
--- a/lib/ipx_gr.c
+++ b/lib/ipx_gr.c
@@ -1,9 +1,9 @@
/* support for ap->rresolv missing */
/*
- Modifications:
- 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets,
- snprintf instead of sprintf
-*/
+ Modifications:
+ 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets,
+ snprintf instead of sprintf
+ */
#include "config.h"
@@ -32,54 +32,52 @@
int IPX_rprint(int options)
{
- /* int ext = options & FLAG_EXT; */
- int numeric = options & FLAG_NUM;
- char buff[1024];
- char net[128], router_net[128];
- char router_node[128];
- int num;
- FILE *fp;
- struct aftype *ap;
- struct sockaddr sa;
-
- printf(_("Kernel IPX routing table\n")); /* xxx */
+ /* int ext = options & FLAG_EXT; */
+ int numeric = options & FLAG_NUM;
+ char buff[1024];
+ char net[128], router_net[128];
+ char router_node[128];
+ int num;
+ FILE *fp;
+ struct aftype *ap;
+ struct sockaddr sa;
- if ((ap = get_afntype(AF_IPX)) == NULL) {
- EINTERN("lib/ipx_rt.c","AF_IPX missing");
- return(-1);
- }
+ printf(_("Kernel IPX routing table\n")); /* xxx */
- printf(_("Destination Router Net Router Node\n"));
+ 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) {
+ if ((fp = fopen(_PATH_PROCNET_IPX_ROUTE, "r")) == NULL) {
perror(_PATH_PROCNET_IPX_ROUTE);
- return(-1);
- }
+ return (-1);
+ }
+ fgets(buff, 1023, fp);
+
+ while (fgets(buff, 1023, fp)) {
+ num = sscanf(buff, "%s %s %s", net, router_net, router_node);
+ if (num < 3)
+ continue;
- fgets(buff, 1023, fp);
-
- while (fgets(buff, 1023, fp))
- {
- num = sscanf(buff, "%s %s %s",net,router_net,router_node);
- if (num < 3) continue;
-
/* Fetch and resolve the Destination */
- (void)ap->input(5,net,&sa);
+ (void) ap->input(5, net, &sa);
strcpy(net, ap->sprint(&sa, numeric));
/* Fetch and resolve the Router Net */
- (void)ap->input(5,router_net,&sa);
+ (void) ap->input(5, router_net, &sa);
strcpy(router_net, ap->sprint(&sa, numeric));
/* Fetch and resolve the Router Node */
- (void)ap->input(2,router_node,&sa);
+ (void) ap->input(2, router_node, &sa);
strcpy(router_node, ap->sprint(&sa, numeric));
- printf("%-25s %-25s %-25s\n",net, router_net, router_node);
- }
+ printf("%-25s %-25s %-25s\n", net, router_net, router_node);
+ }
- (void) fclose(fp);
- return(0);
+ (void) fclose(fp);
+ return (0);
}
-#endif /* HAVE_AFIPX */
+#endif /* HAVE_AFIPX */
diff --git a/lib/ipx_sr.c b/lib/ipx_sr.c
index 74fb591..cb3263b 100644
--- a/lib/ipx_sr.c
+++ b/lib/ipx_sr.c
@@ -23,23 +23,14 @@
#include "net-features.h"
-extern struct aftype ipx_aftype;
+extern struct aftype ipx_aftype;
/* static int skfd = -1; */
-/*
-static int usage(void)
-{
- fprintf(stderr,"IPX usage\n");
-
- return(E_USAGE);
-}
-*/
-
int IPX_rinput(int action, int ext, char **args)
{
-
- fprintf(stderr,_("IPX: this needs to be written\n"));
- return(0);
+
+ fprintf(stderr, _("IPX: this needs to be written\n"));
+ return (0);
}
-#endif /* HAVE_AFIPX */
+#endif /* HAVE_AFIPX */
diff --git a/lib/loopback.c b/lib/loopback.c
index 8c9f4c1..a96fd81 100644
--- a/lib/loopback.c
+++ b/lib/loopback.c
@@ -1,19 +1,19 @@
/*
- * lib/loopback.c This file contains the general hardware types.
+ * lib/loopback.c This file contains the general hardware types.
*
- * Version: @(#)loopback.c 1.10 10/07/93
+ * Version: $Id: loopback.c,v 1.3 1998/11/15 20:11:06 freitag Exp $
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
* Modifications:
* 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets
*
- * 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.
+ * 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"
@@ -31,40 +31,40 @@
#include "intl.h"
/* Display an UNSPEC address. */
-static char *
-pr_unspec(unsigned char *ptr)
+static char *pr_unspec(unsigned char *ptr)
{
- static char buff[64];
- char *pos;
- unsigned int i;
+ static char buff[64];
+ char *pos;
+ unsigned int i;
- pos = buff;
- for(i = 0; i < sizeof(struct sockaddr); i++) {
+ pos = buff;
+ for (i = 0; i < sizeof(struct sockaddr); i++) {
pos += sprintf(pos, "%02X-", (*ptr++ & 0377));
- }
- buff[strlen(buff) - 1] = '\0';
- return(buff);
+ }
+ buff[strlen(buff) - 1] = '\0';
+ return (buff);
}
/* Display an UNSPEC socket address. */
-static char *
-pr_sunspec(struct sockaddr *sap)
+static char *pr_sunspec(struct sockaddr *sap)
{
- static char buf[64];
+ static char buf[64];
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return strncpy (buf, _("[NONE SET]"), sizeof (buf));
- return(pr_unspec(sap->sa_data));
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return strncpy(buf, _("[NONE SET]"), sizeof(buf));
+ return (pr_unspec(sap->sa_data));
}
-struct hwtype unspec_hwtype = {
- "unspec", NULL, /*"UNSPEC",*/ -1, 0,
- pr_unspec, pr_sunspec, NULL, NULL
+struct hwtype unspec_hwtype =
+{
+ "unspec", NULL, /*"UNSPEC", */ -1, 0,
+ pr_unspec, pr_sunspec, NULL, NULL
};
-struct hwtype loop_hwtype = {
- "loop", NULL, /*"Local Loopback",*/ 255/*ARPHRD_LOOPBACK*/, 0,
- NULL, NULL, NULL, NULL
+struct hwtype loop_hwtype =
+{
+ "loop", NULL, /*"Local Loopback", */ 255 /*ARPHRD_LOOPBACK */ , 0,
+ NULL, NULL, NULL, NULL
};
diff --git a/lib/masq_info.c b/lib/masq_info.c
index 339ee88..dd61a3a 100644
--- a/lib/masq_info.c
+++ b/lib/masq_info.c
@@ -1,29 +1,29 @@
/*
- * lib/masq_info.c This file contains a the functio masq_info
- * to print a table of current masquerade connections.
+ * lib/masq_info.c This file contains a the functio masq_info
+ * to print a table of current masquerade connections.
*
- * NET-LIB A collection of functions used from the base set of the
- * NET-3 Networking Distribution for the LINUX operating
- * system. (net-tools, net-drivers)
+ * NET-LIB A collection of functions used from the base set of the
+ * NET-3 Networking Distribution for the LINUX operating
+ * system. (net-tools, net-drivers)
*
- * Version: lib/masq_info.c 0.02 (1996-02-18)
+ * Version: $Id: masq_info.c,v 1.3 1998/11/15 20:11:11 freitag Exp $
*
- * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de>
- * Copyright 1999 Bernd Eckenfels, Germany
+ * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de>
+ * Copyright 1999 Bernd Eckenfels, Germany
*
* Modifications:
*
- *960217 {0.01} Bernd Eckenfels: creatin from the code of
- * Jos Vos' ipfwadm 2.0beta1
- *950218 {0.02} Bernd Eckenfels: <linux/if.h> added
+ *960217 {0.01} Bernd Eckenfels: creatin from the code of
+ * Jos Vos' ipfwadm 2.0beta1
+ *950218 {0.02} Bernd Eckenfels: <linux/if.h> added
*
*980405 {0.03} Arnaldo Carvalho: i18n CATGETS -> gettext
*
- * 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.
+ * 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 <sys/types.h>
#include <sys/socket.h>
@@ -52,173 +52,165 @@
struct masq {
- unsigned long expires; /* Expiration timer */
- char * proto; /* Which protocol are we talking? */
- struct sockaddr_in src, dst; /* Source and destination IP addresses */
- unsigned short sport, dport; /* Source and destination ports */
- unsigned short mport; /* Masqueraded port */
- unsigned long initseq; /* Add delta from this seq. on */
- short delta; /* Delta in sequence numbers */
- short pdelta; /* Delta in sequence numbers before last */
+ unsigned long expires; /* Expiration timer */
+ char *proto; /* Which protocol are we talking? */
+ struct sockaddr_in src, dst; /* Source and destination IP addresses */
+ unsigned short sport, dport; /* Source and destination ports */
+ unsigned short mport; /* Masqueraded port */
+ unsigned long initseq; /* Add delta from this seq. on */
+ short delta; /* Delta in sequence numbers */
+ short pdelta; /* Delta in sequence numbers before last */
};
-static struct aftype *ap; /* current address family */
+static struct aftype *ap; /* current address family */
static int has_pdelta;
-static void
-print_masq(struct masq *ms, int numeric, int ext)
+static void print_masq(struct masq *ms, int numeric, int ext)
{
- unsigned long minutes, seconds, sec100s;
-
- printf("%-4s", ms->proto);
-
- sec100s = ms->expires % 100L;
- seconds = (ms->expires / 100L) % 60;
- minutes = ms->expires / 6000L;
-
- printf("%3ld:%02ld.%02ld ", minutes, seconds, sec100s);
-
- if (ext>1) {
- if (has_pdelta)
- printf("%10lu %5hd %5hd ", ms->initseq,
- ms->delta, ms->pdelta);
- else
- printf("%10lu %5hd - ", ms->initseq,
- ms->delta);
- }
- printf("%-20s ", ap->sprint((struct sockaddr *)&(ms->src),numeric));
- printf("%-20s ", ap->sprint((struct sockaddr *)&(ms->dst),numeric));
-
- printf("%s -> ", get_sname(ms->sport, ms->proto, numeric));
- printf("%s", get_sname(ms->dport, ms->proto, numeric));
- printf(" (%s)\n", get_sname(ms->mport, ms->proto, numeric));
+ unsigned long minutes, seconds, sec100s;
+
+ printf("%-4s", ms->proto);
+
+ sec100s = ms->expires % 100L;
+ seconds = (ms->expires / 100L) % 60;
+ minutes = ms->expires / 6000L;
+
+ printf("%3ld:%02ld.%02ld ", minutes, seconds, sec100s);
+
+ if (ext > 1) {
+ if (has_pdelta)
+ printf("%10lu %5hd %5hd ", ms->initseq,
+ ms->delta, ms->pdelta);
+ else
+ printf("%10lu %5hd - ", ms->initseq,
+ ms->delta);
+ }
+ printf("%-20s ", ap->sprint((struct sockaddr *) &(ms->src), numeric));
+ printf("%-20s ", ap->sprint((struct sockaddr *) &(ms->dst), numeric));
+
+ printf("%s -> ", get_sname(ms->sport, ms->proto, numeric));
+ printf("%s", get_sname(ms->dport, ms->proto, numeric));
+ printf(" (%s)\n", get_sname(ms->mport, ms->proto, numeric));
}
-static int
-read_masqinfo(FILE *f, struct masq *mslist, int nmslist)
+static int read_masqinfo(FILE * f, struct masq *mslist, int nmslist)
{
- int n, nread = 0;
- struct masq *ms;
- char buf[256];
-
- for (nread = 0; nread < nmslist; nread++) {
- ms = &mslist[nread];
- if (has_pdelta) {
- if ((n = fscanf(f, " %s %lX:%hX %lX:%hX %hX %lX %hd %hd %lu",
- buf,
- (unsigned long *) &ms->src.sin_addr.s_addr, &ms->sport,
- (unsigned long *) &ms->dst.sin_addr.s_addr, &ms->dport,
- &ms->mport, &ms->initseq, &ms->delta,
- &ms->pdelta, &ms->expires)) == -1)
- return nread;
- } else {
- if ((n = fscanf(f, " %s %lX:%hX %lX:%hX %hX %lX %hd %lu",
- buf,
- (unsigned long *) &ms->src.sin_addr.s_addr, &ms->sport,
- (unsigned long *) &ms->dst.sin_addr.s_addr, &ms->dport,
- &ms->mport, &ms->initseq, &ms->delta,
- &ms->expires)) == -1)
- return nread;
- }
- if ((has_pdelta && (n !=10)) || (!has_pdelta && (n != 9))) {
- EINTERN("masq_info.c", "ip_masquerade format error");
- return(-1);
- }
-
- ms->src.sin_family = AF_INET;
- ms->dst.sin_family = AF_INET;
-
- if (strcmp("TCP", buf) == 0)
- ms->proto = "tcp";
- else if (strcmp("UDP", buf) == 0)
- ms->proto = "udp";
- else {
- EINTERN("masq_info.c", "ip_masquerade unknown type");
- return(-1);
- }
-
- /* we always keep these addresses in network byte order */
- ms->src.sin_addr.s_addr = htonl(ms->src.sin_addr.s_addr);
- ms->dst.sin_addr.s_addr = htonl(ms->dst.sin_addr.s_addr);
- ms->sport = htons(ms->sport);
- ms->dport = htons(ms->dport);
- ms->mport = htons(ms->mport);
+ int n, nread = 0;
+ struct masq *ms;
+ char buf[256];
+
+ for (nread = 0; nread < nmslist; nread++) {
+ ms = &mslist[nread];
+ if (has_pdelta) {
+ if ((n = fscanf(f, " %s %lX:%hX %lX:%hX %hX %lX %hd %hd %lu",
+ buf,
+ (unsigned long *) &ms->src.sin_addr.s_addr, &ms->sport,
+ (unsigned long *) &ms->dst.sin_addr.s_addr, &ms->dport,
+ &ms->mport, &ms->initseq, &ms->delta,
+ &ms->pdelta, &ms->expires)) == -1)
+ return nread;
+ } else {
+ if ((n = fscanf(f, " %s %lX:%hX %lX:%hX %hX %lX %hd %lu",
+ buf,
+ (unsigned long *) &ms->src.sin_addr.s_addr, &ms->sport,
+ (unsigned long *) &ms->dst.sin_addr.s_addr, &ms->dport,
+ &ms->mport, &ms->initseq, &ms->delta,
+ &ms->expires)) == -1)
+ return nread;
+ }
+ if ((has_pdelta && (n != 10)) || (!has_pdelta && (n != 9))) {
+ EINTERN("masq_info.c", "ip_masquerade format error");
+ return (-1);
}
- return nread;
+ ms->src.sin_family = AF_INET;
+ ms->dst.sin_family = AF_INET;
+
+ if (strcmp("TCP", buf) == 0)
+ ms->proto = "tcp";
+ else if (strcmp("UDP", buf) == 0)
+ ms->proto = "udp";
+ else {
+ EINTERN("masq_info.c", "ip_masquerade unknown type");
+ return (-1);
+ }
+
+ /* we always keep these addresses in network byte order */
+ ms->src.sin_addr.s_addr = htonl(ms->src.sin_addr.s_addr);
+ ms->dst.sin_addr.s_addr = htonl(ms->dst.sin_addr.s_addr);
+ ms->sport = htons(ms->sport);
+ ms->dport = htons(ms->dport);
+ ms->mport = htons(ms->mport);
+ }
+ return nread;
}
int ip_masq_info(int numeric, int ext)
{
- FILE *f;
- int i;
- char buf[256];
- struct masq *mslist;
- int ntotal = 0, nread;
-
- if(!(f=fopen(_PATH_PROCNET_IP_MASQ, "r")))
- {
- if (errno != ENOENT) {
- perror(_PATH_PROCNET_IP_MASQ);
- return(-1);
- }
- ESYSNOT("netstat","ip_masquerade");
- return(1);
+ FILE *f;
+ int i;
+ char buf[256];
+ struct masq *mslist;
+ int ntotal = 0, nread;
+
+ if (!(f = fopen(_PATH_PROCNET_IP_MASQ, "r"))) {
+ if (errno != ENOENT) {
+ perror(_PATH_PROCNET_IP_MASQ);
+ return (-1);
}
-
- if ((ap = get_aftype("inet")) == NULL) {
- ENOSUPP("masq_info","AF INET");
- fclose(f);
- return(-1);
- }
-
- fgets(buf, sizeof(buf), f);
- has_pdelta = strstr(buf,"PDelta")?1:0;
-
- mslist = (struct masq *) malloc(16 * sizeof(struct masq));
+ ESYSNOT("netstat", "ip_masquerade");
+ return (1);
+ }
+ if ((ap = get_aftype("inet")) == NULL) {
+ ENOSUPP("masq_info", "AF INET");
+ fclose(f);
+ return (-1);
+ }
+ fgets(buf, sizeof(buf), f);
+ has_pdelta = strstr(buf, "PDelta") ? 1 : 0;
+
+ mslist = (struct masq *) malloc(16 * sizeof(struct masq));
+ if (!mslist) {
+ EINTERN("masq_info", "malloc() failed");
+ fclose(f);
+ return (-1);
+ }
+ while ((nread = read_masqinfo(f, &(mslist[ntotal]), 16)) == 16) {
+ ntotal += nread;
+ mslist = (struct masq *) realloc(mslist,
+ (ntotal + 16) * sizeof(struct masq));
if (!mslist) {
- EINTERN("masq_info","malloc() failed");
- fclose(f);
- return(-1);
+ EINTERN("masq_info", "realloc() failed");
+ fclose(f);
+ return (-1);
}
- while ((nread = read_masqinfo(f, &(mslist[ntotal]), 16)) == 16) {
- ntotal += nread;
- mslist = (struct masq *) realloc(mslist,
- (ntotal + 16) * sizeof(struct masq));
- if (!mslist) {
- EINTERN("masq_info","realloc() failed");
- fclose(f);
- return(-1);
- }
-
+ }
+ fclose(f);
+
+ if (nread < 0) {
+ if (mslist)
+ free(mslist);
+ return (-1);
+ }
+ ntotal += nread;
+
+ if (ntotal > 0) {
+ printf(_("IP masquerading entries\n"));
+ switch (ext) {
+ case 1:
+ printf(_("prot expire source destination ports\n"));
+ break;
+ default:
+ printf(_("prot expire initseq delta prevd source destination ports\n"));
+ break;
}
- fclose(f);
-
- if (nread < 0) {
- if (mslist)
- free(mslist);
- return(-1);
- }
-
- ntotal += nread;
+ for (i = 0; i < ntotal; i++)
+ print_masq(&(mslist[i]), numeric, ext);
+ if (mslist)
+ free(mslist);
- if (ntotal > 0) {
- printf(_("IP masquerading entries\n"));
- switch(ext) {
- case 1:
- printf(_("prot expire source destination ports\n"));
- break;
- default:
- printf(_("prot expire initseq delta prevd source destination ports\n"));
- break;
- }
- for (i = 0; i < ntotal; i++)
- print_masq(&(mslist[i]), numeric, ext);
- if (mslist)
- free(mslist);
-
- }
- return 0;
+ }
+ return 0;
}
#endif
diff --git a/lib/net-features.h b/lib/net-features.h
index b08ee76..3084e8a 100644
--- a/lib/net-features.h
+++ b/lib/net-features.h
@@ -1,302 +1,302 @@
/*
- * lib/net-features.h This file contains the definitions of all kernel
- * dependend features.
+ * lib/net-features.h This file contains the definitions of all kernel
+ * dependend features.
*
- * Version: features.h 0.03 (1996-03-22)
+ * Version: features.h 0.03 (1996-03-22)
*
- * Author: Bernd Eckenfels <net-tools@lina.inka.de>
- * Copyright 1996 Bernd Eckenfels, Germany
+ * Author: Bernd Eckenfels <net-tools@lina.inka.de>
+ * Copyright 1996 Bernd Eckenfels, Germany
*
* Modifications:
- *960201 {0.01} Bernd Eckenfels: creation
- *960202 {0.02} Bernd Eckenfels: HW and AF added
- *960322 {0.03} Bernd Eckenfels: moved into the NET-LIB
+ *960201 {0.01} Bernd Eckenfels: creation
+ *960202 {0.02} Bernd Eckenfels: HW and AF added
+ *960322 {0.03} Bernd Eckenfels: moved into the NET-LIB
*980630 {0.04} Arnaldo Carvalho de Melo: changed NLS for I18N
*
- * 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.
+ * 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.
*/
/*
- * This needs to be included AFTER the KErnel Header Files
- * one of the FEATURE_ should be defined to get the Feature Variable
- * definition included
+ * This needs to be included AFTER the KErnel Header Files
+ * one of the FEATURE_ should be defined to get the Feature Variable
+ * definition included
*/
-
+
#ifndef _NET_FEATURES_H
#define _NET_FEATURES_H
/* detect the present features */
-#if defined (SIOCADDRTOLD) || defined (RTF_IRTT) /* route */
-# define HAVE_NEW_ADDRT 1
+#if defined (SIOCADDRTOLD) || defined (RTF_IRTT) /* route */
+#define HAVE_NEW_ADDRT 1
#endif
-#ifdef RTF_IRTT /* route */
-# define HAVE_RTF_IRTT 1
+#ifdef RTF_IRTT /* route */
+#define HAVE_RTF_IRTT 1
#endif
-#ifdef RTF_REJECT /* route */
-# define HAVE_RTF_REJECT 1
+#ifdef RTF_REJECT /* route */
+#define HAVE_RTF_REJECT 1
#endif
-#ifdef RTMSG_NEWROUTE /* netstat */
-# define HAVE_RT_NETLINK 1
+#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)
-static char *Features=
+static char *Features =
/* ---------------------------------------------------- */
#ifdef FEATURE_ROUTE
-# if HAVE_NEW_ADDRT
- "+"
-# else
- "-"
-# endif
- "NEW_ADDRT "
-
-# if HAVE_RTF_IRTT
- "+"
-# else
- "-"
-# endif
- "RTF_IRTT "
-
-# if HAVE_RTF_REJECT
- "+"
-# else
- "-"
-# endif
- "RTF_REJECT "
-
-#endif /* FEATURE_ROUTE */
+#if HAVE_NEW_ADDRT
+"+"
+#else
+"-"
+#endif
+"NEW_ADDRT "
+
+#if HAVE_RTF_IRTT
+"+"
+#else
+"-"
+#endif
+"RTF_IRTT "
+
+#if HAVE_RTF_REJECT
+"+"
+#else
+"-"
+#endif
+"RTF_REJECT "
+
+#endif /* FEATURE_ROUTE */
/* ---------------------------------------------------- */
/* ---------------------------------------------------- */
#ifdef FEATURE_NETSTAT
-# if HAVE_NEW_ADDRT
- "+"
-# else
- "-"
-# endif
- "NEW_ADDRT "
-
-# if HAVE_RTF_IRTT
- "+"
-# else
- "-"
-# endif
- "RTF_IRTT "
-
-# if HAVE_RTF_REJECT
- "+"
-# else
- "-"
-# endif
- "RTF_REJECT "
-
-# if HAVE_RT_NETLINK
- "+"
-# else
- "-"
-# endif
- "RT_NETLINK "
-
-# if HAVE_FW_MASQUERADE
- "+"
-# else
- "-"
-# endif
- "FW_MASQUERADE "
-
-#endif /* FEATURE_NETSTAT */
+#if HAVE_NEW_ADDRT
+"+"
+#else
+"-"
+#endif
+"NEW_ADDRT "
+
+#if HAVE_RTF_IRTT
+"+"
+#else
+"-"
+#endif
+"RTF_IRTT "
+
+#if HAVE_RTF_REJECT
+"+"
+#else
+"-"
+#endif
+"RTF_REJECT "
+
+#if HAVE_RT_NETLINK
+"+"
+#else
+"-"
+#endif
+"RT_NETLINK "
+
+#if HAVE_FW_MASQUERADE
+"+"
+#else
+"-"
+#endif
+"FW_MASQUERADE "
+
+#endif /* FEATURE_NETSTAT */
/* ---------------------------------------------------- */
#if I18N
- "+I18N"
+"+I18N"
#else
- "-I18N"
-#endif /* I18N */
+"-I18N"
+#endif /* I18N */
"\nAF: "
#ifdef DFLT_AF
- "("DFLT_AF")"
+"(" DFLT_AF ")"
#endif
#if HAVE_AFUNIX
- " +"
+" +"
#else
- " -"
+" -"
#endif
- "UNIX "
+"UNIX "
#if HAVE_AFINET
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "INET "
+"INET "
#if HAVE_AFINET6
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "INET6 "
+"INET6 "
#if HAVE_AFIPX
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "IPX "
+"IPX "
#if HAVE_AFAX25
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "AX25 "
-#if HAVE_AFNETROM
- "+"
+"AX25 "
+#if HAVE_AFNETROM
+"+"
#else
- "-"
+"-"
#endif
- "NETROM "
+"NETROM "
#if HAVE_AFATALK
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "ATALK "
+"ATALK "
#if HAVE_AFECONET
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "ECONET "
+"ECONET "
#if HAVE_AFROSE
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "ROSE "
+"ROSE "
"\nHW: "
#ifdef DFLT_HW
- "("DFLT_HW")"
+"(" DFLT_HW ")"
#endif
#if HAVE_HWETHER
- " +"
+" +"
#else
- " -"
+" -"
#endif
- "ETHER "
+"ETHER "
#if HAVE_HWARC
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "ARC "
+"ARC "
#if HAVE_HWSLIP
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "SLIP "
+"SLIP "
#if HAVE_HWPPP
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "PPP "
+"PPP "
#if HAVE_HWTUNNEL
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "TUNNEL "
+"TUNNEL "
#if HAVE_HWTR
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "TR "
+"TR "
#if HAVE_HWAX25
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "AX25 "
-
+"AX25 "
+
#if HAVE_HWNETROM
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "NETROM "
+"NETROM "
#if HAVE_HWFR
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "FR "
+"FR "
#if HAVE_HWROSE
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "ROSE "
+"ROSE "
#if HAVE_HWASH
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "ASH "
+"ASH "
#if HAVE_HWSIT
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "SIT "
+"SIT "
#if HAVE_HWFDDI
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "FDDI "
+"FDDI "
#if HAVE_HWHIPPI
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "HIPPI "
+"HIPPI "
#if HAVE_HWHDLCLAPB
- "+"
+"+"
#else
- "-"
+"-"
#endif
- "HDLC/LAPB "
+"HDLC/LAPB "
;
-#endif /* FEATURE_* */
+#endif /* FEATURE_* */
-#endif /* _NET_FEATURES_H */
+#endif /* _NET_FEATURES_H */
/* End of features.h */
diff --git a/lib/net-string.c b/lib/net-string.c
deleted file mode 100644
index d1d662b..0000000
--- a/lib/net-string.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/*-
- * This file is part of a file of tcsh-6.05 used for the purpose of
- * string handling. It is given ``as it is'' with its copyright.
- *
- * -----------------------------------------------------------------------
- * Copyright (c) 1980, 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-char *
-strsave(s)
- register const char *s;
-{
- char *n;
- register char *p;
-
- if (s == NULL)
- s = (const char *) "";
- for (p = (char *) s; *p++ != '\0';)
- continue;
- n = p = (char *) malloc((size_t)
- ((((const char *) p) - s) * sizeof(char)));
- while ((*p++ = *s++) != '\0')
- continue;
- return (n);
-}
-
-
-char *str_in_buff (char *buff, int len, char *string)
-{
- if (string)
- {
- if (strlen (string) >= len) /* does not include \0 */
- {
- strncpy (buff, string, len-1);
- buff[len] = '\0';
- }
- else
- strcpy (buff, string);
- }
- else
- buff[0] = '\0';
-
- return (buff);
-}
diff --git a/lib/net-support.h b/lib/net-support.h
index 435d511..ea3ffe5 100644
--- a/lib/net-support.h
+++ b/lib/net-support.h
@@ -1,86 +1,86 @@
/*
- * lib/support.h This file contains the definitions of what is in the
- * support library. Most of all, it defines structures
- * for accessing support modules, and the function proto-
- * types.
+ * lib/support.h This file contains the definitions of what is in the
+ * support library. Most of all, it defines structures
+ * for accessing support modules, and the function proto-
+ * types.
*
- * NET-LIB A collection of functions used from the base set of the
- * NET-3 Networking Distribution for the LINUX operating
- * system. (net-tools, net-drivers)
+ * NET-LIB A collection of functions used from the base set of the
+ * 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.34 (1996-04-13)
*
- * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
+ * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
* Modifications:
- *960125 {1.20} Bernd Eckenfels: reformated, layout
- *960202 {1.30} Bernd Eckenfels: rprint in aftype
- *960206 {1.31} Bernd Eckenfels: route_init
- *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
+ *960125 {1.20} Bernd Eckenfels: reformated, layout
+ *960202 {1.30} Bernd Eckenfels: rprint in aftype
+ *960206 {1.31} Bernd Eckenfels: route_init
+ *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
*
- * 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.
+ * 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 <sys/socket.h>
/* This structure defines protocol families and their handlers. */
struct aftype {
- char *name;
- char *title;
- int af;
- int alen;
- char *(*print) (unsigned char *);
- char *(*sprint) (struct sockaddr *, int numeric);
- int (*input) (int type, char *bufp, struct sockaddr *);
- void (*herror) (char *text);
- int (*rprint) (int options);
- int (*rinput) (int typ, int ext, char **argv);
-
- /* may modify src */
- int (*getmask) (char *src, struct sockaddr *mask, char *name);
-
- int fd;
- char *flag_file;
+ char *name;
+ char *title;
+ int af;
+ int alen;
+ char *(*print) (unsigned char *);
+ char *(*sprint) (struct sockaddr *, int numeric);
+ int (*input) (int type, char *bufp, struct sockaddr *);
+ void (*herror) (char *text);
+ int (*rprint) (int options);
+ int (*rinput) (int typ, int ext, char **argv);
+
+ /* may modify src */
+ int (*getmask) (char *src, struct sockaddr * mask, char *name);
+
+ int fd;
+ char *flag_file;
};
extern struct aftype *aftypes[];
/* This structure defines hardware protocols and their handlers. */
struct hwtype {
- char *name;
- char *title;
- int type;
- int alen;
- char *(*print) (unsigned char *);
- char *(*sprint) (struct sockaddr *);
- int (*input) (char *, struct sockaddr *);
- int (*activate) (int fd);
+ char *name;
+ char *title;
+ int type;
+ int alen;
+ char *(*print) (unsigned char *);
+ char *(*sprint) (struct sockaddr *);
+ int (*input) (char *, struct sockaddr *);
+ int (*activate) (int fd);
};
-extern struct hwtype *get_hwtype(const char *name);
-extern struct hwtype *get_hwntype(int type);
-extern struct aftype *get_aftype(const char *name);
-extern struct aftype *get_afntype(int type);
+extern struct hwtype *get_hwtype(const char *name);
+extern struct hwtype *get_hwntype(int type);
+extern struct aftype *get_aftype(const char *name);
+extern struct aftype *get_afntype(int type);
-extern int getargs(char *string, char *arguments[]);
+extern int getargs(char *string, char *arguments[]);
-extern int get_socket_for_af(int af);
+extern int get_socket_for_af(int af);
-extern void getroute_init(void);
-extern void setroute_init(void);
-extern void activate_init(void);
-extern int route_info(const char *afname, int flags);
-extern int route_edit(int action, const char *afname, int flags, char **argv);
-extern int activate_ld(const char *hwname, int fd);
+extern void getroute_init(void);
+extern void setroute_init(void);
+extern void activate_init(void);
+extern int route_info(const char *afname, int flags);
+extern int route_edit(int action, const char *afname, int flags, char **argv);
+extern int activate_ld(const char *hwname, int fd);
#define RTACTION_ADD 1
#define RTACTION_DEL 2
@@ -88,33 +88,33 @@ extern int activate_ld(const char *hwname, int fd);
#define RTACTION_FLUSH 4
#define RTACTION_SHOW 5
-#define FLAG_EXT 3 /* AND-Mask */
+#define FLAG_EXT 3 /* AND-Mask */
#define FLAG_NUM 4
#define FLAG_SYM 8
#define FLAG_CACHE 16
#define FLAG_FIB 32
#define FLAG_VERBOSE 64
-
-extern int ip_masq_info(int numeric, int ext);
-
-extern int INET_rprint(int options);
-extern int INET6_rprint(int options);
-extern int DDP_rprint(int options);
-extern int IPX_rprint(int options);
-extern int NETROM_rprint(int options);
-extern int AX25_rprint(int options);
-
-extern int INET_rinput(int action, int flags, char **argv);
-extern int INET6_rinput(int action, int flags, char **argv);
-extern int DDP_rinput(int action, int flags, char **argv);
-extern int IPX_rinput(int action, int flags, char **argv);
-extern int NETROM_rinput(int action, int flags, char **argv);
-extern int AX25_rinput(int action, int flags, char **argv);
-
-int aftrans_opt (const char *arg);
-void aftrans_def (char *tool, char *argv0, char *dflt);
-
-char * get_sname(int socknumber, char *proto, int numeric);
+
+extern int ip_masq_info(int numeric, int ext);
+
+extern int INET_rprint(int options);
+extern int INET6_rprint(int options);
+extern int DDP_rprint(int options);
+extern int IPX_rprint(int options);
+extern int NETROM_rprint(int options);
+extern int AX25_rprint(int options);
+
+extern int INET_rinput(int action, int flags, char **argv);
+extern int INET6_rinput(int action, int flags, char **argv);
+extern int DDP_rinput(int action, int flags, char **argv);
+extern int IPX_rinput(int action, int flags, char **argv);
+extern int NETROM_rinput(int action, int flags, char **argv);
+extern int AX25_rinput(int action, int flags, char **argv);
+
+int aftrans_opt(const char *arg);
+void aftrans_def(char *tool, char *argv0, char *dflt);
+
+char *get_sname(int socknumber, char *proto, int numeric);
extern int flag_unx;
extern int flag_ipx;
diff --git a/lib/netrom.c b/lib/netrom.c
index fce7bfe..0f8f957 100644
--- a/lib/netrom.c
+++ b/lib/netrom.c
@@ -1,27 +1,27 @@
/*
- * lib/netrom.c This file contains an implementation of the "NET/ROM"
- * support functions for the NET-2 base distribution.
+ * lib/netrom.c This file contains an implementation of the "NET/ROM"
+ * support functions for the NET-2 base distribution.
*
- * Version: @(#)netrom.c 1.21 07/01/98
+ * Version: $Id: netrom.c,v 1.5 1998/11/15 20:11:25 freitag Exp $
*
- * NOTE: I will redo this module as soon as I got the libax25.a
- * library sorted out. This library contains some useful
- * and often used address conversion functions, database
- * lookup stuff, and more of the like.
+ * NOTE: I will redo this module as soon as I got the libax25.a
+ * library sorted out. This library contains some useful
+ * and often used address conversion functions, database
+ * lookup stuff, and more of the like.
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
* Changes:
* 980701 {1.21} Arnaldo Carvalho de Melo - GNU gettext instead of catgets,
* strncpy instead of strcpy for
- * i18n strings
+ * i18n strings
*
- * 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.
+ * 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"
@@ -51,156 +51,158 @@ static char netrom_errmsg[128];
extern struct aftype netrom_aftype;
-static char *
-NETROM_print(unsigned char *ptr)
+static char *NETROM_print(unsigned char *ptr)
{
- static char buff[8];
- int i;
+ static char buff[8];
+ int i;
- for (i = 0; i < 6; i++) {
+ for (i = 0; i < 6; i++) {
buff[i] = ((ptr[i] & 0377) >> 1);
- if (buff[i] == ' ') buff[i] = '\0';
- }
- buff[6] = '\0';
- i = ((ptr[6] & 0x1E) >> 1);
- if (i != 0) sprintf(&buff[strlen(buff)], "-%d", i);
- return(buff);
+ if (buff[i] == ' ')
+ buff[i] = '\0';
+ }
+ buff[6] = '\0';
+ i = ((ptr[6] & 0x1E) >> 1);
+ if (i != 0)
+ sprintf(&buff[strlen(buff)], "-%d", i);
+ return (buff);
}
/* Display an AX.25 socket address. */
-static char *
-NETROM_sprint(struct sockaddr *sap, int numeric)
+static char *NETROM_sprint(struct sockaddr *sap, int numeric)
{
- char buf[64];
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return strncpy (buf, _("[NONE SET]"), sizeof (buf));
- return(NETROM_print(((struct sockaddr_ax25 *)sap)->sax25_call.ax25_call));
+ char buf[64];
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return strncpy(buf, _("[NONE SET]"), sizeof(buf));
+ return (NETROM_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call));
}
-static int
-NETROM_input(int type, char *bufp, struct sockaddr *sap)
+static int NETROM_input(int type, char *bufp, struct sockaddr *sap)
{
- unsigned char *ptr;
- char *orig, c;
- unsigned int i;
+ unsigned char *ptr;
+ char *orig, c;
+ unsigned int i;
- sap->sa_family = netrom_aftype.af;
- ptr = ((struct sockaddr_ax25 *)sap)->sax25_call.ax25_call;
+ sap->sa_family = netrom_aftype.af;
+ ptr = ((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call;
- /* First, scan and convert the basic callsign. */
- orig = bufp;
- i = 0;
- while((*bufp != '\0') && (*bufp != '-') && (i < 6)) {
+ /* First, scan and convert the basic callsign. */
+ orig = bufp;
+ i = 0;
+ while ((*bufp != '\0') && (*bufp != '-') && (i < 6)) {
c = *bufp++;
- if (islower(c)) c = toupper(c);
- if (! (isupper(c) || isdigit(c))) {
- strncpy(netrom_errmsg, _("Invalid callsign"), sizeof(netrom_errmsg));
+ if (islower(c))
+ c = toupper(c);
+ if (!(isupper(c) || isdigit(c))) {
+ strncpy(netrom_errmsg, _("Invalid callsign"), sizeof(netrom_errmsg));
#ifdef DEBUG
- fprintf(stderr, "netrom_input(%s): %s !\n", netrom_errmsg, orig);
+ fprintf(stderr, "netrom_input(%s): %s !\n", netrom_errmsg, orig);
#endif
- errno = EINVAL;
- return(-1);
+ errno = EINVAL;
+ return (-1);
}
*ptr++ = (unsigned char) ((c << 1) & 0xFE);
i++;
- }
+ }
- /* Callsign too long? */
- if ((i == 6) && (*bufp != '-') && (*bufp != '\0')) {
+ /* Callsign too long? */
+ if ((i == 6) && (*bufp != '-') && (*bufp != '\0')) {
strncpy(netrom_errmsg, _("Callsign too long"), sizeof(netrom_errmsg));
#ifdef DEBUG
fprintf(stderr, "netrom_input(%s): %s !\n", netrom_errmsg, orig);
#endif
errno = E2BIG;
- return(-1);
- }
-
- /* Nope, fill out the address bytes with blanks. */
- while (i++ < sizeof(ax25_address)-1) {
+ return (-1);
+ }
+ /* Nope, fill out the address bytes with blanks. */
+ while (i++ < sizeof(ax25_address) - 1) {
*ptr++ = (unsigned char) ((' ' << 1) & 0xFE);
- }
+ }
- /* See if we need to add an SSID field. */
- if (*bufp == '-') {
+ /* See if we need to add an SSID field. */
+ if (*bufp == '-') {
i = atoi(++bufp);
*ptr = (unsigned char) ((i << 1) & 0xFE);
- } else {
+ } else {
*ptr = (unsigned char) '\0';
- }
+ }
- /* All done. */
+ /* All done. */
#ifdef DEBUG
- fprintf(stderr, "netrom_input(%s): ", orig);
- for (i = 0; i < sizeof(ax25_address); i++)
+ fprintf(stderr, "netrom_input(%s): ", orig);
+ for (i = 0; i < sizeof(ax25_address); i++)
fprintf(stderr, "%02X ", sap->sa_data[i] & 0377);
- fprintf(stderr, "\n");
+ fprintf(stderr, "\n");
#endif
- return(0);
+ return (0);
}
/* Display an error message. */
-static void
-NETROM_herror(char *text)
+static void NETROM_herror(char *text)
{
- if (text == NULL) fprintf(stderr, "%s\n", netrom_errmsg);
- else fprintf(stderr, "%s: %s\n", text, netrom_errmsg);
+ if (text == NULL)
+ fprintf(stderr, "%s\n", netrom_errmsg);
+ else
+ fprintf(stderr, "%s: %s\n", text, netrom_errmsg);
}
-static char *
-NETROM_hprint(struct sockaddr *sap)
+static char *NETROM_hprint(struct sockaddr *sap)
{
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0) return("[NONE SET]");
- return(NETROM_print(((struct sockaddr_ax25 *)sap)->sax25_call.ax25_call));
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return ("[NONE SET]");
+ return (NETROM_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call));
}
-static int
-NETROM_hinput(char *bufp, struct sockaddr *sap)
+static int NETROM_hinput(char *bufp, struct sockaddr *sap)
{
- if (NETROM_input(0, bufp, sap) < 0) return(-1);
- sap->sa_family = ARPHRD_NETROM;
- return(0);
+ if (NETROM_input(0, bufp, sap) < 0)
+ return (-1);
+ sap->sa_family = ARPHRD_NETROM;
+ return (0);
}
#if 0
/* Set the line discipline of a terminal line. */
-static int
-KISS_set_disc(int fd, int disc)
+static int KISS_set_disc(int fd, int disc)
{
- if (ioctl(fd, TIOCSETD, &disc) < 0) {
+ if (ioctl(fd, TIOCSETD, &disc) < 0) {
fprintf(stderr, "KISS_set_disc(%d): %s\n", disc, strerror(errno));
- return(-errno);
- }
- return(0);
+ return (-errno);
+ }
+ return (0);
}
/* Start the KISS encapsulation on the file descriptor. */
-static int
-KISS_init(int fd)
+static int KISS_init(int fd)
{
- if (KISS_set_disc(fd, N_SLIP) < 0) return(-1);
- if (ioctl(fd, SIOCSIFENCAP, 4) <0) return(-1);
- return(0);
+ if (KISS_set_disc(fd, N_SLIP) < 0)
+ return (-1);
+ if (ioctl(fd, SIOCSIFENCAP, 4) < 0)
+ return (-1);
+ return (0);
}
#endif
-struct hwtype netrom_hwtype = {
- "netrom", NULL, /* "AMPR NET/ROM", */ ARPHRD_NETROM, 7,
- NETROM_print, NETROM_hprint, NETROM_hinput, NULL
+struct hwtype netrom_hwtype =
+{
+ "netrom", NULL, /* "AMPR NET/ROM", */ ARPHRD_NETROM, 7,
+ NETROM_print, NETROM_hprint, NETROM_hinput, NULL
};
-struct aftype netrom_aftype = {
- "netrom", NULL, /* "AMPR NET/ROM", */ AF_NETROM, 7,
- NETROM_print, NETROM_sprint, NETROM_input, NETROM_herror,
- NULL, NULL, NULL,
- -1,
- "/proc/net/nr"
+struct aftype netrom_aftype =
+{
+ "netrom", NULL, /* "AMPR NET/ROM", */ AF_NETROM, 7,
+ NETROM_print, NETROM_sprint, NETROM_input, NETROM_herror,
+ NULL, NULL, NULL,
+ -1,
+ "/proc/net/nr"
};
-#endif /* HAVE_AFNETROM */
+#endif /* HAVE_AFNETROM */
diff --git a/lib/netrom_gr.c b/lib/netrom_gr.c
index 9ddf448..1ff8008 100644
--- a/lib/netrom_gr.c
+++ b/lib/netrom_gr.c
@@ -1,22 +1,22 @@
/*
- * lib/netrom_gr.c This file contains an implementation of the NET/ROM
- * route support functions.
+ * lib/netrom_gr.c This file contains an implementation of the NET/ROM
+ * route support functions.
*
- * Version: lib/netrom_gr.c 0.02 (1998-07-01)
+ * Version: $Id: netrom_gr.c,v 1.3 1998/11/15 20:11:29 freitag Exp $
*
- * Author: Bernd Eckenfels, <ecki@lina.inka.de>
- * Copyright 1999 Bernd Eckenfels, Germany
- * base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK>
+ * Author: Bernd Eckenfels, <ecki@lina.inka.de>
+ * Copyright 1999 Bernd Eckenfels, Germany
+ * base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK>
*
* Changes:
* 980701 {0.02} Arnaldo Carvalho de Melo GNU gettext instead of catgets
*
*
- * 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.
+ * 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"
@@ -32,47 +32,43 @@
int NETROM_rprint(int options)
{
- FILE *f1=fopen(_PATH_PROCNET_NR_NODES, "r");
- FILE *f2=fopen(_PATH_PROCNET_NR_NEIGH, "r");
- char buffer[256];
- int qual,n,w;
- /*int ext = options & FLAG_EXT;
- int numeric = options & FLAG_NUM;*/
+ FILE *f1 = fopen(_PATH_PROCNET_NR_NODES, "r");
+ FILE *f2 = fopen(_PATH_PROCNET_NR_NEIGH, "r");
+ char buffer[256];
+ int qual, n, w;
+ /*int ext = options & FLAG_EXT;
+ int numeric = options & FLAG_NUM; */
- if(f1==NULL||f2==NULL)
- {
- printf(_("NET/ROM not configured in this system.\n")); /* xxx */
- return 1;
+ if (f1 == NULL || f2 == NULL) {
+ printf(_("NET/ROM not configured in this system.\n")); /* xxx */
+ return 1;
+ }
+ printf(_("Kernel NET/ROM routing table\n")); /* xxx */
+ printf(_("Destination Mnemonic Quality Neighbour Iface\n")); /* xxx */
+ fgets(buffer, 256, f1);
+ while (fgets(buffer, 256, f1)) {
+ buffer[9] = 0;
+ buffer[17] = 0;
+ w = atoi(buffer + 19) - 1;
+ printf("%-9s %-7s ",
+ buffer, buffer + 10);
+ qual = atoi(buffer + 24 + 15 * w);
+ n = atoi(buffer + 32 + 15 * w);
+ rewind(f2);
+ fgets(buffer, 256, f2);
+ while (fgets(buffer, 256, f2)) {
+ if (atoi(buffer) == n) {
+ buffer[15] = 0;
+ buffer[20] = 0;
+ printf("%3d %-9s %s\n",
+ qual, buffer + 6, buffer + 16);
+ break;
+ }
}
- printf(_("Kernel NET/ROM routing table\n")); /* xxx */
- printf(_("Destination Mnemonic Quality Neighbour Iface\n")); /* xxx */
- fgets(buffer,256,f1);
- while(fgets(buffer,256,f1))
- {
- buffer[9]=0;
- buffer[17]=0;
- w=atoi(buffer+19)-1;
- printf("%-9s %-7s ",
- buffer,buffer+10);
- qual=atoi(buffer+24+15*w);
- n=atoi(buffer+32+15*w);
- rewind(f2);
- fgets(buffer,256,f2);
- while(fgets(buffer,256,f2))
- {
- if(atoi(buffer)==n)
- {
- buffer[15]=0;
- buffer[20]=0;
- printf("%3d %-9s %s\n",
- qual,buffer+6,buffer+16);
- break;
- }
- }
- }
- fclose(f1);
- fclose(f2);
- return 0;
+ }
+ fclose(f1);
+ fclose(f2);
+ return 0;
}
-#endif /* HAVE_AFNETROM */
+#endif /* HAVE_AFNETROM */
diff --git a/lib/netrom_sr.c b/lib/netrom_sr.c
index 7a19abf..b085344 100644
--- a/lib/netrom_sr.c
+++ b/lib/netrom_sr.c
@@ -23,7 +23,7 @@
#include "intl.h"
#include "net-features.h"
-extern struct aftype netrom_aftype;
+extern struct aftype netrom_aftype;
/* static int skfd = -1; */
@@ -31,17 +31,17 @@ extern struct aftype netrom_aftype;
#if 0
static int usage(void)
{
- fprintf(stderr,_("netrom usage\n"));
+ fprintf(stderr, _("netrom usage\n"));
- return(E_USAGE);
+ return (E_USAGE);
}
#endif
int NETROM_rinput(int action, int ext, char **args)
{
-
- fprintf(stderr,_("NET/ROM: this needs to be written\n"));
- return(0);
+
+ fprintf(stderr, _("NET/ROM: this needs to be written\n"));
+ return (0);
}
-#endif /* HAVE_AFNETROM */
+#endif /* HAVE_AFNETROM */
diff --git a/lib/nstrcmp.c b/lib/nstrcmp.c
index e22faf0..8b1ff30 100644
--- a/lib/nstrcmp.c
+++ b/lib/nstrcmp.c
@@ -1,4 +1,5 @@
-/* Copyright 1998 by Andi Kleen. Subject to the GPL. */
+/* Copyright 1998 by Andi Kleen. Subject to the GPL. */
+/* $Id: nstrcmp.c,v 1.2 1998/11/15 20:11:38 freitag Exp $ */
#include <ctype.h>
#include <stdlib.h>
#include "util.h"
@@ -6,26 +7,28 @@
/* like strcmp(), but knows about numbers */
int nstrcmp(const char *astr, const char *b)
{
- const char *a = astr;
+ const char *a = astr;
- while (*a == *b) {
- if (*a == '\0') return 0;
+ while (*a == *b) {
+ if (*a == '\0')
+ return 0;
+ a++;
+ b++;
+ }
+ if (isdigit(*a)) {
+ if (!isdigit(*b))
+ return -1;
+ while (a > astr) {
+ a--;
+ if (!isdigit(*a)) {
a++;
- b++;
+ break;
+ }
+ if (!isdigit(*b))
+ return -1;
+ b--;
}
- if (isdigit(*a)) {
- if (!isdigit(*b)) return -1;
- while (a > astr) {
- a--;
- if (!isdigit(*a)) {
- a++;
- break;
- }
- if (!isdigit(*b)) return -1;
- b--;
- }
- return atoi(a) > atoi(b) ? 1 : -1;
- }
- return *a - *b;
+ return atoi(a) > atoi(b) ? 1 : -1;
+ }
+ return *a - *b;
}
-
diff --git a/lib/pathnames.h b/lib/pathnames.h
index 66842bc..6fbd43a 100644
--- a/lib/pathnames.h
+++ b/lib/pathnames.h
@@ -1,46 +1,47 @@
+
/*
- * lib/pathnames.h This file contains the definitions of the path
- * names used by the NET-LIB.
+ * lib/pathnames.h This file contains the definitions of the path
+ * names used by the NET-LIB.
*
- * NET-LIB
+ * NET-LIB
*
- * Version: lib/pathnames.h 1.37 (1997-08-23)
+ * Version: lib/pathnames.h 1.37 (1997-08-23)
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
*/
/* pathnames of the procfs files used by NET. */
-# define _PATH_PROCNET_TCP "/proc/net/tcp"
-# define _PATH_PROCNET_TCP6 "/proc/net/tcp6"
-# define _PATH_PROCNET_UDP "/proc/net/udp"
-# define _PATH_PROCNET_UDP6 "/proc/net/udp6"
-# define _PATH_PROCNET_RAW "/proc/net/raw"
-# define _PATH_PROCNET_RAW6 "/proc/net/raw6"
-# define _PATH_PROCNET_UNIX "/proc/net/unix"
-# define _PATH_PROCNET_ROUTE "/proc/net/route"
-# define _PATH_PROCNET_ROUTE6 "/proc/net/ipv6_route"
-# define _PATH_PROCNET_RTCACHE "/proc/net/rt_cache"
-# define _PATH_PROCNET_AX25_ROUTE "/proc/net/ax25_route"
-# define _PATH_PROCNET_NR "/proc/net/nr"
-# define _PATH_PROCNET_NR_NEIGH "/proc/net/nr_neigh"
-# define _PATH_PROCNET_NR_NODES "/proc/net/nr_nodes"
-# define _PATH_PROCNET_ARP "/proc/net/arp"
-# define _PATH_PROCNET_AX25 "/proc/net/ax25"
-# define _PATH_PROCNET_IPX "/proc/net/ipx"
-# define _PATH_PROCNET_IPX_ROUTE "/proc/net/ipx_route"
-# define _PATH_PROCNET_ATALK "/proc/net/appletalk"
-# define _PATH_PROCNET_IP_BLK "/proc/net/ip_block"
-# define _PATH_PROCNET_IP_FWD "/proc/net/ip_forward"
-# define _PATH_PROCNET_IP_ACC "/proc/net/ip_acct"
-# define _PATH_PROCNET_IP_MASQ "/proc/net/ip_masquerade"
-# define _PATH_PROCNET_NDISC "/proc/net/ndisc"
-# define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6"
-# 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"
+#define _PATH_PROCNET_TCP "/proc/net/tcp"
+#define _PATH_PROCNET_TCP6 "/proc/net/tcp6"
+#define _PATH_PROCNET_UDP "/proc/net/udp"
+#define _PATH_PROCNET_UDP6 "/proc/net/udp6"
+#define _PATH_PROCNET_RAW "/proc/net/raw"
+#define _PATH_PROCNET_RAW6 "/proc/net/raw6"
+#define _PATH_PROCNET_UNIX "/proc/net/unix"
+#define _PATH_PROCNET_ROUTE "/proc/net/route"
+#define _PATH_PROCNET_ROUTE6 "/proc/net/ipv6_route"
+#define _PATH_PROCNET_RTCACHE "/proc/net/rt_cache"
+#define _PATH_PROCNET_AX25_ROUTE "/proc/net/ax25_route"
+#define _PATH_PROCNET_NR "/proc/net/nr"
+#define _PATH_PROCNET_NR_NEIGH "/proc/net/nr_neigh"
+#define _PATH_PROCNET_NR_NODES "/proc/net/nr_nodes"
+#define _PATH_PROCNET_ARP "/proc/net/arp"
+#define _PATH_PROCNET_AX25 "/proc/net/ax25"
+#define _PATH_PROCNET_IPX "/proc/net/ipx"
+#define _PATH_PROCNET_IPX_ROUTE "/proc/net/ipx_route"
+#define _PATH_PROCNET_ATALK "/proc/net/appletalk"
+#define _PATH_PROCNET_IP_BLK "/proc/net/ip_block"
+#define _PATH_PROCNET_IP_FWD "/proc/net/ip_forward"
+#define _PATH_PROCNET_IP_ACC "/proc/net/ip_acct"
+#define _PATH_PROCNET_IP_MASQ "/proc/net/ip_masquerade"
+#define _PATH_PROCNET_NDISC "/proc/net/ndisc"
+#define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6"
+#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"
+#define _PATH_DEV_ROUTE "/dev/route"
/* End of pathnames.h */
diff --git a/lib/ppp.c b/lib/ppp.c
index 643a8b5..c05d4b7 100644
--- a/lib/ppp.c
+++ b/lib/ppp.c
@@ -1,22 +1,22 @@
/*
- * lib/ppp.c This file contains the SLIP support for the NET-2 base
- * distribution.
+ * lib/ppp.c This file contains the SLIP support for the NET-2 base
+ * distribution.
*
- * Version: @(#)slip.c 1.12 01/07/98
+ * Version: $Id: ppp.c,v 1.3 1998/11/15 20:11:45 freitag Exp $
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
- * Modified by Alan Cox, May 94 to cover NET-3
+ * Modified by Alan Cox, May 94 to cover NET-3
*
* Changes:
* 980701 {1.12} Arnaldo Carvalho de Melo - GNU gettext instead of catgets
*
- * 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.
+ * 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"
@@ -39,20 +39,20 @@
#include "intl.h"
/* Start the PPP encapsulation on the file descriptor. */
-static int
-do_ppp(int fd)
+static int do_ppp(int fd)
{
- fprintf(stderr,_("You cannot start PPP with this program.\n"));
- return -1;
+ fprintf(stderr, _("You cannot start PPP with this program.\n"));
+ return -1;
}
-struct hwtype ppp_hwtype = {
- "ppp", NULL, /*"Point-Point Protocol",*/ ARPHRD_PPP, 0,
- NULL, NULL, NULL, do_ppp
+struct hwtype ppp_hwtype =
+{
+ "ppp", NULL, /*"Point-Point Protocol", */ ARPHRD_PPP, 0,
+ NULL, NULL, NULL, do_ppp
};
-#endif /* HAVE_PPP */
+#endif /* HAVE_PPP */
diff --git a/lib/ppp_ac.c b/lib/ppp_ac.c
index 8e6985f..3b534f9 100644
--- a/lib/ppp_ac.c
+++ b/lib/ppp_ac.c
@@ -1,16 +1,16 @@
/*
- * lib/ppp_ac.c This file contains the activation for the
- * PPP line disciplines, called from activate_ld().
+ * lib/ppp_ac.c This file contains the activation for the
+ * PPP line disciplines, called from activate_ld().
*
- * Version: ppp_ac.c 0.01 (1996-03-22)
+ * Version: $Id: ppp_ac.c,v 1.3 1998/11/15 20:11:50 freitag Exp $
*
- * Author: Bernd 'eckes' Eckenfels
+ * Author: Bernd 'eckes' Eckenfels
*
- * 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.
+ * 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"
@@ -35,8 +35,8 @@
/* Start the VJ-SLIP encapsulation on the file descriptor. */
int PPP_activate(int fd)
{
- fprintf(stderr,_("Sorry, use pppd!\n")); /* FIXME */
- return(-1);
+ fprintf(stderr, _("Sorry, use pppd!\n")); /* FIXME */
+ return (-1);
}
-#endif /* HAVE_HWPPP */
+#endif /* HAVE_HWPPP */
diff --git a/lib/proc.c b/lib/proc.c
index 482deb0..5466029 100644
--- a/lib/proc.c
+++ b/lib/proc.c
@@ -1,46 +1,50 @@
-/* Tolerant /proc file parser. Copyright 1998 Andi Kleen */
+/* Tolerant /proc file parser. Copyright 1998 Andi Kleen */
+/* $Id: proc.c,v 1.3 1998/11/15 20:11:55 freitag Exp $ */
+/* Fixme: cannot currently cope with removed fields */
-#include <string.h>
+#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
-/* Caller must free return string. */
+/* Caller must free return string. */
-char *
-proc_gen_fmt(char *name, int more, FILE *fh, ...)
+char *proc_gen_fmt(char *name, int more, FILE * fh,...)
{
- char buf[512], format[512] = "";
- char *title, *head, *hdr;
- va_list ap;
+ char buf[512], format[512] = "";
+ char *title, *head, *hdr;
+ va_list ap;
- if (!fgets(buf, (sizeof buf)-1, fh))
- return NULL;
- strcat(buf," ");
+ if (!fgets(buf, (sizeof buf) - 1, fh))
+ return NULL;
+ strcat(buf, " ");
- va_start(ap,fh);
- title = va_arg(ap, char *);
- for (hdr = buf; hdr; ) {
- while (isspace(*hdr) || *hdr == '|') hdr++;
- head = hdr;
- hdr = strpbrk(hdr,"| \t\n");
- if (hdr) *hdr++ = 0;
+ va_start(ap, fh);
+ title = va_arg(ap, char *);
+ for (hdr = buf; hdr;) {
+ while (isspace(*hdr) || *hdr == '|')
+ hdr++;
+ head = hdr;
+ hdr = strpbrk(hdr, "| \t\n");
+ if (hdr)
+ *hdr++ = 0;
- if (!strcmp(title, head)) {
- strcat(format, va_arg(ap, char *));
- title = va_arg(ap, char *);
- if (!title || !head) break;
- } else {
- strcat(format, "%*s"); /* XXX */
- }
- strcat(format, " ");
+ if (!strcmp(title, head)) {
+ strcat(format, va_arg(ap, char *));
+ title = va_arg(ap, char *);
+ if (!title || !head)
+ break;
+ } else {
+ strcat(format, "%*s"); /* XXX */
}
- va_end(ap);
+ strcat(format, " ");
+ }
+ va_end(ap);
- if (!more && title) {
- fprintf(stderr, "warning: %s does not contain required field %s\n",
- name, title);
- return NULL;
- }
- return strdup(format);
+ if (!more && title) {
+ fprintf(stderr, "warning: %s does not contain required field %s\n",
+ name, title);
+ return NULL;
+ }
+ return strdup(format);
}
diff --git a/lib/proc.h b/lib/proc.h
index 1139d5c..a9c67c5 100644
--- a/lib/proc.h
+++ b/lib/proc.h
@@ -1,4 +1,4 @@
-/* Generate a suitable scanf format for a column title line */
-char *proc_gen_fmt(char *name, int more, FILE *fh, ...);
+/* Generate a suitable scanf format for a column title line */
+char *proc_gen_fmt(char *name, int more, FILE * fh,...);
diff --git a/lib/rose.c b/lib/rose.c
index 7c6b753..7ae0025 100644
--- a/lib/rose.c
+++ b/lib/rose.c
@@ -1,19 +1,19 @@
/*
- * lib/rose.c This file contains an implementation of the "ROSE"
- * support functions for the NET-2 base distribution.
+ * lib/rose.c This file contains an implementation of the "ROSE"
+ * support functions for the NET-2 base distribution.
*
- * Version: @(#)rose.c 1.00 03/08/97
+ * Version: $Id: rose.c,v 1.5 1998/11/15 20:12:00 freitag Exp $
*
- * Author: Terry Dawson, VK2KTJ, <terry@perf.no.itg.telstra.com.au>
- * based on ax25.c by:
- * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Terry Dawson, VK2KTJ, <terry@perf.no.itg.telstra.com.au>
+ * based on ax25.c by:
+ * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
- * 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.
+ * 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"
@@ -22,7 +22,7 @@
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
-#include <net/if_arp.h> /* ARPHRD_ROSE */
+#include <net/if_arp.h> /* ARPHRD_ROSE */
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
@@ -44,102 +44,102 @@ static char ROSE_errmsg[128];
extern struct aftype rose_aftype;
static char *
-ROSE_print(unsigned char *ptr)
+ ROSE_print(unsigned char *ptr)
{
- static char buff[12];
+ static char buff[12];
- snprintf(buff,sizeof(buff),"%02x%02x%02x%02x%02x",ptr[0],ptr[1],ptr[2],ptr[3],ptr[4]);
- buff[10] = '\0';
- return(buff);
+ snprintf(buff, sizeof(buff), "%02x%02x%02x%02x%02x", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4]);
+ buff[10] = '\0';
+ return (buff);
}
/* Display a ROSE socket address. */
static char *
-ROSE_sprint(struct sockaddr *sap, int numeric)
+ ROSE_sprint(struct sockaddr *sap, int numeric)
{
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return _("[NONE SET]");
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return _("[NONE SET]");
- return(ROSE_print(((struct sockaddr_rose *)sap)->srose_addr.rose_addr));
+ return (ROSE_print(((struct sockaddr_rose *) sap)->srose_addr.rose_addr));
}
-static int
-ROSE_input(int type, char *bufp, struct sockaddr *sap)
+static int ROSE_input(int type, char *bufp, struct sockaddr *sap)
{
- char *ptr;
- int i,o;
+ char *ptr;
+ int i, o;
- sap->sa_family = rose_aftype.af;
- ptr = ((struct sockaddr_rose *)sap)->srose_addr.rose_addr;
+ sap->sa_family = rose_aftype.af;
+ ptr = ((struct sockaddr_rose *) sap)->srose_addr.rose_addr;
- /* Node address the correct length ? */
- if (strlen(bufp)!=10) {
+ /* Node address the correct length ? */
+ if (strlen(bufp) != 10) {
strcpy(ROSE_errmsg, _("Node address must be ten digits"));
#ifdef DEBUG
fprintf(stderr, "rose_input(%s): %s !\n", ROSE_errmsg, orig);
#endif
errno = EINVAL;
- return(-1);
- }
-
- /* Ok, lets set it */
- for (i=0, o=0; i<5; i++) {
- o=i*2;
- ptr[i]=(((bufp[o]-'0')<<4) | (bufp[o+1]-'0'));
- }
-
- /* All done. */
+ return (-1);
+ }
+ /* Ok, lets set it */
+ for (i = 0, o = 0; i < 5; i++) {
+ o = i * 2;
+ ptr[i] = (((bufp[o] - '0') << 4) | (bufp[o + 1] - '0'));
+ }
+
+ /* All done. */
#ifdef DEBUG
- fprintf(stderr, "rose_input(%s): ", orig);
- for (i = 0; i < sizeof(rose_address); i++)
+ fprintf(stderr, "rose_input(%s): ", orig);
+ for (i = 0; i < sizeof(rose_address); i++)
fprintf(stderr, "%02X ", sap->sa_data[i] & 0377);
- fprintf(stderr, "\n");
+ fprintf(stderr, "\n");
#endif
- return(0);
+ return (0);
}
/* Display an error message. */
-static void
-ROSE_herror(char *text)
+static void ROSE_herror(char *text)
{
- if (text == NULL) fprintf(stderr, "%s\n", ROSE_errmsg);
- else fprintf(stderr, "%s: %s\n", text, ROSE_errmsg);
+ if (text == NULL)
+ fprintf(stderr, "%s\n", ROSE_errmsg);
+ else
+ fprintf(stderr, "%s: %s\n", text, ROSE_errmsg);
}
static char *
-ROSE_hprint(struct sockaddr *sap)
+ ROSE_hprint(struct sockaddr *sap)
{
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return _("[NONE SET]");
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return _("[NONE SET]");
- return(ROSE_print(((struct sockaddr_rose *)sap)->srose_addr.rose_addr));
+ return (ROSE_print(((struct sockaddr_rose *) sap)->srose_addr.rose_addr));
}
-static int
-ROSE_hinput(char *bufp, struct sockaddr *sap)
+static int ROSE_hinput(char *bufp, struct sockaddr *sap)
{
- if (ROSE_input(0, bufp, sap) < 0) return(-1);
- sap->sa_family = ARPHRD_ROSE;
- return(0);
+ if (ROSE_input(0, bufp, sap) < 0)
+ return (-1);
+ sap->sa_family = ARPHRD_ROSE;
+ return (0);
}
-struct hwtype rose_hwtype = {
- "rose", NULL, /*"AMPR ROSE",*/ ARPHRD_ROSE, 10,
- ROSE_print, ROSE_hprint, ROSE_hinput, NULL
+struct hwtype rose_hwtype =
+{
+ "rose", NULL, /*"AMPR ROSE", */ ARPHRD_ROSE, 10,
+ ROSE_print, ROSE_hprint, ROSE_hinput, NULL
};
-struct aftype rose_aftype = {
- "rose", NULL, /*"AMPR ROSE",*/ AF_ROSE, 10,
- ROSE_print, ROSE_sprint, ROSE_input, ROSE_herror,
- NULL, NULL, NULL,
- -1,
- "/proc/net/rose"
+struct aftype rose_aftype =
+{
+ "rose", NULL, /*"AMPR ROSE", */ AF_ROSE, 10,
+ ROSE_print, ROSE_sprint, ROSE_input, ROSE_herror,
+ NULL, NULL, NULL,
+ -1,
+ "/proc/net/rose"
};
-#endif /* HAVE_xxROSE */
-
+#endif /* HAVE_xxROSE */
diff --git a/lib/rose_gr.c b/lib/rose_gr.c
index 182c720..e67750b 100644
--- a/lib/rose_gr.c
+++ b/lib/rose_gr.c
@@ -1,20 +1,21 @@
+
/*
- * lib/rose_gr.c This file contains an implementation of the "ROSE"
- * route print support functions.
+ * lib/rose_gr.c This file contains an implementation of the "ROSE"
+ * route print support functions.
*
- * Version: lib/rose_gr.c 1.00 03/08/97
+ * Version: $Id: rose_gr.c,v 1.3 1998/11/15 20:12:03 freitag Exp $
*
- * Author: Terry Dawson, VK2KTJ, <terry@perf.no.itg.telstra.com.au>
- * based on ax25_gr.c by:
- * Bernd Eckenfels, <ecki@lina.inka.de>
- * Copyright 1999 Bernd Eckenfels, Germany
- * base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK>
+ * Author: Terry Dawson, VK2KTJ, <terry@perf.no.itg.telstra.com.au>
+ * based on ax25_gr.c by:
+ * Bernd Eckenfels, <ecki@lina.inka.de>
+ * Copyright 1999 Bernd Eckenfels, Germany
+ * base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK>
*
- * 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.
+ * 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"
@@ -24,7 +25,7 @@
#include <sys/ioctl.h>
#include <linux/rose.h>
#include <sys/socket.h>
-#include <net/if_arp.h> /* ARPHRD_ROSE */
+#include <net/if_arp.h> /* ARPHRD_ROSE */
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@@ -40,28 +41,26 @@
int ROSE_rprint(int options)
{
- FILE *f=fopen(_PATH_PROCNET_ROSE_ROUTE, "r");
- char buffer[256];
- int use;
+ FILE *f = fopen(_PATH_PROCNET_ROSE_ROUTE, "r");
+ char buffer[256];
+ int use;
- if(f==NULL)
- {
- printf(_("ROSE not configured in this system.\n")); /* xxx */
- return 1;
- }
- printf(_("Kernel ROSE routing table\n")); /* xxx */
- printf(_("Destination Iface Use\n")); /* xxx */
- fgets(buffer,256,f);
- while(fgets(buffer,256,f))
- {
- buffer[9]=0;
- buffer[14]=0;
- use=atoi(buffer+15);
- printf("%-9s %-5s %5d\n",
- buffer,buffer+10,use);
- }
- fclose(f);
- return 0;
+ if (f == NULL) {
+ printf(_("ROSE not configured in this system.\n")); /* xxx */
+ return 1;
+ }
+ printf(_("Kernel ROSE routing table\n")); /* xxx */
+ printf(_("Destination Iface Use\n")); /* xxx */
+ fgets(buffer, 256, f);
+ while (fgets(buffer, 256, f)) {
+ buffer[9] = 0;
+ buffer[14] = 0;
+ use = atoi(buffer + 15);
+ printf("%-9s %-5s %5d\n",
+ buffer, buffer + 10, use);
+ }
+ fclose(f);
+ return 0;
}
-#endif /* HAVE_AFROSE */
+#endif /* HAVE_AFROSE */
diff --git a/lib/setroute.c b/lib/setroute.c
index 482f1c1..9a8b9d6 100644
--- a/lib/setroute.c
+++ b/lib/setroute.c
@@ -1,28 +1,28 @@
/*
- * lib/setroute.c This file contains a small interface function to
- * use the AF specific input routine for the routing
- * table.
+ * lib/setroute.c This file contains a small interface function to
+ * use the AF specific input routine for the routing
+ * table.
*
- * NET-LIB A collection of functions used from the base set of the
- * NET-3 Networking Distribution for the LINUX operating
- * system. (net-tools, net-drivers)
+ * NET-LIB A collection of functions used from the base set of the
+ * NET-3 Networking Distribution for the LINUX operating
+ * system. (net-tools, net-drivers)
*
- * Version: lib/setroute.c 0.02 (1996-04-13)
+ * Version: $Id: setroute.c,v 1.3 1998/11/15 20:12:07 freitag Exp $
*
- * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de>
- * Copyright 1999 Bernd Eckenfels, Germany
+ * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de>
+ * Copyright 1999 Bernd Eckenfels, Germany
*
* Modifications:
*
- *960221 {0.01} Bernd Eckenfels: generated from getroute.c
- *960413 {0.02} Bernd Eckenfels: new RTACTION support
+ *960221 {0.01} Bernd Eckenfels: generated from getroute.c
+ *960413 {0.02} Bernd Eckenfels: new RTACTION support
*960809 Frank Strauss: INET6
*
- * 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.
+ * 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 <stdio.h>
#include <string.h>
@@ -32,57 +32,53 @@
#include "config.h"
#include "intl.h"
-extern struct aftype unspec_aftype;
-extern struct aftype unix_aftype;
-extern struct aftype inet_aftype;
-extern struct aftype inet6_aftype;
-extern struct aftype ax25_aftype;
-extern struct aftype netrom_aftype;
-extern struct aftype ipx_aftype;
-extern struct aftype ddp_aftype;
+extern struct aftype unspec_aftype;
+extern struct aftype unix_aftype;
+extern struct aftype inet_aftype;
+extern struct aftype inet6_aftype;
+extern struct aftype ax25_aftype;
+extern struct aftype netrom_aftype;
+extern struct aftype ipx_aftype;
+extern struct aftype ddp_aftype;
-void
-setroute_init(void)
+void setroute_init(void)
{
#if HAVE_AFINET
- inet_aftype.rinput = INET_rinput;
+ inet_aftype.rinput = INET_rinput;
#endif
#if HAVE_AFINET6
- inet6_aftype.rinput = INET6_rinput;
+ inet6_aftype.rinput = INET6_rinput;
#endif
#if HAVE_AFNETROM
- netrom_aftype.rinput = NETROM_rinput;
+ netrom_aftype.rinput = NETROM_rinput;
#endif
#if HAVE_AFIPX
- ipx_aftype.rinput = IPX_rinput;
+ ipx_aftype.rinput = IPX_rinput;
#endif
#if 0
#if HAVE_AFAX25
- ax25_aftype.rinput = AX25_rinput;
+ ax25_aftype.rinput = AX25_rinput;
#endif
#if HAVE_AFATALK
- ddp_aftype.rinput = DDP_rinput;
+ ddp_aftype.rinput = DDP_rinput;
#endif
#endif
}
-int
-route_edit(int action, const char *afname, int options, char **argv)
+int route_edit(int action, const char *afname, int options, char **argv)
{
- struct aftype *ap;
-
- ap = get_aftype(afname);
+ struct aftype *ap;
- if (!ap) {
- fprintf(stderr,_("Address family `%s' not supported.\n"),afname);
- return(E_OPTERR);
- }
+ ap = get_aftype(afname);
- if (!ap->rinput) {
- fprintf(stderr,_("No routing for address family `%s'.\n"),ap->name);
- return(E_OPTERR);
- }
-
- return(ap->rinput(action, options, argv));
+ if (!ap) {
+ fprintf(stderr, _("Address family `%s' not supported.\n"), afname);
+ return (E_OPTERR);
+ }
+ if (!ap->rinput) {
+ fprintf(stderr, _("No routing for address family `%s'.\n"), ap->name);
+ return (E_OPTERR);
+ }
+ return (ap->rinput(action, options, argv));
}
diff --git a/lib/sit.c b/lib/sit.c
index 8db82df..88c3ae2 100644
--- a/lib/sit.c
+++ b/lib/sit.c
@@ -1,18 +1,18 @@
/*
- * lib/sit.c This file contains the SIT HW-type support.
+ * lib/sit.c This file contains the SIT HW-type support.
*
- * Version: sit.c 0.01 (1996-08-08)
+ * Version: $Id: sit.c,v 1.3 1998/11/15 20:12:12 freitag Exp $
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
- * Based on slip.c, modified by Frank Strauss, Aug 1996
+ * Based on slip.c, modified by Frank Strauss, Aug 1996
*
- * 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.
+ * 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"
@@ -33,9 +33,10 @@
#include "net-support.h"
#include "pathnames.h"
-struct hwtype sit_hwtype = {
- "sit", NULL, /*"IPv6-in-IPv4",*/ ARPHRD_SIT, 0,
- NULL, NULL, NULL, NULL
+struct hwtype sit_hwtype =
+{
+ "sit", NULL, /*"IPv6-in-IPv4", */ ARPHRD_SIT, 0,
+ NULL, NULL, NULL, NULL
};
-#endif /* HAVE_HWSIT */
+#endif /* HAVE_HWSIT */
diff --git a/lib/slip.c b/lib/slip.c
index 392ab37..a37ae84 100644
--- a/lib/slip.c
+++ b/lib/slip.c
@@ -1,18 +1,18 @@
/*
- * lib/slip.c This file contains the SLIP HW-type support.
+ * lib/slip.c This file contains the SLIP HW-type support.
*
- * Version: slip.c 1.20 (1996-03-22)
+ * Version: $Id: slip.c,v 1.3 1998/11/15 20:12:16 freitag Exp $
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
- * Modified by Alan Cox, May 94 to cover NET-3
+ * Modified by Alan Cox, May 94 to cover NET-3
*
- * 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.
+ * 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"
@@ -34,24 +34,29 @@
#include "pathnames.h"
-struct hwtype slip_hwtype = {
- "slip", NULL, /*"Serial Line IP",*/ ARPHRD_SLIP, 0,
- NULL, NULL, NULL, NULL
+struct hwtype slip_hwtype =
+{
+ "slip", NULL, /*"Serial Line IP", */ ARPHRD_SLIP, 0,
+ NULL, NULL, NULL, NULL
};
-struct hwtype cslip_hwtype = {
- "cslip", NULL, /*"VJ Serial Line IP",*/ ARPHRD_CSLIP, 0,
- NULL, NULL, NULL, NULL
+struct hwtype cslip_hwtype =
+{
+ "cslip", NULL, /*"VJ Serial Line IP", */ ARPHRD_CSLIP, 0,
+ NULL, NULL, NULL, NULL
};
-struct hwtype slip6_hwtype = {
- "slip6", NULL, /*"6-bit Serial Line IP",*/ ARPHRD_SLIP6, 0,
- NULL, NULL, NULL, NULL
+struct hwtype slip6_hwtype =
+{
+ "slip6", NULL, /*"6-bit Serial Line IP", */ ARPHRD_SLIP6, 0,
+ NULL, NULL, NULL, NULL
};
-struct hwtype cslip6_hwtype = {
- "cslip6", NULL, /*"VJ 6-bit Serial Line IP",*/ ARPHRD_CSLIP6, 0,
- NULL, NULL, NULL, NULL
+struct hwtype cslip6_hwtype =
+{
+ "cslip6", NULL, /*"VJ 6-bit Serial Line IP", */ ARPHRD_CSLIP6, 0,
+ NULL, NULL, NULL, NULL
};
-struct hwtype adaptive_hwtype = {
- "adaptive", NULL, /*"Adaptive Serial Line IP",*/ ARPHRD_ADAPT,0,
- NULL, NULL, NULL, NULL
+struct hwtype adaptive_hwtype =
+{
+ "adaptive", NULL, /*"Adaptive Serial Line IP", */ ARPHRD_ADAPT, 0,
+ NULL, NULL, NULL, NULL
};
-#endif /* HAVE_HWSLIP */
+#endif /* HAVE_HWSLIP */
diff --git a/lib/slip_ac.c b/lib/slip_ac.c
index 2d78efb..c48937b 100644
--- a/lib/slip_ac.c
+++ b/lib/slip_ac.c
@@ -1,20 +1,20 @@
/*
- * lib/slip_ac.c This file contains the activation for the
- * SLIP line disciplines, called from activate_ld().
+ * lib/slip_ac.c This file contains the activation for the
+ * SLIP line disciplines, called from activate_ld().
*
- * Version: slip.c 0.11 (1996-03-22)
+ * Version: $Id: slip_ac.c,v 1.3 1998/11/15 20:12:20 freitag Exp $
*
- * Author: Bernd 'eckes' Eckenfels
- * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Bernd 'eckes' Eckenfels
+ * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
- * Modified by Alan Cox, May 94 to cover NET-3
+ * Modified by Alan Cox, May 94 to cover NET-3
*
- * 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.
+ * 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"
@@ -37,70 +37,78 @@
/* Set the line discipline of a terminal line. */
-static int
-SLIP_set_disc(int fd, int disc)
+static int SLIP_set_disc(int fd, int disc)
{
- if (ioctl(fd, TIOCSETD, &disc) < 0) {
+ if (ioctl(fd, TIOCSETD, &disc) < 0) {
fprintf(stderr, "SLIP_set_disc(%d): %s\n", disc, strerror(errno));
- return(-errno);
- }
- return(0);
+ return (-errno);
+ }
+ return (0);
}
/* Set the encapsulation type of a terminal line. */
-static int
-SLIP_set_encap(int fd, int encap)
+static int SLIP_set_encap(int fd, int encap)
{
- if (ioctl(fd, SIOCSIFENCAP, &encap) < 0) {
+ if (ioctl(fd, SIOCSIFENCAP, &encap) < 0) {
fprintf(stderr, "SLIP_set_encap(%d): %s\n", encap, strerror(errno));
- return(-errno);
- }
- return(0);
+ return (-errno);
+ }
+ return (0);
}
/* Start the SLIP encapsulation on the file descriptor. */
int SLIP_activate(int fd)
{
- if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1);
- if (SLIP_set_encap(fd, 0) < 0) return(-1);
- return(0);
+ if (SLIP_set_disc(fd, N_SLIP) < 0)
+ return (-1);
+ if (SLIP_set_encap(fd, 0) < 0)
+ return (-1);
+ return (0);
}
/* Start the VJ-SLIP encapsulation on the file descriptor. */
int CSLIP_activate(int fd)
{
- if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1);
- if (SLIP_set_encap(fd, 1) < 0) return(-1);
- return(0);
+ if (SLIP_set_disc(fd, N_SLIP) < 0)
+ return (-1);
+ if (SLIP_set_encap(fd, 1) < 0)
+ return (-1);
+ return (0);
}
/* Start the SLIP-6 encapsulation on the file descriptor. */
int SLIP6_activate(int fd)
{
- if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1);
- if (SLIP_set_encap(fd, 2) < 0) return(-1);
- return(0);
+ if (SLIP_set_disc(fd, N_SLIP) < 0)
+ return (-1);
+ if (SLIP_set_encap(fd, 2) < 0)
+ return (-1);
+ return (0);
}
/* Start the VJ-SLIP-6 encapsulation on the file descriptor. */
int CSLIP6_activate(int fd)
{
- if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1);
- if (SLIP_set_encap(fd, 3) < 0) return(-1);
- return(0);
+ if (SLIP_set_disc(fd, N_SLIP) < 0)
+ return (-1);
+ if (SLIP_set_encap(fd, 3) < 0)
+ return (-1);
+ return (0);
}
/* Start adaptive encapsulation on the file descriptor. */
int ADAPTIVE_activate(int fd)
{
- if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1);
- if (SLIP_set_encap(fd, 8) < 0) return(-1);
- return(0);
+ if (SLIP_set_disc(fd, N_SLIP) < 0)
+ return (-1);
+ if (SLIP_set_encap(fd, 8) < 0)
+ return (-1);
+ return (0);
}
-#endif /* HAVE_HWSLIP */
+#endif /* HAVE_HWSLIP */
diff --git a/lib/tr.c b/lib/tr.c
index bdf621a..e7fc55b 100644
--- a/lib/tr.c
+++ b/lib/tr.c
@@ -1,17 +1,17 @@
/*
- * lib/tr.c This file contains an implementation of the "Ethernet"
- * support functions for the NET-2 base distribution.
+ * lib/tr.c This file contains an implementation of the "Tokenring"
+ * support functions.
*
- * Version: @(#)tr.c 1.10 10/07/93
+ * Version: $Id: tr.c,v 1.3 1998/11/15 20:12:25 freitag Exp $
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
- * 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.
+ * 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"
@@ -33,105 +33,105 @@
extern struct hwtype tr_hwtype;
-
-/* Display an Ethernet address in readable format. */
-static char *
-pr_tr(unsigned char *ptr)
+static char *pr_tr(unsigned char *ptr)
{
- static char buff[64];
+ static char buff[64];
- snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X",
- (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
- (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
- );
- return(buff);
+ snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X",
+ (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
+ (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
+ );
+ return (buff);
}
-/* Display an Ethernet socket address. */
-static char *
-pr_str(struct sockaddr *sap)
+static char *pr_str(struct sockaddr *sap)
{
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0) return("[NONE SET]");
- return(pr_tr(sap->sa_data));
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return ("[NONE SET]");
+ return (pr_tr(sap->sa_data));
}
-/* Input an Ethernet address and convert to binary. */
-static int
-in_tr(char *bufp, struct sockaddr *sap)
+static int in_tr(char *bufp, struct sockaddr *sap)
{
- unsigned char *ptr;
- char c, *orig;
- int i, val;
+ unsigned char *ptr;
+ char c, *orig;
+ int i, val;
- sap->sa_family = tr_hwtype.type;
- ptr = sap->sa_data;
+ sap->sa_family = tr_hwtype.type;
+ ptr = sap->sa_data;
- i = 0;
- orig = bufp;
- while((*bufp != '\0') && (i < TR_ALEN)) {
+ i = 0;
+ orig = bufp;
+ while ((*bufp != '\0') && (i < TR_ALEN)) {
val = 0;
c = *bufp++;
- if (isdigit(c)) val = c - '0';
- else if (c >= 'a' && c <= 'f') val = c - 'a' + 10;
- else if (c >= 'A' && c <= 'F') val = c - 'A' + 10;
- else {
+ if (isdigit(c))
+ val = c - '0';
+ else if (c >= 'a' && c <= 'f')
+ val = c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ val = c - 'A' + 10;
+ else {
#ifdef DEBUG
- fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig);
+ fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig);
#endif
- errno = EINVAL;
- return(-1);
+ errno = EINVAL;
+ return (-1);
}
val <<= 4;
c = *bufp++;
- if (isdigit(c)) val |= c - '0';
- else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10;
- else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10;
- else {
+ if (isdigit(c))
+ val |= c - '0';
+ else if (c >= 'a' && c <= 'f')
+ val |= c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ val |= c - 'A' + 10;
+ else {
#ifdef DEBUG
- fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig);
+ fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig);
#endif
- errno = EINVAL;
- return(-1);
+ errno = EINVAL;
+ return (-1);
}
*ptr++ = (unsigned char) (val & 0377);
i++;
/* We might get a semicolon here - not required. */
if (*bufp == ':') {
- if (i == TR_ALEN) {
+ if (i == TR_ALEN) {
#ifdef DEBUG
- fprintf(stderr, _("in_tr(%s): trailing : ignored!\n"),
- orig)
+ fprintf(stderr, _("in_tr(%s): trailing : ignored!\n"),
+ orig)
#endif
- ; /* nothing */
- }
- bufp++;
+ ; /* nothing */
+ }
+ bufp++;
}
- }
+ }
- /* That's it. Any trailing junk? */
- if ((i == TR_ALEN) && (*bufp != '\0')) {
+ /* That's it. Any trailing junk? */
+ if ((i == TR_ALEN) && (*bufp != '\0')) {
#ifdef DEBUG
fprintf(stderr, _("in_tr(%s): trailing junk!\n"), orig);
errno = EINVAL;
- return(-1);
+ return (-1);
#endif
- }
-
+ }
#ifdef DEBUG
- fprintf(stderr, "in_tr(%s): %s\n", orig, pr_tr(sap->sa_data));
+ fprintf(stderr, "in_tr(%s): %s\n", orig, pr_tr(sap->sa_data));
#endif
- return(0);
+ return (0);
}
-struct hwtype tr_hwtype = {
- "tr", "16/4 Mbps TR", ARPHRD_IEEE802, TR_ALEN,
- pr_tr, pr_str, in_tr, NULL
+struct hwtype tr_hwtype =
+{
+ "tr", "16/4 Mbps TR", ARPHRD_IEEE802, TR_ALEN,
+ pr_tr, pr_str, in_tr, NULL
};
-#endif /* HAVE_HWTR */
+#endif /* HAVE_HWTR */
diff --git a/lib/tunnel.c b/lib/tunnel.c
index 4a72d8f..2e8cf4b 100644
--- a/lib/tunnel.c
+++ b/lib/tunnel.c
@@ -1,8 +1,8 @@
/*
- * Tunnel.c, Alan Cox 1995.
+ * Tunnel.c, Alan Cox 1995.
*
*/
-
+
#include "config.h"
#if HAVE_HWTUNNEL
@@ -21,31 +21,29 @@
extern struct hwtype ether_hwtype;
-
-static char *
-pr_tunnel(unsigned char *ptr)
+static char *pr_tunnel(unsigned char *ptr)
{
- return("");
+ return ("");
}
static char *pr_stunnel(struct sockaddr *sap)
{
- return("");
+ return ("");
}
-static int
-in_tunnel(char *bufp, struct sockaddr *sap)
+static int in_tunnel(char *bufp, struct sockaddr *sap)
{
- return(-1);
+ return (-1);
}
-struct hwtype tunnel_hwtype = {
- "tunnel", NULL, /*"IPIP Tunnel",*/ ARPHRD_TUNNEL, 0,
- pr_tunnel, pr_stunnel, in_tunnel, NULL
+struct hwtype tunnel_hwtype =
+{
+ "tunnel", NULL, /*"IPIP Tunnel", */ ARPHRD_TUNNEL, 0,
+ pr_tunnel, pr_stunnel, in_tunnel, NULL
};
-#endif /* HAVE_HWTUNNEL */
+#endif /* HAVE_HWTUNNEL */
diff --git a/lib/unix.c b/lib/unix.c
index 50d3bac..ec138fa 100644
--- a/lib/unix.c
+++ b/lib/unix.c
@@ -1,23 +1,23 @@
/*
- * lib/unix.c This file contains the general hardware types.
+ * lib/unix.c This file contains the general hardware types.
*
- * Version: @(#)unix.c 1.10 10/07/93
+ * Version: $Id: unix.c,v 1.4 1998/11/15 20:12:31 freitag Exp $
*
- * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Copyright 1993 MicroWalt Corporation
+ * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Copyright 1993 MicroWalt Corporation
*
- * 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.
+ * 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"
#include <sys/types.h>
#include <sys/socket.h>
#if HAVE_AFUNIX
-# include <sys/un.h>
+#include <sys/un.h>
#endif
#include <stdlib.h>
#include <stdio.h>
@@ -31,68 +31,66 @@
/* Display an UNSPEC address. */
-static char *
-UNSPEC_print(unsigned char *ptr)
+static char *UNSPEC_print(unsigned char *ptr)
{
- static char buff[64];
- char *pos;
- unsigned int i;
+ static char buff[64];
+ char *pos;
+ unsigned int i;
- pos = buff;
- for(i = 0; i < sizeof(struct sockaddr); i++) {
+ pos = buff;
+ for (i = 0; i < sizeof(struct sockaddr); i++) {
pos += sprintf(pos, "%02X-", (*ptr++ & 0377));
- }
- buff[strlen(buff) - 1] = '\0';
- return(buff);
+ }
+ buff[strlen(buff) - 1] = '\0';
+ return (buff);
}
/* Display an UNSPEC socket address. */
-static char *
-UNSPEC_sprint(struct sockaddr *sap, int numeric)
+static char *UNSPEC_sprint(struct sockaddr *sap, int numeric)
{
- static char buf[64];
+ static char buf[64];
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return strncpy (buf, _("[NONE SET]"), sizeof(buf));
- return(UNSPEC_print(sap->sa_data));
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return strncpy(buf, _("[NONE SET]"), sizeof(buf));
+ return (UNSPEC_print(sap->sa_data));
}
#if HAVE_AFUNIX
/* Display a UNIX domain address. */
-static char *
-UNIX_print(unsigned char *ptr)
+static char *UNIX_print(unsigned char *ptr)
{
- return(ptr);
+ return (ptr);
}
/* Display a UNIX domain address. */
-static char *
-UNIX_sprint(struct sockaddr *sap, int numeric)
+static char *UNIX_sprint(struct sockaddr *sap, int numeric)
{
- static char buf[64];
+ static char buf[64];
- if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
- return strncpy (buf, _("[NONE SET]"), sizeof(buf));
- return(UNIX_print(sap->sa_data));
+ if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
+ return strncpy(buf, _("[NONE SET]"), sizeof(buf));
+ return (UNIX_print(sap->sa_data));
}
-struct aftype unix_aftype = {
- "unix", NULL, /*"UNIX Domain",*/ AF_UNIX, 0,
- UNIX_print, UNIX_sprint, NULL, NULL,
- NULL, NULL, NULL,
- -1,
- "/proc/net/unix"
+struct aftype unix_aftype =
+{
+ "unix", NULL, /*"UNIX Domain", */ AF_UNIX, 0,
+ UNIX_print, UNIX_sprint, NULL, NULL,
+ NULL, NULL, NULL,
+ -1,
+ "/proc/net/unix"
};
-#endif /* HAVE_AFUNIX */
+#endif /* HAVE_AFUNIX */
-struct aftype unspec_aftype = {
- "unspec", NULL, /*"UNSPEC",*/ AF_UNSPEC, 0,
- UNSPEC_print, UNSPEC_sprint, NULL, NULL,
- NULL,
+struct aftype unspec_aftype =
+{
+ "unspec", NULL, /*"UNSPEC", */ AF_UNSPEC, 0,
+ UNSPEC_print, UNSPEC_sprint, NULL, NULL,
+ NULL,
};
diff --git a/lib/util.c b/lib/util.c
index a8236fb..44d6d4e 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -1,38 +1,40 @@
+/* Copyright 1998 by Andi Kleen. Subject to the GPL. */
+/* $Id: util.c,v 1.3 1998/11/15 20:12:35 freitag Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include "util.h"
#include <sys/utsname.h>
static void oom(void)
-{
- fprintf(stderr, "out of virtual memory\n");
- exit(2);
+{
+ fprintf(stderr, "out of virtual memory\n");
+ exit(2);
}
void *xmalloc(size_t sz)
{
- void *p = calloc(sz,1);
- if (!p)
- oom();
- return p;
+ void *p = calloc(sz, 1);
+ if (!p)
+ oom();
+ return p;
}
void *xrealloc(void *oldp, size_t sz)
{
- void *p = realloc(oldp,sz);
- if (!p)
- oom();
- return p;
+ void *p = realloc(oldp, sz);
+ if (!p)
+ oom();
+ return p;
}
int kernel_version(void)
{
- struct utsname uts;
- int major, minor, patch;
+ struct utsname uts;
+ int major, minor, patch;
- if (uname(&uts) < 0)
- return -1;
- if (sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch) != 3)
- return -1;
- return KRELEASE(major,minor,patch);
+ if (uname(&uts) < 0)
+ return -1;
+ if (sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch) != 3)
+ return -1;
+ return KRELEASE(major, minor, patch);
}
diff --git a/lib/util.h b/lib/util.h
index 6ae1fc5..987a9fb 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -1,13 +1,13 @@
#include <stddef.h>
-void *xmalloc(size_t sz);
-void *xrealloc(void *p, size_t sz);
+void *xmalloc(size_t sz);
+void *xrealloc(void *p, size_t sz);
#define new(p) ((p) = xmalloc(sizeof(*(p))))
-
-int kernel_version(void);
-#define KRELEASE(maj,min,patch) ((maj) * 10000 + (min)*1000 + (patch))
+int kernel_version(void);
+#define KRELEASE(maj,min,patch) ((maj) * 10000 + (min)*1000 + (patch))
-int nstrcmp(const char *, const char *);
+
+int nstrcmp(const char *, const char *);
diff --git a/netstat.c b/netstat.c
index f296e79..dbf2eab 100644
--- a/netstat.c
+++ b/netstat.c
@@ -1,57 +1,57 @@
/*
- * netstat This file contains an implementation of the command
- * that helps in debugging the networking modules.
+ * netstat This file contains an implementation of the command
+ * that helps in debugging the networking modules.
*
- * NET-TOOLS A collection of programs that form the base set of the
- * NET-3 Networking Distribution for the LINUX operating
- * system.
+ * NET-TOOLS A collection of programs that form the base set of the
+ * NET-3 Networking Distribution for the LINUX operating
+ * system.
*
- * Version: netstat 1.26 (1998-03-02)
+ * Version: $Id: netstat.c,v 1.9 1998/11/15 20:08:03 freitag Exp $
*
- * Authors: Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de>
- * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * Phil Packer, <pep@wicked.demon.co.uk>
- * Johannes Stille, <johannes@titan.os.open.de>
- * Bernd Eckenfels, <net-tools@lina.inka.de>
- * Phil Blundell <philb@gnu.ai.mit.edu>
+ * Authors: Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de>
+ * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
+ * Phil Packer, <pep@wicked.demon.co.uk>
+ * Johannes Stille, <johannes@titan.os.open.de>
+ * Bernd Eckenfels, <net-tools@lina.inka.de>
+ * Phil Blundell <philb@gnu.ai.mit.edu>
*
* Tuned for NET3 by:
- * Alan Cox, <A.Cox@swansea.ac.uk>
- * Copyright (c) 1993 Fred Baumgarten
+ * Alan Cox, <A.Cox@swansea.ac.uk>
+ * Copyright (c) 1993 Fred Baumgarten
*
* Modified:
*
- *960116 {1.01} Bernd Eckenfels: verbose, cleanups
- *960204 {1.10} Bernd Eckenfels: aftrans, usage, new route_info,
- * DLFT_AF
- *960204 {1.11} Bernd Eckenfels: netlink support
- *960204 {1.12} Bernd Eckenfels: route_init()
- *960215 {1.13} Bernd Eckenfels: netlink_print honors HAVE_
- *960217 {1.14} Bernd Eckenfels: masq_info from Jos Vos and
- * ax25_info from Jonathan Naylor.
- *960218 {1.15} Bernd Eckenfels: ipx_info rewritten, -e for tcp/ipx
- *960220 {1.16} Bernd Eckenfels: minor output reformats, -a for -x
- *960221 {1.17} Bernd Eckenfels: route_init->getroute_init
- *960426 {1.18} Bernd Eckenfels: new RTACTION, SYM/NUM, FIB/CACHE
- *960517 {1.19} Bernd Eckenfels: usage() spelling fix and --unix inode,
- * ':' is part of sock_addr for --inet
+ *960116 {1.01} Bernd Eckenfels: verbose, cleanups
+ *960204 {1.10} Bernd Eckenfels: aftrans, usage, new route_info,
+ * DLFT_AF
+ *960204 {1.11} Bernd Eckenfels: netlink support
+ *960204 {1.12} Bernd Eckenfels: route_init()
+ *960215 {1.13} Bernd Eckenfels: netlink_print honors HAVE_
+ *960217 {1.14} Bernd Eckenfels: masq_info from Jos Vos and
+ * ax25_info from Jonathan Naylor.
+ *960218 {1.15} Bernd Eckenfels: ipx_info rewritten, -e for tcp/ipx
+ *960220 {1.16} Bernd Eckenfels: minor output reformats, -a for -x
+ *960221 {1.17} Bernd Eckenfels: route_init->getroute_init
+ *960426 {1.18} Bernd Eckenfels: new RTACTION, SYM/NUM, FIB/CACHE
+ *960517 {1.19} Bernd Eckenfels: usage() spelling fix and --unix inode,
+ * ':' is part of sock_addr for --inet
*960822 {x.xx} Frank Strauss: INET6 support
*
- *970406 {1.33} Philip Copeland Added snmp reporting support module -s
- * code provided by Andi Kleen
- * (relly needs to be kernel hooked but
- * this will do in the meantime)
- * minor header file misplacement tidy up.
+ *970406 {1.33} Philip Copeland Added snmp reporting support module -s
+ * code provided by Andi Kleen
+ * (relly needs to be kernel hooked but
+ * this will do in the meantime)
+ * 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.
+ * of sprintf for snprintf
+ *10/1998 Andi Kleen Use new interface primitives.
*
- * 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.
+ * 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 <errno.h>
@@ -85,25 +85,23 @@ void parsesnmp(void);
void inittab(void);
typedef enum {
- SS_FREE = 0, /* not allocated */
- SS_UNCONNECTED, /* unconnected to any socket */
- SS_CONNECTING, /* in process of connecting */
- SS_CONNECTED, /* connected to socket */
- SS_DISCONNECTING /* in process of disconnecting */
+ SS_FREE = 0, /* not allocated */
+ SS_UNCONNECTED, /* unconnected to any socket */
+ SS_CONNECTING, /* in process of connecting */
+ SS_CONNECTED, /* connected to socket */
+ SS_DISCONNECTING /* in process of disconnecting */
} socket_state;
-#define SO_ACCEPTCON (1<<16) /* performed a listen */
-#define SO_WAITDATA (1<<17) /* wait data to read */
-#define SO_NOSPACE (1<<18) /* no space to write */
+#define SO_ACCEPTCON (1<<16) /* performed a listen */
+#define SO_WAITDATA (1<<17) /* wait data to read */
+#define SO_NOSPACE (1<<18) /* no space to write */
#define DFLT_AF "inet"
#define FEATURE_NETSTAT
#include "lib/net-features.h"
-char *Release = RELEASE,
- *Version = "netstat 1.34 (1998-06-29)",
- *Signature = "Fred Baumgarten <dc6iq@insu1.etec.uni-karlsruhe.de> and Alan Cox.";
+char *Release = RELEASE, *Version = "netstat 1.34 (1998-06-29)", *Signature = "Fred Baumgarten <dc6iq@insu1.etec.uni-karlsruhe.de> and Alan Cox.";
#define E_READ -1
@@ -118,7 +116,7 @@ int flag_all = 0;
int flag_cnt = 0;
int flag_deb = 0;
int flag_not = 0;
-int flag_cf = 0;
+int flag_cf = 0;
int flag_opt = 0;
int flag_raw = 0;
int flag_tcp = 0;
@@ -171,7 +169,7 @@ FILE *procinfo;
#endif
#define INFO_GUTS3 \
- return(0);
+ return(0);
#define INFO_GUTS6(file,file6,name,proc) \
INFO_GUTS1(file,name,proc) \
@@ -183,148 +181,146 @@ FILE *procinfo;
INFO_GUTS3
#if HAVE_RT_NETLINK && 0
-static int
-netlink_print(void)
+static int netlink_print(void)
{
- int flag;
+ 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);
+ 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 (ret != sizeof(buf)) {
- EINTERN("netstat.c", _("netlink message size mismatch"));
- return(-1);
+ if (flag_ver) {
+ printf(_("Netlink Kernel Messages"));
+ if (flag_cnt)
+ printf(_(" (continous)"));
+ printf("\n");
}
-
- flag=0;
+ 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) {
+ switch (buf.rtmsg_type) {
case RTMSG_NEWROUTE:
- printf("NEWROUTE\t");
- flag=NL_DEV|NL_ADDR|NL_MISC;
- break;
+ 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;
+ printf("DELROUTE\t");
+ flag = NL_DEV | NL_ADDR | NL_MISC;
+ break;
case RTMSG_NEWDEVICE:
- printf("NEWDEVICE\t");
- flag=NL_DEV|NL_MISC;
- break;
+ printf("NEWDEVICE\t");
+ flag = NL_DEV | NL_MISC;
+ break;
case RTMSG_DELDEVICE:
- printf("DELDEVICE\t");
- flag=NL_DEV|NL_MISC;
- break;
+ 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;
+ 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_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_MISC) {
+ printf("0x%x %d ", buf.rtmsg_flags, buf.rtmsg_metric);
}
- if (flag&NL_DEV) {
- printf("%s",buf.rtmsg_device);
+ if (flag & NL_DEV) {
+ printf("%s", buf.rtmsg_device);
}
printf("\n");
- } while(flag_cnt);
- close(fd);
- return(0);
+ } while (flag_cnt);
+ close(fd);
+ return (0);
}
#endif
#if HAVE_AFNETROM
-static const char *netrom_state[]=
+static const char *netrom_state[] =
{
- N_("LISTENING"),
- N_("CONN SENT"),
- N_("DISC SENT"),
- N_("ESTABLISHED")
+ N_("LISTENING"),
+ N_("CONN SENT"),
+ N_("DISC SENT"),
+ N_("ESTABLISHED")
};
static int netrom_info(void)
{
- FILE *f;
- char buffer[256],dev[16];
- int st,vs,vr,sendq,recvq;
-
- f = fopen(_PATH_PROCNET_NR, "r");
- if (f == NULL) {
- if (errno != ENOENT) {
- perror(_PATH_PROCNET_NR);
- return(-1);
+ FILE *f;
+ char buffer[256], dev[16];
+ int st, vs, vr, sendq, recvq;
+
+ f = fopen(_PATH_PROCNET_NR, "r");
+ if (f == NULL) {
+ if (errno != ENOENT) {
+ perror(_PATH_PROCNET_NR);
+ return (-1);
+ }
+ if (flag_arg || flag_ver)
+ ESYSNOT("netstat", "AF NETROM");
+ if (flag_arg)
+ return (1);
+ else
+ return (0);
}
- if (flag_arg || flag_ver)
- ESYSNOT("netstat","AF NETROM");
- if (flag_arg)
- return(1);
- else
- return(0);
- }
-
- printf(_("Activate NET/ROM sockets\n"));
- printf(_("User Dest Source Device State Vr/Vs Send-Q Recv-Q\n"));
- fgets(buffer,256,f);
-
- while (fgets(buffer,256,f)) {
- buffer[9]=0;
- buffer[19]=0;
- buffer[29]=0;
- sscanf(buffer+30,"%s %*d/%*d %*d/%*d %d %d %d %*d %*d/%*d %*d/%*d %*d/%*d %*d %*d %d %d",
- dev,&st,&vs,&vr,&sendq,&recvq);
- printf("%-9s %-9s %-9s %-6s %-11s %02d/%02d %-6d %-6d\n",
- buffer,buffer+10,buffer+20,
- dev,
- _(netrom_state[st]),
- vr,vs,sendq,recvq);
- }
- fclose(f);
- return 0;
+ printf(_("Activate NET/ROM sockets\n"));
+ printf(_("User Dest Source Device State Vr/Vs Send-Q Recv-Q\n"));
+ fgets(buffer, 256, f);
+
+ while (fgets(buffer, 256, f)) {
+ buffer[9] = 0;
+ buffer[19] = 0;
+ buffer[29] = 0;
+ sscanf(buffer + 30, "%s %*d/%*d %*d/%*d %d %d %d %*d %*d/%*d %*d/%*d %*d/%*d %*d %*d %d %d",
+ dev, &st, &vs, &vr, &sendq, &recvq);
+ printf("%-9s %-9s %-9s %-6s %-11s %02d/%02d %-6d %-6d\n",
+ buffer, buffer + 10, buffer + 20,
+ dev,
+ _(netrom_state[st]),
+ vr, vs, sendq, recvq);
+ }
+ fclose(f);
+ return 0;
}
#endif
@@ -332,452 +328,449 @@ static int netrom_info(void)
#if HAVE_AFINET
enum {
- TCP_ESTABLISHED = 1,
- TCP_SYN_SENT,
- TCP_SYN_RECV,
- TCP_FIN_WAIT1,
- TCP_FIN_WAIT2,
- TCP_TIME_WAIT,
- TCP_CLOSE,
- TCP_CLOSE_WAIT,
- TCP_LAST_ACK,
- TCP_LISTEN,
- TCP_CLOSING /* now a valid state */
+ TCP_ESTABLISHED = 1,
+ TCP_SYN_SENT,
+ TCP_SYN_RECV,
+ TCP_FIN_WAIT1,
+ TCP_FIN_WAIT2,
+ TCP_TIME_WAIT,
+ TCP_CLOSE,
+ TCP_CLOSE_WAIT,
+ TCP_LAST_ACK,
+ TCP_LISTEN,
+ TCP_CLOSING /* now a valid state */
};
-static const char *tcp_state[] = {
- "",
- N_("ESTABLISHED"),
- N_("SYN_SENT"),
- N_("SYN_RECV"),
- N_("FIN_WAIT1"),
- N_("FIN_WAIT2"),
- N_("TIME_WAIT"),
- N_("CLOSE"),
- N_("CLOSE_WAIT"),
- N_("LAST_ACK"),
- N_("LISTEN"),
- N_("CLOSING")
+static const char *tcp_state[] =
+{
+ "",
+ N_("ESTABLISHED"),
+ N_("SYN_SENT"),
+ N_("SYN_RECV"),
+ N_("FIN_WAIT1"),
+ N_("FIN_WAIT2"),
+ N_("TIME_WAIT"),
+ N_("CLOSE"),
+ N_("CLOSE_WAIT"),
+ N_("LAST_ACK"),
+ N_("LISTEN"),
+ N_("CLOSING")
};
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];
- struct aftype *ap;
- struct passwd *pw;
+ 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];
+ struct aftype *ap;
+ struct passwd *pw;
#if HAVE_AFINET6
- struct sockaddr_in6 localaddr, remaddr;
- char addr6p[16][3], addr6[128];
- extern struct aftype inet6_aftype;
+ struct sockaddr_in6 localaddr, remaddr;
+ char addr6p[16][3], addr6[128];
+ extern struct aftype inet6_aftype;
#else
- struct sockaddr_in localaddr, remaddr;
+ struct sockaddr_in localaddr, remaddr;
#endif
- if (lnr == 0)
- 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, local_addr, &local_port, rem_addr, &rem_port, &state,
- &txq, &rxq, &timer_run, &time_len, &retr, &uid);
-
- if (strlen(local_addr) > 8) {
-#if HAVE_AFINET6
- /* Demangle what the kernel gives us */
- sscanf(local_addr,
- "%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s",
- addr6p[0], addr6p[1], addr6p[2], addr6p[3],
- addr6p[4], addr6p[5], addr6p[6], addr6p[7],
- addr6p[8], addr6p[9], addr6p[10], addr6p[11],
- addr6p[12], addr6p[13], addr6p[14], addr6p[15]);
- snprintf(addr6, sizeof(addr6), "%s%s:%s%s:%s%s:%s%s:%s%s:%s%s:%s%s:%s%s",
- addr6p[3], addr6p[2], addr6p[1], addr6p[0],
- addr6p[7], addr6p[6], addr6p[5], addr6p[4],
- addr6p[11], addr6p[10], addr6p[9], addr6p[8],
- addr6p[15], addr6p[14], addr6p[13], addr6p[12]);
- inet6_aftype.input(1, addr6, (struct sockaddr *)&localaddr);
- sscanf(rem_addr,
- "%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s",
- addr6p[0], addr6p[1], addr6p[2], addr6p[3],
- addr6p[4], addr6p[5], addr6p[6], addr6p[7],
- addr6p[8], addr6p[9], addr6p[10], addr6p[11],
- addr6p[12], addr6p[13], addr6p[14], addr6p[15]);
- snprintf(addr6, sizeof(addr6), "%s%s:%s%s:%s%s:%s%s:%s%s:%s%s:%s%s:%s%s",
- addr6p[3], addr6p[2], addr6p[1], addr6p[0],
- addr6p[7], addr6p[6], addr6p[5], addr6p[4],
- addr6p[11], addr6p[10], addr6p[9], addr6p[8],
- addr6p[15], addr6p[14], addr6p[13], addr6p[12]);
- inet6_aftype.input(1, addr6, (struct sockaddr *)&remaddr);
- localaddr.sin6_family = AF_INET6;
- remaddr.sin6_family = AF_INET6;
-#endif
- } else {
- sscanf(local_addr, "%X",
- &((struct sockaddr_in *)&localaddr)->sin_addr.s_addr);
- sscanf(rem_addr, "%X",
- &((struct sockaddr_in *)&remaddr)->sin_addr.s_addr);
- ((struct sockaddr *)&localaddr)->sa_family = AF_INET;
- ((struct sockaddr *)&remaddr)->sa_family = AF_INET;
- }
+ if (lnr == 0)
+ return;
- if (num < 11) {
- fprintf(stderr, _("warning, got bogus tcp line.\n"));
- 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, local_addr, &local_port, rem_addr, &rem_port, &state,
+ &txq, &rxq, &timer_run, &time_len, &retr, &uid);
- if ((ap = get_afntype(((struct sockaddr *)&localaddr)->sa_family)) == NULL) {
- fprintf(stderr, _("netstat: unsupported address family %d !\n"),
- ((struct sockaddr *)&localaddr)->sa_family);
- return;
- }
+ if (strlen(local_addr) > 8) {
+#if HAVE_AFINET6
+ /* Demangle what the kernel gives us */
+ sscanf(local_addr,
+ "%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s",
+ addr6p[0], addr6p[1], addr6p[2], addr6p[3],
+ addr6p[4], addr6p[5], addr6p[6], addr6p[7],
+ addr6p[8], addr6p[9], addr6p[10], addr6p[11],
+ addr6p[12], addr6p[13], addr6p[14], addr6p[15]);
+ snprintf(addr6, sizeof(addr6), "%s%s:%s%s:%s%s:%s%s:%s%s:%s%s:%s%s:%s%s",
+ addr6p[3], addr6p[2], addr6p[1], addr6p[0],
+ addr6p[7], addr6p[6], addr6p[5], addr6p[4],
+ addr6p[11], addr6p[10], addr6p[9], addr6p[8],
+ addr6p[15], addr6p[14], addr6p[13], addr6p[12]);
+ inet6_aftype.input(1, addr6, (struct sockaddr *) &localaddr);
+ sscanf(rem_addr,
+ "%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s%2s",
+ addr6p[0], addr6p[1], addr6p[2], addr6p[3],
+ addr6p[4], addr6p[5], addr6p[6], addr6p[7],
+ addr6p[8], addr6p[9], addr6p[10], addr6p[11],
+ addr6p[12], addr6p[13], addr6p[14], addr6p[15]);
+ snprintf(addr6, sizeof(addr6), "%s%s:%s%s:%s%s:%s%s:%s%s:%s%s:%s%s:%s%s",
+ addr6p[3], addr6p[2], addr6p[1], addr6p[0],
+ addr6p[7], addr6p[6], addr6p[5], addr6p[4],
+ addr6p[11], addr6p[10], addr6p[9], addr6p[8],
+ addr6p[15], addr6p[14], addr6p[13], addr6p[12]);
+ inet6_aftype.input(1, addr6, (struct sockaddr *) &remaddr);
+ localaddr.sin6_family = AF_INET6;
+ remaddr.sin6_family = AF_INET6;
+#endif
+ } else {
+ sscanf(local_addr, "%X",
+ &((struct sockaddr_in *) &localaddr)->sin_addr.s_addr);
+ sscanf(rem_addr, "%X",
+ &((struct sockaddr_in *) &remaddr)->sin_addr.s_addr);
+ ((struct sockaddr *) &localaddr)->sa_family = AF_INET;
+ ((struct sockaddr *) &remaddr)->sa_family = AF_INET;
+ }
- if (state == TCP_LISTEN) {
- time_len = 0;
- retr = 0L;
- rxq=0L;
- txq=0L;
- }
-
- 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) {
- snprintf(buffer, sizeof (buffer), "%s", get_sname(htons(local_port), "tcp", 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), "tcp", flag_not));
-
- if ((strlen(rem_addr) + strlen(buffer)) > 22)
- rem_addr[22-strlen(buffer)] = '\0';
-
- strcat(rem_addr, ":");
- strcat(rem_addr, buffer);
- timers[0] = '\0';
-
- if (flag_opt)
- switch (timer_run) {
- case 0:
- snprintf(timers, sizeof(timers), _("off (0.00/%ld)"), retr);
- break;
-
- case 1:
- snprintf(timers, sizeof(timers), _("on (%2.2f/%ld)"),
- (double)time_len / 100, retr);
- break;
-
- default:
- snprintf(timers, sizeof(timers), _("unkn-%d (%2.2f/%ld)"),
- timer_run, (double)time_len / 100, retr);
- break;
- }
- printf("tcp %6ld %6ld %-23s %-23s %-12s",
- rxq, txq, local_addr, rem_addr, _(tcp_state[state]));
-
- if (flag_exp > 1) {
- if (!flag_not && ((pw = getpwuid(uid)) != NULL))
- printf("%-10s ", pw->pw_name);
- else
- printf("%-10d ", uid);
+ if (num < 11) {
+ fprintf(stderr, _("warning, got bogus tcp line.\n"));
+ return;
+ }
+ if ((ap = get_afntype(((struct sockaddr *) &localaddr)->sa_family)) == NULL) {
+ fprintf(stderr, _("netstat: unsupported address family %d !\n"),
+ ((struct sockaddr *) &localaddr)->sa_family);
+ return;
+ }
+ if (state == TCP_LISTEN) {
+ time_len = 0;
+ retr = 0L;
+ rxq = 0L;
+ txq = 0L;
+ }
+ 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) {
+ snprintf(buffer, sizeof(buffer), "%s", get_sname(htons(local_port), "tcp", 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), "tcp", flag_not));
+
+ if ((strlen(rem_addr) + strlen(buffer)) > 22)
+ rem_addr[22 - strlen(buffer)] = '\0';
+
+ strcat(rem_addr, ":");
+ strcat(rem_addr, buffer);
+ timers[0] = '\0';
+
+ if (flag_opt)
+ switch (timer_run) {
+ case 0:
+ snprintf(timers, sizeof(timers), _("off (0.00/%ld)"), retr);
+ break;
+
+ case 1:
+ snprintf(timers, sizeof(timers), _("on (%2.2f/%ld)"),
+ (double) time_len / 100, retr);
+ break;
+
+ default:
+ snprintf(timers, sizeof(timers), _("unkn-%d (%2.2f/%ld)"),
+ timer_run, (double) time_len / 100, retr);
+ break;
+ }
+ printf("tcp %6ld %6ld %-23s %-23s %-12s",
+ rxq, txq, local_addr, rem_addr, _(tcp_state[state]));
+
+ if (flag_exp > 1) {
+ if (!flag_not && ((pw = getpwuid(uid)) != NULL))
+ printf("%-10s ", pw->pw_name);
+ else
+ printf("%-10d ", uid);
+ }
+ if (flag_opt)
+ printf("%s", timers);
+ printf("\n");
}
-
- if (flag_opt) printf("%s", timers);
- printf("\n");
- }
}
-static int
-tcp_info(void)
+static int tcp_info(void)
{
- INFO_GUTS6(_PATH_PROCNET_TCP, _PATH_PROCNET_TCP6, "AF INET (tcp)",
- tcp_do_one);
+ INFO_GUTS6(_PATH_PROCNET_TCP, _PATH_PROCNET_TCP6, "AF INET (tcp)",
+ tcp_do_one);
}
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 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;
#if HAVE_AFINET6
- struct sockaddr_in6 localaddr, remaddr;
- char addr6p[8][5];
- char addr6[128];
- extern struct aftype inet6_aftype;
+ struct sockaddr_in6 localaddr, remaddr;
+ char addr6p[8][5];
+ char addr6[128];
+ extern struct aftype inet6_aftype;
#else
- struct sockaddr_in localaddr, remaddr;
+ struct sockaddr_in localaddr, remaddr;
#endif
- struct aftype *ap;
- unsigned long rxq, txq, time_len, retr;
-
- 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, local_addr, &local_port,
- rem_addr, &rem_port, &state,
- &txq, &rxq, &timer_run, &time_len, &retr, &timer_queued, more);
-
- if (strlen(local_addr) > 8) {
+ struct aftype *ap;
+ unsigned long rxq, txq, time_len, retr;
+
+ 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, local_addr, &local_port,
+ rem_addr, &rem_port, &state,
+ &txq, &rxq, &timer_run, &time_len, &retr, &timer_queued, more);
+
+ if (strlen(local_addr) > 8) {
#if HAVE_AFINET6
- sscanf(local_addr, "%4s%4s%4s%4s%4s%4s%4s%4s",
- addr6p[0], addr6p[1], addr6p[2], addr6p[3],
- addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
- snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
- addr6p[0], addr6p[1], addr6p[2], addr6p[3],
- addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
- inet6_aftype.input(1, addr6, (struct sockaddr *)&localaddr);
- sscanf(rem_addr, "%4s%4s%4s%4s%4s%4s%4s%4s",
- addr6p[0], addr6p[1], addr6p[2], addr6p[3],
- addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
- snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
- addr6p[0], addr6p[1], addr6p[2], addr6p[3],
- addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
- inet6_aftype.input(1, addr6, (struct sockaddr *)&remaddr);
- localaddr.sin6_family = AF_INET6;
- remaddr.sin6_family = AF_INET6;
+ sscanf(local_addr, "%4s%4s%4s%4s%4s%4s%4s%4s",
+ addr6p[0], addr6p[1], addr6p[2], addr6p[3],
+ addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
+ snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
+ addr6p[0], addr6p[1], addr6p[2], addr6p[3],
+ addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
+ inet6_aftype.input(1, addr6, (struct sockaddr *) &localaddr);
+ sscanf(rem_addr, "%4s%4s%4s%4s%4s%4s%4s%4s",
+ addr6p[0], addr6p[1], addr6p[2], addr6p[3],
+ addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
+ snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
+ addr6p[0], addr6p[1], addr6p[2], addr6p[3],
+ addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
+ inet6_aftype.input(1, addr6, (struct sockaddr *) &remaddr);
+ localaddr.sin6_family = AF_INET6;
+ remaddr.sin6_family = AF_INET6;
#endif
- } else {
- sscanf(local_addr, "%X",
- &((struct sockaddr_in *)&localaddr)->sin_addr.s_addr);
- sscanf(rem_addr, "%X",
- &((struct sockaddr_in *)&remaddr)->sin_addr.s_addr);
- ((struct sockaddr *)&localaddr)->sa_family = AF_INET;
- ((struct sockaddr *)&remaddr)->sa_family = AF_INET;
- }
+ } else {
+ sscanf(local_addr, "%X",
+ &((struct sockaddr_in *) &localaddr)->sin_addr.s_addr);
+ sscanf(rem_addr, "%X",
+ &((struct sockaddr_in *) &remaddr)->sin_addr.s_addr);
+ ((struct sockaddr *) &localaddr)->sa_family = AF_INET;
+ ((struct sockaddr *) &remaddr)->sa_family = AF_INET;
+ }
- retr = 0L;
- if (!flag_opt)
- more[0] = '\0';
-
- if (num < 10) {
- fprintf(stderr, _("warning, got bogus udp line.\n"));
- return;
- }
-
- if ((ap = get_afntype(((struct sockaddr *)&localaddr)->sa_family)) == NULL) {
- fprintf(stderr, _("netstat: unsupported address family %d !\n"),
- ((struct sockaddr *)&localaddr)->sa_family);
- return;
- }
-
- switch (state) {
- case TCP_ESTABLISHED:
- udp_state = _("ESTABLISHED");
- break;
-
- case TCP_CLOSE:
- udp_state = "";
- break;
-
- default:
- udp_state = _("UNKNOWN");
- break;
- }
-
- strcpy(local_addr, ap->sprint((struct sockaddr *)&localaddr, flag_not));
- strcpy(rem_addr, ap->sprint((struct sockaddr *)&remaddr, flag_not));
+ retr = 0L;
+ if (!flag_opt)
+ more[0] = '\0';
+
+ if (num < 10) {
+ fprintf(stderr, _("warning, got bogus udp line.\n"));
+ return;
+ }
+ if ((ap = get_afntype(((struct sockaddr *) &localaddr)->sa_family)) == NULL) {
+ fprintf(stderr, _("netstat: unsupported address family %d !\n"),
+ ((struct sockaddr *) &localaddr)->sa_family);
+ return;
+ }
+ switch (state) {
+ case TCP_ESTABLISHED:
+ udp_state = _("ESTABLISHED");
+ break;
+
+ case TCP_CLOSE:
+ udp_state = "";
+ break;
+
+ default:
+ udp_state = _("UNKNOWN");
+ 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))
+ 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)
+ if (flag_all || localaddr.sin_addr.s_addr)
#endif
- {
- 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));
- if ((strlen(rem_addr) + strlen(buffer)) > 22)
- rem_addr[22-strlen(buffer)] = '\0';
-
- strcat(rem_addr, ":");
- strcat(rem_addr, buffer);
-
- timers[0] = '\0';
- if (flag_opt) switch (timer_run) {
- case 0:
- snprintf(timers, sizeof(timers), _("off (0.00/%ld) %c"), retr, timer_queued);
- break;
-
- case 1:
- snprintf(timers, sizeof(timers), _("on (%2.2f/%ld) %c"), (double)time_len / 100, retr, timer_queued);
- break;
-
- default:
- snprintf(timers, sizeof(timers), _("unkn-%d (%2.2f/%ld) %c"), timer_run, (double)time_len / 100,
- retr, timer_queued);
- break;
+ {
+ 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));
+ if ((strlen(rem_addr) + strlen(buffer)) > 22)
+ rem_addr[22 - strlen(buffer)] = '\0';
+
+ strcat(rem_addr, ":");
+ strcat(rem_addr, buffer);
+
+ timers[0] = '\0';
+ if (flag_opt)
+ switch (timer_run) {
+ case 0:
+ snprintf(timers, sizeof(timers), _("off (0.00/%ld) %c"), retr, timer_queued);
+ break;
+
+ case 1:
+ snprintf(timers, sizeof(timers), _("on (%2.2f/%ld) %c"), (double) time_len / 100, retr, timer_queued);
+ break;
+
+ default:
+ snprintf(timers, sizeof(timers), _("unkn-%d (%2.2f/%ld) %c"), timer_run, (double) time_len / 100,
+ retr, timer_queued);
+ break;
+ }
+ printf("udp %6ld %6ld %-23s %-23s %-12s",
+ rxq, txq, local_addr, rem_addr, udp_state);
+
+ if (flag_exp > 1)
+ printf("%-10s ", "");
+
+ if (flag_opt)
+ printf("%s", timers);
+ printf("\n");
}
- printf("udp %6ld %6ld %-23s %-23s %-12s",
- rxq, txq, local_addr, rem_addr, udp_state);
-
- if (flag_exp > 1)
- printf("%-10s ", "");
-
- if (flag_opt) printf("%s", timers);
- printf("\n");
- }
-}
+}
-static int
-udp_info(void)
+static int udp_info(void)
{
- INFO_GUTS6(_PATH_PROCNET_UDP, _PATH_PROCNET_UDP6, "AF INET (udp)",
- udp_do_one);
+ INFO_GUTS6(_PATH_PROCNET_UDP, _PATH_PROCNET_UDP6, "AF INET (udp)",
+ udp_do_one);
}
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 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;
#if HAVE_AFINET6
- struct sockaddr_in6 localaddr, remaddr;
- char addr6p[8][5];
- char addr6[128];
- extern struct aftype inet6_aftype;
+ struct sockaddr_in6 localaddr, remaddr;
+ char addr6p[8][5];
+ char addr6[128];
+ extern struct aftype inet6_aftype;
#else
- struct sockaddr_in localaddr, remaddr;
+ struct sockaddr_in localaddr, remaddr;
#endif
- struct aftype *ap;
- unsigned long rxq, txq, time_len, retr;
-
- 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, local_addr, &local_port, rem_addr, &rem_port, &state,
- &txq, &rxq, &timer_run, &time_len, &retr, &timer_queued, more);
-
- if (strlen(local_addr) > 8) {
+ struct aftype *ap;
+ unsigned long rxq, txq, time_len, retr;
+
+ 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, local_addr, &local_port, rem_addr, &rem_port, &state,
+ &txq, &rxq, &timer_run, &time_len, &retr, &timer_queued, more);
+
+ if (strlen(local_addr) > 8) {
#if HAVE_AFINET6
- sscanf(local_addr, "%4s%4s%4s%4s%4s%4s%4s%4s",
- addr6p[0], addr6p[1], addr6p[2], addr6p[3],
- addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
- snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
- addr6p[0], addr6p[1], addr6p[2], addr6p[3],
- addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
- inet6_aftype.input(1, addr6, (struct sockaddr *)&localaddr);
- sscanf(rem_addr, "%4s%4s%4s%4s%4s%4s%4s%4s",
- addr6p[0], addr6p[1], addr6p[2], addr6p[3],
- addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
- snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
- addr6p[0], addr6p[1], addr6p[2], addr6p[3],
- addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
- inet6_aftype.input(1, addr6, (struct sockaddr *)&remaddr);
- localaddr.sin6_family = AF_INET6;
- remaddr.sin6_family = AF_INET6;
+ sscanf(local_addr, "%4s%4s%4s%4s%4s%4s%4s%4s",
+ addr6p[0], addr6p[1], addr6p[2], addr6p[3],
+ addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
+ snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
+ addr6p[0], addr6p[1], addr6p[2], addr6p[3],
+ addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
+ inet6_aftype.input(1, addr6, (struct sockaddr *) &localaddr);
+ sscanf(rem_addr, "%4s%4s%4s%4s%4s%4s%4s%4s",
+ addr6p[0], addr6p[1], addr6p[2], addr6p[3],
+ addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
+ snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
+ addr6p[0], addr6p[1], addr6p[2], addr6p[3],
+ addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
+ inet6_aftype.input(1, addr6, (struct sockaddr *) &remaddr);
+ localaddr.sin6_family = AF_INET6;
+ remaddr.sin6_family = AF_INET6;
#endif
- } else {
- sscanf(local_addr, "%X",
- &((struct sockaddr_in *)&localaddr)->sin_addr.s_addr);
- sscanf(rem_addr, "%X",
- &((struct sockaddr_in *)&remaddr)->sin_addr.s_addr);
- ((struct sockaddr *)&localaddr)->sa_family = AF_INET;
- ((struct sockaddr *)&remaddr)->sa_family = AF_INET;
- }
+ } else {
+ sscanf(local_addr, "%X",
+ &((struct sockaddr_in *) &localaddr)->sin_addr.s_addr);
+ sscanf(rem_addr, "%X",
+ &((struct sockaddr_in *) &remaddr)->sin_addr.s_addr);
+ ((struct sockaddr *) &localaddr)->sa_family = AF_INET;
+ ((struct sockaddr *) &remaddr)->sa_family = AF_INET;
+ }
#if HAVE_AFINET6
- if ((ap = get_afntype(localaddr.sin6_family)) == NULL) {
- fprintf(stderr, _("netstat: unsupported address family %d !\n"), localaddr.sin6_family);
- return;
- }
+ if ((ap = get_afntype(localaddr.sin6_family)) == NULL) {
+ fprintf(stderr, _("netstat: unsupported address family %d !\n"), localaddr.sin6_family);
+ return;
+ }
#else
- if ((ap = get_afntype(localaddr.sin_family)) == NULL) {
- fprintf(stderr, _("netstat: unsupported address family %d !\n"), localaddr.sin_family);
- return;
- }
-#endif
-
- if (!flag_opt)
- more[0] = '\0';
+ if ((ap = get_afntype(localaddr.sin_family)) == NULL) {
+ fprintf(stderr, _("netstat: unsupported address family %d !\n"), localaddr.sin_family);
+ return;
+ }
+#endif
- if (num < 10) {
- fprintf(stderr, _("warning, got bogus raw line.\n"));
- return;
- }
+ if (!flag_opt)
+ more[0] = '\0';
- raw_state = "";
- strcpy(local_addr, ap->sprint((struct sockaddr *)&localaddr, flag_not));
- strcpy(rem_addr, ap->sprint((struct sockaddr *)&remaddr, flag_not));
+ if (num < 10) {
+ 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))
+ 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)
+ if (flag_all || localaddr.sin_addr.s_addr)
#endif
- {
- snprintf(buffer, sizeof(buffer), "%s", get_sname(htons(local_port), "raw", 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));
- if ((strlen(rem_addr) + strlen(buffer)) > 22)
- rem_addr[22-strlen(buffer)] = '\0';
-
- strcat(rem_addr, ":");
- strcat(rem_addr, buffer);
-
- timers[0] = '\0';
- if (flag_opt) switch (timer_run) {
- case 0:
- snprintf(timers, sizeof(timers), _("off (0.00/%ld) %c"), retr, timer_queued);
- break;
-
- case 1:
- snprintf(timers, sizeof(timers), _("on (%2.2f/%ld) %c"), (double)time_len / 100,
- retr, timer_queued);
- break;
-
- default:
- snprintf(timers, sizeof(timers), _("unkn-%d (%2.2f/%ld) %c"),
- timer_run, (double)time_len / 100,
- retr, timer_queued);
- break;
+ {
+ snprintf(buffer, sizeof(buffer), "%s", get_sname(htons(local_port), "raw", 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));
+ if ((strlen(rem_addr) + strlen(buffer)) > 22)
+ rem_addr[22 - strlen(buffer)] = '\0';
+
+ strcat(rem_addr, ":");
+ strcat(rem_addr, buffer);
+
+ timers[0] = '\0';
+ if (flag_opt)
+ switch (timer_run) {
+ case 0:
+ snprintf(timers, sizeof(timers), _("off (0.00/%ld) %c"), retr, timer_queued);
+ break;
+
+ case 1:
+ snprintf(timers, sizeof(timers), _("on (%2.2f/%ld) %c"), (double) time_len / 100,
+ retr, timer_queued);
+ break;
+
+ default:
+ snprintf(timers, sizeof(timers), _("unkn-%d (%2.2f/%ld) %c"),
+ timer_run, (double) time_len / 100,
+ retr, timer_queued);
+ break;
+ }
+ printf("raw %6ld %6ld %-23s %-23s %-12s",
+ rxq, txq, local_addr, rem_addr, raw_state);
+
+ if (flag_exp > 1)
+ printf("%-10s ", "");
+
+ if (flag_opt)
+ printf("%s", timers);
+ printf("\n");
}
- printf("raw %6ld %6ld %-23s %-23s %-12s",
- rxq, txq, local_addr, rem_addr, raw_state);
-
- if (flag_exp > 1)
- printf("%-10s ", "");
-
- if (flag_opt) printf("%s", timers);
- printf("\n");
- }
}
-static int
-raw_info(void)
+static int raw_info(void)
{
- INFO_GUTS6(_PATH_PROCNET_RAW, _PATH_PROCNET_RAW6, "AF INET (raw)",
- raw_do_one);
+ INFO_GUTS6(_PATH_PROCNET_RAW, _PATH_PROCNET_RAW6, "AF INET (raw)",
+ raw_do_one);
}
+
#endif
@@ -787,126 +780,128 @@ raw_info(void)
static void unix_do_one(int nr, const char *line)
{
- static int has = 0;
- char inode[MAXPATHLEN], path[MAXPATHLEN], ss_flags[32];
- char *ss_proto, *ss_state, *ss_type;
- int num, state, type;
- void *d;
- unsigned long refcnt, proto, flags;
-
- if (nr == 0) {
- if (strstr(line, "Inode"))
- has |= HAS_INODE;
- return;
- }
+ static int has = 0;
+ char inode[MAXPATHLEN], path[MAXPATHLEN], ss_flags[32];
+ char *ss_proto, *ss_state, *ss_type;
+ int num, state, type;
+ void *d;
+ unsigned long refcnt, proto, flags;
+
+ if (nr == 0) {
+ if (strstr(line, "Inode"))
+ has |= HAS_INODE;
+ return;
+ }
+ path[0] = '\0';
+ inode[0] = '\0';
+ num = sscanf(line, "%p: %lX %lX %lX %X %X %s %s",
+ &d, &refcnt, &proto, &flags, &type, &state, inode, path);
+ if (num < 6) {
+ fprintf(stderr, _("warning, got bogus unix line.\n"));
+ return;
+ }
+ if (!(has & HAS_INODE)) {
+ strcpy(path, inode);
+ strcpy(inode, "-");
+ }
+ if (!flag_all && (state == SS_UNCONNECTED) && (flags & SO_ACCEPTCON))
+ return;
- path[0] = '\0';
- inode[0] = '\0';
- num = sscanf(line, "%p: %lX %lX %lX %X %X %s %s",
- &d, &refcnt, &proto, &flags, &type, &state, inode, path);
- if (num < 6) {
- fprintf(stderr, _("warning, got bogus unix line.\n"));
- return;
- }
+ switch (proto) {
+ case 0:
+ ss_proto = "unix";
+ break;
- if (!(has&HAS_INODE)) {
- strcpy(path,inode);
- strcpy(inode,"-");
- }
- if (!flag_all && (state == SS_UNCONNECTED) && (flags & SO_ACCEPTCON))
- return;
-
- switch(proto) {
- case 0:
- ss_proto = "unix";
- break;
-
- default:
- ss_proto = "??";
- }
-
- switch(type) {
- case SOCK_STREAM:
- ss_type = _("STREAM");
- break;
-
- case SOCK_DGRAM:
- ss_type = _("DGRAM");
- break;
-
- case SOCK_RAW:
- ss_type = _("RAW");
- break;
-
- case SOCK_RDM:
- ss_type = _("RDM");
- break;
-
- case SOCK_SEQPACKET:
- ss_type = _("SEQPACKET");
- break;
-
- default:
- ss_type = _("UNKNOWN");
- }
-
- switch(state) {
- case SS_FREE:
- ss_state = _("FREE");
- break;
-
- case SS_UNCONNECTED:
- /*
- * Unconnected sockets may be listening
- * for something.
- */
- if (flags & SO_ACCEPTCON) {
- ss_state = _("LISTENING");
- } else {
- ss_state = "";
+ default:
+ ss_proto = "??";
}
- break;
-
- case SS_CONNECTING:
- ss_state = _("CONNECTING");
- break;
-
- case SS_CONNECTED:
- ss_state = _("CONNECTED");
- break;
-
- case SS_DISCONNECTING:
- ss_state = _("DISCONNECTING");
- break;
-
- default:
- ss_state = _("UNKNOWN");
- }
-
- strcpy(ss_flags, "[ ");
- if (flags & SO_ACCEPTCON) strcat(ss_flags, "ACC ");
- if (flags & SO_WAITDATA) strcat(ss_flags, "W ");
- if (flags & SO_NOSPACE) strcat(ss_flags, "N ");
-
- strcat(ss_flags, "]");
-
- printf("%-5s %-6ld %-11s %-10s %-13s %-6s %s\n",
- ss_proto, refcnt, ss_flags, ss_type, ss_state, inode, path);
+
+ switch (type) {
+ case SOCK_STREAM:
+ ss_type = _("STREAM");
+ break;
+
+ case SOCK_DGRAM:
+ ss_type = _("DGRAM");
+ break;
+
+ case SOCK_RAW:
+ ss_type = _("RAW");
+ break;
+
+ case SOCK_RDM:
+ ss_type = _("RDM");
+ break;
+
+ case SOCK_SEQPACKET:
+ ss_type = _("SEQPACKET");
+ break;
+
+ default:
+ ss_type = _("UNKNOWN");
+ }
+
+ switch (state) {
+ case SS_FREE:
+ ss_state = _("FREE");
+ break;
+
+ case SS_UNCONNECTED:
+ /*
+ * Unconnected sockets may be listening
+ * for something.
+ */
+ if (flags & SO_ACCEPTCON) {
+ ss_state = _("LISTENING");
+ } else {
+ ss_state = "";
+ }
+ break;
+
+ case SS_CONNECTING:
+ ss_state = _("CONNECTING");
+ break;
+
+ case SS_CONNECTED:
+ ss_state = _("CONNECTED");
+ break;
+
+ case SS_DISCONNECTING:
+ ss_state = _("DISCONNECTING");
+ break;
+
+ default:
+ ss_state = _("UNKNOWN");
+ }
+
+ strcpy(ss_flags, "[ ");
+ if (flags & SO_ACCEPTCON)
+ strcat(ss_flags, "ACC ");
+ if (flags & SO_WAITDATA)
+ strcat(ss_flags, "W ");
+ if (flags & SO_NOSPACE)
+ strcat(ss_flags, "N ");
+
+ strcat(ss_flags, "]");
+
+ printf("%-5s %-6ld %-11s %-10s %-13s %-6s %s\n",
+ ss_proto, refcnt, ss_flags, ss_type, ss_state, inode, path);
}
-static int
-unix_info(void)
+static int unix_info(void)
{
-
- printf(_("Active UNIX domain sockets ")); /* xxx */
- if (flag_all) printf(_("(including servers)")); /* xxx */
- else printf(_("(w/o servers)")); /* xxx */
- printf(_("\nProto RefCnt Flags Type State I-Node Path\n")); /* xxx */
+ printf(_("Active UNIX domain sockets ")); /* xxx */
+ if (flag_all)
+ printf(_("(including servers)")); /* xxx */
+ else
+ printf(_("(w/o servers)")); /* xxx */
- {
- INFO_GUTS(_PATH_PROCNET_UNIX, "AF UNIX", unix_do_one);
- }
+ printf(_("\nProto RefCnt Flags Type State I-Node Path\n")); /* xxx */
+
+ {
+ INFO_GUTS(_PATH_PROCNET_UNIX, "AF UNIX", unix_do_one);
+ }
}
#endif
@@ -914,47 +909,45 @@ unix_info(void)
#if HAVE_AFAX25
static int ax25_info(void)
{
- FILE *f=fopen(_PATH_PROCNET_AX25, "r");
- char buffer[256],dev[16];
- int st,vs,vr,sendq,recvq;
- static char *ax25_state[5]=
- {
- N_("LISTENING"),
- N_("SABM SENT"),
- N_("DISC SENT"),
- N_("ESTABLISHED"),
- N_("RECOVERY")
- };
- if(!(f=fopen(_PATH_PROCNET_AX25, "r")))
- {
- if (errno != ENOENT) {
- perror(_PATH_PROCNET_AX25);
- return(-1);
- }
- if (flag_arg || flag_ver)
- ESYSNOT("netstat","AF AX25");
- if (flag_arg)
- return(1);
- else
- return(0);
- }
- printf(_("Activate AX.25 sockets\n"));
- printf(_("Dest Source Device State Vr/Vs Send-Q Recv-Q\n"));
- fgets(buffer,256,f);
- while(fgets(buffer,256,f))
- {
- buffer[9]=0;
- buffer[19]=0;
- sscanf(buffer+20,"%s %d %d %d %*d %*d/%*d %*d/%*d %*d/%*d %*d/%*d %*d %*d %d %d",
- dev,&st,&vs,&vr,&sendq,&recvq);
- printf("%-9s %-9s %-6s %-11s %02d/%02d %-6d %-6d\n",
- buffer,buffer+10,
- dev,
- _(ax25_state[st]),
- vr,vs,sendq,recvq);
- }
- fclose(f);
- return 0;
+ FILE *f = fopen(_PATH_PROCNET_AX25, "r");
+ char buffer[256], dev[16];
+ int st, vs, vr, sendq, recvq;
+ static char *ax25_state[5] =
+ {
+ N_("LISTENING"),
+ N_("SABM SENT"),
+ N_("DISC SENT"),
+ N_("ESTABLISHED"),
+ N_("RECOVERY")
+ };
+ if (!(f = fopen(_PATH_PROCNET_AX25, "r"))) {
+ if (errno != ENOENT) {
+ perror(_PATH_PROCNET_AX25);
+ return (-1);
+ }
+ if (flag_arg || flag_ver)
+ ESYSNOT("netstat", "AF AX25");
+ if (flag_arg)
+ return (1);
+ else
+ return (0);
+ }
+ printf(_("Activate AX.25 sockets\n"));
+ printf(_("Dest Source Device State Vr/Vs Send-Q Recv-Q\n"));
+ fgets(buffer, 256, f);
+ while (fgets(buffer, 256, f)) {
+ buffer[9] = 0;
+ buffer[19] = 0;
+ sscanf(buffer + 20, "%s %d %d %d %*d %*d/%*d %*d/%*d %*d/%*d %*d/%*d %*d %*d %d %d",
+ dev, &st, &vs, &vr, &sendq, &recvq);
+ printf("%-9s %-9s %-6s %-11s %02d/%02d %-6d %-6d\n",
+ buffer, buffer + 10,
+ dev,
+ _(ax25_state[st]),
+ vr, vs, sendq, recvq);
+ }
+ fclose(f);
+ return 0;
}
#endif
@@ -962,481 +955,496 @@ static int ax25_info(void)
#if HAVE_AFIPX
static int ipx_info(void)
{
- FILE *f;
- char buf[256];
- unsigned long txq,rxq;
- unsigned int state;
- unsigned int uid;
- char *st;
- int nc;
- struct aftype *ap;
- struct passwd *pw;
- char sad[50],dad[50];
- struct sockaddr sa;
- unsigned sport=0,dport=0;
-
- if(!(f=fopen(_PATH_PROCNET_IPX,"r")))
- {
- if (errno != ENOENT) {
- perror(_PATH_PROCNET_IPX);
- return(-1);
- }
- if (flag_arg || flag_ver)
- ESYSNOT("netstat","AF IPX");
- if (flag_arg)
- return(1);
- else
- return(0);
- }
- printf(_("Active IPX sockets\nProto Recv-Q Send-Q Local Address Foreign Address State")); /* xxx */
- if (flag_exp>1)
- printf(_(" User")); /* xxx */
- printf("\n");
- if ((ap = get_afntype(AF_IPX)) == NULL) {
- EINTERN("netstat.c","AF_IPX missing");
- return(-1);
- }
-
- fgets(buf,255,f);
-
- while(fgets(buf,255,f)!=NULL)
- {
- sscanf(buf, "%s %s %lX %lX %d %d",
- sad,dad,&txq,&rxq,&state,&uid);
- if ((st = rindex(sad,':'))) {
- *st++ = '\0';
- sscanf(st,"%X",&sport); /* net byt order */
- sport = ntohs(sport);
- } else {
- EINTERN("netstat.c",_PATH_PROCNET_IPX" sport format error");
- return(-1);
- }
- nc = 0;
- if (strcmp(dad,"Not_Connected")!=0) {
- if ((st = rindex(dad,':'))) {
- *st++ = '\0';
- sscanf(st,"%X",&dport); /* net byt order */
- dport = ntohs(dport);
- } else {
- EINTERN("netstat.c",_PATH_PROCNET_IPX" dport format error");
- return(-1);
- }
- } else
- nc = 1;
-
- switch(state)
- {
- case TCP_ESTABLISHED:
- st = _("ESTAB");
- break;
-
- case TCP_CLOSE:
- st = "";
- break;
-
- default:
- st = _("UNK.");
- break;
- }
-
- /* Fetch and resolve the Source */
- (void)ap->input(4,sad,&sa);
- strcpy(buf, ap->sprint(&sa, flag_not));
- snprintf(sad,sizeof(sad),"%s:%04X",buf,sport);
-
- if (!nc) {
- /* Fetch and resolve the Destination */
- (void)ap->input(4,dad,&sa);
- strcpy(buf, ap->sprint(&sa, flag_not));
- snprintf(dad,sizeof(dad),"%s:%04X",buf,dport);
- } else strcpy(dad,"-");
-
- printf("IPX %6ld %6ld %-26s %-26s %-5s", txq, rxq, sad, dad, st);
- if (flag_exp>1) {
- if (!flag_not && ((pw = getpwuid(uid)) != NULL))
- printf(" %-10s", pw->pw_name);
- else
- printf(" %-10d",uid);
- }
- printf("\n");
+ FILE *f;
+ char buf[256];
+ unsigned long txq, rxq;
+ unsigned int state;
+ unsigned int uid;
+ char *st;
+ int nc;
+ struct aftype *ap;
+ struct passwd *pw;
+ char sad[50], dad[50];
+ struct sockaddr sa;
+ unsigned sport = 0, dport = 0;
+
+ if (!(f = fopen(_PATH_PROCNET_IPX, "r"))) {
+ if (errno != ENOENT) {
+ perror(_PATH_PROCNET_IPX);
+ return (-1);
}
- fclose(f);
- return 0;
-}
+ if (flag_arg || flag_ver)
+ ESYSNOT("netstat", "AF IPX");
+ if (flag_arg)
+ return (1);
+ else
+ return (0);
+ }
+ printf(_("Active IPX sockets\nProto Recv-Q Send-Q Local Address Foreign Address State")); /* xxx */
+ if (flag_exp > 1)
+ printf(_(" User")); /* xxx */
+ printf("\n");
+ if ((ap = get_afntype(AF_IPX)) == NULL) {
+ EINTERN("netstat.c", "AF_IPX missing");
+ return (-1);
+ }
+ fgets(buf, 255, f);
+
+ while (fgets(buf, 255, f) != NULL) {
+ sscanf(buf, "%s %s %lX %lX %d %d",
+ sad, dad, &txq, &rxq, &state, &uid);
+ if ((st = rindex(sad, ':'))) {
+ *st++ = '\0';
+ sscanf(st, "%X", &sport); /* net byt order */
+ sport = ntohs(sport);
+ } else {
+ EINTERN("netstat.c", _PATH_PROCNET_IPX " sport format error");
+ return (-1);
+ }
+ nc = 0;
+ if (strcmp(dad, "Not_Connected") != 0) {
+ if ((st = rindex(dad, ':'))) {
+ *st++ = '\0';
+ sscanf(st, "%X", &dport); /* net byt order */
+ dport = ntohs(dport);
+ } else {
+ EINTERN("netstat.c", _PATH_PROCNET_IPX " dport format error");
+ return (-1);
+ }
+ } else
+ nc = 1;
+
+ switch (state) {
+ case TCP_ESTABLISHED:
+ st = _("ESTAB");
+ break;
+
+ case TCP_CLOSE:
+ st = "";
+ break;
+
+ default:
+ st = _("UNK.");
+ break;
+ }
+
+ /* Fetch and resolve the Source */
+ (void) ap->input(4, sad, &sa);
+ strcpy(buf, ap->sprint(&sa, flag_not));
+ snprintf(sad, sizeof(sad), "%s:%04X", buf, sport);
+
+ if (!nc) {
+ /* Fetch and resolve the Destination */
+ (void) ap->input(4, dad, &sa);
+ strcpy(buf, ap->sprint(&sa, flag_not));
+ snprintf(dad, sizeof(dad), "%s:%04X", buf, dport);
+ } else
+ strcpy(dad, "-");
+
+ printf("IPX %6ld %6ld %-26s %-26s %-5s", txq, rxq, sad, dad, st);
+ if (flag_exp > 1) {
+ if (!flag_not && ((pw = getpwuid(uid)) != NULL))
+ printf(" %-10s", pw->pw_name);
+ else
+ printf(" %-10d", uid);
+ }
+ printf("\n");
+ }
+ fclose(f);
+ return 0;
+}
#endif
-static void
-ife_print(struct interface *ptr)
+static void ife_print(struct interface *ptr)
{
- printf("%-7.7s ", ptr->name);
- printf("%5d %3d ", ptr->mtu, ptr->metric);
- /* If needed, display the interface statistics. */
- if (ptr->statistics_valid) {
- printf("%6lu %6lu %6lu %6lu ",
- ptr->stats.rx_packets, ptr->stats.rx_errors,
- ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors);
- printf("%6lu %6lu %6lu %6lu ",
- ptr->stats.tx_packets, ptr->stats.tx_errors,
- ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors);
- } else {
- printf("%-56s", " - no statistics available -");
- }
- if (ptr->flags == 0) printf(_("[NO FLAGS]"));
- if (ptr->flags & IFF_ALLMULTI) printf("A");
- if (ptr->flags & IFF_BROADCAST) printf("B");
- if (ptr->flags & IFF_DEBUG) printf("D");
- if (ptr->flags & IFF_LOOPBACK) printf("L");
- if (ptr->flags & IFF_PROMISC) printf("M");
- if (ptr->flags & IFF_NOTRAILERS) printf("N");
- if (ptr->flags & IFF_NOARP) printf("O");
- if (ptr->flags & IFF_POINTOPOINT) printf("P");
- if (ptr->flags & IFF_RUNNING) printf("R");
- if (ptr->flags & IFF_UP) printf("U");
- printf("\n");
+ printf("%-7.7s ", ptr->name);
+ printf("%5d %3d ", ptr->mtu, ptr->metric);
+ /* If needed, display the interface statistics. */
+ if (ptr->statistics_valid) {
+ printf("%6lu %6lu %6lu %6lu ",
+ ptr->stats.rx_packets, ptr->stats.rx_errors,
+ ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors);
+ printf("%6lu %6lu %6lu %6lu ",
+ ptr->stats.tx_packets, ptr->stats.tx_errors,
+ ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors);
+ } else {
+ printf("%-56s", " - no statistics available -");
+ }
+ if (ptr->flags == 0)
+ printf(_("[NO FLAGS]"));
+ if (ptr->flags & IFF_ALLMULTI)
+ printf("A");
+ if (ptr->flags & IFF_BROADCAST)
+ printf("B");
+ if (ptr->flags & IFF_DEBUG)
+ printf("D");
+ if (ptr->flags & IFF_LOOPBACK)
+ printf("L");
+ if (ptr->flags & IFF_PROMISC)
+ printf("M");
+ if (ptr->flags & IFF_NOTRAILERS)
+ printf("N");
+ if (ptr->flags & IFF_NOARP)
+ printf("O");
+ if (ptr->flags & IFF_POINTOPOINT)
+ printf("P");
+ if (ptr->flags & IFF_RUNNING)
+ printf("R");
+ if (ptr->flags & IFF_UP)
+ printf("U");
+ printf("\n");
}
static int do_if_print(struct interface *ife, void *cookie)
{
- int *opt_a = (int *)cookie;
+ int *opt_a = (int *) cookie;
if (if_fetch(ife->name, ife) < 0) {
- fprintf (stderr, _("%s: unknown interface.\n"), ife->name);
- return -1;
+ fprintf(stderr, _("%s: unknown interface.\n"), ife->name);
+ return -1;
}
if (!(ife->flags & IFF_UP) && !(*opt_a))
- return 0;
- ife_print(ife);
return 0;
+ ife_print(ife);
+ return 0;
}
-static int
-iface_info(void)
+static int iface_info(void)
{
- if ((skfd = sockets_open(0)) < 0) {
- perror("socket");
- exit(1);
- }
+ if ((skfd = sockets_open(0)) < 0) {
+ perror("socket");
+ exit(1);
+ }
+ printf(_("Kernel Interface table\n"));
+ printf(_("Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flags\n"));
- printf(_("Kernel Interface table\n"));
- printf(_("Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flags\n"));
-
- if (for_all_interfaces(do_if_print, &flag_all) < 0) {
- perror(_("missing interface information"));
- exit(1);
- }
+ if (for_all_interfaces(do_if_print, &flag_all) < 0) {
+ perror(_("missing interface information"));
+ exit(1);
+ }
+ close(skfd);
+ skfd = -1;
- close(skfd);
- skfd = -1;
-
- return 0;
+ return 0;
}
-static void
-version(void)
+static void version(void)
{
- printf("%s\n%s\n%s\n%s\n", Release, Version, Signature, Features);
- exit(1);
+ printf("%s\n%s\n%s\n%s\n", Release, Version, Signature, Features);
+ exit(1);
}
-static void
-usage(void)
+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, _(" -i, --interfaces display interface table\n"));
- fprintf(stderr, _(" -M, --masquerade display masqueraded connections\n\n"));
- fprintf(stderr, _(" -v, --verbose be verbose\n"));
- fprintf(stderr, _(" -n, --numeric dont resolve 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"));
+ 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, _(" -i, --interfaces display interface table\n"));
+ fprintf(stderr, _(" -M, --masquerade display masqueraded connections\n\n"));
+ fprintf(stderr, _(" -v, --verbose be verbose\n"));
+ fprintf(stderr, _(" -n, --numeric dont resolve 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"));
+ 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"));
+ fprintf(stderr, _("<Af>= -A {inet|ipx|netrom|ddp|ax25},... --inet --ipx --netrom --ddp --ax25\n"));
#endif
- exit(1);
+ exit(1);
}
int main
-(int argc, char *argv[])
-{
- int i;
- int lop;
- struct option longopts[]=
- {
- AFTRANS_OPTS,
- {"version", 0, 0, 'V'},
- {"interfaces", 0, 0, 'i'},
- {"help", 0, 0, 'h'},
- {"route", 0, 0, 'r'},
- {"netlink", 2, 0, 'L'},
- {"masquerade", 0, 0, 'M'},
- {"protocol", 1, 0, 'A'},
- {"tcp", 0, 0, 't'},
- {"udp", 0, 0, 'u'},
- {"raw", 0, 0, 'w'},
- {"unix", 0, 0, 'x'},
- {"listening", 0, 0, 'a'},
- {"all", 0, 0, 'a'},
- {"timers", 0, 0, 'o'},
- {"continuous", 0, 0, 'c'},
- {"extend", 0, 0, 'e'},
- {"verbose", 0, 0, 'v'},
- {"statistics", 0, 0, 's'},
- {"numeric", 0, 0, 'n'},
- {"symbolic", 0, 0, 'N'},
- {"cache", 0, 0, 'C'},
- {"fib", 0, 0, 'F'},
- {NULL, 0, 0, 0}
- };
-
+ (int argc, char *argv[]) {
+ int i;
+ int lop;
+ struct option longopts[] =
+ {
+ AFTRANS_OPTS,
+ {"version", 0, 0, 'V'},
+ {"interfaces", 0, 0, 'i'},
+ {"help", 0, 0, 'h'},
+ {"route", 0, 0, 'r'},
+ {"netlink", 2, 0, 'L'},
+ {"masquerade", 0, 0, 'M'},
+ {"protocol", 1, 0, 'A'},
+ {"tcp", 0, 0, 't'},
+ {"udp", 0, 0, 'u'},
+ {"raw", 0, 0, 'w'},
+ {"unix", 0, 0, 'x'},
+ {"listening", 0, 0, 'a'},
+ {"all", 0, 0, 'a'},
+ {"timers", 0, 0, 'o'},
+ {"continuous", 0, 0, 'c'},
+ {"extend", 0, 0, 'e'},
+ {"verbose", 0, 0, 'v'},
+ {"statistics", 0, 0, 's'},
+ {"numeric", 0, 0, 'n'},
+ {"symbolic", 0, 0, 'N'},
+ {"cache", 0, 0, 'C'},
+ {"fib", 0, 0, 'F'},
+ {NULL, 0, 0, 0}
+ };
+
#if I18N
- bindtextdomain("net-tools", "/usr/share/locale");
- textdomain("net-tools");
+ bindtextdomain("net-tools", "/usr/share/locale");
+ textdomain("net-tools");
#endif
- getroute_init(); /* Set up AF routing support */
-
- afname[0]='\0';
- while ((i = getopt_long(argc, argv, "MLCFA:acdehinNorstuVv?wx", longopts, &lop)) != EOF) switch(i) {
- case -1:
- break;
- case 1:
- if (lop < 0 || lop >= AFTRANS_CNT) {
- EINTERN("netstat.c","longopts 1 range");
- break;
- }
- if (aftrans_opt(longopts[lop].name))
- exit(1);
- break;
- case 'A':
- if (aftrans_opt(optarg))
- exit(1);
- break;
- case 'L':
- flag_nlp++;
- break;
- case 'M':
- flag_mas++;
- break;
- case 'a':
- flag_all++;
- break;
- case 'c':
- flag_cnt++;
- break;
-
- case 'd':
- flag_deb++;
- break;
- case 'e':
- flag_exp++;
- break;
- case 'i':
- flag_int++;
- break;
-
- case 'n':
- flag_not|=FLAG_NUM;
- break;
- case 'N':
- flag_not|=FLAG_SYM;
- break;
- case 'C':
- flag_cf|=FLAG_CACHE;
- break;
- case 'F':
- flag_cf|=FLAG_FIB;
- break;
- case 'o':
- flag_opt++;
- break;
- case 'V':
- version();
- /*NOTREACHED*/
- case 'v':
- flag_ver|=FLAG_VERBOSE;
- break;
- case 'r':
- flag_rou++;
- break;
-
- case 't':
- flag_tcp++;
- break;
-
- case 'u':
- flag_udp++;
- break;
- case 'w':
- flag_raw++;
- break;
- case 'x':
- if (aftrans_opt("unix"))
- exit(1);
- break;
- case '?':
- case 'h':
- usage();
- case 's':
- inittab();
- parsesnmp();
- exit(0);
- }
-
- if (flag_int + flag_rou + flag_nlp + flag_mas > 1)
- usage();
-
- if (flag_inet)
- flag_tcp = flag_udp = flag_raw = 1;
-
- flag_arg = flag_tcp + flag_udp + flag_raw + flag_unx + flag_ipx
- + flag_ax25 + flag_netrom;
-
- if (flag_nlp) {
+ getroute_init(); /* Set up AF routing support */
+
+ afname[0] = '\0';
+ while ((i = getopt_long(argc, argv, "MLCFA:acdehinNorstuVv?wx", longopts, &lop)) != EOF)
+ switch (i) {
+ case -1:
+ break;
+ case 1:
+ if (lop < 0 || lop >= AFTRANS_CNT) {
+ EINTERN("netstat.c", "longopts 1 range");
+ break;
+ }
+ if (aftrans_opt(longopts[lop].name))
+ exit(1);
+ break;
+ case 'A':
+ if (aftrans_opt(optarg))
+ exit(1);
+ break;
+ case 'L':
+ flag_nlp++;
+ break;
+ case 'M':
+ flag_mas++;
+ break;
+ case 'a':
+ flag_all++;
+ break;
+ case 'c':
+ flag_cnt++;
+ break;
+
+ case 'd':
+ flag_deb++;
+ break;
+ case 'e':
+ flag_exp++;
+ break;
+ case 'i':
+ flag_int++;
+ break;
+
+ case 'n':
+ flag_not |= FLAG_NUM;
+ break;
+ case 'N':
+ flag_not |= FLAG_SYM;
+ break;
+ case 'C':
+ flag_cf |= FLAG_CACHE;
+ break;
+ case 'F':
+ flag_cf |= FLAG_FIB;
+ break;
+ case 'o':
+ flag_opt++;
+ break;
+ case 'V':
+ version();
+ /*NOTREACHED */
+ case 'v':
+ flag_ver |= FLAG_VERBOSE;
+ break;
+ case 'r':
+ flag_rou++;
+ break;
+
+ case 't':
+ flag_tcp++;
+ break;
+
+ case 'u':
+ flag_udp++;
+ break;
+ case 'w':
+ flag_raw++;
+ break;
+ case 'x':
+ if (aftrans_opt("unix"))
+ exit(1);
+ break;
+ case '?':
+ case 'h':
+ usage();
+ case 's':
+ inittab();
+ parsesnmp();
+ exit(0);
+ }
+
+ if (flag_int + flag_rou + flag_nlp + flag_mas > 1)
+ usage();
+
+ if (flag_inet)
+ flag_tcp = flag_udp = flag_raw = 1;
+
+ 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();
+ i = netlink_print();
#else
- ENOSUPP("netstat.c","RT_NETLINK");
- i=-1;
-#endif
- return(i);
- }
- if (flag_mas) {
+ 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
- if (!afname[0])
- strcpy(afname,DFLT_AF);
-#endif
- for(;;) {
- i = ip_masq_info(flag_not, flag_exp);
- if (i || !flag_cnt) break;
- sleep(1);
- }
+ if (!afname[0])
+ strcpy(afname, DFLT_AF);
+#endif
+ for (;;) {
+ i = ip_masq_info(flag_not, flag_exp);
+ if (i || !flag_cnt)
+ break;
+ sleep(1);
+ }
#else
- ENOSUPP("netstat.c","FW_MASQUERADE");
- i=-1;
+ ENOSUPP("netstat.c", "FW_MASQUERADE");
+ i = -1;
#endif
- return(i);
- }
- if (flag_rou) {
- int options=0;
-
- if (!afname[0])
- strcpy(afname,DFLT_AF);
-
- if (flag_exp == 2)
- flag_exp = 1;
- else if (flag_exp == 1)
- flag_exp = 2;
-
- options = (flag_exp & FLAG_EXT) | flag_not | flag_cf | flag_ver ;
- if (!flag_cf)
- options |= FLAG_FIB;
-
- for(;;) {
- i = route_info(afname,options);
- if (i || !flag_cnt) break;
- sleep(1);
+ return (i);
}
- return(i);
- }
-
- if (flag_int) {
- for (;;) {
- i = iface_info();
- if (!flag_cnt || i) break;
- sleep(1);
+ if (flag_rou) {
+ int options = 0;
+
+ if (!afname[0])
+ strcpy(afname, DFLT_AF);
+
+ if (flag_exp == 2)
+ flag_exp = 1;
+ else if (flag_exp == 1)
+ flag_exp = 2;
+
+ options = (flag_exp & FLAG_EXT) | flag_not | flag_cf | flag_ver;
+ if (!flag_cf)
+ options |= FLAG_FIB;
+
+ for (;;) {
+ i = route_info(afname, options);
+ if (i || !flag_cnt)
+ break;
+ sleep(1);
+ }
+ return (i);
}
- return(i);
- }
-
- for (;;) {
- if (!flag_arg || flag_tcp || flag_udp || flag_raw) {
+ if (flag_int) {
+ for (;;) {
+ i = iface_info();
+ if (!flag_cnt || i)
+ break;
+ sleep(1);
+ }
+ return (i);
+ }
+ for (;;) {
+ 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 */
-
- printf(_("\nProto Recv-Q Send-Q Local Address Foreign Address State ")); /* xxx */
- if (flag_exp > 1)
- printf(_(" User ")); /* xxx */
- if (flag_opt)
- printf(_(" Timer")); /* xxx */
- printf("\n");
+ printf(_("Active Internet connections ")); /* xxx */
+ if (flag_all)
+ printf(_("(including servers)")); /* xxx */
+ else
+ printf(_("(w/o servers)")); /* xxx */
+
+ printf(_("\nProto Recv-Q Send-Q Local Address Foreign Address State ")); /* xxx */
+ if (flag_exp > 1)
+ printf(_(" User ")); /* xxx */
+ if (flag_opt)
+ printf(_(" Timer")); /* xxx */
+ printf("\n");
#else
- if (flag_arg) {
- i = 1;
- ENOSUPP("netstat","AF INET");
- }
+ if (flag_arg) {
+ i = 1;
+ ENOSUPP("netstat", "AF INET");
+ }
#endif
- }
+ }
#if HAVE_AFINET
- if (!flag_arg || flag_tcp) {
- i = tcp_info();
- if (i) return(i);
- }
-
- if (!flag_arg || flag_udp) {
- i = udp_info();
- if (i) return(i);
- }
-
- if (!flag_arg || flag_raw) {
- i = raw_info();
- if (i) return(i);
- }
+ if (!flag_arg || flag_tcp) {
+ i = tcp_info();
+ if (i)
+ return (i);
+ }
+ if (!flag_arg || flag_udp) {
+ i = udp_info();
+ if (i)
+ return (i);
+ }
+ if (!flag_arg || flag_raw) {
+ i = raw_info();
+ if (i)
+ return (i);
+ }
#endif
-
- if (!flag_arg || flag_unx) {
+
+ if (!flag_arg || flag_unx) {
#if HAVE_AFUNIX
- i = unix_info();
- if (i) return(i);
+ i = unix_info();
+ if (i)
+ return (i);
#else
- if (flag_arg)
- { i=1; ENOSUPP("netstat","AF UNIX"); }
+ if (flag_arg) {
+ i = 1;
+ ENOSUPP("netstat", "AF UNIX");
+ }
#endif
- }
-
- if(!flag_arg || flag_ipx) {
+ }
+ if (!flag_arg || flag_ipx) {
#if HAVE_AFIPX
- i = ipx_info();
- if(i) return(i);
+ i = ipx_info();
+ if (i)
+ return (i);
#else
- if (flag_arg)
- { i=1; ENOSUPP("netstat","AF IPX"); }
+ if (flag_arg) {
+ i = 1;
+ ENOSUPP("netstat", "AF IPX");
+ }
#endif
- }
-
- if(!flag_arg || flag_ax25) {
+ }
+ if (!flag_arg || flag_ax25) {
#if HAVE_AFAX25
- i = ax25_info();
- if(i) return(i);
+ i = ax25_info();
+ if (i)
+ return (i);
#else
- if (flag_arg)
- { i=1; ENOSUPP("netstat","AF AX25"); }
+ if (flag_arg) {
+ i = 1;
+ ENOSUPP("netstat", "AF AX25");
+ }
#endif
- }
-
- if(!flag_arg || flag_netrom) {
+ }
+ if (!flag_arg || flag_netrom) {
#if HAVE_AFNETROM
- i = netrom_info();
- if(i) return(i);
+ i = netrom_info();
+ if (i)
+ return (i);
#else
- if (flag_arg)
- { i=1; ENOSUPP("netstat","AF NETROM"); }
+ if (flag_arg) {
+ i = 1;
+ ENOSUPP("netstat", "AF NETROM");
+ }
#endif
+ }
+ if (!flag_cnt || i)
+ break;
+ sleep(1);
}
-
- if (!flag_cnt || i) break;
- sleep(1);
- }
- return(i);
+ return (i);
}
diff --git a/rarp.c b/rarp.c
index 0993ae8..2e21738 100644
--- a/rarp.c
+++ b/rarp.c
@@ -1,12 +1,14 @@
/*
- * rarp This file contains an implementation of the command
- * that maintains the kernel's RARP cache. It is derived
+ * rarp This file contains an implementation of the command
+ * 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 $
+ *
* Usage: rarp -d hostname Delete entry
- * rarp -s hostname ethernet_address Add entry
+ * rarp -s hostname ethernet_address Add entry
* rarp -a Print entries
- * rarp -f Add frop /etc/ethers
+ * rarp -f Add frop /etc/ethers
*
* 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
@@ -44,138 +46,135 @@ static struct hwtype *hardware = NULL;
/* Delete an entry from the RARP cache. */
static int rarp_delete(int fd, struct hostent *hp)
{
- struct arpreq req;
- struct sockaddr_in *si;
- unsigned int found = 0;
- char **addr;
+ struct arpreq req;
+ struct sockaddr_in *si;
+ unsigned int found = 0;
+ char **addr;
- /* The host can have more than one address, so we loop on them. */
- for (addr = hp->h_addr_list; *addr != NULL; addr++) {
- memset((char *) &req, 0, sizeof(req));
- si = (struct sockaddr_in *) &req.arp_pa;
- si->sin_family = hp->h_addrtype;
- memcpy((char *) &si->sin_addr, *addr, hp->h_length);
-
- /* Call the kernel. */
- if (ioctl(fd, SIOCDRARP, &req) == 0) {
- found++;
- } else {
- switch (errno) {
- case ENXIO:
- break;
- case ENODEV:
- fputs(_(no_rarp_message), stderr);
- return 1;
- default:
- perror("SIOCDRARP");
- return 1;
- }
+ /* The host can have more than one address, so we loop on them. */
+ for (addr = hp->h_addr_list; *addr != NULL; addr++) {
+ memset((char *) &req, 0, sizeof(req));
+ si = (struct sockaddr_in *) &req.arp_pa;
+ si->sin_family = hp->h_addrtype;
+ memcpy((char *) &si->sin_addr, *addr, hp->h_length);
+
+ /* Call the kernel. */
+ if (ioctl(fd, SIOCDRARP, &req) == 0) {
+ found++;
+ } else {
+ switch (errno) {
+ case ENXIO:
+ break;
+ case ENODEV:
+ fputs(_(no_rarp_message), stderr);
+ return 1;
+ default:
+ perror("SIOCDRARP");
+ return 1;
+ }
+ }
}
- }
- if (found == 0)
- printf(_("no RARP entry for %s.\n"), hp->h_name);
- return 0;
+ if (found == 0)
+ printf(_("no RARP entry for %s.\n"), hp->h_name);
+ return 0;
}
/* Set an entry in the RARP cache. */
static int rarp_set(int fd, struct hostent *hp, char *hw_addr)
{
- struct arpreq req;
- struct sockaddr_in *si;
- struct sockaddr sap;
-
- if (hardware->input(hw_addr, &sap)) {
- fprintf(stderr, _("%s: bad hardware address\n"), hw_addr);
- return 1;
- }
+ struct arpreq req;
+ struct sockaddr_in *si;
+ struct sockaddr sap;
- /* Clear and fill in the request block. */
- memset((char *) &req, 0, sizeof(req));
- si = (struct sockaddr_in *) &req.arp_pa;
- si->sin_family = hp->h_addrtype;
- memcpy((char *) &si->sin_addr, hp->h_addr_list[0], hp->h_length);
- req.arp_ha.sa_family = hardware->type;
- memcpy(req.arp_ha.sa_data, sap.sa_data, hardware->alen);
+ if (hardware->input(hw_addr, &sap)) {
+ fprintf(stderr, _("%s: bad hardware address\n"), hw_addr);
+ return 1;
+ }
+ /* Clear and fill in the request block. */
+ memset((char *) &req, 0, sizeof(req));
+ si = (struct sockaddr_in *) &req.arp_pa;
+ si->sin_family = hp->h_addrtype;
+ memcpy((char *) &si->sin_addr, hp->h_addr_list[0], hp->h_length);
+ req.arp_ha.sa_family = hardware->type;
+ memcpy(req.arp_ha.sa_data, sap.sa_data, hardware->alen);
- /* Call the kernel. */
- if (ioctl(fd, SIOCSRARP, &req) < 0) {
- if (errno == ENODEV)
- fputs(_(no_rarp_message), stderr);
- else
- perror("SIOCSRARP");
- return 1;
- }
- return 0;
+ /* Call the kernel. */
+ if (ioctl(fd, SIOCSRARP, &req) < 0) {
+ if (errno == ENODEV)
+ fputs(_(no_rarp_message), stderr);
+ else
+ perror("SIOCSRARP");
+ return 1;
+ }
+ return 0;
}
/* Process an EtherFile */
static int rarp_file(int fd, const char *name)
{
- char buff[1024];
- char *host, *addr;
- int linenr;
- FILE *fp;
- struct hostent *hp;
+ char buff[1024];
+ char *host, *addr;
+ int linenr;
+ FILE *fp;
+ struct hostent *hp;
- if ((fp = fopen(name, "r")) == NULL) {
- fprintf(stderr, _("rarp: cannot open file %s:%s.\n"), name, strerror(errno));
- return -1;
- }
-
- /* Read the lines in the file. */
- linenr = 0;
- while (fgets(buff, sizeof(buff), fp)) {
- ++linenr;
- if (buff[0] == '#' || buff[0] == '\0')
- continue;
- if ((addr = strtok(buff, "\n \t")) == NULL)
- continue;
- if ((host = strtok(NULL, "\n \t")) == NULL) {
- fprintf(stderr, _("rarp: format error at %s:%u\n"), name, linenr);
- continue;
- }
-
- if ((hp = gethostbyname(host)) == NULL) {
- fprintf(stderr, _("rarp: %s: unknown host\n"), host);
+ if ((fp = fopen(name, "r")) == NULL) {
+ fprintf(stderr, _("rarp: cannot open file %s:%s.\n"), name, strerror(errno));
+ return -1;
}
- if (rarp_set(fd,hp,addr) != 0) {
- fprintf(stderr, _("rarp: cannot set entry from %s:%u\n"), name, linenr);
+ /* Read the lines in the file. */
+ linenr = 0;
+ while (fgets(buff, sizeof(buff), fp)) {
+ ++linenr;
+ if (buff[0] == '#' || buff[0] == '\0')
+ continue;
+ if ((addr = strtok(buff, "\n \t")) == NULL)
+ continue;
+ if ((host = strtok(NULL, "\n \t")) == NULL) {
+ fprintf(stderr, _("rarp: format error at %s:%u\n"), name, linenr);
+ continue;
+ }
+ if ((hp = gethostbyname(host)) == NULL) {
+ fprintf(stderr, _("rarp: %s: unknown host\n"), host);
+ }
+ if (rarp_set(fd, hp, addr) != 0) {
+ fprintf(stderr, _("rarp: cannot set entry from %s:%u\n"), name, linenr);
+ }
}
- }
-
- (void) fclose(fp);
- return 0;
+
+ (void) fclose(fp);
+ return 0;
}
-
+
static int display_cache(void)
{
- FILE *fd = fopen(_PATH_PROCNET_RARP, "r");
- char buffer[256];
- if (fd == NULL) {
- if (errno == ENOENT)
- fputs(_(no_rarp_message), stderr);
- else
- perror(_PATH_PROCNET_RARP);
- return 1;
- }
- while (feof(fd) == 0) {
- if (fgets(buffer, 255, fd))
- fputs(buffer, stdout);
- }
- fclose(fd);
- return 0;
+ FILE *fd = fopen(_PATH_PROCNET_RARP, "r");
+ char buffer[256];
+ if (fd == NULL) {
+ if (errno == ENOENT)
+ fputs(_(no_rarp_message), stderr);
+ else
+ perror(_PATH_PROCNET_RARP);
+ return 1;
+ }
+ while (feof(fd) == 0) {
+ if (fgets(buffer, 255, fd))
+ fputs(buffer, stdout);
+ }
+ fclose(fd);
+ return 0;
}
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, _("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);
}
#define MODE_DISPLAY 1
@@ -183,122 +182,123 @@ static void usage(void)
#define MODE_SET 3
#define MODE_ETHERS 4
-static struct option longopts[] = {
- { "version", 0, NULL, 'V' },
- { "verbose", 0, NULL, 'v' },
- { "list", 0, NULL, 'a' },
- { "set", 0, NULL, 's' },
- { "delete", 0, NULL, 'd' },
- { "help", 0, NULL, 'h' },
- { NULL, 0, NULL, 0 }
+static struct option longopts[] =
+{
+ {"version", 0, NULL, 'V'},
+ {"verbose", 0, NULL, 'v'},
+ {"list", 0, NULL, 'a'},
+ {"set", 0, NULL, 's'},
+ {"delete", 0, NULL, 'd'},
+ {"help", 0, NULL, 'h'},
+ {NULL, 0, NULL, 0}
};
-
+
int main(int argc, char **argv)
{
- int result = 0, mode = 0, c, nargs = 0, verbose = 0;
- char *args[3];
- struct hostent *hp;
- int fd;
+ int result = 0, mode = 0, c, nargs = 0, verbose = 0;
+ char *args[3];
+ struct hostent *hp;
+ int fd;
#if I18N
- bindtextdomain("net-tools", "/usr/share/locale");
- textdomain("net-tools");
+ bindtextdomain("net-tools", "/usr/share/locale");
+ textdomain("net-tools");
#endif
#if HAVE_HWETHER
- /* Get a default hardware type. */
- hardware = get_hwtype("ether");
+ /* Get a default hardware type. */
+ hardware = get_hwtype("ether");
#endif
- do {
- c = getopt_long(argc, argv, "-ht:adsVvf", longopts, NULL);
- switch (c) {
- case EOF:
- break;
- case 'h':
- usage();
- case 'V':
- fprintf(stderr, version_string);
- exit(1);
- break;
- case 'v':
- verbose++;
- break;
- case 'a':
- case 's':
- case 'd':
- if (mode) {
- fprintf(stderr, _("%s: illegal option mix.\n"), argv[0]);
- usage();
- } else {
- mode = (c == 'a'?MODE_DISPLAY:(c == 'd'?MODE_DELETE:MODE_SET));
- }
- break;
- case 'f':
- mode=MODE_ETHERS;
- break;
- case 't':
- if (optarg) {
- hardware = get_hwtype(optarg);
- } else {
- usage();
- }
- break;
- case 1:
- if (nargs == 2) {
- usage();
+ do {
+ c = getopt_long(argc, argv, "-ht:adsVvf", longopts, NULL);
+ switch (c) {
+ case EOF:
+ break;
+ case 'h':
+ usage();
+ case 'V':
+ fprintf(stderr, version_string);
+ exit(1);
+ break;
+ case 'v':
+ verbose++;
+ break;
+ case 'a':
+ case 's':
+ case 'd':
+ if (mode) {
+ fprintf(stderr, _("%s: illegal option mix.\n"), argv[0]);
+ usage();
+ } else {
+ mode = (c == 'a' ? MODE_DISPLAY : (c == 'd' ? MODE_DELETE : MODE_SET));
+ }
+ break;
+ case 'f':
+ mode = MODE_ETHERS;
+ break;
+ case 't':
+ if (optarg) {
+ hardware = get_hwtype(optarg);
+ } else {
+ usage();
+ }
+ break;
+ case 1:
+ if (nargs == 2) {
+ usage();
+ exit(1);
+ } else {
+ args[nargs++] = optarg;
+ }
+ break;
+ default:
+ usage();
+ }
+ } while (c != EOF);
+
+ if (hardware == NULL) {
+ fprintf(stderr, _("rarp: %s: unknown hardware type.\n"), optarg);
exit(1);
- } else {
- args[nargs++] = optarg;
- }
- break;
- default:
- usage();
}
- } while (c != EOF);
+ switch (mode) {
+ case 0:
+ usage();
- if (hardware == NULL) {
- fprintf(stderr, _("rarp: %s: unknown hardware type.\n"), optarg);
- exit(1);
- }
+ case MODE_DISPLAY:
+ if (nargs != (mode - 1)) {
+ usage();
+ }
+ result = display_cache();
+ break;
- switch (mode) {
- case 0:
- usage();
+ case MODE_DELETE:
+ case MODE_SET:
+ if (nargs != (mode - 1)) {
+ usage();
+ }
+ if ((hp = gethostbyname(args[0])) == NULL) {
+ fprintf(stderr, _("rarp: %s: unknown host\n"), args[0]);
+ exit(1);
+ }
+ if (fd = socket(PF_INET, SOCK_DGRAM, 0), fd < 0) {
+ perror("socket");
+ exit(1);
+ }
+ result = (mode == MODE_DELETE) ? rarp_delete(fd, hp) : rarp_set(fd, hp, args[1]);
+ close(fd);
+ break;
- case MODE_DISPLAY:
- if (nargs != (mode-1)) {
- usage();
- }
- result = display_cache();
- break;
+ case MODE_ETHERS:
+ if (nargs != 0 && nargs != 1)
+ usage();
+ if (fd = socket(PF_INET, SOCK_DGRAM, 0), fd < 0) {
+ perror("socket");
+ exit(1);
+ }
+ result = rarp_file(fd, nargs ? args[0] : _PATH_ETHERS);
+ close(fd);
- case MODE_DELETE:
- case MODE_SET:
- if (nargs != (mode-1)) {
- usage();
- }
- if ((hp = gethostbyname(args[0])) == NULL) {
- fprintf(stderr, _("rarp: %s: unknown host\n"), args[0]);
- exit(1);
}
- if (fd = socket(PF_INET, SOCK_DGRAM, 0), fd < 0) {
- perror("socket");
- exit (1);
- }
- result = (mode == MODE_DELETE)?rarp_delete(fd, hp):rarp_set(fd, hp, args[1]);
- close(fd);
- break;
-
- case MODE_ETHERS:
- if (nargs!=0 && nargs!=1) usage();
- if (fd = socket(PF_INET, SOCK_DGRAM, 0), fd < 0) {
- perror("socket");
- exit (1);
- }
- result = rarp_file(fd, nargs ? args[0] : _PATH_ETHERS);
- close(fd);
-
- }
exit(result);
}
diff --git a/route.c b/route.c
index b572881..65fc81e 100644
--- a/route.c
+++ b/route.c
@@ -2,35 +2,35 @@
* route This file contains an implementation of the command
* that manages the IP routing table in the kernel.
*
- * Version: route 1.95 (1998-06-29)
+ * Version: $Id: route.c,v 1.3 1998/11/15 20:08:17 freitag Exp $
*
- * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
+ * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
- * (derived from FvK's 'route.c 1.70 01/04/94')
+ * (derived from FvK's 'route.c 1.70 01/04/94')
*
* Modifications:
- * Johannes Stille: for Net-2Debugged by
- * <johannes@titan.os.open.de>
- * Linus Torvalds: Misc Changes
- * Alan Cox: add the new mtu/window stuff
- * Miquel van Smoorenburg: rt_add and rt_del
- * {1.79} Bernd Eckenfels: route_info
- * {1.80} Bernd Eckenfels: reject, metric, irtt, 1.2.x support.
- * {1.81} Bernd Eckenfels: reject routes need a dummy device
- *960127 {1.82} Bernd Eckenfels: 'mod' and 'dyn' 'reinstate' added
- *960129 {1.83} Bernd Eckenfels: resolve and getsock now in lib/,
- * REJECT displays '-' as gatway.
- *960202 {1.84} Bernd Eckenfels: net-features support added
- *960203 {1.85} Bernd Eckenfels: "#ifdef' in '#if' for net-features
- * -A (aftrans) support, get_longopts
- *960206 {1.86} Bernd Eckenfels: route_init();
- *960218 {1.87} Bernd Eckenfels: netinet/in.h added
- *960221 {1.88} Bernd Eckenfels: aftrans_dfl support
- *960222 {1.90} Bernd Eckenfels: moved all AF specific code to lib/.
- *960413 {1.91} Bernd Eckenfels: new RTACTION support+FLAG_CACHE/FIB
- *960426 {1.92} Bernd Eckenfels: FLAG_SYM/-N support
- *960823 {x.xx} Frank Strauss: INET6 stuff
+ * Johannes Stille: for Net-2Debugged by
+ * <johannes@titan.os.open.de>
+ * Linus Torvalds: Misc Changes
+ * Alan Cox: add the new mtu/window stuff
+ * Miquel van Smoorenburg: rt_add and rt_del
+ * {1.79} Bernd Eckenfels: route_info
+ * {1.80} Bernd Eckenfels: reject, metric, irtt, 1.2.x support.
+ * {1.81} Bernd Eckenfels: reject routes need a dummy device
+ *960127 {1.82} Bernd Eckenfels: 'mod' and 'dyn' 'reinstate' added
+ *960129 {1.83} Bernd Eckenfels: resolve and getsock now in lib/,
+ * REJECT displays '-' as gatway.
+ *960202 {1.84} Bernd Eckenfels: net-features support added
+ *960203 {1.85} Bernd Eckenfels: "#ifdef' in '#if' for net-features
+ * -A (aftrans) support, get_longopts
+ *960206 {1.86} Bernd Eckenfels: route_init();
+ *960218 {1.87} Bernd Eckenfels: netinet/in.h added
+ *960221 {1.88} Bernd Eckenfels: aftrans_dfl support
+ *960222 {1.90} Bernd Eckenfels: moved all AF specific code to lib/.
+ *960413 {1.91} Bernd Eckenfels: new RTACTION support+FLAG_CACHE/FIB
+ *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
*
*/
@@ -62,157 +62,157 @@
#define DFLT_AF "inet"
#define FEATURE_ROUTE
-#include "lib/net-features.h" /* needs some of the system includes above! */
+#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.95 (1998-06-29)";
-int opt_n = 0; /* numerical output flag */
-int opt_v = 0; /* debugging output flag */
-int opt_e = 1; /* 1,2,3=type of routetable */
-int opt_fc = 0; /* routing cache/FIB */
-int opt_h = 0; /* help selected */
-struct aftype *ap; /* current address family */
+int opt_n = 0; /* numerical output flag */
+int opt_v = 0; /* debugging output flag */
+int opt_e = 1; /* 1,2,3=type of routetable */
+int opt_fc = 0; /* routing cache/FIB */
+int opt_h = 0; /* help selected */
+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, _(" 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"));
- exit(E_USAGE);
+ 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, _(" 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"));
+ exit(E_USAGE);
}
static void version(void)
{
- fprintf(stderr,"%s\n%s\n%s\n",Release,Version,Features);
- exit(E_VERSION);
+ fprintf(stderr, "%s\n%s\n%s\n", Release, Version, Features);
+ exit(E_VERSION);
}
int main(int argc, char **argv)
{
- int i,lop,what=0;
- struct option longopts[]=
- {
- AFTRANS_OPTS,
- {"extend", 0, 0, 'e'},
- {"verbose", 0, 0, 'v'},
- {"version", 0, 0, 'V'},
- {"numeric", 0, 0, 'n'},
- {"symbolic", 0, 0, 'N'},
- {"protocol", 1, 0, 'A'},
- {"cache", 0, 0, 'C'},
- {"fib", 0, 0, 'F'},
- {"help", 0, 0, 'h'},
- {NULL, 0, 0, 0}
- };
- char **tmp;
- char *progname;
- int options;
+ int i, lop, what = 0;
+ struct option longopts[] =
+ {
+ AFTRANS_OPTS,
+ {"extend", 0, 0, 'e'},
+ {"verbose", 0, 0, 'v'},
+ {"version", 0, 0, 'V'},
+ {"numeric", 0, 0, 'n'},
+ {"symbolic", 0, 0, 'N'},
+ {"protocol", 1, 0, 'A'},
+ {"cache", 0, 0, 'C'},
+ {"fib", 0, 0, 'F'},
+ {"help", 0, 0, 'h'},
+ {NULL, 0, 0, 0}
+ };
+ char **tmp;
+ char *progname;
+ int options;
#if I18N
- bindtextdomain("net-tools", "/usr/share/locale");
- textdomain("net-tools");
+ bindtextdomain("net-tools", "/usr/share/locale");
+ textdomain("net-tools");
#endif
- getroute_init(); /* Set up AF routing support */
- setroute_init();
- afname[0] = '\0';
- progname=argv[0];
-
- /* getopts and -net wont work :-/ */
- for(tmp=argv;*tmp;tmp++) {
- if (!strcmp(*tmp, "-net"))
- strcpy(*tmp, "#net");
- else if (!strcmp(*tmp, "-host"))
- strcpy(*tmp, "#host");
- }
-
- /* Fetch the command-line arguments. */
- while ((i = getopt_long(argc, argv, "A:eCFhnNVv?", longopts, &lop)) != EOF) switch(i) {
- case -1:
- break;
- case 'n':
- opt_n |= FLAG_NUM;
- break;
- case 'N':
- opt_n |= FLAG_SYM;
- break;
- case 'v':
- opt_v |= FLAG_VERBOSE;
- break;
- case 'e':
- opt_e++;
- break;
- case 1:
- if (lop < 0 || lop >= AFTRANS_CNT) {
- EINTERN("route.c","longopts 1 range");
- break;
- }
- if ((i = aftrans_opt(longopts[lop].name)))
- exit(i);
- break;
- case 'C':
- opt_fc |= FLAG_CACHE;
- break;
- case 'F':
- opt_fc |= FLAG_FIB;
- break;
- case 'A':
- if ((i = aftrans_opt(optarg)))
- exit(i);
- break;
- case 'V':
- version();
- case 'h':
- case '?':
- opt_h++;
- break;
- default:
- usage();
- }
-
- argv += optind;
- argc -= optind;
-
- if (opt_h) {
- if (!afname[0])
- usage();
- else
- what = RTACTION_HELP;
- } else {
- if (!afname[0])
- /* this will initialise afname[] */
- aftrans_def("route", progname, DFLT_AF);
-
- /* Do we have to show the contents of the routing table? */
- if (*argv == NULL) {
- what = RTACTION_SHOW;
- } else {
- if (!strcmp(*argv, "add"))
- what = RTACTION_ADD;
- else if (!strcmp(*argv, "del") || !strcmp(*argv, "delete"))
- what = RTACTION_DEL;
- else if (!strcmp(*argv,"flush"))
- what = RTACTION_FLUSH;
- else
- usage();
- }
+ getroute_init(); /* Set up AF routing support */
+ setroute_init();
+ afname[0] = '\0';
+ progname = argv[0];
+
+ /* getopts and -net wont work :-/ */
+ for (tmp = argv; *tmp; tmp++) {
+ if (!strcmp(*tmp, "-net"))
+ strcpy(*tmp, "#net");
+ else if (!strcmp(*tmp, "-host"))
+ strcpy(*tmp, "#host");
+ }
+
+ /* Fetch the command-line arguments. */
+ while ((i = getopt_long(argc, argv, "A:eCFhnNVv?", longopts, &lop)) != EOF)
+ switch (i) {
+ case -1:
+ break;
+ case 'n':
+ opt_n |= FLAG_NUM;
+ break;
+ case 'N':
+ opt_n |= FLAG_SYM;
+ break;
+ case 'v':
+ opt_v |= FLAG_VERBOSE;
+ break;
+ case 'e':
+ opt_e++;
+ break;
+ case 1:
+ if (lop < 0 || lop >= AFTRANS_CNT) {
+ EINTERN("route.c", "longopts 1 range");
+ break;
+ }
+ if ((i = aftrans_opt(longopts[lop].name)))
+ exit(i);
+ break;
+ case 'C':
+ opt_fc |= FLAG_CACHE;
+ break;
+ case 'F':
+ opt_fc |= FLAG_FIB;
+ break;
+ case 'A':
+ if ((i = aftrans_opt(optarg)))
+ exit(i);
+ break;
+ case 'V':
+ version();
+ case 'h':
+ case '?':
+ opt_h++;
+ break;
+ default:
+ usage();
}
- options = (opt_e & FLAG_EXT) | opt_n | opt_fc | opt_v;
- if (!opt_fc)
- options |= FLAG_FIB;
+ argv += optind;
+ argc -= optind;
- if (what == RTACTION_SHOW)
- i = route_info(afname,options);
+ if (opt_h) {
+ if (!afname[0])
+ usage();
else
- i = route_edit(what,afname,options,++argv);
+ what = RTACTION_HELP;
+ } else {
+ if (!afname[0])
+ /* this will initialise afname[] */
+ aftrans_def("route", progname, DFLT_AF);
- if (i == E_OPTERR)
+ /* Do we have to show the contents of the routing table? */
+ if (*argv == NULL) {
+ what = RTACTION_SHOW;
+ } else {
+ if (!strcmp(*argv, "add"))
+ what = RTACTION_ADD;
+ else if (!strcmp(*argv, "del") || !strcmp(*argv, "delete"))
+ what = RTACTION_DEL;
+ else if (!strcmp(*argv, "flush"))
+ what = RTACTION_FLUSH;
+ else
usage();
+ }
+ }
+
+ options = (opt_e & FLAG_EXT) | opt_n | opt_fc | opt_v;
+ if (!opt_fc)
+ options |= FLAG_FIB;
+
+ if (what == RTACTION_SHOW)
+ i = route_info(afname, options);
+ else
+ i = route_edit(what, afname, options, ++argv);
+
+ if (i == E_OPTERR)
+ usage();
- return (i);
+ return (i);
}
diff --git a/sockets.c b/sockets.c
index 3def961..35cb0e0 100644
--- a/sockets.c
+++ b/sockets.c
@@ -16,40 +16,40 @@
#include "util.h"
#include "net-support.h"
-int skfd = -1; /* generic raw socket desc. */
+int skfd = -1; /* generic raw socket desc. */
int sockets_open(int family)
{
- struct aftype **aft;
- int sfd = -1;
- static int force = -1;
+ struct aftype **aft;
+ int sfd = -1;
+ static int force = -1;
- if (force < 0) {
- force = 0;
- if (kernel_version() < KRELEASE(2,1,0))
- force = 1;
- if (access("/proc/net",R_OK))
- force = 1;
+ if (force < 0) {
+ force = 0;
+ if (kernel_version() < KRELEASE(2, 1, 0))
+ force = 1;
+ if (access("/proc/net", R_OK))
+ force = 1;
+ }
+ for (aft = aftypes; *aft; aft++) {
+ struct aftype *af = *aft;
+ if (af->af == AF_UNSPEC)
+ continue;
+ if (family && family != af->af)
+ continue;
+ if (af->fd != -1) {
+ sfd = af->fd;
+ continue;
}
- for (aft = aftypes; *aft; aft++) {
- struct aftype *af = *aft;
- if (af->af == AF_UNSPEC)
- continue;
- if (family && family != af->af)
- continue;
- if (af->fd != -1) {
- sfd = af->fd;
- continue;
- }
- /* Check some /proc file first to not stress kmod */
- if (!force && af->flag_file) {
- if (access(af->flag_file, R_OK))
- continue;
- }
- sfd = socket(af->af, SOCK_DGRAM, 0);
- af->fd = sfd;
- }
- if (sfd < 0)
- fprintf(stderr, _("No usable address families found.\n"));
- return sfd;
+ /* Check some /proc file first to not stress kmod */
+ if (!force && af->flag_file) {
+ if (access(af->flag_file, R_OK))
+ continue;
+ }
+ sfd = socket(af->af, SOCK_DGRAM, 0);
+ af->fd = sfd;
+ }
+ if (sfd < 0)
+ fprintf(stderr, _("No usable address families found.\n"));
+ return sfd;
}
diff --git a/sockets.h b/sockets.h
index f808074..74baacb 100644
--- a/sockets.h
+++ b/sockets.h
@@ -1,3 +1,4 @@
-extern int skfd, ipx_sock, ax25_sock, rose_sock, inet_sock, inet6_sock, ddp_sock, ec_sock;
+extern int skfd, ipx_sock, ax25_sock, rose_sock, inet_sock, inet6_sock,
+ ddp_sock, ec_sock;
extern int sockets_open(int family);
diff --git a/statistics.c b/statistics.c
index bc21be4..a5876af 100644
--- a/statistics.c
+++ b/statistics.c
@@ -1,11 +1,12 @@
/* Copyright '97 by Andi Kleen. Subject to the GPL. */
+/* $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> */
/*
XXX: rewrite to 2 pass to support /proc/net/netstat too
- support -t -u
- */
+ support -t -u
+ */
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
@@ -18,31 +19,36 @@
#ifdef WARN
#define UFWARN(x) x
#else
-#define UFWARN(x)
+#define UFWARN(x)
#endif
-int print_static;
+int print_static;
+
+enum State {
+ number = 0, i_forward, i_inp_icmp, i_outp_icmp, i_rto_alg
+};
-enum State { number = 0, i_forward, i_inp_icmp, i_outp_icmp, i_rto_alg };
#define normal number
struct entry {
- char *title;
- char *out;
- enum State type;
-};
+ char *title;
+ char *out;
+ enum State type;
+};
static enum State state;
-static int indent[] = { 4, 4, 8, 8, 4 }; /* for each state */
+static int indent[] =
+{4, 4, 8, 8, 4}; /* for each state */
-#define I_STATIC (1<<16) /* static configuration option. */
+#define I_STATIC (1<<16) /* static configuration option. */
#define I_TITLE (1<<17)
-char *titles[] = { /* for each state */
- NULL, NULL,
- N_("ICMP input histogram:"),
- N_("ICMP output histogram:"),
- NULL
+char *titles[] =
+{ /* for each state */
+ NULL, NULL,
+ N_("ICMP input histogram:"),
+ N_("ICMP output histogram:"),
+ NULL
};
/* XXX check against the snmp mib rfc.
@@ -50,237 +56,246 @@ char *titles[] = { /* for each state */
/*
Don't mark the first field as translatable! It's a snmp MIB standard.
- - acme
- */
-struct entry Iptab[] = {
- { "Forwarding", N_("Forwarding is %s"), i_forward|I_STATIC },
- { "DefaultTTL", N_("Default TTL is %d"), number|I_STATIC },
- { "InReceives", N_("%d total packets received"), number },
- { "InHdrErrors", N_("%d with invalid headers"), number },
- { "InAddrErrors", N_("%d with invalid addresses"), number },
- { "ForwDatagrams", N_("%d forwarded"), number },
- { "InUnknownProtos", N_("%d with unknown protocol"), number },
- { "InDiscards", N_("%d incoming packets discarded"), number },
- { "InDelivers", N_("%d incoming packets delivered"), number },
- { "OutRequests", N_("%d requests sent out"), number }, /*?*/
- { "OutDiscards", N_("%d outgoing packets dropped"), number },
- { "OutNoRoutes", N_("%d dropped because of missing route"), number },
- { "ReasmTimeout", N_("%d fragments dropped after timeout"), number },
- { "ReasmReqds", N_("%d reassemblies required"), number }, /* ? */
- { "ReasmOKs", N_("%d packets reassembled ok"), number },
- { "ReasmFails", N_("%d packet reassembles failed"), number },
- { "FragOKs", N_("%d fragments received ok"), number },
- { "FragFails", N_("%d fragments failed"), number },
- { "FragCreates", N_("%d fragments created"), number }
+ - acme
+ */
+struct entry Iptab[] =
+{
+ {"Forwarding", N_("Forwarding is %s"), i_forward | I_STATIC},
+ {"DefaultTTL", N_("Default TTL is %d"), number | I_STATIC},
+ {"InReceives", N_("%d total packets received"), number},
+ {"InHdrErrors", N_("%d with invalid headers"), number},
+ {"InAddrErrors", N_("%d with invalid addresses"), number},
+ {"ForwDatagrams", N_("%d forwarded"), number},
+ {"InUnknownProtos", N_("%d with unknown protocol"), number},
+ {"InDiscards", N_("%d incoming packets discarded"), number},
+ {"InDelivers", N_("%d incoming packets delivered"), number},
+ {"OutRequests", N_("%d requests sent out"), number}, /*? */
+ {"OutDiscards", N_("%d outgoing packets dropped"), number},
+ {"OutNoRoutes", N_("%d dropped because of missing route"), number},
+ {"ReasmTimeout", N_("%d fragments dropped after timeout"), number},
+ {"ReasmReqds", N_("%d reassemblies required"), number}, /* ? */
+ {"ReasmOKs", N_("%d packets reassembled ok"), number},
+ {"ReasmFails", N_("%d packet reassembles failed"), number},
+ {"FragOKs", N_("%d fragments received ok"), number},
+ {"FragFails", N_("%d fragments failed"), number},
+ {"FragCreates", N_("%d fragments created"), number}
};
-struct entry Icmptab[] = {
- { "InMsgs", N_("%d ICMP messages received"), number },
- { "InErrors", N_("%d input ICMP message failed."), number },
- { "InDestUnreachs", N_("destination unreachable: %d"), i_inp_icmp|I_TITLE },
- { "InTimeExcds", N_("timeout in transit: %d"), i_inp_icmp|I_TITLE },
- { "InParmProbs", N_("wrong parameters: %d"), i_inp_icmp|I_TITLE }, /*?*/
- { "InSrcQuenchs", N_("source quenchs: %d"), i_inp_icmp|I_TITLE },
- { "InRedirects", N_("redirects: %d"), i_inp_icmp|I_TITLE },
- { "InEchos", N_("echo requests: %d"), i_inp_icmp|I_TITLE },
- { "InEchoReps", N_("echo replies: %d"), i_inp_icmp|I_TITLE },
- { "InTimestamps", N_("timestamp request: %d"), i_inp_icmp|I_TITLE },
- { "InTimestampReps", N_("timestamp reply: %d"), i_inp_icmp|I_TITLE },
- { "InAddrMasks", N_("address mask request: %d"), i_inp_icmp|I_TITLE }, /*?*/
- { "InAddrMaskReps", N_("address mask replies"), i_inp_icmp|I_TITLE }, /*?*/
- { "OutMsgs", N_("%d ICMP messages sent"), number },
- { "OutErrors", N_("%d ICMP messages failed"), number },
- { "OutDestUnreachs", N_("destination unreachable: %d"), i_outp_icmp|I_TITLE },
- { "OutTimeExcds", N_("time exceeded: %d"), i_outp_icmp|I_TITLE },
- { "OutParmProbs", N_("wrong parameters: %d"), i_outp_icmp|I_TITLE }, /*?*/
- { "OutSrcQuenchs", N_("source quench: %d"), i_outp_icmp|I_TITLE },
- { "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 },
- { "OutAddrMaskReps", N_("address mask replies: %d"), i_outp_icmp|I_TITLE },
+struct entry Icmptab[] =
+{
+ {"InMsgs", N_("%d ICMP messages received"), number},
+ {"InErrors", N_("%d input ICMP message failed."), number},
+ {"InDestUnreachs", N_("destination unreachable: %d"), i_inp_icmp | I_TITLE},
+ {"InTimeExcds", N_("timeout in transit: %d"), i_inp_icmp | I_TITLE},
+ {"InParmProbs", N_("wrong parameters: %d"), i_inp_icmp | I_TITLE}, /*? */
+ {"InSrcQuenchs", N_("source quenchs: %d"), i_inp_icmp | I_TITLE},
+ {"InRedirects", N_("redirects: %d"), i_inp_icmp | I_TITLE},
+ {"InEchos", N_("echo requests: %d"), i_inp_icmp | I_TITLE},
+ {"InEchoReps", N_("echo replies: %d"), i_inp_icmp | I_TITLE},
+ {"InTimestamps", N_("timestamp request: %d"), i_inp_icmp | I_TITLE},
+ {"InTimestampReps", N_("timestamp reply: %d"), i_inp_icmp | I_TITLE},
+ {"InAddrMasks", N_("address mask request: %d"), i_inp_icmp | I_TITLE}, /*? */
+ {"InAddrMaskReps", N_("address mask replies"), i_inp_icmp | I_TITLE}, /*? */
+ {"OutMsgs", N_("%d ICMP messages sent"), number},
+ {"OutErrors", N_("%d ICMP messages failed"), number},
+ {"OutDestUnreachs", N_("destination unreachable: %d"), i_outp_icmp | I_TITLE},
+ {"OutTimeExcds", N_("time exceeded: %d"), i_outp_icmp | I_TITLE},
+ {"OutParmProbs", N_("wrong parameters: %d"), i_outp_icmp | I_TITLE}, /*? */
+ {"OutSrcQuenchs", N_("source quench: %d"), i_outp_icmp | I_TITLE},
+ {"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},
+ {"OutAddrMaskReps", N_("address mask replies: %d"), i_outp_icmp | I_TITLE},
};
-struct entry Tcptab[] = {
- { "RtoAlgorithm", N_("RTO algorithm is %s"), i_rto_alg|I_STATIC },
- { "RtoMin", "", number },
- { "RtoMax", "", number },
- { "MaxConn", "", number },
- { "ActiveOpens", N_("%d active opens"), number },
- { "PassiveOpens", N_("%d passive opens"), number },
- { "AttemptFails", N_("%d failed connection attempts"), number },
- { "EstabResets", N_("%d connection resets received"), number },
- { "CurrEstab", N_("%d connections established"), number },
- { "InSegs", N_("%d segments received"), number },
- { "OutSegs", N_("%d segments send out"), number },
- { "RetransSegs", N_("%d segments retransmited"), number },
- { "InErrs", N_("%d bad segments received."), number },
- { "OutRsts", N_("%d resets sent"), number },
+struct entry Tcptab[] =
+{
+ {"RtoAlgorithm", N_("RTO algorithm is %s"), i_rto_alg | I_STATIC},
+ {"RtoMin", "", number},
+ {"RtoMax", "", number},
+ {"MaxConn", "", number},
+ {"ActiveOpens", N_("%d active opens"), number},
+ {"PassiveOpens", N_("%d passive opens"), number},
+ {"AttemptFails", N_("%d failed connection attempts"), number},
+ {"EstabResets", N_("%d connection resets received"), number},
+ {"CurrEstab", N_("%d connections established"), number},
+ {"InSegs", N_("%d segments received"), number},
+ {"OutSegs", N_("%d segments send out"), number},
+ {"RetransSegs", N_("%d segments retransmited"), number},
+ {"InErrs", N_("%d bad segments received."), number},
+ {"OutRsts", N_("%d resets sent"), number},
};
-struct entry Udptab[] = {
- { "InDatagrams", N_("%d packets received"), number },
- { "NoPorts", N_("%d packets to unknown port received."), number },
- { "InErrors", N_("%d packet receive errors"), number },
- { "OutDatagrams", N_("%d packets send"), number },
+struct entry Udptab[] =
+{
+ {"InDatagrams", N_("%d packets received"), number},
+ {"NoPorts", N_("%d packets to unknown port received."), number},
+ {"InErrors", N_("%d packet receive errors"), number},
+ {"OutDatagrams", N_("%d packets send"), number},
};
struct tabtab {
- char *title;
- struct entry *tab;
- size_t size;
-};
-
-struct tabtab snmptabs[] = {
- { "Ip", Iptab, sizeof(Iptab) },
- { "Icmp", Icmptab, sizeof(Icmptab) },
- { "Tcp", Tcptab, sizeof(Tcptab) },
- { "Udp", Udptab, sizeof(Udptab) },
- { NULL }
-};
+ char *title;
+ struct entry *tab;
+ size_t size;
+};
+
+struct tabtab snmptabs[] =
+{
+ {"Ip", Iptab, sizeof(Iptab)},
+ {"Icmp", Icmptab, sizeof(Icmptab)},
+ {"Tcp", Tcptab, sizeof(Tcptab)},
+ {"Udp", Udptab, sizeof(Udptab)},
+ {NULL}
+};
static char *skiptok(char *s)
{
- while (!isspace(*s) && *s != '\0')
- s++;
- return s;
+ while (!isspace(*s) && *s != '\0')
+ s++;
+ return s;
}
-/* XXX IGMP */
+/* XXX IGMP */
int cmpentries(const void *a, const void *b)
{
- return strcmp( ((struct entry*)a)->title, ((struct entry*)b)->title);
+ return strcmp(((struct entry *) a)->title, ((struct entry *) b)->title);
}
-void printval(struct tabtab *tab, char *title, int val)
+void printval(struct tabtab *tab, char *title, int val)
{
- struct entry *ent, key;
- int type;
- char buf[512];
-
- key.title = title;
- ent = bsearch(&key, tab->tab, tab->size/sizeof(struct entry),
- sizeof(struct entry), cmpentries);
- if (!ent) { /* try our best */
- printf("%*s%s: %d\n", indent[state], "", title, val);
- return;
- }
- type = ent->type;
- if (type & I_STATIC) {
- type &= ~I_STATIC;
- if (!print_static)
- return;
- }
- if (*ent->out == '\0')
- return;
-
- if (type & I_TITLE) {
- type &= ~I_TITLE;
- if (state != type)
- printf("%*s%s\n", indent[state], "", _(titles[type]));
- }
-
- buf[0] = '\0';
- switch (type) {
- case number:
- snprintf(buf, sizeof(buf), _(ent->out), val);
- break;
- case i_forward:
- type = normal;
- snprintf(buf, sizeof(buf), _(ent->out), val == 2 ? _("enabled") : _("disabled"));
- break;
- case i_outp_icmp:
- case i_inp_icmp:
- if (val > 0)
- snprintf(buf, sizeof(buf), _(ent->out), val);
- break;
- case i_rto_alg: /* XXXX */
- break;
- default:
- abort();
- }
- if (buf[0])
- printf("%*s%s\n",indent[type],"", buf);
-
- state = type;
+ struct entry *ent, key;
+ int type;
+ char buf[512];
+
+ key.title = title;
+ ent = bsearch(&key, tab->tab, tab->size / sizeof(struct entry),
+ sizeof(struct entry), cmpentries);
+ if (!ent) { /* try our best */
+ printf("%*s%s: %d\n", indent[state], "", title, val);
+ return;
+ }
+ type = ent->type;
+ if (type & I_STATIC) {
+ type &= ~I_STATIC;
+ if (!print_static)
+ return;
+ }
+ if (*ent->out == '\0')
+ return;
+
+ if (type & I_TITLE) {
+ type &= ~I_TITLE;
+ if (state != type)
+ printf("%*s%s\n", indent[state], "", _(titles[type]));
+ }
+ buf[0] = '\0';
+ switch (type) {
+ case number:
+ snprintf(buf, sizeof(buf), _(ent->out), val);
+ break;
+ case i_forward:
+ type = normal;
+ snprintf(buf, sizeof(buf), _(ent->out), val == 2 ? _("enabled") : _("disabled"));
+ break;
+ case i_outp_icmp:
+ case i_inp_icmp:
+ if (val > 0)
+ snprintf(buf, sizeof(buf), _(ent->out), val);
+ break;
+ case i_rto_alg: /* XXXX */
+ break;
+ default:
+ abort();
+ }
+ if (buf[0])
+ printf("%*s%s\n", indent[type], "", buf);
+
+ state = type;
}
-struct tabtab *newtable(struct tabtab *tabs, char *title)
+struct tabtab *newtable(struct tabtab *tabs, char *title)
{
- struct tabtab *t;
-
- for (t = tabs; t->title; t++)
- if (!strcmp(title, t->title)) {
- printf("%s:\n", _(title));
- state = normal;
- return t;
- }
- return NULL;
+ struct tabtab *t;
+
+ for (t = tabs; t->title; t++)
+ if (!strcmp(title, t->title)) {
+ printf("%s:\n", _(title));
+ state = normal;
+ return t;
+ }
+ return NULL;
}
void parsesnmp()
{
- 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;
+ 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;
+
+ if (!fgets(buf2, sizeof buf2, f))
+ break;
+ sp = strchr(buf1, ':');
+ np = strchr(buf2, ':');
+ if (!np || !sp)
+ goto formaterr;
+ *sp = '\0';
+ tab = newtable(snmptabs, buf1);
+ if (tab == NULL) {
+ UFWARN((printf(_("unknown title %s\n"), buf1)));
+ continue;
}
- while (fgets(buf1,sizeof buf1,f)) {
- int endflag;
- struct tabtab *tab;
-
- if (!fgets(buf2,sizeof buf2,f)) break;
- sp = strchr(buf1, ':');
- np = strchr(buf2, ':');
- if (!np || !sp)
- goto formaterr;
- *sp = '\0';
- tab = newtable(snmptabs, buf1);
- if (tab == NULL) {
- UFWARN((printf(_("unknown title %s\n"), buf1)));
- continue;
- }
- np++; sp++;
-
- endflag = 0;
- while (!endflag) {
- while(isspace(*sp)) sp++;
- while(isspace(*np)) np++;
- /*if (*np == '\0') goto formaterr;*/
-
- p = skiptok(sp);
- if (*p == '\0') endflag=1;
- *p = '\0';
-
- if (*sp != '\0') /* XXX */
- printval(tab, sp, strtoul(np,&np,10));
- sp = p+1;
- }
+ np++;
+ sp++;
+
+ endflag = 0;
+ while (!endflag) {
+ while (isspace(*sp))
+ sp++;
+ while (isspace(*np))
+ np++;
+ /*if (*np == '\0') goto formaterr; */
+
+ p = skiptok(sp);
+ if (*p == '\0')
+ endflag = 1;
+ *p = '\0';
+
+ if (*sp != '\0') /* XXX */
+ printval(tab, sp, strtoul(np, &np, 10));
+ sp = p + 1;
}
- if (ferror(f))
- perror("/proc/net/snmp");
- fclose(f);
- return;
-
-formaterr:
- perror(_("error parsing /proc/net/snmp"));
- return;
+ }
+ if (ferror(f))
+ perror("/proc/net/snmp");
+ fclose(f);
+ return;
+
+ formaterr:
+ perror(_("error parsing /proc/net/snmp"));
+ return;
}
void inittab()
{
- struct tabtab *t;
-
- /* we sort at runtime because I'm lazy ;) */
- for (t = snmptabs; t->title; t++)
- qsort(t->tab, t->size/sizeof(struct entry),
- sizeof(struct entry), cmpentries);
+ struct tabtab *t;
+
+ /* we sort at runtime because I'm lazy ;) */
+ for (t = snmptabs; t->title; t++)
+ qsort(t->tab, t->size / sizeof(struct entry),
+ sizeof(struct entry), cmpentries);
}