1 | /* |
---|
2 | * $Source: /afs/dev.mit.edu/source/repository/athena/bin/mon/netif.c,v $ |
---|
3 | * $Author: dgg $ |
---|
4 | * $Locker: $ |
---|
5 | * $Header: /afs/dev.mit.edu/source/repository/athena/bin/mon/netif.c,v 1.1 1984-12-13 12:01:10 dgg Exp $ |
---|
6 | */ |
---|
7 | |
---|
8 | #ifndef lint |
---|
9 | static char *rcsid_netif_c = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/mon/netif.c,v 1.1 1984-12-13 12:01:10 dgg Exp $"; |
---|
10 | #endif lint |
---|
11 | |
---|
12 | /* |
---|
13 | * N E T I F . C |
---|
14 | * |
---|
15 | * This section of mon handles the network interfaces. |
---|
16 | * |
---|
17 | * nifinit() initializes "static" info on interfaces. |
---|
18 | * nifupdate() gets "dynamic" info on net interfaces. |
---|
19 | */ |
---|
20 | #include "mon.h" |
---|
21 | #include <sys/socket.h> |
---|
22 | #include <net/if.h> |
---|
23 | #include <netinet/in.h> |
---|
24 | |
---|
25 | char *index(); |
---|
26 | |
---|
27 | /* |
---|
28 | * NIFINIT - initialize the static network interfaces info such |
---|
29 | * as device names, addresses, etc. Also calls nifupdate() once |
---|
30 | * to set up initial values for data with running totals. |
---|
31 | */ |
---|
32 | nifinit() |
---|
33 | { |
---|
34 | off_t firstifnet; /* offset to first ifnet struct */ |
---|
35 | off_t ifnetp; /* points to ifnet struct in kmem */ |
---|
36 | struct ifnet ifnet; |
---|
37 | struct nifinfo *nifip; |
---|
38 | |
---|
39 | /* check for valid kernal offset */ |
---|
40 | if (namelist[N_IFNET].n_type == NULL) { |
---|
41 | fprintf(stderr, "mon: ifnet symbol not defined!\n"); |
---|
42 | return; |
---|
43 | } |
---|
44 | |
---|
45 | /* get starting address of ifnet structure chain */ |
---|
46 | lseek(kmem, namelist[N_IFNET].n_value, 0); |
---|
47 | read(kmem, &firstifnet, sizeof(firstifnet)); |
---|
48 | |
---|
49 | /* get info for each interface in chain */ |
---|
50 | numif = 0; /* count number of interfaces */ |
---|
51 | ifnetp = firstifnet; |
---|
52 | nifip = &nifinfo[0]; |
---|
53 | while (ifnetp) { |
---|
54 | char *cp; |
---|
55 | |
---|
56 | numif++; |
---|
57 | /* get an ifnet entry */ |
---|
58 | lseek(kmem, (long)ifnetp, 0); |
---|
59 | read(kmem, &ifnet, sizeof(ifnet)); |
---|
60 | |
---|
61 | /* build its interface name */ |
---|
62 | lseek(kmem, (long)ifnet.if_name, 0); |
---|
63 | read(kmem, nifip->name, 15); |
---|
64 | nifip->name[15] = '\0'; |
---|
65 | cp = index(nifip->name, '\0'); |
---|
66 | sprintf(cp, "%d", ifnet.if_unit); |
---|
67 | |
---|
68 | /* other info comes here */ |
---|
69 | |
---|
70 | if (++nifip >= &nifinfo[MAXIF]) |
---|
71 | break; /* no more room for interfaces */ |
---|
72 | |
---|
73 | ifnetp = (off_t)ifnet.if_next; /* link to next ifnet struct */ |
---|
74 | } |
---|
75 | |
---|
76 | nifupdate(); /* init running totals */ |
---|
77 | } |
---|
78 | |
---|
79 | /* |
---|
80 | * NIFUPDATE - gets the "dynamic" info about the network interfaces. |
---|
81 | */ |
---|
82 | nifupdate() |
---|
83 | { |
---|
84 | off_t ifnetp; /* pointer to ifnet struct in kmem */ |
---|
85 | struct ifnet ifnet; |
---|
86 | int i; |
---|
87 | |
---|
88 | if (namelist[N_IFNET].n_type == NULL) |
---|
89 | return; /* no net interfaces */ |
---|
90 | |
---|
91 | /* get info from ifnet struct chain */ |
---|
92 | lseek(kmem, namelist[N_IFNET].n_value, 0); |
---|
93 | read(kmem, &ifnetp, sizeof(ifnetp)); |
---|
94 | i = 0; |
---|
95 | while (ifnetp) { |
---|
96 | lseek(kmem, (long)ifnetp, 0); |
---|
97 | read (kmem, &ifnet, sizeof(ifnet)); |
---|
98 | |
---|
99 | /* extract interval data from ifnet and update totals */ |
---|
100 | nifdat[i].ipackets = ifnet.if_ipackets - niftot[i].ipackets; |
---|
101 | niftot[i].ipackets = ifnet.if_ipackets; |
---|
102 | nifdat[i].ierrors = ifnet.if_ierrors - niftot[i].ierrors; |
---|
103 | niftot[i].ierrors = ifnet.if_ierrors; |
---|
104 | nifdat[i].opackets = ifnet.if_opackets - niftot[i].opackets; |
---|
105 | niftot[i].opackets = ifnet.if_opackets; |
---|
106 | nifdat[i].oerrors = ifnet.if_oerrors - niftot[i].oerrors; |
---|
107 | niftot[i].oerrors = ifnet.if_oerrors; |
---|
108 | nifdat[i].collisions = ifnet.if_collisions - niftot[i].collisions; |
---|
109 | niftot[i].collisions = ifnet.if_collisions; |
---|
110 | /* extract nifinfo (other stuff) data from ifnet */ |
---|
111 | /* OTHER STUFF OF INTEREST HERE */ |
---|
112 | nifinfo[i].outqlen = ifnet.if_snd.ifq_len; |
---|
113 | |
---|
114 | if (++i >= MAXIF) |
---|
115 | break; /* no more room for interfaces */ |
---|
116 | |
---|
117 | ifnetp = (off_t)ifnet.if_next; /* link to next ifnet struct */ |
---|
118 | } |
---|
119 | } |
---|