Commit 90da8a01 authored by Bernard Pidoux's avatar Bernard Pidoux Committed by Mike Frysinger

netstat: improve ROSE support

Netstat is not handling properly ROSE kernel nodes and neighbour tables.
This patch add /proc/net/rose/nodes and /proc/net/rose/neigh display in
rose_gr.c.
Code is using the same style as NetRom and AX.25 hamradio options.

This code was written in 1999 and it is operational on my AX.25 Raspbian
Linux distro dor RapsBerry Pi for years.
Committed patch is against last net-tools-2.10-alpha snapshot on
sourceforge.
parent aab9274b
......@@ -48,6 +48,9 @@
#define _PATH_PROCNET_DEV "/proc/net/dev"
#define _PATH_PROCNET_RARP "/proc/net/rarp"
#define _PATH_ETHERS "/etc/ethers"
#define _PATH_PROCNET_ROSE "/proc/net/rose"
#define _PATH_PROCNET_ROSE_NEIGH "/proc/net/rose_neigh"
#define _PATH_PROCNET_ROSE_NODES "/proc/net/rose_nodes"
#define _PATH_PROCNET_ROSE_ROUTE "/proc/net/rose_routes"
#define _PATH_PROCNET_X25 "/proc/net/x25"
#define _PATH_PROCNET_X25_ROUTE "/proc/net/x25/route"
......
......@@ -11,6 +11,9 @@
* Copyright 1999 Bernd Eckenfels, Germany
* base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK>
*
* Bernard Pidoux f6bvp@amsat.org added ROSE_NEIGH proc
* completing ROSE routing table - November 2009.
*
* 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
......@@ -41,28 +44,48 @@
int ROSE_rprint(int options)
{
FILE *f = NULL;
char buffer[256];
int use;
FILE *f1, *f2;
char buffer1[256], buffer2[256];
int i, neigh, use;
f=fopen(_PATH_PROCNET_ROSE_ROUTE, "r");
if (f == NULL) {
perror(_PATH_PROCNET_ROSE_ROUTE);
printf(_("ROSE not configured in this system.\n")); /* xxx */
f2 = fopen(_PATH_PROCNET_ROSE_NEIGH, "r");
f1 = fopen(_PATH_PROCNET_ROSE_NODES, "r");
if (f1 == NULL) {
perror(_PATH_PROCNET_ROSE_NODES);
fprintf(stderr, _("ROSE not configured in this system.\n")); /* xxx */
return 1;
}
printf(_("Kernel ROSE routing table\n"));
printf(_("Destination Iface Use\n"));
if (fgets(buffer, 256, f))
printf(_("Destination neigh1 callsign device neigh2 callsign device neigh3 callsign device\n"));
if (fgets(buffer1, 256, f1))
/* eat line */;
while (fgets(buffer, 256, f)) {
buffer[9] = 0;
buffer[14] = 0;
use = atoi(buffer + 15);
printf("%-9s %-5s %5d\n",
buffer, buffer + 10, use);
while (fgets(buffer1, 256, f1)) {
buffer1[10] = 0; /* address */
buffer1[15] = 0; /* mask */
buffer1[17] = 0; /* use */
buffer1[23] = 0; /* neigh 1 */
buffer1[29] = 0; /* neigh 2 */
buffer1[35] = 0; /* neigh 3 */
use = atoi(buffer1 + 16);
neigh = atoi(buffer1 + 18);
printf("%-10s ", buffer1);
for (i = 0; i < use; i++) {
neigh = atoi(buffer1 + 6 * (i + 3));
printf("%05d ", neigh);
rewind(f2);
if (fgets(buffer2, 256, f2))
/* eat line */;
while (fgets(buffer2, 256, f2)) {
buffer2[15] = 0;
buffer2[21] = 0;
if (atoi(buffer2) == neigh)
printf("%-10s %-4s", buffer2 + 6, buffer2 + 16);
}
}
printf("\n");
}
fclose(f);
fclose(f1);
fclose(f2);
return 0;
}
......
......@@ -555,6 +555,55 @@ static int netrom_info(void)
}
#endif
#if HAVE_AFROSE
static const char * const rose_state[] =
{
N_("LISTENING"),
N_("CONN SENT"),
N_("DISC SENT"),
N_("ESTABLISHED"),
};
static int rose_info(void)
{
FILE *f;
char buffer[256], dev[6];
int ret, st, lci, neigh;
char src_addr[10], src_call[9], dest_addr[10], dest_call[9];
f = fopen(_PATH_PROCNET_ROSE, "r");
if (f == NULL) {
if (errno != ENOENT) {
perror(_PATH_PROCNET_ROSE);
return (-1);
}
if (flag_arg || flag_ver)
ESYSNOT("netstat", "AF ROSE");
if (flag_arg)
return (1);
else
return (0);
}
printf(_("Active ROSE sockets\n"));
printf(_("dest_addr dest_call src_addr src_call dev lci neigh state\n"));
if (fgets(buffer, 256, f))
/* eat line */;
while (fgets(buffer, 256, f)) {
ret = sscanf(buffer, "%s %s %s %s %s %d %d %d",
dest_addr, dest_call, src_addr, src_call, dev, &lci, &neigh, &st);
if (ret != 8) {
printf(_("Problem reading data from %s\n"), _PATH_PROCNET_ROSE);
continue;
}
printf("%-10s %-9s %-10s %-9s %-5s %3d %5d %s\n",
dest_addr, dest_call, src_addr, src_call, dev, lci, neigh, _(rose_state[st]));
}
fclose(f);
return 0;
}
#endif
/* These enums are used by IPX too. :-( */
enum {
TCP_ESTABLISHED = 1,
......@@ -2369,7 +2418,7 @@ int main
#endif
}
if (!flag_arg || flag_rose) {
#if 0 && HAVE_AFROSE
#if HAVE_AFROSE
i = rose_info();
if (i)
return (i);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment