~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to ksysguard/ksysguardd/Solaris/NetDev.c

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    KSysGuard, the KDE System Guard
 
3
   
 
4
        Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
 
5
 
 
6
        Solaris support by Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
 
7
    
 
8
    This program is free software; you can redistribute it and/or
 
9
    modify it under the terms of version 2 of the GNU General Public
 
10
    License as published by the Free Software Foundation.
 
11
 
 
12
    This program is distributed in the hope that it will be useful,
 
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
    GNU General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU General Public License
 
18
    along with this program; if not, write to the Free Software
 
19
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
20
 
 
21
*/
 
22
 
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
#include <unistd.h>
 
26
#include <string.h>
 
27
#include <errno.h>
 
28
#include <stropts.h>
 
29
#include <ctype.h>
 
30
#include <sys/types.h>
 
31
#include <sys/socket.h>
 
32
#include <sys/sockio.h>
 
33
#include <net/if.h>
 
34
#include <sys/time.h>
 
35
 
 
36
#ifdef HAVE_KSTAT
 
37
#include <kstat.h>
 
38
#endif
 
39
 
 
40
#include "ksysguardd.h"
 
41
#include "Command.h"
 
42
#include "NetDev.h"
 
43
 
 
44
/*
 
45
 *  available network interface statistics through kstat(3):
 
46
 *
 
47
 *      kstat name              value
 
48
 *  ----------------------------------------------------------------------
 
49
 *  for the loopback interface(s) we can get
 
50
 *      ipackets                # packets received
 
51
 *      opackets                # packets sent
 
52
 *  in addition to those, for "real" interfaces:
 
53
 *      oerrors                 # xmit errors
 
54
 *      ierrors                 # recv errors
 
55
 *      macxmt_errors           # xmit errors reported by hardware?
 
56
 *      macrcv_errors           # recv errors reported by hardware?
 
57
 *      opackets64              same as opackets (64bit)
 
58
 *      ipackets64              same as ipackets (64bit)
 
59
 *      obytes                  # bytes sent
 
60
 *      rbytes                  # bytes received
 
61
 *      obytes64                same as obytes (64bit)
 
62
 *      rbytes64                same as ibytes (64bit)
 
63
 *      collisions              # collisions
 
64
 *      multixmt                # multicasts sent?
 
65
 *      multircv                # multicasts received?
 
66
 *      brdcstxmt               # broadcasts transmitted
 
67
 *      brdcstrcv               # broadcasts received
 
68
 *      unknowns
 
69
 *      blocked
 
70
 *      ex_collisions
 
71
 *      defer_xmts
 
72
 *      align_errors
 
73
 *      fcs_errors
 
74
 *      oflo                    # overflow errors
 
75
 *      uflo                    # underflow errors
 
76
 *      runt_errors
 
77
 *      missed
 
78
 *      tx_late_collisions
 
79
 *      carrier_errors
 
80
 *      noxmtbuf
 
81
 *      norcvbuf
 
82
 *      xmt_badinterp
 
83
 *      rcv_badinterp
 
84
 *      intr                    # interrupts?
 
85
 *      xmtretry                # xmit retries?
 
86
 *      ifspeed                 interface speed: 10000000 for 10BaseT
 
87
 *      duplex                  "half" or "full"
 
88
 *      media                   e.g. "PHY/MII"
 
89
 *      promisc                 promiscuous mode (e.g. "off")
 
90
 *      first_collisions
 
91
 *      multi_collisions
 
92
 *      sqe_errors
 
93
 *      toolong_errors
 
94
 */
 
95
 
 
96
typedef struct {
 
97
        char            *Name;
 
98
        short           flags;
 
99
        unsigned long   ipackets;
 
100
        unsigned long   OLDipackets;
 
101
        unsigned long   opackets;
 
102
        unsigned long   OLDopackets;
 
103
        unsigned long   rbytes;
 
104
        unsigned long   OLDrbytes;
 
105
        unsigned long   obytes;
 
106
        unsigned long   OLDobytes;
 
107
        unsigned long   ierrors;
 
108
        unsigned long   OLDierrors;
 
109
        unsigned long   oerrors;
 
110
        unsigned long   OLDoerrors;
 
111
        unsigned long   collisions;
 
112
        unsigned long   OLDcollisions;
 
113
        unsigned long   multixmt;
 
114
        unsigned long   OLDmultixmt;
 
115
        unsigned long   multircv;
 
116
        unsigned long   OLDmultircv;
 
117
        unsigned long   brdcstxmt;
 
118
        unsigned long   OLDbrdcstxmt;
 
119
        unsigned long   brdcstrcv;
 
120
        unsigned long   OLDbrdcstrcv;
 
121
} NetDevInfo;
 
122
 
 
123
 
 
124
#define NBUFFERS 64
 
125
#define MAXNETDEVS 64
 
126
static NetDevInfo IfInfo[MAXNETDEVS];
 
127
 
 
128
static int NetDevCount;
 
129
static float timeInterval = 0;
 
130
static struct timeval lastSampling;
 
131
static struct timeval currSampling;
 
132
 
 
133
/*
 
134
 *  insertnetdev()  --  insert device name & flags into our list
 
135
 */
 
136
int insertnetdev( const char *name, const short flags ) {
 
137
 
 
138
        int     i = 0;
 
139
 
 
140
        /*
 
141
         *  interface "aliases" don't seem to have
 
142
         *  separate kstat statistics, so we skip them
 
143
         */
 
144
        if( strchr( name, (int) ':' ) != NULL )
 
145
                return( 0 );
 
146
 
 
147
        while( (i < NetDevCount) && (strcmp( IfInfo[i].Name, name ) != 0) ) {
 
148
                if( strcmp( IfInfo[i].Name, name ) == 0 )
 
149
                        return( 0 );
 
150
                i++;
 
151
        }
 
152
 
 
153
        /*
 
154
         *  init new slot
 
155
         */
 
156
        IfInfo[i].Name = strdup( name );
 
157
        IfInfo[i].flags = flags;
 
158
        IfInfo[i].ipackets = 0L;
 
159
        IfInfo[i].OLDipackets = 0L;
 
160
        IfInfo[i].opackets = 0L;
 
161
        IfInfo[i].OLDopackets = 0L;
 
162
        IfInfo[i].ierrors = 0L;
 
163
        IfInfo[i].OLDierrors = 0L;
 
164
        IfInfo[i].oerrors = 0L;
 
165
        IfInfo[i].OLDoerrors = 0L;
 
166
        IfInfo[i].collisions = 0L;
 
167
        IfInfo[i].OLDcollisions = 0L;
 
168
        IfInfo[i].multixmt = 0L;
 
169
        IfInfo[i].OLDmultixmt = 0L;
 
170
        IfInfo[i].multircv = 0L;
 
171
        IfInfo[i].OLDmultircv = 0L;
 
172
        IfInfo[i].brdcstxmt = 0L;
 
173
        IfInfo[i].OLDbrdcstxmt = 0L;
 
174
        IfInfo[i].brdcstrcv = 0L;
 
175
        IfInfo[i].OLDbrdcstrcv = 0L;
 
176
        NetDevCount = ++i;
 
177
 
 
178
        /*  XXX: need sanity checks!  */
 
179
        return( 0 );
 
180
}
 
181
 
 
182
/*
 
183
 *  getnetdevlist()  --  get a list of all "up" interfaces
 
184
 */
 
185
int getnetdevlist( void ) {
 
186
 
 
187
        int             fd;
 
188
        int             buffsize;
 
189
        int             prevsize;
 
190
        int             prevCount;
 
191
        struct ifconf   ifc;
 
192
        struct ifreq    *ifr;
 
193
 
 
194
        if( (fd = socket( PF_INET, SOCK_DGRAM, 0 )) < 0 ) {
 
195
                return( -1 );
 
196
        }
 
197
 
 
198
        /*
 
199
         *  get the interface list via iotl( SIOCGIFCONF )
 
200
         *  the following algorithm based on ideas from W.R. Stevens'
 
201
         *  "UNIX Network Programming", Vol. 1:
 
202
         *  Since the ioctl may return 0, indicating success, even if the
 
203
         *  ifreq buffer was too small, we have to make sure, it didn't
 
204
         *  get truncated by comparing our initial size guess with the
 
205
         *  actual returned size.
 
206
         */
 
207
        prevsize = 0;
 
208
        buffsize = NBUFFERS * sizeof( struct ifreq );
 
209
        while( 1 ) {
 
210
                if( (ifc.ifc_buf = malloc( buffsize )) == NULL )
 
211
                        return( -1 );
 
212
 
 
213
                ifc.ifc_len = buffsize;
 
214
                if( ioctl( fd, SIOCGIFCONF, &ifc ) < 0 ) {
 
215
                        if( errno != EINVAL || prevsize != 0 ) {
 
216
                                free( ifc.ifc_buf );
 
217
                                return( -1 );
 
218
                        }
 
219
                } else {
 
220
                        if( ifc.ifc_len == prevsize )
 
221
                                /*  success  */
 
222
                                break;
 
223
                        prevsize = ifc.ifc_len;
 
224
                }
 
225
                /*
 
226
                 *  initial buffer guessed too small, allocate a bigger one
 
227
                 */
 
228
                free( ifc.ifc_buf );
 
229
                buffsize = (NBUFFERS + 10) * sizeof( struct ifreq );
 
230
        }
 
231
 
 
232
        /*
 
233
         *  get the names for all interfaces which are configured "up"
 
234
         *  we're not interested in the ifc data (address), so we reuse the
 
235
         *  same structure (with ifc.len set) for the next ioctl()
 
236
         */
 
237
        prevCount = NetDevCount;
 
238
        for( ifr = (struct ifreq *) ifc.ifc_buf;
 
239
                        ifr < (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
 
240
                        ifr++ ) {
 
241
                if( ioctl( fd, SIOCGIFFLAGS, ifr ) < 0 ) {
 
242
                        free( ifc.ifc_buf );
 
243
                        return( -1 );
 
244
                }
 
245
                if( ifr->ifr_flags & IFF_UP )
 
246
                        insertnetdev( ifr->ifr_name, ifr->ifr_flags );
 
247
        }
 
248
        free( ifc.ifc_buf );
 
249
        close( fd );
 
250
 
 
251
        if( (prevCount > 0) && (prevCount != NetDevCount) ) {
 
252
                print_error( "RECONFIGURE" );
 
253
                prevCount = NetDevCount;
 
254
        }
 
255
 
 
256
        return( NetDevCount );
 
257
}
 
258
 
 
259
void initNetDev( struct SensorModul* sm ) {
 
260
#ifdef HAVE_KSTAT
 
261
        char    mon[128];
 
262
        int     i;
 
263
 
 
264
        getnetdevlist();
 
265
        for( i = 0; i < NetDevCount; i++ ) {
 
266
                sprintf( mon, "network/interfaces/%s/receiver/packets", IfInfo[i].Name );
 
267
                registerMonitor( mon, "integer",
 
268
                                        printIPackets, printIPacketsInfo, sm );
 
269
                sprintf( mon, "network/interfaces/%s/transmitter/packets", IfInfo[i].Name );
 
270
                registerMonitor( mon, "integer",
 
271
                                        printOPackets, printOPacketsInfo, sm );
 
272
                /*
 
273
                 *  if this isn't a loopback interface,
 
274
                 *  register additional monitors
 
275
                 */
 
276
                if( ! (IfInfo[i].flags & IFF_LOOPBACK) ) {
 
277
                        /*
 
278
                         *  recv errors
 
279
                         */
 
280
                        sprintf( mon, "network/interfaces/%s/receiver/errors",
 
281
                                        IfInfo[i].Name );
 
282
                        registerMonitor( mon, "integer",
 
283
                                        printIErrors, printIErrorsInfo, sm );
 
284
                        /*
 
285
                         *  xmit errors
 
286
                         */
 
287
                        sprintf( mon, "network/interfaces/%s/transmitter/errors",
 
288
                                        IfInfo[i].Name );
 
289
                        registerMonitor( mon, "integer",
 
290
                                        printOErrors, printOErrorsInfo, sm );
 
291
                        /*
 
292
                         *  collisions
 
293
                         */
 
294
                        sprintf( mon, "network/interfaces/%s/transmitter/collisions",
 
295
                                        IfInfo[i].Name );
 
296
                        registerMonitor( mon, "integer",
 
297
                                        printCollisions, printCollisionsInfo, sm );
 
298
                        /*
 
299
                         *  multicast xmits
 
300
                         */
 
301
                        sprintf( mon, "network/interfaces/%s/transmitter/multicast",
 
302
                                        IfInfo[i].Name );
 
303
                        registerMonitor( mon, "integer",
 
304
                                        printMultiXmits, printMultiXmitsInfo, sm );
 
305
                        /*
 
306
                         *  multicast recvs
 
307
                         */
 
308
                        sprintf( mon, "network/interfaces/%s/receiver/multicast",
 
309
                                        IfInfo[i].Name );
 
310
                        registerMonitor( mon, "integer",
 
311
                                        printMultiRecvs, printMultiRecvsInfo, sm );
 
312
                        /*
 
313
                         *  broadcast xmits
 
314
                         */
 
315
                        sprintf( mon, "network/interfaces/%s/transmitter/broadcast",
 
316
                                        IfInfo[i].Name );
 
317
                        registerMonitor( mon, "integer",
 
318
                                        printBcastXmits, printBcastXmitsInfo, sm );
 
319
                        /*
 
320
                         *  broadcast recvs
 
321
                         */
 
322
                        sprintf( mon, "network/interfaces/%s/receiver/broadcast",
 
323
                                        IfInfo[i].Name );
 
324
                        registerMonitor( mon, "integer",
 
325
                                        printBcastRecvs, printBcastRecvsInfo, sm );
 
326
 
 
327
                        /*
 
328
                         * Transmitted/Received Data.
 
329
                         */
 
330
                        sprintf( mon, "network/interfaces/%s/receiver/data",
 
331
                                        IfInfo[i].Name );
 
332
                        registerMonitor( mon, "integer",
 
333
                                        printRBytes, printRBytesInfo, sm );
 
334
                        sprintf( mon, "network/interfaces/%s/transmitter/data",
 
335
                                        IfInfo[i].Name );
 
336
                        registerMonitor( mon, "integer",
 
337
                                        printOBytes, printOBytesInfo, sm );
 
338
                }
 
339
        }
 
340
        gettimeofday(&lastSampling, 0);
 
341
#endif
 
342
}
 
343
 
 
344
void exitNetDev( void ) {
 
345
}
 
346
 
 
347
int updateNetDev( void ) {
 
348
 
 
349
#ifdef HAVE_KSTAT
 
350
        kstat_ctl_t             *kctl;
 
351
        kstat_t                 *ksp;
 
352
        kstat_named_t           *kdata;
 
353
        int                     i;
 
354
 
 
355
        /*
 
356
         *  get a kstat handle and update the user's kstat chain
 
357
         */
 
358
        if( (kctl = kstat_open()) == NULL )
 
359
                return( 0 );
 
360
        while( kstat_chain_update( kctl ) != 0 )
 
361
                ;
 
362
 
 
363
        gettimeofday(&currSampling, 0);
 
364
        for( i = 0; i < NetDevCount; i++ ) {
 
365
                char    *name;
 
366
                char    *ptr;
 
367
 
 
368
                /*
 
369
                 *  chop off the trailing interface no
 
370
                 */
 
371
                name = strdup( IfInfo[i].Name );
 
372
                ptr = name + strlen( name ) - 1;
 
373
                while( (ptr > name) && isdigit( (int) *ptr ) ) {
 
374
                        *ptr = '\0';
 
375
                        ptr--;
 
376
                }
 
377
 
 
378
                /*
 
379
                 *  find the appropriate statistics; e.g. 'kstat e1000g:0:e1000g0'
 
380
                 */
 
381
                if( (ksp = kstat_lookup( kctl, name, 0, IfInfo[i].Name )) == NULL ) {
 
382
                        /*
 
383
                         *  try module "link"; e.g. 'kstat link:0:e1000g0'
 
384
                         */
 
385
                        if( (ksp = kstat_lookup( kctl, "link", 0, IfInfo[i].Name )) == NULL ) {
 
386
                                free( name );
 
387
                                continue;
 
388
                        }
 
389
                }
 
390
                if( kstat_read( kctl, ksp, NULL ) == -1 ) {
 
391
                        free( name );
 
392
                        continue;
 
393
                }
 
394
                free( name );
 
395
 
 
396
                /*
 
397
                 *  lookup & store the data
 
398
                 */
 
399
                kdata = (kstat_named_t *) kstat_data_lookup( ksp, "ipackets" );
 
400
                if( kdata != NULL ) {
 
401
                        IfInfo[i].OLDipackets = IfInfo[i].ipackets;
 
402
                        IfInfo[i].ipackets = kdata->value.ul;
 
403
                }
 
404
                kdata = (kstat_named_t *) kstat_data_lookup( ksp, "opackets" );
 
405
                if( kdata != NULL ) {
 
406
                        IfInfo[i].OLDopackets = IfInfo[i].opackets;
 
407
                        IfInfo[i].opackets = kdata->value.ul;
 
408
                }
 
409
                kdata = (kstat_named_t *) kstat_data_lookup( ksp, "ierrors" );
 
410
                if( kdata != NULL ) {
 
411
                        IfInfo[i].OLDierrors = IfInfo[i].ierrors;
 
412
                        IfInfo[i].ierrors = kdata->value.ul;
 
413
                }
 
414
                kdata = (kstat_named_t *) kstat_data_lookup( ksp, "oerrors" );
 
415
                if( kdata != NULL ) {
 
416
                        IfInfo[i].OLDoerrors = IfInfo[i].oerrors;
 
417
                        IfInfo[i].oerrors = kdata->value.ul;
 
418
                }
 
419
                kdata = (kstat_named_t *) kstat_data_lookup( ksp, "collisions" );
 
420
                if( kdata != NULL ) {
 
421
                        IfInfo[i].OLDcollisions = IfInfo[i].collisions;
 
422
                        IfInfo[i].collisions = kdata->value.ul;
 
423
                }
 
424
                kdata = (kstat_named_t *) kstat_data_lookup( ksp, "multixmt" );
 
425
                if( kdata != NULL ) {
 
426
                        IfInfo[i].OLDmultixmt = IfInfo[i].multixmt;
 
427
                        IfInfo[i].multixmt = kdata->value.ul;
 
428
                }
 
429
                kdata = (kstat_named_t *) kstat_data_lookup( ksp, "multircv" );
 
430
                if( kdata != NULL ) {
 
431
                        IfInfo[i].OLDmultircv = IfInfo[i].multircv;
 
432
                        IfInfo[i].multircv = kdata->value.ul;
 
433
                }
 
434
                kdata = (kstat_named_t *) kstat_data_lookup( ksp, "brdcstxmt" );
 
435
                if( kdata != NULL ) {
 
436
                        IfInfo[i].OLDbrdcstxmt = IfInfo[i].brdcstxmt;
 
437
                        IfInfo[i].brdcstxmt = kdata->value.ul;
 
438
                }
 
439
                kdata = (kstat_named_t *) kstat_data_lookup( ksp, "brdcstrcv" );
 
440
                if( kdata != NULL ) {
 
441
                        IfInfo[i].OLDbrdcstrcv = IfInfo[i].brdcstrcv;
 
442
                        IfInfo[i].brdcstrcv = kdata->value.ul;
 
443
                }
 
444
                kdata = (kstat_named_t *) kstat_data_lookup( ksp, "rbytes" );
 
445
                if( kdata != NULL ) {
 
446
                        IfInfo[i].OLDrbytes = IfInfo[i].rbytes;
 
447
                        IfInfo[i].rbytes = kdata->value.ul;
 
448
                }
 
449
                kdata = (kstat_named_t *) kstat_data_lookup( ksp, "obytes" );
 
450
                if( kdata != NULL ) {
 
451
                        IfInfo[i].OLDobytes = IfInfo[i].obytes;
 
452
                        IfInfo[i].obytes = kdata->value.ul;
 
453
                }
 
454
        }
 
455
 
 
456
        kstat_close( kctl );
 
457
        timeInterval = currSampling.tv_sec - lastSampling.tv_sec +
 
458
            ( currSampling.tv_usec - lastSampling.tv_usec ) / 1000000.0;
 
459
        lastSampling = currSampling;
 
460
#endif /* ! HAVE_KSTAT */
 
461
 
 
462
        return( 0 );
 
463
}
 
464
 
 
465
void printIPacketsInfo( const char *cmd ) {
 
466
        fprintf(CurrentClient, "Received Packets\t0\t0\tPackets\n" );
 
467
}
 
468
 
 
469
void printIPackets( const char *cmd ) {
 
470
 
 
471
        char    *cmdcopy = strdup( cmd );
 
472
        char    *name, *ptr;
 
473
        int     i;
 
474
 
 
475
        ptr = strchr( cmdcopy, (int) '/' );
 
476
        name = ++ptr;
 
477
        ptr = strchr( name, (int) '/' );
 
478
        name = ++ptr;
 
479
        ptr = strchr( name, (int) '/' );
 
480
        *ptr = '\0';
 
481
 
 
482
        for( i = 0; i < NetDevCount; i++ ) {
 
483
                if( (IfInfo[i].OLDipackets > 0)
 
484
                                && (strcmp( IfInfo[i].Name, name ) == 0) ) {
 
485
                        fprintf(CurrentClient, "%ld\n",
 
486
                                IfInfo[i].ipackets - IfInfo[i].OLDipackets);
 
487
                        free( cmdcopy );
 
488
                        return;
 
489
                }
 
490
        }
 
491
        free( cmdcopy );
 
492
        fprintf(CurrentClient, "0\n" );
 
493
}
 
494
 
 
495
void printOPacketsInfo( const char *cmd ) {
 
496
        fprintf(CurrentClient, "Transmitted Packets\t0\t0\tPackets\n" );
 
497
}
 
498
 
 
499
void printOPackets( const char *cmd ) {
 
500
 
 
501
        char    *cmdcopy = strdup( cmd );
 
502
        char    *name, *ptr;
 
503
        int     i;
 
504
 
 
505
        ptr = strchr( cmdcopy, (int) '/' );
 
506
        name = ++ptr;
 
507
        ptr = strchr( name, (int) '/' );
 
508
        name = ++ptr;
 
509
        ptr = strchr( name, (int) '/' );
 
510
        *ptr = '\0';
 
511
 
 
512
        for( i = 0; i < NetDevCount; i++ ) {
 
513
                if( (IfInfo[i].OLDopackets > 0)
 
514
                                && (strcmp( IfInfo[i].Name, name ) == 0) ) {
 
515
                        fprintf(CurrentClient, "%ld\n",
 
516
                                IfInfo[i].opackets - IfInfo[i].OLDopackets );
 
517
                        free( cmdcopy );
 
518
                        return;
 
519
                }
 
520
        }
 
521
        free( cmdcopy );
 
522
        fprintf(CurrentClient, "0\n" );
 
523
}
 
524
 
 
525
void printRBytesInfo( const char *cmd ) {
 
526
        fprintf(CurrentClient, "Received Data\t0\t0\tKB/s\n" );
 
527
}
 
528
 
 
529
void printRBytes( const char *cmd ) {
 
530
 
 
531
        char    *cmdcopy = strdup( cmd );
 
532
        char    *name, *ptr;
 
533
        int     i;
 
534
 
 
535
        ptr = strchr( cmdcopy, (int) '/' );
 
536
        name = ++ptr;
 
537
        ptr = strchr( name, (int) '/' );
 
538
        name = ++ptr;
 
539
        ptr = strchr( name, (int) '/' );
 
540
        *ptr = '\0';
 
541
 
 
542
        for( i = 0; i < NetDevCount; i++ ) {
 
543
                if( (IfInfo[i].OLDrbytes > 0)
 
544
                                && (strcmp( IfInfo[i].Name, name ) == 0) ) {
 
545
                        long rate = ((float)(IfInfo[i].rbytes - IfInfo[i].OLDrbytes) / timeInterval) / 1024;
 
546
                        fprintf(CurrentClient, "%ld\n", rate);
 
547
                        free( cmdcopy );
 
548
                        return;
 
549
                }
 
550
        }
 
551
        free( cmdcopy );
 
552
        fprintf(CurrentClient, "0\n" );
 
553
}
 
554
 
 
555
void printOBytesInfo( const char *cmd ) {
 
556
        fprintf(CurrentClient, "Transmitted Data\t0\t0\tKB/s\n" );
 
557
}
 
558
 
 
559
void printOBytes( const char *cmd ) {
 
560
 
 
561
        char    *cmdcopy = strdup( cmd );
 
562
        char    *name, *ptr;
 
563
        int     i;
 
564
 
 
565
        ptr = strchr( cmdcopy, (int) '/' );
 
566
        name = ++ptr;
 
567
        ptr = strchr( name, (int) '/' );
 
568
        name = ++ptr;
 
569
        ptr = strchr( name, (int) '/' );
 
570
        *ptr = '\0';
 
571
 
 
572
        for( i = 0; i < NetDevCount; i++ ) {
 
573
                if( (IfInfo[i].OLDobytes > 0)
 
574
                                && (strcmp( IfInfo[i].Name, name ) == 0) ) {
 
575
                        long rate = ((float)(IfInfo[i].obytes - IfInfo[i].OLDobytes) / timeInterval) / 1024;
 
576
                        fprintf(CurrentClient, "%ld\n", rate);
 
577
                        free( cmdcopy );
 
578
                        return;
 
579
                }
 
580
        }
 
581
        free( cmdcopy );
 
582
        fprintf(CurrentClient, "0\n" );
 
583
}
 
584
 
 
585
void printIErrorsInfo( const char *cmd ) {
 
586
        fprintf(CurrentClient, "Input Errors\t0\t0\tPackets\n" );
 
587
}
 
588
 
 
589
void printIErrors( const char *cmd ) {
 
590
 
 
591
        char    *cmdcopy = strdup( cmd );
 
592
        char    *name, *ptr;
 
593
        int     i;
 
594
 
 
595
        ptr = strchr( cmdcopy, (int) '/' );
 
596
        name = ++ptr;
 
597
        ptr = strchr( name, (int) '/' );
 
598
        name = ++ptr;
 
599
        ptr = strchr( name, (int) '/' );
 
600
        *ptr = '\0';
 
601
 
 
602
        for( i = 0; i < NetDevCount; i++ ) {
 
603
                if( (IfInfo[i].OLDierrors > 0)
 
604
                                && (strcmp( IfInfo[i].Name, name ) == 0) ) {
 
605
                        fprintf(CurrentClient, "%ld\n",
 
606
                                IfInfo[i].ierrors - IfInfo[i].OLDierrors );
 
607
                        free( cmdcopy );
 
608
                        return;
 
609
                }
 
610
        }
 
611
        free( cmdcopy );
 
612
        fprintf(CurrentClient, "0\n" );
 
613
}
 
614
 
 
615
void printOErrorsInfo( const char *cmd ) {
 
616
        fprintf(CurrentClient, "Output Errors\t0\t0\tPackets\n" );
 
617
}
 
618
 
 
619
void printOErrors( const char *cmd ) {
 
620
 
 
621
        char    *cmdcopy = strdup( cmd );
 
622
        char    *name, *ptr;
 
623
        int     i;
 
624
 
 
625
        ptr = strchr( cmdcopy, (int) '/' );
 
626
        name = ++ptr;
 
627
        ptr = strchr( name, (int) '/' );
 
628
        name = ++ptr;
 
629
        ptr = strchr( name, (int) '/' );
 
630
        *ptr = '\0';
 
631
 
 
632
        for( i = 0; i < NetDevCount; i++ ) {
 
633
                if( (IfInfo[i].OLDoerrors > 0)
 
634
                                && (strcmp( IfInfo[i].Name, name ) == 0) ) {
 
635
                        fprintf(CurrentClient, "%ld\n",
 
636
                                IfInfo[i].oerrors - IfInfo[i].OLDoerrors );
 
637
                        free( cmdcopy );
 
638
                        return;
 
639
                }
 
640
        }
 
641
        free( cmdcopy );
 
642
        fprintf(CurrentClient, "0\n" );
 
643
}
 
644
 
 
645
void printCollisionsInfo( const char *cmd ) {
 
646
        fprintf(CurrentClient, "Collisions\t0\t0\tPackets\n" );
 
647
}
 
648
 
 
649
void printCollisions( const char *cmd ) {
 
650
 
 
651
        char    *cmdcopy = strdup( cmd );
 
652
        char    *name, *ptr;
 
653
        int     i;
 
654
 
 
655
        ptr = strchr( cmdcopy, (int) '/' );
 
656
        name = ++ptr;
 
657
        ptr = strchr( name, (int) '/' );
 
658
        name = ++ptr;
 
659
        ptr = strchr( name, (int) '/' );
 
660
        *ptr = '\0';
 
661
 
 
662
        for( i = 0; i < NetDevCount; i++ ) {
 
663
                if( (IfInfo[i].OLDcollisions > 0)
 
664
                                && (strcmp( IfInfo[i].Name, name ) == 0) ) {
 
665
                        fprintf(CurrentClient, "%ld\n",
 
666
                                IfInfo[i].collisions - IfInfo[i].OLDcollisions );
 
667
                        free( cmdcopy );
 
668
                        return;
 
669
                }
 
670
        }
 
671
        free( cmdcopy );
 
672
        fprintf(CurrentClient, "0\n" );
 
673
}
 
674
 
 
675
void printMultiXmitsInfo( const char *cmd ) {
 
676
        fprintf(CurrentClient, "Multicasts Sent\t0\t0\tPackets\n" );
 
677
}
 
678
 
 
679
void printMultiXmits( const char *cmd ) {
 
680
 
 
681
        char    *cmdcopy = strdup( cmd );
 
682
        char    *name, *ptr;
 
683
        int     i;
 
684
 
 
685
        ptr = strchr( cmdcopy, (int) '/' );
 
686
        name = ++ptr;
 
687
        ptr = strchr( name, (int) '/' );
 
688
        name = ++ptr;
 
689
        ptr = strchr( name, (int) '/' );
 
690
        *ptr = '\0';
 
691
 
 
692
        for( i = 0; i < NetDevCount; i++ ) {
 
693
                if( (IfInfo[i].OLDmultixmt > 0)
 
694
                                && (strcmp( IfInfo[i].Name, name ) == 0) ) {
 
695
                        fprintf(CurrentClient, "%ld\n",
 
696
                                IfInfo[i].multixmt - IfInfo[i].OLDmultixmt );
 
697
                        free( cmdcopy );
 
698
                        return;
 
699
                }
 
700
        }
 
701
        free( cmdcopy );
 
702
        fprintf(CurrentClient, "0\n" );
 
703
}
 
704
 
 
705
void printMultiRecvsInfo( const char *cmd ) {
 
706
        fprintf(CurrentClient, "Multicasts Received\t0\t0\tPackets\n" );
 
707
}
 
708
 
 
709
void printMultiRecvs( const char *cmd ) {
 
710
 
 
711
        char    *cmdcopy = strdup( cmd );
 
712
        char    *name, *ptr;
 
713
        int     i;
 
714
 
 
715
        ptr = strchr( cmdcopy, (int) '/' );
 
716
        name = ++ptr;
 
717
        ptr = strchr( name, (int) '/' );
 
718
        name = ++ptr;
 
719
        ptr = strchr( name, (int) '/' );
 
720
        *ptr = '\0';
 
721
 
 
722
        for( i = 0; i < NetDevCount; i++ ) {
 
723
                if( (IfInfo[i].OLDmultircv > 0)
 
724
                                && (strcmp( IfInfo[i].Name, name ) == 0) ) {
 
725
                        fprintf(CurrentClient, "%ld\n",
 
726
                                IfInfo[i].multircv - IfInfo[i].OLDmultircv );
 
727
                        free( cmdcopy );
 
728
                        return;
 
729
                }
 
730
        }
 
731
        free( cmdcopy );
 
732
        fprintf(CurrentClient, "0\n" );
 
733
}
 
734
 
 
735
void printBcastXmitsInfo( const char *cmd ) {
 
736
        fprintf(CurrentClient, "Broadcasts Sent\t0\t0\tPackets\n" );
 
737
}
 
738
 
 
739
void printBcastXmits( const char *cmd ) {
 
740
 
 
741
        char    *cmdcopy = strdup( cmd );
 
742
        char    *name, *ptr;
 
743
        int     i;
 
744
 
 
745
        ptr = strchr( cmdcopy, (int) '/' );
 
746
        name = ++ptr;
 
747
        ptr = strchr( name, (int) '/' );
 
748
        name = ++ptr;
 
749
        ptr = strchr( name, (int) '/' );
 
750
        *ptr = '\0';
 
751
 
 
752
        for( i = 0; i < NetDevCount; i++ ) {
 
753
                if( (IfInfo[i].OLDbrdcstxmt > 0)
 
754
                                && (strcmp( IfInfo[i].Name, name ) == 0) ) {
 
755
                        fprintf(CurrentClient, "%ld\n",
 
756
                                IfInfo[i].brdcstxmt - IfInfo[i].OLDbrdcstxmt );
 
757
                        free( cmdcopy );
 
758
                        return;
 
759
                }
 
760
        }
 
761
        free( cmdcopy );
 
762
        fprintf(CurrentClient, "0\n" );
 
763
}
 
764
 
 
765
void printBcastRecvsInfo( const char *cmd ) {
 
766
        fprintf(CurrentClient, "Broadcasts Received\t0\t0\tPackets\n" );
 
767
}
 
768
 
 
769
void printBcastRecvs( const char *cmd ) {
 
770
 
 
771
        char    *cmdcopy = strdup( cmd );
 
772
        char    *name, *ptr;
 
773
        int     i;
 
774
 
 
775
        ptr = strchr( cmdcopy, (int) '/' );
 
776
        name = ++ptr;
 
777
        ptr = strchr( name, (int) '/' );
 
778
        name = ++ptr;
 
779
        ptr = strchr( name, (int) '/' );
 
780
        *ptr = '\0';
 
781
 
 
782
        for( i = 0; i < NetDevCount; i++ ) {
 
783
                if( (IfInfo[i].OLDbrdcstrcv > 0)
 
784
                                && (strcmp( IfInfo[i].Name, name ) == 0) ) {
 
785
                        fprintf(CurrentClient, "%ld\n",
 
786
                                IfInfo[i].brdcstrcv - IfInfo[i].OLDbrdcstrcv );
 
787
                        free( cmdcopy );
 
788
                        return;
 
789
                }
 
790
        }
 
791
        free( cmdcopy );
 
792
        fprintf(CurrentClient, "0\n" );
 
793
}