source: rtems/cpukit/libnetworking/rtems/rtems_showifstat.c @ 787f51f

5
Last change on this file since 787f51f was 787f51f, checked in by Sebastian Huber <sebastian.huber@…>, on 06/06/17 at 09:08:16

Do not include <sys/ioctl.h> in kernel-space

Update #2833.

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