source: rtems/cpukit/libnetworking/rtems/rtems_showifstat.c @ 3274c876

4.104.114.84.95
Last change on this file since 3274c876 was 3274c876, checked in by Joel Sherrill <joel.sherrill@…>, on 04/28/05 at 21:49:50

2005-04-28 Joel Sherrill <joel@…>

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