source: rtems/cpukit/libnetworking/rtems/rtems_showifstat.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1#if HAVE_CONFIG_H
2#include "config.h"
3#endif
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 <sys/mbuf.h>
14#include <net/if.h>
15#include <net/if_dl.h>
16#include <net/if_types.h>
17#include <netinet/in.h>
18#include <arpa/inet.h>
19
20/*
21 * Display an address
22 */
23static int
24showaddress (char *name, struct sockaddr *a)
25{
26        struct sockaddr_in *sa;
27        char    buf[17];
28
29        if (!a)
30                return 0;
31        printf ("%s:", name);
32        sa = (struct sockaddr_in *)a;
33        printf ("%-16s", inet_ntop (AF_INET, &sa->sin_addr, buf, sizeof(buf)));
34        return 1;
35}
36
37/*
38 * Display interface statistics
39 */
40void
41rtems_bsdnet_show_if_stats (void)
42{
43        struct ifnet *ifp;
44        struct ifaddr *ifa;
45        unsigned short bit, flags;
46
47        printf ("************ INTERFACE STATISTICS ************\n");
48        for (ifp = ifnet; ifp; ifp = ifp->if_next) {
49                printf ("***** %s%d *****\n", ifp->if_name, ifp->if_unit);
50                for (ifa = ifp->if_addrlist ; ifa ; ifa = ifa->ifa_next) {
51
52                        if ( !ifa->ifa_addr )
53                                continue;
54
55                        switch ( ifa->ifa_addr->sa_family ) {
56                                case AF_LINK:
57                                        {
58                                        struct sockaddr_dl *sdl = (struct sockaddr_dl *)ifa->ifa_addr;
59                                        unsigned char *cp = (unsigned char *)LLADDR(sdl);
60                                        int                    i;
61
62                                        switch ( sdl->sdl_type ) {
63                                                case IFT_ETHER:
64                                                        if ( (i=sdl->sdl_alen) > 0 ) {
65                                                                printf("Ethernet Address: ");
66                                                                do {
67                                                                        i--;
68                                                                        printf("%02X%c", *cp++, i ? ':' : '\n');
69                                                                } while ( i>0 );
70                                                        }
71                                                break;
72
73                                                default:
74                                                break;
75                                        }
76                                        }
77                                break;
78
79                                case AF_INET:
80                                        {
81                                        int printed;
82                                        printed = showaddress ("Address", ifa->ifa_addr);
83                                        if (ifp->if_flags & IFF_BROADCAST)
84                                                printed |= showaddress ("Broadcast Address", ifa->ifa_broadaddr);
85                                        if (ifp->if_flags & IFF_POINTOPOINT)
86                                                printed |= showaddress ("Destination Address", ifa->ifa_dstaddr);
87                                        printed |= showaddress ("Net mask", ifa->ifa_netmask);
88                                        if (printed)
89                                                printf ("\n");
90                                        }
91                                break;
92
93                                default:
94                                break;
95                        }
96                }
97
98                printf ("Flags:");
99                for (bit = 1, flags = ifp->if_flags ; flags ; bit <<= 1) {
100                        char *cp;
101                        char xbuf[20];
102                        switch (flags & bit) {
103                        case 0:                 cp = NULL;              break;
104                        case IFF_UP:            cp = "Up";              break;
105                        case IFF_BROADCAST:     cp = "Broadcast";       break;
106                        case IFF_DEBUG:         cp = "Debug";           break;
107                        case IFF_LOOPBACK:      cp = "Loopback";        break;
108                        case IFF_POINTOPOINT:   cp = "Point-to-point";  break;
109                        case IFF_RUNNING:       cp = "Running";         break;
110                        case IFF_NOARP:         cp = "No-ARP";          break;
111                        case IFF_PROMISC:       cp = "Promiscuous";     break;
112                        case IFF_ALLMULTI:      cp = "All-multicast";   break;
113                        case IFF_OACTIVE:       cp = "Active";          break;
114                        case IFF_SIMPLEX:       cp = "Simplex";         break;
115                        case IFF_LINK0:         cp = "Link0";           break;
116                        case IFF_LINK1:         cp = "Link1";           break;
117                        case IFF_LINK2:         cp = "Link2";           break;
118                        case IFF_MULTICAST:     cp = "Multicast";       break;
119                        default: sprintf (xbuf, "%#x", bit); cp = xbuf; break;
120                        }
121                        if (cp) {
122                                flags &= ~bit;
123                                printf (" %s", cp);
124                        }
125                }
126                printf ("\n");
127
128                printf ("Send queue limit:%-4d length:%-4d Dropped:%-8d\n",
129                                                        ifp->if_snd.ifq_maxlen,
130                                                        ifp->if_snd.ifq_len,
131                                                        ifp->if_snd.ifq_drops);
132
133                /*
134                 * FIXME: Could print if_data statistics here,
135                 *        but right now the drivers maintain their
136                 *        own statistics.
137                 */
138
139                /*
140                 * Grab the network semaphore.
141                 * In most cases this is not necessary, but it's
142                 * easier to always call the driver ioctl function
143                 * while holding the semaphore than to try
144                 * and explain why some ioctl commands are invoked
145                 * while holding the semaphore and others are
146                 * invoked while not holding the semaphore.
147                 */
148                rtems_bsdnet_semaphore_obtain ();
149                (*ifp->if_ioctl)(ifp, SIO_RTEMS_SHOW_STATS, NULL);
150                rtems_bsdnet_semaphore_release ();
151        }
152        printf ("\n");
153}
Note: See TracBrowser for help on using the repository browser.