summaryrefslogtreecommitdiffstats
path: root/freebsd/usr.bin
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2013-10-30 15:42:53 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2013-10-31 13:18:54 +0100
commit6da9b2397b6ed81c8d73d040a10543330af4659b (patch)
treed3930e0973052defe663ad6a77e3d2cd61a540fb /freebsd/usr.bin
parentNETSTAT(1): Fix isalpha() and isdigit() usage (diff)
downloadrtems-libbsd-6da9b2397b6ed81c8d73d040a10543330af4659b.tar.bz2
NETSTAT(1): Initialize global variables
Use BSD program lock.
Diffstat (limited to 'freebsd/usr.bin')
-rw-r--r--freebsd/usr.bin/netstat/inet.c7
-rw-r--r--freebsd/usr.bin/netstat/main.c47
-rw-r--r--freebsd/usr.bin/netstat/netstat.h18
-rw-r--r--freebsd/usr.bin/netstat/route.c16
4 files changed, 65 insertions, 23 deletions
diff --git a/freebsd/usr.bin/netstat/inet.c b/freebsd/usr.bin/netstat/inet.c
index 5a414592..4915a4dd 100644
--- a/freebsd/usr.bin/netstat/inet.c
+++ b/freebsd/usr.bin/netstat/inet.c
@@ -306,7 +306,6 @@ void
protopr(u_long off, const char *name, int af1, int proto)
{
int istcp;
- static int first = 1;
char *buf;
const char *vchar;
struct tcpcb *tp = NULL;
@@ -394,7 +393,7 @@ protopr(u_long off, const char *name, int af1, int proto)
))
continue;
- if (first) {
+ if (!protopr_initialized) {
if (!Lflag) {
printf("Active Internet connections");
if (aflag)
@@ -424,7 +423,7 @@ protopr(u_long off, const char *name, int af1, int proto)
else
printf("(state)\n");
}
- first = 0;
+ protopr_initialized = 1;
}
if (Lflag && so->so_qlimit == 0)
continue;
@@ -913,7 +912,7 @@ arp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
-static const char *icmpnames[ICMP_MAXTYPE + 1] = {
+static const char *const icmpnames[ICMP_MAXTYPE + 1] = {
"echo reply", /* RFC 792 */
"#1",
"#2",
diff --git a/freebsd/usr.bin/netstat/main.c b/freebsd/usr.bin/netstat/main.c
index fd08002c..acb256d5 100644
--- a/freebsd/usr.bin/netstat/main.c
+++ b/freebsd/usr.bin/netstat/main.c
@@ -364,13 +364,54 @@ int af; /* address family */
int live; /* true if we are examining a live system */
#ifdef __rtems__
+int protopr_initialized;
+int do_rtent;
+struct radix_node_head **rt_tables;
+
static int main(int argc, char *argv[]);
int rtems_bsd_command_netstat(int argc, char *argv[])
{
- noutputs = 0;
-
- return rtems_bsd_program_call_main("netstat", main, argc, argv);
+ int exit_code;
+
+ rtems_bsd_program_lock();
+
+ Aflag = 0;
+ aflag = 0;
+ bflag = 0;
+ dflag = 0;
+ gflag = 0;
+ hflag = 0;
+ iflag = 0;
+ Lflag = 0;
+ mflag = 0;
+ noutputs = 0;
+ numeric_addr = 0;
+ numeric_port = 0;
+ pflag = 0;
+ rflag = 0;
+ sflag = 0;
+ tflag = 0;
+ Wflag = 0;
+ xflag = 0;
+ zflag = 0;
+ interval = 0;
+ interface = 0;
+ unit = 0;
+ af = 0;
+ live = 0;
+
+ protopr_initialized = 0;
+ do_rtent = 0;
+
+ exit_code = rtems_bsd_program_call_main("netstat", main, argc, argv);
+
+ free(rt_tables);
+ rt_tables = NULL;
+
+ rtems_bsd_program_unlock();
+
+ return exit_code;
}
#endif /* __rtems__ */
int
diff --git a/freebsd/usr.bin/netstat/netstat.h b/freebsd/usr.bin/netstat/netstat.h
index c3073ec3..9b2db595 100644
--- a/freebsd/usr.bin/netstat/netstat.h
+++ b/freebsd/usr.bin/netstat/netstat.h
@@ -36,6 +36,12 @@
#include <sys/cdefs.h>
+#ifdef __rtems__
+#define rt_tables netstat_rt_tables
+#define routename rtems_shell_netstats_routername
+#define netname rtems_shell_netstats_netname
+#define sotoxsocket rtems_shell_netstats_sotoxsocket
+#endif /* __rtems__ */
extern int Aflag; /* show addresses of protocol control block */
extern int aflag; /* show all sockets (including servers) */
extern int bflag; /* show i/f total bytes in/out */
@@ -62,6 +68,11 @@ extern int unit; /* unit number for above */
extern int af; /* address family */
extern int live; /* true if we are examining a live system */
+#ifdef __rtems__
+extern int protopr_initialized;
+extern int do_rtent;
+extern struct radix_node_head **rt_tables;
+#endif /* __rtems__ */
int kread(u_long addr, void *buf, size_t size);
const char *plural(uintmax_t);
@@ -126,13 +137,6 @@ char *ipx_phost(struct sockaddr *);
char *ns_phost(struct sockaddr *);
void upHex(char *);
-#ifdef __rtems__
-#define rt_tables netstat_rt_tables
-#define routename rtems_shell_netstats_routername
-#define netname rtems_shell_netstats_netname
-#define sotoxsocket rtems_shell_netstats_sotoxsocket
-#endif
-
char *routename(in_addr_t);
char *netname(in_addr_t, u_long);
char *atalk_print(struct sockaddr *, int);
diff --git a/freebsd/usr.bin/netstat/route.c b/freebsd/usr.bin/netstat/route.c
index 1829e1bc..584ce132 100644
--- a/freebsd/usr.bin/netstat/route.c
+++ b/freebsd/usr.bin/netstat/route.c
@@ -126,16 +126,14 @@ typedef union {
static sa_u pt_u;
-int fibnum;
-int do_rtent = 0;
-struct rtentry rtentry;
-struct radix_node rnode;
-struct radix_mask rmask;
-struct radix_node_head **rt_tables;
+static int fibnum;
+static struct rtentry rtentry;
+static struct radix_node rnode;
+static struct radix_mask rmask;
-int NewTree = 0;
+static const int NewTree = 0;
-struct timespec uptime;
+static struct timespec uptime;
static struct sockaddr *kgetsa(struct sockaddr *);
static void size_cols(int ef, struct radix_node *rn);
@@ -493,7 +491,7 @@ again:
}
}
-char nbuf[20];
+static char nbuf[20];
static void
p_rtnode(void)