source: rtems/c/src/exec/libnetworking/rtems/rtems_showifstat.c @ 39e6e65a

4.104.114.84.95
Last change on this file since 39e6e65a was 39e6e65a, checked in by Joel Sherrill <joel.sherrill@…>, on 08/19/98 at 21:32:28

Base files

  • Property mode set to 100644
File size: 2.9 KB
Line 
1#include <sys/param.h>
2#include <sys/queue.h>
3#include <sys/systm.h>
4#include <sys/kernel.h>
5#include <sys/sysctl.h>
6#include <sys/proc.h>
7#include <sys/socket.h>
8#include <sys/ioctl.h>
9#include <net/if.h>
10#include <netinet/in.h>
11
12/*
13 * Display an address
14 */
15static int
16showaddress (char *name, struct sockaddr *a)
17{
18        struct sockaddr_in *sa;
19
20        if (!a || (a->sa_family != AF_INET))
21                return 0;
22        printf ("%s:", name);
23        sa = (struct sockaddr_in *)a;
24        printf ("%-16s", inet_ntoa (sa->sin_addr));
25        return 1;
26}
27
28/*
29 * Display interface statistics
30 */
31void
32rtems_bsdnet_show_if_stats (void)
33{
34        struct ifnet *ifp;
35        struct ifaddr *ifa;
36        unsigned int bit, flags;
37        int printed;
38
39        printf ("************ INTERFACE STATISTICS ************\n");
40        for (ifp = ifnet; ifp; ifp = ifp->if_next) {
41                printf ("***** %s%d *****\n", ifp->if_name, ifp->if_unit);
42                for (ifa = ifp->if_addrlist ; ifa ; ifa = ifa->ifa_next) {
43                        printed = showaddress ("Address", ifa->ifa_addr);
44                        if (ifp->if_flags & IFF_BROADCAST)
45                                printed |= showaddress ("Broadcast Address", ifa->ifa_broadaddr);
46                        if (ifp->if_flags & IFF_POINTOPOINT)
47                                printed |= showaddress ("Destination Address", ifa->ifa_dstaddr);
48                        printed |= showaddress ("Net mask", ifa->ifa_netmask);
49                        if (printed)
50                                printf ("\n");
51                }
52
53                printf ("Flags:");
54                for (bit = 1, flags = ifp->if_flags ; flags ; bit <<= 1) {
55                        char *cp;
56                        switch (flags & bit) {
57                        default:                cp = NULL;              break;
58                        case IFF_UP:            cp = "Up";              break;
59                        case IFF_BROADCAST:     cp = "Broadcast";       break;
60                        case IFF_DEBUG:         cp = "Debug";           break;
61                        case IFF_LOOPBACK:      cp = "Loopback";        break;
62                        case IFF_POINTOPOINT:   cp = "Point-to-point";  break;
63                        case IFF_RUNNING:       cp = "Running";         break;
64                        case IFF_NOARP:         cp = "No-ARP";          break;
65                        case IFF_PROMISC:       cp = "Promiscuous";     break;
66                        case IFF_ALLMULTI:      cp = "All-multicast";   break;
67                        case IFF_OACTIVE:       cp = "Active";          break;
68                        case IFF_SIMPLEX:       cp = "Simplex";         break;
69                        case IFF_LINK0:         cp = "Link0";           break;
70                        case IFF_LINK1:         cp = "Link1";           break;
71                        case IFF_LINK2:         cp = "Link2";           break;
72                        case IFF_MULTICAST:     cp = "Multicast";       break;
73                        }
74                        if (cp) {
75                                flags &= ~bit;
76                                printf (" %s", cp);
77                        }
78                }
79                printf ("\n");
80
81                printf ("Send queue limit:%-4d length:%-4d Dropped:%-8d\n",
82                                                        ifp->if_snd.ifq_maxlen,
83                                                        ifp->if_snd.ifq_len,
84                                                        ifp->if_snd.ifq_drops);
85
86                /*
87                 * FIXME: Could print if_data statistics here,
88                 *        but right now the drivers maintain their
89                 *        own statistics.
90                 */
91
92                /*
93                 * Grab the network semaphore.
94                 * In most cases this is not necessary, but it's
95                 * easier to always call the driver ioctl function
96                 * while holding the semaphore than to try
97                 * and explain why some ioctl commands are invoked
98                 * while holding the semaphore and others are
99                 * invoked while not holding the semaphore.
100                 */
101                rtems_bsdnet_semaphore_obtain ();
102                (*ifp->if_ioctl)(ifp, SIO_RTEMS_SHOW_STATS, NULL);
103                rtems_bsdnet_semaphore_release ();
104        }
105        printf ("\n");
106}
Note: See TracBrowser for help on using the repository browser.