source: rtems/cpukit/libnetworking/rtems/rtems_showifstat.c @ 28e7d7fa

4.104.114.84.95
Last change on this file since 28e7d7fa was 96b39164, checked in by Joel Sherrill <joel.sherrill@…>, on 08/20/98 at 21:56:40

Added CVS Ids

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