source: rtems/cpukit/libnetworking/rtems/rtems_showifstat.c @ ea59f45

4.104.114.84.95
Last change on this file since ea59f45 was ea59f45, checked in by Eric Norum <WENorum@…>, on 10/25/05 at 20:38:57

Don't sign-extend address components.

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