ncurses/tic: Remove bogus definitions of _XOPEN_SOURCE_EXTENDED.
[dragonfly.git] / tools / tools / ifinfo / rfc1650.c
1 /*
2  * $DragonFly: src/tools/tools/ifinfo/rfc1650.c,v 1.2 2003/11/07 14:38:38 eirikn Exp $
3  */
4
5 #include <sys/types.h>
6 #include <sys/socket.h>         /* for PF_LINK */
7 #include <sys/sysctl.h>
8 #include <sys/time.h>
9
10 #include <err.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <sysexits.h>
14
15 #include <net/if.h>
16 #include <net/if_types.h>
17 #include <net/if_mib.h>
18
19 #include "ifinfo.h"
20
21 #define print(msg, var) \
22         if (var) printf("\t" msg ": %lu\n", (u_long)var)
23
24 static void identify_chipset(u_int32_t chipset);
25
26 void
27 print_1650(const void *xmd, size_t len)
28 {
29         const struct ifmib_iso_8802_3 *md = xmd;
30
31         if (len != sizeof *md)
32                 warnx("cannot interpret %lu bytes of MIB data", (u_long)len);
33
34         identify_chipset(md->dot3StatsEtherChipSet);
35         print("Alignment errors", md->dot3StatsAlignmentErrors);
36         print("FCS errors", md->dot3StatsFCSErrors);
37         print("Single-collision frames", md->dot3StatsSingleCollisionFrames);
38         print("Multiple-collision frames", md->dot3StatsMultipleCollisionFrames);
39         print("SQE (Heartbeat) test errors", md->dot3StatsSQETestErrors);
40         print("Deferred transmissions", md->dot3StatsDeferredTransmissions);
41         print("Late collisions", md->dot3StatsLateCollisions);
42         print("Excessive collisions", md->dot3StatsExcessiveCollisions);
43         print("Internal transmit errors", md->dot3StatsInternalMacTransmitErrors);
44         print("Carrier sense errors", md->dot3StatsCarrierSenseErrors);
45         print("Frame-too-long errors", md->dot3StatsFrameTooLongs);
46         print("Internal receive errors", md->dot3StatsInternalMacReceiveErrors);
47         print("Missed frames", md->dot3StatsMissedFrames);
48 #define cprint(num) print("Packets with " #num " collisions", \
49                           md->dot3StatsCollFrequencies[num - 1])
50         if (md->dot3Compliance >= DOT3COMPLIANCE_COLLS) {
51                 cprint(1); cprint(2); cprint(3); cprint(4);
52                 cprint(5); cprint(6); cprint(7); cprint(8);
53                 cprint(9); cprint(10); cprint(11); cprint(12);
54                 cprint(13); cprint(14); cprint(15); cprint(16);
55         }
56         switch(md->dot3Compliance) {
57         case DOT3COMPLIANCE_STATS:
58                 printf("\tCompliance: statistics only\n");
59                 break;
60         case DOT3COMPLIANCE_COLLS:
61                 printf("\tCompliance: statistics and collisions\n");
62                 break;
63         }
64 }
65
66 static const char *const amd[] = {
67         0, "Am7990", "Am79900", "Am79C940"
68 };
69
70 static const char *const intel[] = {
71         0, "82586", "82596", "82557"
72 };
73
74 static const char *const national[] = {
75         0, "8390", "Sonic"
76 };
77
78 static const char *const fujitsu[] = {
79         0, "86950"
80 };
81
82 static const char *const digital[] = {
83         0, "DC21040", "DC21140", "DC21041", "DC21140A", "DC21142"
84 };
85
86 static const char *const westerndigital[] = {
87         0, "83C690", "83C790"
88 };
89
90 #define vendor(name, sets) { name, sets, (sizeof sets)/(sizeof sets[0]) }
91 static struct {
92         const char *name;
93         const char *const *chips;
94         size_t len;
95 } chipset_names[] = {
96         { 0 },
97         vendor("AMD", amd),
98         vendor("Intel", intel),
99         { 0 },
100         vendor("National Semiconductor", national),
101         vendor("Fujitsu", fujitsu),
102         vendor("Digital", digital),
103         vendor("Western Digital", westerndigital)
104 };
105
106 static void
107 identify_chipset(u_int32_t chipset)
108 {
109         enum dot3Vendors vendor = DOT3CHIPSET_VENDOR(chipset);
110         u_int part = DOT3CHIPSET_PART(chipset);
111
112         printf("\tChipset: ");
113         if (vendor < 1 
114             || vendor >= (sizeof chipset_names)/(sizeof chipset_names[0])
115             || !chipset_names[vendor].name) {
116                 printf("unknown\n");
117                 return;
118         }
119
120         printf("%s ", chipset_names[vendor].name);
121         if (part < 1 || part >= chipset_names[vendor].len) {
122                 printf("unknown\n");
123                 return;
124         }
125
126         printf("%s\n", chipset_names[vendor].chips[part]);
127 }
128