This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Net =- dump interface & routing tables
- From: Gary Thomas <gthomas at ecoscentric dot com>
- To: eCos patches <ecos-patches at sources dot redhat dot com>
- Date: 03 Dec 2002 10:23:07 -0700
- Subject: Net =- dump interface & routing tables
Index: net/bsd_tcpip/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/bsd_tcpip/current/ChangeLog,v
retrieving revision 1.11
diff -u -5 -p -r1.11 ChangeLog
--- net/bsd_tcpip/current/ChangeLog 12 Nov 2002 17:38:55 -0000 1.11
+++ net/bsd_tcpip/current/ChangeLog 3 Dec 2002 16:56:08 -0000
@@ -1,5 +1,10 @@
+2002-12-03 Gary Thomas <gthomas@ecoscentric.com>
+
+ * src/ecos/support.c (show_network_tables): New function to
+ print information about network tables (interfaces, routing).
+
2002-11-12 Gary Thomas <gary@mlbassoc.com>
* src/ecos/timeout.c (callout_reset): Check for finding the
correct "delta" was wrong - only used with asserts enabled.
Index: net/bsd_tcpip/current/src/ecos/support.c
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/bsd_tcpip/current/src/ecos/support.c,v
retrieving revision 1.3
diff -u -5 -p -r1.3 support.c
--- net/bsd_tcpip/current/src/ecos/support.c 26 Jul 2002 15:04:02 -0000 1.3
+++ net/bsd_tcpip/current/src/ecos/support.c 3 Dec 2002 16:52:57 -0000
@@ -12,10 +12,11 @@
// copyright disclaimers included herein.
//
// Portions created by Red Hat are
// Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
//
+// Copyright (C) 2002 Gary Thomas
// -------------------------------------------
//
//####BSDCOPYRIGHTEND####
//==========================================================================
@@ -813,10 +814,133 @@ cyg_net_init(void)
}
log(LOG_INIT, "[%s] Done\n", __FUNCTION__);
// Done
_init = true;
+}
+
+
+#include <net/if.h>
+#include <net/netdb.h>
+#include <net/route.h>
+externC void if_indextoname(int indx, char *buf, int len);
+
+typedef void pr_fun(char *fmt, ...);
+
+static void
+_mask(struct sockaddr *sa, char *buf, int _len)
+{
+ char *cp = ((char *)sa) + 4;
+ int len = sa->sa_len - 4;
+ int tot = 0;
+
+ while (len-- > 0) {
+ if (tot) *buf++ = '.';
+ buf += diag_sprintf(buf, "%d", *cp++);
+ tot++;
+ }
+
+ while (tot < 4) {
+ if (tot) *buf++ = '.';
+ buf += diag_sprintf(buf, "%d", 0);
+ tot++;
+ }
+}
+
+static void
+_show_ifp(struct ifnet *ifp, pr_fun *pr)
+{
+ struct ifaddr *ifa;
+ char name[64], addr[64], netmask[64], broadcast[64];
+
+ if_indextoname(ifp->if_index, name, 64);
+ (*pr)("%-8s", name);
+ TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
+ if (ifa->ifa_addr->sa_family != AF_LINK) {
+ getnameinfo (ifa->ifa_addr, ifa->ifa_addr->sa_len, addr, sizeof(addr), 0, 0, 0);
+ getnameinfo (ifa->ifa_dstaddr, ifa->ifa_dstaddr->sa_len, broadcast, sizeof(broadcast), 0, 0, 0);
+ _mask(ifa->ifa_netmask, netmask, 64);
+ (*pr)("IP: %s, Broadcast: %s, Netmask: %s\n", addr, broadcast, netmask);
+ (*pr)(" ");
+ if ((ifp->if_flags & IFF_UP)) (*pr)("UP ");
+ if ((ifp->if_flags & IFF_BROADCAST)) (*pr)("BROADCAST ");
+ if ((ifp->if_flags & IFF_LOOPBACK)) (*pr)("LOOPBACK ");
+ if ((ifp->if_flags & IFF_RUNNING)) (*pr)("RUNNING ");
+ if ((ifp->if_flags & IFF_PROMISC)) (*pr)("PROMISC ");
+ if ((ifp->if_flags & IFF_MULTICAST)) (*pr)("MULTICAST ");
+ if ((ifp->if_flags & IFF_ALLMULTI)) (*pr)("ALLMULTI ");
+ (*pr)("MTU: %d, Metric: %d\n", ifp->if_mtu, ifp->if_metric);
+ (*pr)(" Rx - Packets: %d, Bytes: %d", ifa->if_data.ifi_ipackets, ifa->if_data.ifi_ibytes);
+ (*pr)(", Tx - Packets: %d, Bytes: %d\n", ifa->if_data.ifi_opackets, ifa->if_data.ifi_obytes);
+ }
+ }
+}
+
+static int
+_dumpentry(struct radix_node *rn, pr_fun *pr)
+{
+ struct rtentry *rt = (struct rtentry *)rn;
+ struct sockaddr *dst, *gate, *netmask, *genmask;
+ char addr[32], *cp;
+
+ dst = rt_key(rt);
+ gate = rt->rt_gateway;
+ netmask = rt_mask(rt);
+ genmask = rt->rt_genmask;
+ if ((rt->rt_flags & (RTF_UP | RTF_WASCLONED)) == RTF_UP) {
+ if (netmask == NULL) {
+ return 0;
+ }
+ _inet_ntop(dst, addr, sizeof(addr));
+ (*pr)("%-15s ", addr);
+ if (gate != NULL) {
+ _inet_ntop(gate, addr, sizeof(addr));
+ (*pr)("%-15s ", addr);
+ } else {
+ (*pr)("%-15s ", " ");
+ }
+ if (netmask != NULL) {
+ _mask(netmask, addr, sizeof(addr));
+ (*pr)("%-15s ", addr);
+ } else {
+ (*pr)("%-15s ", " ");
+ }
+ cp = addr;
+ if ((rt->rt_flags & RTF_UP)) *cp++ = 'U';
+ if ((rt->rt_flags & RTF_GATEWAY)) *cp++ = 'G';
+ if ((rt->rt_flags & RTF_STATIC)) *cp++ = 'S';
+ if ((rt->rt_flags & RTF_DYNAMIC)) *cp++ = 'D';
+ *cp = '\0';
+ (*pr)("%-8s ", addr); // Flags
+ if_indextoname(rt->rt_ifp->if_index, addr, 64);
+ (*pr)("%-8s ", addr);
+ (*pr)("\n");
+ }
+ return 0;
+}
+
+void
+show_network_tables(pr_fun *pr)
+{
+ int i, error;
+ struct radix_node_head *rnh;
+ struct ifnet *ifp;
+
+ cyg_scheduler_lock();
+ (*pr)("Routing tables\n");
+ (*pr)("Destination Gateway Mask Flags Interface\n");
+ for (i = 1; i <= AF_MAX; i++) {
+ if ((rnh = rt_tables[i]) != NULL) {
+ error = rnh->rnh_walktree(rnh, _dumpentry, pr);
+ }
+ }
+
+ (*pr)("Interface statistics\n");
+ for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_link.tqe_next) {
+ _show_ifp(ifp, pr);
+ }
+ cyg_scheduler_unlock();
}
#endif // CYGPKG_NET_DRIVER_FRAMEWORK
// EOF support.c
Index: net/tcpip/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/tcpip/current/ChangeLog,v
retrieving revision 1.39
diff -u -5 -p -r1.39 ChangeLog
--- net/tcpip/current/ChangeLog 23 May 2002 23:08:23 -0000 1.39
+++ net/tcpip/current/ChangeLog 3 Dec 2002 16:55:38 -0000
@@ -1,5 +1,10 @@
+2002-12-03 Gary Thomas <gthomas@ecoscentric.com>
+
+ * src/ecos/support.c (show_network_tables): New function used
+ to print network information (interface, routing).
+
2002-05-21 Jesper Skov <jskov@redhat.com>
* src/lib/recv.c: Fix warning. socket.h declarations are not
available to the kernel code. Added missing argument in the
recvfrom call.
Index: net/tcpip/current/src/ecos/support.c
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/tcpip/current/src/ecos/support.c,v
retrieving revision 1.16
diff -u -5 -p -r1.16 support.c
--- net/tcpip/current/src/ecos/support.c 20 May 2002 22:25:19 -0000 1.16
+++ net/tcpip/current/src/ecos/support.c 3 Dec 2002 16:54:10 -0000
@@ -600,8 +600,130 @@ cyg_net_init(void)
// Done
_init = true;
}
+// Copyright (C) 2002 Gary Thomas
+
+#include <net/if.h>
+#include <net/route.h>
+externC void if_indextoname(int indx, char *buf, int len);
+
+typedef void pr_fun(char *fmt, ...);
+
+static void
+_mask(struct sockaddr *sa, char *buf, int _len)
+{
+ char *cp = ((char *)sa) + 4;
+ int len = sa->sa_len - 4;
+ int tot = 0;
+
+ while (len-- > 0) {
+ if (tot) *buf++ = '.';
+ buf += diag_sprintf(buf, "%d", *cp++);
+ tot++;
+ }
+
+ while (tot < 4) {
+ if (tot) *buf++ = '.';
+ buf += diag_sprintf(buf, "%d", 0);
+ tot++;
+ }
+}
+
+static void
+_show_ifp(struct ifnet *ifp, pr_fun *pr)
+{
+ struct ifaddr *ifa;
+ char name[64], addr[64], netmask[64], broadcast[64];
+
+ (*pr)("%-8s", ifp->if_xname);
+ TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
+ if (ifa->ifa_addr->sa_family != AF_LINK) {
+ getnameinfo (ifa->ifa_addr, ifa->ifa_addr->sa_len, addr, sizeof(addr), 0, 0, 0);
+ getnameinfo (ifa->ifa_dstaddr, ifa->ifa_dstaddr->sa_len, broadcast, sizeof(broadcast), 0, 0, 0);
+ _mask(ifa->ifa_netmask, netmask, 64);
+ (*pr)("IP: %s, Broadcast: %s, Netmask: %s\n", addr, broadcast, netmask);
+ (*pr)(" ");
+ if ((ifp->if_flags & IFF_UP)) (*pr)("UP ");
+ if ((ifp->if_flags & IFF_BROADCAST)) (*pr)("BROADCAST ");
+ if ((ifp->if_flags & IFF_LOOPBACK)) (*pr)("LOOPBACK ");
+ if ((ifp->if_flags & IFF_RUNNING)) (*pr)("RUNNING ");
+ if ((ifp->if_flags & IFF_PROMISC)) (*pr)("PROMISC ");
+ if ((ifp->if_flags & IFF_MULTICAST)) (*pr)("MULTICAST ");
+ if ((ifp->if_flags & IFF_ALLMULTI)) (*pr)("ALLMULTI ");
+ (*pr)("MTU: %d, Metric: %d\n", ifp->if_mtu, ifp->if_metric);
+ (*pr)(" Rx - Packets: %d, Bytes: %d", ifp->if_data.ifi_ipackets, ifp->if_data.ifi_ibytes);
+ (*pr)(", Tx - Packets: %d, Bytes: %d\n", ifp->if_data.ifi_opackets, ifp->if_data.ifi_obytes);
+ }
+ }
+}
+
+static int
+_dumpentry(struct radix_node *rn, pr_fun *pr)
+{
+ struct rtentry *rt = (struct rtentry *)rn;
+ struct sockaddr *dst, *gate, *netmask, *genmask;
+ char addr[32], *cp;
+
+ dst = rt_key(rt);
+ gate = rt->rt_gateway;
+ netmask = rt_mask(rt);
+ genmask = rt->rt_genmask;
+ if ((rt->rt_flags & (RTF_UP | RTF_LLINFO)) == RTF_UP) {
+ if (netmask == NULL) {
+ return 0;
+ }
+ _inet_ntop(dst, addr, sizeof(addr));
+ (*pr)("%-15s ", addr);
+ if (gate != NULL) {
+ _inet_ntop(gate, addr, sizeof(addr));
+ (*pr)("%-15s ", addr);
+ } else {
+ (*pr)("%-15s ", " ");
+ }
+ if (netmask != NULL) {
+ _mask(netmask, addr, sizeof(addr));
+ (*pr)("%-15s ", addr);
+ } else {
+ (*pr)("%-15s ", " ");
+ }
+ cp = addr;
+ if ((rt->rt_flags & RTF_UP)) *cp++ = 'U';
+ if ((rt->rt_flags & RTF_GATEWAY)) *cp++ = 'G';
+ if ((rt->rt_flags & RTF_STATIC)) *cp++ = 'S';
+ if ((rt->rt_flags & RTF_DYNAMIC)) *cp++ = 'D';
+ *cp = '\0';
+ (*pr)("%-8s ", addr); // Flags
+ if_indextoname(rt->rt_ifp->if_index, addr, 64);
+ (*pr)("%-8s ", addr);
+ (*pr)("\n");
+ }
+ return 0;
+}
+
+void
+show_network_tables(pr_fun *pr)
+{
+ int i, error;
+ struct radix_node_head *rnh;
+ struct ifnet *ifp;
+
+ cyg_scheduler_lock();
+ (*pr)("Routing tables\n");
+ (*pr)("Destination Gateway Mask Flags Interface\n");
+ for (i = 1; i <= AF_MAX; i++) {
+ if ((rnh = rt_tables[i]) != NULL) {
+ error = rnh->rnh_walktree(rnh, _dumpentry, pr);
+ }
+ }
+
+ (*pr)("Interface statistics\n");
+ for (ifp = ifnet.tqh_first; ifp != 0; ifp = ifp->if_list.tqe_next) {
+ _show_ifp(ifp);
+ }
+ cyg_scheduler_unlock();
+}
+
#endif // CYGPKG_NET_DRIVER_FRAMEWORK
// EOF support.c
--
------------------------------------------------------------
Gary Thomas |
eCosCentric, Ltd. |
+1 (970) 229-1963 | eCos & RedBoot experts
gthomas@ecoscentric.com |
http://www.ecoscentric.com/ |
------------------------------------------------------------