|
|
1c4448 |
diff -up net-tools-2.0/lib/interface.c.cycle net-tools-2.0/lib/interface.c
|
|
|
1c4448 |
--- net-tools-2.0/lib/interface.c.cycle 2016-02-15 16:54:18.000000000 +0100
|
|
|
1c4448 |
+++ net-tools-2.0/lib/interface.c 2016-03-30 09:58:18.247891588 +0200
|
|
|
1c4448 |
@@ -93,6 +93,7 @@ int if_list_all = 0; /* do we have reque
|
|
|
1c4448 |
static struct interface *int_list, *int_last;
|
|
|
1c4448 |
|
|
|
1c4448 |
static int if_readlist_proc(const char *);
|
|
|
1c4448 |
+static int if_readlist_rep(const char *, struct interface *);
|
|
|
1c4448 |
|
|
|
1c4448 |
static struct interface *if_cache_add(const char *name)
|
|
|
1c4448 |
{
|
|
|
1c4448 |
@@ -138,11 +139,14 @@ struct interface *lookup_interface(const
|
|
|
1c4448 |
int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie)
|
|
|
1c4448 |
{
|
|
|
1c4448 |
struct interface *ife;
|
|
|
1c4448 |
+ int err;
|
|
|
1c4448 |
|
|
|
1c4448 |
if (!if_list_all && (if_readlist() < 0))
|
|
|
1c4448 |
return -1;
|
|
|
1c4448 |
for (ife = int_list; ife; ife = ife->next) {
|
|
|
1c4448 |
- int err = doit(ife, cookie);
|
|
|
1c4448 |
+ if_readlist_rep(ife->name, ife);
|
|
|
1c4448 |
+ err = doit(ife, cookie);
|
|
|
1c4448 |
+
|
|
|
1c4448 |
if (err)
|
|
|
1c4448 |
return err;
|
|
|
1c4448 |
}
|
|
|
1c4448 |
@@ -210,16 +214,24 @@ out:
|
|
|
1c4448 |
return err;
|
|
|
1c4448 |
}
|
|
|
1c4448 |
|
|
|
1c4448 |
-static const char *get_name(char *name, const char *p)
|
|
|
1c4448 |
+static const char *get_name(char **namep, const char *p)
|
|
|
1c4448 |
{
|
|
|
1c4448 |
+ int count = 0;
|
|
|
1c4448 |
while (isspace(*p))
|
|
|
1c4448 |
p++;
|
|
|
1c4448 |
+ char *name = *namep = p;
|
|
|
1c4448 |
while (*p) {
|
|
|
1c4448 |
if (isspace(*p))
|
|
|
1c4448 |
break;
|
|
|
1c4448 |
if (*p == ':') { /* could be an alias */
|
|
|
1c4448 |
const char *dot = p++;
|
|
|
1c4448 |
- while (*p && isdigit(*p)) p++;
|
|
|
1c4448 |
+ count++;
|
|
|
1c4448 |
+ while (*p && isdigit(*p)) {
|
|
|
1c4448 |
+ p++;
|
|
|
1c4448 |
+ count++;
|
|
|
1c4448 |
+ if (count == (IFNAMSIZ-1))
|
|
|
1c4448 |
+ break;
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
if (*p == ':') {
|
|
|
1c4448 |
/* Yes it is, backup and copy it. */
|
|
|
1c4448 |
p = dot;
|
|
|
1c4448 |
@@ -235,6 +247,9 @@ static const char *get_name(char *name,
|
|
|
1c4448 |
break;
|
|
|
1c4448 |
}
|
|
|
1c4448 |
*name++ = *p++;
|
|
|
1c4448 |
+ count++;
|
|
|
1c4448 |
+ if (count == (IFNAMSIZ-1))
|
|
|
1c4448 |
+ break;
|
|
|
1c4448 |
}
|
|
|
1c4448 |
*name++ = '\0';
|
|
|
1c4448 |
return p;
|
|
|
1c4448 |
@@ -316,9 +331,10 @@ static int get_dev_fields(const char *bp
|
|
|
1c4448 |
static int if_readlist_proc(const char *target)
|
|
|
1c4448 |
{
|
|
|
1c4448 |
FILE *fh;
|
|
|
1c4448 |
- char buf[512];
|
|
|
1c4448 |
struct interface *ife;
|
|
|
1c4448 |
int err;
|
|
|
1c4448 |
+ char *line = NULL;
|
|
|
1c4448 |
+ size_t linelen = 0;
|
|
|
1c4448 |
|
|
|
1c4448 |
fh = fopen(_PATH_PROCNET_DEV, "r");
|
|
|
1c4448 |
if (!fh) {
|
|
|
1c4448 |
@@ -326,10 +342,11 @@ static int if_readlist_proc(const char *
|
|
|
1c4448 |
_PATH_PROCNET_DEV, strerror(errno));
|
|
|
1c4448 |
return -2;
|
|
|
1c4448 |
}
|
|
|
1c4448 |
- if (fgets(buf, sizeof buf, fh))
|
|
|
1c4448 |
- /* eat line */;
|
|
|
1c4448 |
- if (fgets(buf, sizeof buf, fh))
|
|
|
1c4448 |
- /* eat line */;
|
|
|
1c4448 |
+ if (getline(&line, &linelen, fh) == -1 /* eat line */
|
|
|
1c4448 |
+ || getline(&line, &linelen, fh) == -1) { /* eat line */
|
|
|
1c4448 |
+ err = -1;
|
|
|
1c4448 |
+ goto out;
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
|
|
|
1c4448 |
#if 0 /* pretty, but can't cope with missing fields */
|
|
|
1c4448 |
fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh,
|
|
|
1c4448 |
@@ -354,14 +371,14 @@ static int if_readlist_proc(const char *
|
|
|
1c4448 |
if (!fmt)
|
|
|
1c4448 |
return -1;
|
|
|
1c4448 |
#else
|
|
|
1c4448 |
- procnetdev_vsn = procnetdev_version(buf);
|
|
|
1c4448 |
+ procnetdev_vsn = procnetdev_version(line);
|
|
|
1c4448 |
#endif
|
|
|
1c4448 |
|
|
|
1c4448 |
err = 0;
|
|
|
1c4448 |
- while (fgets(buf, sizeof buf, fh)) {
|
|
|
1c4448 |
+ while (getline(&line, &linelen, fh) != -1) {
|
|
|
1c4448 |
const char *s;
|
|
|
1c4448 |
- char name[IFNAMSIZ];
|
|
|
1c4448 |
- s = get_name(name, buf);
|
|
|
1c4448 |
+ char *name;
|
|
|
1c4448 |
+ s = get_name(&name, line);
|
|
|
1c4448 |
ife = if_cache_add(name);
|
|
|
1c4448 |
get_dev_fields(s, ife);
|
|
|
1c4448 |
ife->statistics_valid = 1;
|
|
|
1c4448 |
@@ -376,6 +393,51 @@ static int if_readlist_proc(const char *
|
|
|
1c4448 |
#if 0
|
|
|
1c4448 |
free(fmt);
|
|
|
1c4448 |
#endif
|
|
|
1c4448 |
+ out:
|
|
|
1c4448 |
+ free(line);
|
|
|
1c4448 |
+ fclose(fh);
|
|
|
1c4448 |
+ return err;
|
|
|
1c4448 |
+}
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+static int if_readlist_rep(const char *target, struct interface *ife)
|
|
|
1c4448 |
+{
|
|
|
1c4448 |
+ FILE *fh;
|
|
|
1c4448 |
+ int err;
|
|
|
1c4448 |
+ char *line = NULL;
|
|
|
1c4448 |
+ size_t linelen = 0;
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ fh = fopen(_PATH_PROCNET_DEV, "r");
|
|
|
1c4448 |
+ if (!fh) {
|
|
|
1c4448 |
+ fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"),
|
|
|
1c4448 |
+ _PATH_PROCNET_DEV, strerror(errno));
|
|
|
1c4448 |
+ return if_readconf();
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+ if (getline(&line, &linelen, fh) == -1 /* eat line */
|
|
|
1c4448 |
+ || getline(&line, &linelen, fh) == -1) { /* eat line */
|
|
|
1c4448 |
+ err = -1;
|
|
|
1c4448 |
+ goto out;
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ procnetdev_vsn = procnetdev_version(line);
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ err = 0;
|
|
|
1c4448 |
+ while (getline(&line, &linelen, fh) != -1) {
|
|
|
1c4448 |
+ char *s, *name;
|
|
|
1c4448 |
+ s = get_name(&name, line);
|
|
|
1c4448 |
+ get_dev_fields(s, ife);
|
|
|
1c4448 |
+ if (target && !strcmp(target,name))
|
|
|
1c4448 |
+ {
|
|
|
1c4448 |
+ ife->statistics_valid = 1;
|
|
|
1c4448 |
+ break;
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+ if (ferror(fh)) {
|
|
|
1c4448 |
+ perror(_PATH_PROCNET_DEV);
|
|
|
1c4448 |
+ err = -1;
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ out:
|
|
|
1c4448 |
+ free(line);
|
|
|
1c4448 |
fclose(fh);
|
|
|
1c4448 |
return err;
|
|
|
1c4448 |
}
|
|
|
1c4448 |
diff -up net-tools-2.0/man/en_US/netstat.8.cycle net-tools-2.0/man/en_US/netstat.8
|
|
|
1c4448 |
--- net-tools-2.0/man/en_US/netstat.8.cycle 2016-02-15 16:54:18.000000000 +0100
|
|
|
1c4448 |
+++ net-tools-2.0/man/en_US/netstat.8 2016-03-30 09:58:18.241891637 +0200
|
|
|
1c4448 |
@@ -36,6 +36,7 @@ netstat \- Print network connections, ro
|
|
|
1c4448 |
.RB [ \-\-verbose | \-v ]
|
|
|
1c4448 |
.RB [ \-\-continuous | \-c]
|
|
|
1c4448 |
.RB [ \-\-wide | \-W ]
|
|
|
1c4448 |
+.RB [delay]
|
|
|
1c4448 |
.P
|
|
|
1c4448 |
.B netstat
|
|
|
1c4448 |
.RB { \-\-route | \-r }
|
|
|
1c4448 |
@@ -45,22 +46,25 @@ netstat \- Print network connections, ro
|
|
|
1c4448 |
.RB [ \-\-numeric | \-n ]
|
|
|
1c4448 |
.RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ]
|
|
|
1c4448 |
.RB [ \-\-continuous | \-c ]
|
|
|
1c4448 |
+.RB [delay]
|
|
|
1c4448 |
.P
|
|
|
1c4448 |
.B netstat
|
|
|
1c4448 |
-.RB { \-\-interfaces | \-i }
|
|
|
1c4448 |
+.RB { \-\-interfaces | \-I | \-i }
|
|
|
1c4448 |
.RB [ \-\-all | \-a ]
|
|
|
1c4448 |
-.RB [ \-\-extend | \-e [ \-\-extend | \-e] ]
|
|
|
1c4448 |
+.RB [ \-\-extend | \-e ]
|
|
|
1c4448 |
.RB [ \-\-verbose | \-v ]
|
|
|
1c4448 |
.RB [ \-\-program | \-p ]
|
|
|
1c4448 |
.RB [ \-\-numeric | \-n ]
|
|
|
1c4448 |
.RB [ \-\-numeric-hosts "] [" \-\-numeric-ports "] [" \-\-numeric-users ]
|
|
|
1c4448 |
.RB [ \-\-continuous | \-c ]
|
|
|
1c4448 |
+.RB [delay]
|
|
|
1c4448 |
.P
|
|
|
1c4448 |
.B netstat
|
|
|
1c4448 |
.RB { \-\-groups | \-g }
|
|
|
1c4448 |
.RB [ \-\-numeric | \-n ]
|
|
|
1c4448 |
.RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ]
|
|
|
1c4448 |
.RB [ \-\-continuous | \-c ]
|
|
|
1c4448 |
+.RB [delay]
|
|
|
1c4448 |
.P
|
|
|
1c4448 |
.B netstat
|
|
|
1c4448 |
.RB { \-\-masquerade | \-M }
|
|
|
1c4448 |
@@ -68,6 +72,7 @@ netstat \- Print network connections, ro
|
|
|
1c4448 |
.RB [ \-\-numeric | \-n ]
|
|
|
1c4448 |
.RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ]
|
|
|
1c4448 |
.RB [ \-\-continuous | \-c ]
|
|
|
1c4448 |
+.RB [delay]
|
|
|
1c4448 |
.P
|
|
|
1c4448 |
.B netstat
|
|
|
1c4448 |
.RB { \-\-statistics | -s }
|
|
|
1c4448 |
@@ -76,6 +81,7 @@ netstat \- Print network connections, ro
|
|
|
1c4448 |
.RB [ \-\-udplite | \-U ]
|
|
|
1c4448 |
.RB [ \-\-sctp | \-S ]
|
|
|
1c4448 |
.RB [ \-\-raw | \-w ]
|
|
|
1c4448 |
+.RB [delay]
|
|
|
1c4448 |
.P
|
|
|
1c4448 |
.B netstat
|
|
|
1c4448 |
.RB { \-\-version | \-V }
|
|
|
1c4448 |
@@ -128,8 +134,8 @@ and
|
|
|
1c4448 |
produce the same output.
|
|
|
1c4448 |
.SS "\-\-groups, \-g"
|
|
|
1c4448 |
Display multicast group membership information for IPv4 and IPv6.
|
|
|
1c4448 |
-.SS "\-\-interfaces, \-i"
|
|
|
1c4448 |
-Display a table of all network interfaces.
|
|
|
1c4448 |
+.SS "\-\-interfaces=\fIiface \fR, \fB\-I=\fIiface \fR, \fB\-i"
|
|
|
1c4448 |
+Display a table of all network interfaces, or the specified \fIiface\fR.
|
|
|
1c4448 |
.SS "\-\-masquerade, \-M"
|
|
|
1c4448 |
Display a list of masqueraded connections.
|
|
|
1c4448 |
.SS "\-\-statistics, \-s"
|
|
|
1c4448 |
@@ -201,13 +207,18 @@ Show the PID and name of the program to
|
|
|
1c4448 |
.SS "\-l, \-\-listening"
|
|
|
1c4448 |
Show only listening sockets. (These are omitted by default.)
|
|
|
1c4448 |
.SS "\-a, \-\-all"
|
|
|
1c4448 |
-Show both listening and non-listening sockets. With the
|
|
|
1c4448 |
+Show both listening and non-listening (for TCP this means established
|
|
|
1c4448 |
+connections) sockets. With the
|
|
|
1c4448 |
.B \-\-interfaces
|
|
|
1c4448 |
option, show interfaces that are not up
|
|
|
1c4448 |
.SS "\-F"
|
|
|
1c4448 |
Print routing information from the FIB. (This is the default.)
|
|
|
1c4448 |
.SS "\-C"
|
|
|
1c4448 |
Print routing information from the route cache.
|
|
|
1c4448 |
+.SS delay
|
|
|
1c4448 |
+Netstat will cycle printing through statistics every
|
|
|
1c4448 |
+.B delay
|
|
|
1c4448 |
+seconds.
|
|
|
1c4448 |
.P
|
|
|
1c4448 |
.SH OUTPUT
|
|
|
1c4448 |
.P
|
|
|
1c4448 |
diff -up net-tools-2.0/netstat.c.cycle net-tools-2.0/netstat.c
|
|
|
1c4448 |
--- net-tools-2.0/netstat.c.cycle 2016-02-15 16:54:18.000000000 +0100
|
|
|
1c4448 |
+++ net-tools-2.0/netstat.c 2016-03-30 10:04:07.617171984 +0200
|
|
|
1c4448 |
@@ -115,8 +115,8 @@
|
|
|
1c4448 |
#endif
|
|
|
1c4448 |
|
|
|
1c4448 |
/* prototypes for statistics.c */
|
|
|
1c4448 |
-void parsesnmp(int, int, int, int);
|
|
|
1c4448 |
-void parsesnmp6(int, int, int);
|
|
|
1c4448 |
+int parsesnmp(int, int, int, int);
|
|
|
1c4448 |
+int parsesnmp6(int, int, int);
|
|
|
1c4448 |
|
|
|
1c4448 |
typedef enum {
|
|
|
1c4448 |
SS_FREE = 0, /* not allocated */
|
|
|
1c4448 |
@@ -142,6 +142,7 @@ static char *Release = RELEASE, *Signatu
|
|
|
1c4448 |
#define E_IOCTL -3
|
|
|
1c4448 |
|
|
|
1c4448 |
int flag_int = 0;
|
|
|
1c4448 |
+char *flag_int_name = NULL;
|
|
|
1c4448 |
int flag_rou = 0;
|
|
|
1c4448 |
int flag_mas = 0;
|
|
|
1c4448 |
int flag_sta = 0;
|
|
|
1c4448 |
@@ -340,10 +341,10 @@ static void prg_cache_clear(void)
|
|
|
1c4448 |
prg_cache_loaded = 0;
|
|
|
1c4448 |
}
|
|
|
1c4448 |
|
|
|
1c4448 |
-static void wait_continous(void)
|
|
|
1c4448 |
+static void wait_continous(int reptimer)
|
|
|
1c4448 |
{
|
|
|
1c4448 |
fflush(stdout);
|
|
|
1c4448 |
- sleep(1);
|
|
|
1c4448 |
+ sleep(reptimer);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
|
|
|
1c4448 |
static int extract_type_1_socket_inode(const char lname[], unsigned long * inode_p) {
|
|
|
1c4448 |
@@ -501,6 +502,121 @@ static void prg_cache_load(void)
|
|
|
1c4448 |
" will not be shown, you would have to be root to see it all.)\n"));
|
|
|
1c4448 |
}
|
|
|
1c4448 |
|
|
|
1c4448 |
+#define TCP_HASH_SIZE 1009
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+static struct tcp_node {
|
|
|
1c4448 |
+ struct tcp_node *next;
|
|
|
1c4448 |
+ char *socket_pair;
|
|
|
1c4448 |
+} *tcp_node_hash[TCP_HASH_SIZE];
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+static unsigned int tcp_node_compute_string_hash(const char *p)
|
|
|
1c4448 |
+{
|
|
|
1c4448 |
+ unsigned int h = *p;
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ if (h)
|
|
|
1c4448 |
+ for (p += 1; *p != '\0'; p++)
|
|
|
1c4448 |
+ h = (h << 5) - h + *p;
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ return h;
|
|
|
1c4448 |
+}
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+#define TCP_NODE_HASH_STRING(x) \
|
|
|
1c4448 |
+ (tcp_node_compute_string_hash(x) % TCP_HASH_SIZE)
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+static void tcp_node_hash_clear(void)
|
|
|
1c4448 |
+{
|
|
|
1c4448 |
+ int i;
|
|
|
1c4448 |
+ struct tcp_node *next_node;
|
|
|
1c4448 |
+ struct tcp_node *tmp_node;
|
|
|
1c4448 |
+ for (i=0; i < TCP_HASH_SIZE; i++) {
|
|
|
1c4448 |
+ if (tcp_node_hash[i]) {
|
|
|
1c4448 |
+ /* free the children of this hash bucket */
|
|
|
1c4448 |
+ next_node = tcp_node_hash[i]->next;
|
|
|
1c4448 |
+ while (next_node) {
|
|
|
1c4448 |
+ tmp_node = next_node;
|
|
|
1c4448 |
+ next_node = next_node->next;
|
|
|
1c4448 |
+ free(tmp_node->socket_pair);
|
|
|
1c4448 |
+ free(tmp_node);
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ /* free the bucket itself */
|
|
|
1c4448 |
+ free(tcp_node_hash[i]->socket_pair);
|
|
|
1c4448 |
+ free(tcp_node_hash[i]);
|
|
|
1c4448 |
+ tcp_node_hash[i] = NULL;
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+}
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+/* This function takes a socket pair string. If it already exists in
|
|
|
1c4448 |
+ the hash it returns -1, otherwise it returns 0. */
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+static int tcp_node_hash_check_and_append(const char *local_addr,
|
|
|
1c4448 |
+ int local_port,
|
|
|
1c4448 |
+ const char *rem_addr,
|
|
|
1c4448 |
+ int rem_port)
|
|
|
1c4448 |
+{
|
|
|
1c4448 |
+ unsigned int hash_val;
|
|
|
1c4448 |
+ struct tcp_node *tmp_node;
|
|
|
1c4448 |
+ int tmp_string_len;
|
|
|
1c4448 |
+ char *tmp_string;;
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ /* Size of the string is the size of the two lengths of the address
|
|
|
1c4448 |
+ strings plus enough sizes for the colons and the ports. */
|
|
|
1c4448 |
+ tmp_string_len = strlen(local_addr) + strlen(rem_addr) + 32;
|
|
|
1c4448 |
+ tmp_string = malloc(tmp_string_len);
|
|
|
1c4448 |
+ if (!tmp_string)
|
|
|
1c4448 |
+ return 0;
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ if (snprintf(tmp_string, tmp_string_len - 1, "%s:%d:%s:%d",
|
|
|
1c4448 |
+ local_addr, local_port, rem_addr, rem_port) < 0) {
|
|
|
1c4448 |
+ free(tmp_string);
|
|
|
1c4448 |
+ return 0;
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ hash_val = TCP_NODE_HASH_STRING(tmp_string);
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ /* See if we have to allocate this node */
|
|
|
1c4448 |
+ if (!tcp_node_hash[hash_val]) {
|
|
|
1c4448 |
+ tcp_node_hash[hash_val] = malloc(sizeof(struct tcp_node));
|
|
|
1c4448 |
+ if (!tcp_node_hash[hash_val]) {
|
|
|
1c4448 |
+ free(tmp_string);
|
|
|
1c4448 |
+ return 0;
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ memset(tcp_node_hash[hash_val], 0, sizeof(struct tcp_node));
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ /* Stuff this new value into the hash bucket and return early */
|
|
|
1c4448 |
+ tcp_node_hash[hash_val]->socket_pair = tmp_string;
|
|
|
1c4448 |
+ return 0;
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ /* Try to find the value in the hash bucket. */
|
|
|
1c4448 |
+ tmp_node = tcp_node_hash[hash_val];
|
|
|
1c4448 |
+ while (tmp_node) {
|
|
|
1c4448 |
+ if (!strcmp(tmp_node->socket_pair, tmp_string)) {
|
|
|
1c4448 |
+ free(tmp_string);
|
|
|
1c4448 |
+ return -1;
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+ tmp_node = tmp_node->next;
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ /* If we got this far it means that it isn't in the hash bucket.
|
|
|
1c4448 |
+ Add it to the front since it's faster that way. */
|
|
|
1c4448 |
+ tmp_node = tcp_node_hash[hash_val];
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ tcp_node_hash[hash_val] = malloc(sizeof(struct tcp_node));
|
|
|
1c4448 |
+ if (!tcp_node_hash[hash_val]) {
|
|
|
1c4448 |
+ free(tmp_string);
|
|
|
1c4448 |
+ tcp_node_hash[hash_val] = tmp_node;
|
|
|
1c4448 |
+ return 0;
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ tcp_node_hash[hash_val]->socket_pair = tmp_string;
|
|
|
1c4448 |
+ tcp_node_hash[hash_val]->next = tmp_node;
|
|
|
1c4448 |
+
|
|
|
1c4448 |
+ return 0;
|
|
|
1c4448 |
+}
|
|
|
1c4448 |
+
|
|
|
1c4448 |
#if HAVE_AFNETROM
|
|
|
1c4448 |
static const char *netrom_state[] =
|
|
|
1c4448 |
{
|
|
|
1c4448 |
@@ -1109,6 +1225,12 @@ static void tcp_do_one(int lnr, const ch
|
|
|
1c4448 |
return;
|
|
|
1c4448 |
}
|
|
|
1c4448 |
|
|
|
1c4448 |
+ /* make sure that we haven't seen this socket pair before */
|
|
|
1c4448 |
+ if (tcp_node_hash_check_and_append(local_addr, local_port, rem_addr, rem_port) < 0) {
|
|
|
1c4448 |
+ /* fprintf(stderr, _("warning, got duplicate tcp line.\n")); */
|
|
|
1c4448 |
+ return;
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+
|
|
|
1c4448 |
addr_do_one(local_addr, sizeof(local_addr), 22, ap, &localsas, local_port, "tcp");
|
|
|
1c4448 |
addr_do_one(rem_addr, sizeof(rem_addr), 22, ap, &remsas, rem_port, "tcp");
|
|
|
1c4448 |
|
|
|
1c4448 |
@@ -1877,6 +1999,9 @@ static int rfcomm_info(void)
|
|
|
1c4448 |
|
|
|
1c4448 |
static int iface_info(void)
|
|
|
1c4448 |
{
|
|
|
1c4448 |
+ static int count=0;
|
|
|
1c4448 |
+ struct interface *ife = NULL;
|
|
|
1c4448 |
+
|
|
|
1c4448 |
if (skfd < 0) {
|
|
|
1c4448 |
if ((skfd = sockets_open(0)) < 0) {
|
|
|
1c4448 |
perror("socket");
|
|
|
1c4448 |
@@ -1886,20 +2011,25 @@ static int iface_info(void)
|
|
|
1c4448 |
}
|
|
|
1c4448 |
if (flag_exp < 2) {
|
|
|
1c4448 |
ife_short = 1;
|
|
|
1c4448 |
- printf(_("Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n"));
|
|
|
1c4448 |
+ if(!(count % 8))
|
|
|
1c4448 |
+ printf(_("Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n"));
|
|
|
1c4448 |
}
|
|
|
1c4448 |
|
|
|
1c4448 |
- if (for_all_interfaces(do_if_print, &flag_all) < 0) {
|
|
|
1c4448 |
+ if (flag_int_name) {
|
|
|
1c4448 |
+ ife = lookup_interface(flag_int_name);
|
|
|
1c4448 |
+ do_if_print(ife, &flag_all);
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+ else if (for_all_interfaces(do_if_print, &flag_all) < 0) {
|
|
|
1c4448 |
perror(_("missing interface information"));
|
|
|
1c4448 |
exit(1);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
- if (flag_cnt)
|
|
|
1c4448 |
+ if (!flag_cnt) {
|
|
|
1c4448 |
if_cache_free();
|
|
|
1c4448 |
- else {
|
|
|
1c4448 |
close(skfd);
|
|
|
1c4448 |
skfd = -1;
|
|
|
1c4448 |
}
|
|
|
1c4448 |
|
|
|
1c4448 |
+ count++;
|
|
|
1c4448 |
return 0;
|
|
|
1c4448 |
}
|
|
|
1c4448 |
|
|
|
1c4448 |
@@ -1915,9 +2045,10 @@ static void usage(int rc)
|
|
|
1c4448 |
{
|
|
|
1c4448 |
fprintf(stderr, _("usage: netstat [-vWeenNcCF] [<Af>] -r netstat {-V|--version|-h|--help}\n"));
|
|
|
1c4448 |
fprintf(stderr, _(" netstat [-vWnNcaeol] [<Socket> ...]\n"));
|
|
|
1c4448 |
- fprintf(stderr, _(" netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] }\n\n"));
|
|
|
1c4448 |
+ fprintf(stderr, _(" netstat { [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]\n\n"));
|
|
|
1c4448 |
|
|
|
1c4448 |
fprintf(stderr, _(" -r, --route display routing table\n"));
|
|
|
1c4448 |
+ fprintf(stderr, _(" -I, --interfaces=<Iface> display interface table for <Iface>\n"));
|
|
|
1c4448 |
fprintf(stderr, _(" -i, --interfaces display interface table\n"));
|
|
|
1c4448 |
fprintf(stderr, _(" -g, --groups display multicast group memberships\n"));
|
|
|
1c4448 |
fprintf(stderr, _(" -s, --statistics display networking statistics (like SNMP)\n"));
|
|
|
1c4448 |
@@ -1957,11 +2088,12 @@ int main
|
|
|
1c4448 |
(int argc, char *argv[]) {
|
|
|
1c4448 |
int i;
|
|
|
1c4448 |
int lop;
|
|
|
1c4448 |
+ int reptimer = 1;
|
|
|
1c4448 |
static struct option longopts[] =
|
|
|
1c4448 |
{
|
|
|
1c4448 |
AFTRANS_OPTS,
|
|
|
1c4448 |
{"version", 0, 0, 'V'},
|
|
|
1c4448 |
- {"interfaces", 0, 0, 'i'},
|
|
|
1c4448 |
+ {"interfaces", 2, 0, 'I'},
|
|
|
1c4448 |
{"help", 0, 0, 'h'},
|
|
|
1c4448 |
{"route", 0, 0, 'r'},
|
|
|
1c4448 |
#if HAVE_FW_MASQUERADE
|
|
|
1c4448 |
@@ -2005,7 +2137,7 @@ int main
|
|
|
1c4448 |
getroute_init(); /* Set up AF routing support */
|
|
|
1c4448 |
|
|
|
1c4448 |
afname[0] = '\0';
|
|
|
1c4448 |
- while ((i = getopt_long(argc, argv, "A:CFMacdeghilnNoprsStuUvVWw2fx64?Z", longopts, &lop)) != EOF)
|
|
|
1c4448 |
+ while ((i = getopt_long(argc, argv, "A:CFMacdeghiI::lnNoprsStuUvVWw2fx64?Z", longopts, &lop)) != EOF)
|
|
|
1c4448 |
switch (i) {
|
|
|
1c4448 |
case -1:
|
|
|
1c4448 |
break;
|
|
|
1c4448 |
@@ -2046,6 +2178,13 @@ int main
|
|
|
1c4448 |
case 'p':
|
|
|
1c4448 |
flag_prg++;
|
|
|
1c4448 |
break;
|
|
|
1c4448 |
+ case 'I':
|
|
|
1c4448 |
+ if (optarg && strcmp(optarg, "(null)"))
|
|
|
1c4448 |
+ if (optarg[0] == '=') optarg++;
|
|
|
1c4448 |
+ if (optarg && strcmp(optarg, "(null)"))
|
|
|
1c4448 |
+ flag_int_name = strdup(optarg);
|
|
|
1c4448 |
+ flag_int++;
|
|
|
1c4448 |
+ break;
|
|
|
1c4448 |
case 'i':
|
|
|
1c4448 |
flag_int++;
|
|
|
1c4448 |
break;
|
|
|
1c4448 |
@@ -2140,6 +2279,12 @@ int main
|
|
|
1c4448 |
flag_sta++;
|
|
|
1c4448 |
}
|
|
|
1c4448 |
|
|
|
1c4448 |
+ if(argc == optind + 1) {
|
|
|
1c4448 |
+ if((reptimer = atoi(argv[optind])) <= 0)
|
|
|
1c4448 |
+ usage(E_USAGE);
|
|
|
1c4448 |
+ flag_cnt++;
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+
|
|
|
1c4448 |
if (flag_int + flag_rou + flag_mas + flag_sta > 1)
|
|
|
1c4448 |
usage(E_OPTERR);
|
|
|
1c4448 |
|
|
|
1c4448 |
@@ -2169,7 +2314,7 @@ int main
|
|
|
1c4448 |
flag_not & FLAG_NUM_PORT, flag_exp);
|
|
|
1c4448 |
if (i || !flag_cnt)
|
|
|
1c4448 |
break;
|
|
|
1c4448 |
- wait_continous();
|
|
|
1c4448 |
+ wait_continous(reptimer);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
#else
|
|
|
1c4448 |
ENOSUPP("netstat", "FW_MASQUERADE");
|
|
|
1c4448 |
@@ -2182,15 +2327,16 @@ int main
|
|
|
1c4448 |
if (!afname[0])
|
|
|
1c4448 |
safe_strncpy(afname, DFLT_AF, sizeof(afname));
|
|
|
1c4448 |
|
|
|
1c4448 |
+ for (;;) {
|
|
|
1c4448 |
if (!strcmp(afname, "inet")) {
|
|
|
1c4448 |
#if HAVE_AFINET
|
|
|
1c4448 |
- parsesnmp(flag_raw, flag_tcp, flag_udp, flag_sctp);
|
|
|
1c4448 |
+ i = parsesnmp(flag_raw, flag_tcp, flag_udp, flag_sctp);
|
|
|
1c4448 |
#else
|
|
|
1c4448 |
ENOSUPP("netstat", "AF INET");
|
|
|
1c4448 |
#endif
|
|
|
1c4448 |
} else if(!strcmp(afname, "inet6")) {
|
|
|
1c4448 |
#if HAVE_AFINET6
|
|
|
1c4448 |
- parsesnmp6(flag_raw, flag_tcp, flag_udp);
|
|
|
1c4448 |
+ i = parsesnmp6(flag_raw, flag_tcp, flag_udp);
|
|
|
1c4448 |
#else
|
|
|
1c4448 |
ENOSUPP("netstat", "AF INET6");
|
|
|
1c4448 |
#endif
|
|
|
1c4448 |
@@ -2198,7 +2344,11 @@ int main
|
|
|
1c4448 |
printf(_("netstat: No statistics support for specified address family: %s\n"), afname);
|
|
|
1c4448 |
exit(1);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
- exit(0);
|
|
|
1c4448 |
+ if(i || !flag_cnt)
|
|
|
1c4448 |
+ break;
|
|
|
1c4448 |
+ sleep(reptimer);
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
+ return (i);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
|
|
|
1c4448 |
if (flag_rou) {
|
|
|
1c4448 |
@@ -2220,7 +2370,7 @@ int main
|
|
|
1c4448 |
i = route_info(afname, options);
|
|
|
1c4448 |
if (i || !flag_cnt)
|
|
|
1c4448 |
break;
|
|
|
1c4448 |
- wait_continous();
|
|
|
1c4448 |
+ wait_continous(reptimer);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
return (i);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
@@ -2229,7 +2379,7 @@ int main
|
|
|
1c4448 |
i = iface_info();
|
|
|
1c4448 |
if (!flag_cnt || i)
|
|
|
1c4448 |
break;
|
|
|
1c4448 |
- wait_continous();
|
|
|
1c4448 |
+ wait_continous(reptimer);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
return (i);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
@@ -2416,8 +2566,9 @@ int main
|
|
|
1c4448 |
|
|
|
1c4448 |
if (!flag_cnt || i)
|
|
|
1c4448 |
break;
|
|
|
1c4448 |
- wait_continous();
|
|
|
1c4448 |
+ wait_continous(reptimer);
|
|
|
1c4448 |
prg_cache_clear();
|
|
|
1c4448 |
+ tcp_node_hash_clear();
|
|
|
1c4448 |
}
|
|
|
1c4448 |
return (i);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
diff -up net-tools-2.0/statistics.c.cycle net-tools-2.0/statistics.c
|
|
|
1c4448 |
--- net-tools-2.0/statistics.c.cycle 2016-02-15 16:54:18.000000000 +0100
|
|
|
1c4448 |
+++ net-tools-2.0/statistics.c 2016-03-30 09:58:18.238891661 +0200
|
|
|
1c4448 |
@@ -527,7 +527,7 @@ static void process_fd2(FILE *f, const c
|
|
|
1c4448 |
}
|
|
|
1c4448 |
}
|
|
|
1c4448 |
|
|
|
1c4448 |
-void parsesnmp(int flag_raw, int flag_tcp, int flag_udp, int flag_sctp)
|
|
|
1c4448 |
+int parsesnmp(int flag_raw, int flag_tcp, int flag_udp, int flag_sctp)
|
|
|
1c4448 |
{
|
|
|
1c4448 |
FILE *f;
|
|
|
1c4448 |
|
|
|
1c4448 |
@@ -536,14 +536,17 @@ void parsesnmp(int flag_raw, int flag_tc
|
|
|
1c4448 |
f = proc_fopen("/proc/net/snmp");
|
|
|
1c4448 |
if (!f) {
|
|
|
1c4448 |
perror(_("cannot open /proc/net/snmp"));
|
|
|
1c4448 |
- return;
|
|
|
1c4448 |
+ return(1);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
|
|
|
1c4448 |
if (process_fd(f, 1, NULL) < 0)
|
|
|
1c4448 |
fprintf(stderr, _("Problem while parsing /proc/net/snmp\n"));
|
|
|
1c4448 |
|
|
|
1c4448 |
- if (ferror(f))
|
|
|
1c4448 |
+ if (ferror(f)) {
|
|
|
1c4448 |
perror("/proc/net/snmp");
|
|
|
1c4448 |
+ fclose(f);
|
|
|
1c4448 |
+ return(1);
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
|
|
|
1c4448 |
fclose(f);
|
|
|
1c4448 |
|
|
|
1c4448 |
@@ -553,8 +556,11 @@ void parsesnmp(int flag_raw, int flag_tc
|
|
|
1c4448 |
if (process_fd(f, 1, NULL) <0)
|
|
|
1c4448 |
fprintf(stderr, _("Problem while parsing /proc/net/netstat\n"));
|
|
|
1c4448 |
|
|
|
1c4448 |
- if (ferror(f))
|
|
|
1c4448 |
- perror("/proc/net/netstat");
|
|
|
1c4448 |
+ if (ferror(f)) {
|
|
|
1c4448 |
+ perror("/proc/net/netstat");
|
|
|
1c4448 |
+ fclose(f);
|
|
|
1c4448 |
+ return(1);
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
|
|
|
1c4448 |
fclose(f);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
@@ -567,9 +573,10 @@ void parsesnmp(int flag_raw, int flag_tc
|
|
|
1c4448 |
fclose(f);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
}
|
|
|
1c4448 |
+ return(0);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
|
|
|
1c4448 |
-void parsesnmp6(int flag_raw, int flag_tcp, int flag_udp)
|
|
|
1c4448 |
+int parsesnmp6(int flag_raw, int flag_tcp, int flag_udp)
|
|
|
1c4448 |
{
|
|
|
1c4448 |
FILE *f;
|
|
|
1c4448 |
|
|
|
1c4448 |
@@ -578,7 +585,7 @@ void parsesnmp6(int flag_raw, int flag_t
|
|
|
1c4448 |
f = fopen("/proc/net/snmp6", "r");
|
|
|
1c4448 |
if (!f) {
|
|
|
1c4448 |
perror(_("cannot open /proc/net/snmp6"));
|
|
|
1c4448 |
- return;
|
|
|
1c4448 |
+ return(1);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
process6_fd(f);
|
|
|
1c4448 |
if (ferror(f))
|
|
|
1c4448 |
@@ -588,11 +595,14 @@ void parsesnmp6(int flag_raw, int flag_t
|
|
|
1c4448 |
f = fopen("/proc/net/snmp", "r");
|
|
|
1c4448 |
if (!f) {
|
|
|
1c4448 |
perror(_("cannot open /proc/net/snmp"));
|
|
|
1c4448 |
- return;
|
|
|
1c4448 |
+ return(1);
|
|
|
1c4448 |
}
|
|
|
1c4448 |
process_fd(f, 0, "Tcp");
|
|
|
1c4448 |
- if (ferror(f))
|
|
|
1c4448 |
+ if (ferror(f)) {
|
|
|
1c4448 |
perror("/proc/net/snmp");
|
|
|
1c4448 |
+ return(1);
|
|
|
1c4448 |
+ }
|
|
|
1c4448 |
|
|
|
1c4448 |
fclose(f);
|
|
|
1c4448 |
+ return(0);
|
|
|
1c4448 |
}
|