File: NetDev.c

package info (click to toggle)
kde-workspace 4:4.11.13-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 67,756 kB
  • ctags: 47,705
  • sloc: cpp: 358,638; ansic: 34,695; xml: 5,231; perl: 1,598; sh: 1,307; ruby: 1,135; python: 651; asm: 566; makefile: 37
file content (678 lines) | stat: -rw-r--r-- 16,218 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
/*
    KSysGuard, the KDE System Guard
   
	Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>

	Solaris support by Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
    
    This program is free software; you can redistribute it and/or
    modify it under the terms of version 2 of the GNU General Public
    License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stropts.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>

#include "config.h"

#ifdef HAVE_KSTAT
#include <kstat.h>
#endif

#include "ksysguardd.h"
#include "Command.h"
#include "NetDev.h"

/*
 *  available network interface statistics through kstat(3):
 *
 *	kstat name		value
 *  ----------------------------------------------------------------------
 *  for the loopback interface(s) we can get
 *	ipackets		# packets received
 *	opackets		# packets sent
 *  in addition to those, for "real" interfaces:
 *	oerrors			# xmit errors
 *	ierrors			# recv errors
 *	macxmt_errors		# xmit errors reported by hardware?
 *	macrcv_errors		# recv errors reported by hardware?
 *	opackets64		same as opackets (64bit)
 *	ipackets64		same as ipackets (64bit)
 *	obytes			# bytes sent
 *	rbytes			# bytes received
 *	obytes64		same as obytes (64bit)
 *	rbytes64		same as ibytes (64bit)
 *	collisions		# collisions
 *	multixmt		# multicasts sent?
 *	multircv		# multicasts received?
 *	brdcstxmt		# broadcasts transmitted
 *	brdcstrcv		# broadcasts received
 *	unknowns
 *	blocked
 *	ex_collisions
 *	defer_xmts
 *	align_errors
 *	fcs_errors
 *	oflo			# overflow errors
 *	uflo			# underflow errors
 *	runt_errors
 *	missed
 *	tx_late_collisions
 *	carrier_errors
 *	noxmtbuf
 *	norcvbuf
 *	xmt_badinterp
 *	rcv_badinterp
 *	intr			# interrupts?
 *	xmtretry		# xmit retries?
 *	ifspeed			interface speed: 10000000 for 10BaseT
 *	duplex			"half" or "full"
 *	media			e.g. "PHY/MII"
 *	promisc			promiscuous mode (e.g. "off")
 *	first_collisions
 *	multi_collisions
 *	sqe_errors
 *	toolong_errors
 */

typedef struct {
	char		*Name;
	short		flags;
	unsigned long	ipackets;
	unsigned long	OLDipackets;
	unsigned long	opackets;
	unsigned long	OLDopackets;
	unsigned long	ierrors;
	unsigned long	OLDierrors;
	unsigned long	oerrors;
	unsigned long	OLDoerrors;
	unsigned long	collisions;
	unsigned long	OLDcollisions;
	unsigned long	multixmt;
	unsigned long	OLDmultixmt;
	unsigned long	multircv;
	unsigned long	OLDmultircv;
	unsigned long	brdcstxmt;
	unsigned long	OLDbrdcstxmt;
	unsigned long	brdcstrcv;
	unsigned long	OLDbrdcstrcv;
} NetDevInfo;


#define NBUFFERS 64
#define MAXNETDEVS 64
static NetDevInfo IfInfo[MAXNETDEVS];

static int NetDevCount;

/*
 *  insertnetdev()  --  insert device name & flags into our list
 */
int insertnetdev( const char *name, const short flags ) {

	int	i = 0;

	/*
	 *  interface "aliases" don't seem to have
	 *  separate kstat statistics, so we skip them
	 */
	if( strchr( name, (int) ':' ) != NULL )
		return( 0 );

	while( (i < NetDevCount) && (strcmp( IfInfo[i].Name, name ) != 0) ) {
		if( strcmp( IfInfo[i].Name, name ) == 0 )
			return( 0 );
		i++;
	}

	/*
	 *  init new slot
	 */
	IfInfo[i].Name = strdup( name );
	IfInfo[i].flags = flags;
	IfInfo[i].ipackets = 0L;
	IfInfo[i].OLDipackets = 0L;
	IfInfo[i].opackets = 0L;
	IfInfo[i].OLDopackets = 0L;
	IfInfo[i].ierrors = 0L;
	IfInfo[i].OLDierrors = 0L;
	IfInfo[i].oerrors = 0L;
	IfInfo[i].OLDoerrors = 0L;
	IfInfo[i].collisions = 0L;
	IfInfo[i].OLDcollisions = 0L;
	IfInfo[i].multixmt = 0L;
	IfInfo[i].OLDmultixmt = 0L;
	IfInfo[i].multircv = 0L;
	IfInfo[i].OLDmultircv = 0L;
	IfInfo[i].brdcstxmt = 0L;
	IfInfo[i].OLDbrdcstxmt = 0L;
	IfInfo[i].brdcstrcv = 0L;
	IfInfo[i].OLDbrdcstrcv = 0L;
	NetDevCount = ++i;

	/*  XXX: need sanity checks!  */
	return( 0 );
}

/*
 *  getnetdevlist()  --  get a list of all "up" interfaces
 */
int getnetdevlist( void ) {

	int		fd;
	int		buffsize;
	int		prevsize;
	int		prevCount;
	struct ifconf	ifc;
	struct ifreq	*ifr;

	if( (fd = socket( PF_INET, SOCK_DGRAM, 0 )) < 0 ) {
		return( -1 );
	}

	/*
	 *  get the interface list via iotl( SIOCGIFCONF )
	 *  the following algorithm based on ideas from W.R. Stevens'
	 *  "UNIX Network Programming", Vol. 1:
	 *  Since the ioctl may return 0, indicating success, even if the
	 *  ifreq buffer was too small, we have to make sure, it didn't
	 *  get truncated by comparing our initial size guess with the
	 *  actual returned size.
	 */
	prevsize = 0;
	buffsize = NBUFFERS * sizeof( struct ifreq );
	while( 1 ) {
		if( (ifc.ifc_buf = malloc( buffsize )) == NULL )
			return( -1 );

		ifc.ifc_len = buffsize;
		if( ioctl( fd, SIOCGIFCONF, &ifc ) < 0 ) {
			if( errno != EINVAL || prevsize != 0 ) {
				free( ifc.ifc_buf );
				return( -1 );
			}
		} else {
			if( ifc.ifc_len == prevsize )
				/*  success  */
				break;
			prevsize = ifc.ifc_len;
		}
		/*
		 *  initial buffer guessed too small, allocate a bigger one
		 */
		free( ifc.ifc_buf );
		buffsize = (NBUFFERS + 10) * sizeof( struct ifreq );
	}

	/*
	 *  get the names for all interfaces which are configured "up"
	 *  we're not interested in the ifc data (address), so we reuse the
	 *  same structure (with ifc.len set) for the next ioctl()
	 */
	prevCount = NetDevCount;
	for( ifr = (struct ifreq *) ifc.ifc_buf;
			ifr < (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
			ifr++ ) {
		if( ioctl( fd, SIOCGIFFLAGS, ifr ) < 0 ) {
			free( ifc.ifc_buf );
			return( -1 );
		}
		if( ifr->ifr_flags & IFF_UP )
			insertnetdev( ifr->ifr_name, ifr->ifr_flags );
	}
	free( ifc.ifc_buf );
	close( fd );

	if( (prevCount > 0) && (prevCount != NetDevCount) ) {
		print_error( "RECONFIGURE" );
		prevCount = NetDevCount;
	}

	return( NetDevCount );
}

void initNetDev( struct SensorModul* sm ) {
#ifdef HAVE_KSTAT
	char	mon[128];
	int	i;

	getnetdevlist();
	for( i = 0; i < NetDevCount; i++ ) {
		sprintf( mon, "network/%s/ipackets", IfInfo[i].Name );
		registerMonitor( mon, "integer",
					printIPackets, printIPacketsInfo, sm );
		sprintf( mon, "network/%s/opackets", IfInfo[i].Name );
		registerMonitor( mon, "integer",
					printOPackets, printOPacketsInfo, sm );
		/*
		 *  if this isn't a loopback interface,
		 *  register additional monitors
		 */
		if( ! (IfInfo[i].flags & IFF_LOOPBACK) ) {
			/*
			 *  recv errors
			 */
			sprintf( mon, "network/%s/ierrors",
					IfInfo[i].Name );
			registerMonitor( mon, "integer",
					printIErrors, printIErrorsInfo, sm );
			/*
			 *  xmit errors
			 */
			sprintf( mon, "network/%s/oerrors",
					IfInfo[i].Name );
			registerMonitor( mon, "integer",
					printOErrors, printOErrorsInfo, sm );
			/*
			 *  collisions
			 */
			sprintf( mon, "network/%s/collisions",
					IfInfo[i].Name );
			registerMonitor( mon, "integer",
					printCollisions, printCollisionsInfo, sm );
			/*
			 *  multicast xmits
			 */
			sprintf( mon, "network/%s/multixmt",
					IfInfo[i].Name );
			registerMonitor( mon, "integer",
					printMultiXmits, printMultiXmitsInfo, sm );
			/*
			 *  multicast recvs
			 */
			sprintf( mon, "network/%s/multircv",
					IfInfo[i].Name );
			registerMonitor( mon, "integer",
					printMultiRecvs, printMultiRecvsInfo, sm );
			/*
			 *  broadcast xmits
			 */
			sprintf( mon, "network/%s/brdcstxmt",
					IfInfo[i].Name );
			registerMonitor( mon, "integer",
					printBcastXmits, printBcastXmitsInfo, sm );
			/*
			 *  broadcast recvs
			 */
			sprintf( mon, "network/%s/brdcstrcv",
					IfInfo[i].Name );
			registerMonitor( mon, "integer",
					printBcastRecvs, printBcastRecvsInfo, sm );
		}
	}
#endif
}

void exitNetDev( void ) {
}

int updateNetDev( void ) {

#ifdef HAVE_KSTAT
	kstat_ctl_t		*kctl;
	kstat_t			*ksp;
	kstat_named_t		*kdata;
	int			i;

	/*
	 *  get a kstat handle and update the user's kstat chain
	 */
	if( (kctl = kstat_open()) == NULL )
		return( 0 );
	while( kstat_chain_update( kctl ) != 0 )
		;

	for( i = 0; i < NetDevCount; i++ ) {
		char	*name;
		char	*ptr;

		/*
		 *  chop off the trailing interface no
		 */
		name = strdup( IfInfo[i].Name );
		ptr = name + strlen( name ) - 1;
		while( (ptr > name) && isdigit( (int) *ptr ) ) {
			*ptr = '\0';
			ptr--;
		}

		/*
		 *  traverse the kstat chain
		 *  to find the appropriate statistics
		 */
		if( (ksp = kstat_lookup( kctl,
				name, 0, IfInfo[i].Name )) == NULL ) {
			free( name );
			return( 0 );
		}
		if( kstat_read( kctl, ksp, NULL ) == -1 ) {
			free( name );
			return( 0 );
		}
		free( name );

		/*
		 *  lookup & store the data
		 */
		kdata = (kstat_named_t *) kstat_data_lookup( ksp, "ipackets" );
		if( kdata != NULL ) {
			IfInfo[i].OLDipackets = IfInfo[i].ipackets;
			IfInfo[i].ipackets = kdata->value.ul;
		}
		kdata = (kstat_named_t *) kstat_data_lookup( ksp, "opackets" );
		if( kdata != NULL ) {
			IfInfo[i].OLDopackets = IfInfo[i].opackets;
			IfInfo[i].opackets = kdata->value.ul;
		}
		kdata = (kstat_named_t *) kstat_data_lookup( ksp, "ierrors" );
		if( kdata != NULL ) {
			IfInfo[i].OLDierrors = IfInfo[i].ierrors;
			IfInfo[i].ierrors = kdata->value.ul;
		}
		kdata = (kstat_named_t *) kstat_data_lookup( ksp, "oerrors" );
		if( kdata != NULL ) {
			IfInfo[i].OLDoerrors = IfInfo[i].oerrors;
			IfInfo[i].oerrors = kdata->value.ul;
		}
		kdata = (kstat_named_t *) kstat_data_lookup( ksp, "collisions" );
		if( kdata != NULL ) {
			IfInfo[i].OLDcollisions = IfInfo[i].collisions;
			IfInfo[i].collisions = kdata->value.ul;
		}
		kdata = (kstat_named_t *) kstat_data_lookup( ksp, "multixmt" );
		if( kdata != NULL ) {
			IfInfo[i].OLDmultixmt = IfInfo[i].multixmt;
			IfInfo[i].multixmt = kdata->value.ul;
		}
		kdata = (kstat_named_t *) kstat_data_lookup( ksp, "multircv" );
		if( kdata != NULL ) {
			IfInfo[i].OLDmultircv = IfInfo[i].multircv;
			IfInfo[i].multircv = kdata->value.ul;
		}
		kdata = (kstat_named_t *) kstat_data_lookup( ksp, "brdcstxmt" );
		if( kdata != NULL ) {
			IfInfo[i].OLDbrdcstxmt = IfInfo[i].brdcstxmt;
			IfInfo[i].brdcstxmt = kdata->value.ul;
		}
		kdata = (kstat_named_t *) kstat_data_lookup( ksp, "brdcstrcv" );
		if( kdata != NULL ) {
			IfInfo[i].OLDbrdcstrcv = IfInfo[i].brdcstrcv;
			IfInfo[i].brdcstrcv = kdata->value.ul;
		}
	}

	kstat_close( kctl );
#endif /* ! HAVE_KSTAT */

	return( 0 );
}

void printIPacketsInfo( const char *cmd ) {
	fprintf(CurrentClient, "Received Packets\t0\t0\tPackets\n" );
}

void printIPackets( const char *cmd ) {

	char	*cmdcopy = strdup( cmd );
	char	*name, *ptr;
	int	i;

	ptr = strchr( cmdcopy, (int) '/' );
	name = ++ptr;
	ptr = strchr( name, (int) '/' );
	*ptr = '\0';

	for( i = 0; i < NetDevCount; i++ ) {
		if( (IfInfo[i].OLDipackets > 0)
				&& (strcmp( IfInfo[i].Name, name ) == 0) ) {
			fprintf(CurrentClient, "%ld\n",
				IfInfo[i].ipackets - IfInfo[i].OLDipackets);
			free( cmdcopy );
			return;
		}
	}
	free( cmdcopy );
	fprintf(CurrentClient, "0\n" );
}

void printOPacketsInfo( const char *cmd ) {
	fprintf(CurrentClient, "Transmitted Packets\t0\t0\tPackets\n" );
}

void printOPackets( const char *cmd ) {

	char	*cmdcopy = strdup( cmd );
	char	*name, *ptr;
	int	i;

	ptr = strchr( cmdcopy, (int) '/' );
	name = ++ptr;
	ptr = strchr( name, (int) '/' );
	*ptr = '\0';

	for( i = 0; i < NetDevCount; i++ ) {
		if( (IfInfo[i].OLDopackets > 0)
				&& (strcmp( IfInfo[i].Name, name ) == 0) ) {
			fprintf(CurrentClient, "%ld\n",
				IfInfo[i].opackets - IfInfo[i].OLDopackets );
			free( cmdcopy );
			return;
		}
	}
	free( cmdcopy );
	fprintf(CurrentClient, "0\n" );
}

void printIErrorsInfo( const char *cmd ) {
	fprintf(CurrentClient, "Input Errors\t0\t0\tPackets\n" );
}

void printIErrors( const char *cmd ) {

	char	*cmdcopy = strdup( cmd );
	char	*name, *ptr;
	int	i;

	ptr = strchr( cmdcopy, (int) '/' );
	name = ++ptr;
	ptr = strchr( name, (int) '/' );
	*ptr = '\0';

	for( i = 0; i < NetDevCount; i++ ) {
		if( (IfInfo[i].OLDierrors > 0)
				&& (strcmp( IfInfo[i].Name, name ) == 0) ) {
			fprintf(CurrentClient, "%ld\n",
				IfInfo[i].ierrors - IfInfo[i].OLDierrors );
			free( cmdcopy );
			return;
		}
	}
	free( cmdcopy );
	fprintf(CurrentClient, "0\n" );
}

void printOErrorsInfo( const char *cmd ) {
	fprintf(CurrentClient, "Output Errors\t0\t0\tPackets\n" );
}

void printOErrors( const char *cmd ) {

	char	*cmdcopy = strdup( cmd );
	char	*name, *ptr;
	int	i;

	ptr = strchr( cmdcopy, (int) '/' );
	name = ++ptr;
	ptr = strchr( name, (int) '/' );
	*ptr = '\0';

	for( i = 0; i < NetDevCount; i++ ) {
		if( (IfInfo[i].OLDoerrors > 0)
				&& (strcmp( IfInfo[i].Name, name ) == 0) ) {
			fprintf(CurrentClient, "%ld\n",
				IfInfo[i].oerrors - IfInfo[i].OLDoerrors );
			free( cmdcopy );
			return;
		}
	}
	free( cmdcopy );
	fprintf(CurrentClient, "0\n" );
}

void printCollisionsInfo( const char *cmd ) {
	fprintf(CurrentClient, "Collisions\t0\t0\tPackets\n" );
}

void printCollisions( const char *cmd ) {

	char	*cmdcopy = strdup( cmd );
	char	*name, *ptr;
	int	i;

	ptr = strchr( cmdcopy, (int) '/' );
	name = ++ptr;
	ptr = strchr( name, (int) '/' );
	*ptr = '\0';

	for( i = 0; i < NetDevCount; i++ ) {
		if( (IfInfo[i].OLDcollisions > 0)
				&& (strcmp( IfInfo[i].Name, name ) == 0) ) {
			fprintf(CurrentClient, "%ld\n",
				IfInfo[i].collisions - IfInfo[i].OLDcollisions );
			free( cmdcopy );
			return;
		}
	}
	free( cmdcopy );
	fprintf(CurrentClient, "0\n" );
}

void printMultiXmitsInfo( const char *cmd ) {
	fprintf(CurrentClient, "Multicasts Sent\t0\t0\tPackets\n" );
}

void printMultiXmits( const char *cmd ) {

	char	*cmdcopy = strdup( cmd );
	char	*name, *ptr;
	int	i;

	ptr = strchr( cmdcopy, (int) '/' );
	name = ++ptr;
	ptr = strchr( name, (int) '/' );
	*ptr = '\0';

	for( i = 0; i < NetDevCount; i++ ) {
		if( (IfInfo[i].OLDmultixmt > 0)
				&& (strcmp( IfInfo[i].Name, name ) == 0) ) {
			fprintf(CurrentClient, "%ld\n",
				IfInfo[i].multixmt - IfInfo[i].OLDmultixmt );
			free( cmdcopy );
			return;
		}
	}
	free( cmdcopy );
	fprintf(CurrentClient, "0\n" );
}

void printMultiRecvsInfo( const char *cmd ) {
	fprintf(CurrentClient, "Multicasts Received\t0\t0\tPackets\n" );
}

void printMultiRecvs( const char *cmd ) {

	char	*cmdcopy = strdup( cmd );
	char	*name, *ptr;
	int	i;

	ptr = strchr( cmdcopy, (int) '/' );
	name = ++ptr;
	ptr = strchr( name, (int) '/' );
	*ptr = '\0';

	for( i = 0; i < NetDevCount; i++ ) {
		if( (IfInfo[i].OLDmultircv > 0)
				&& (strcmp( IfInfo[i].Name, name ) == 0) ) {
			fprintf(CurrentClient, "%ld\n",
				IfInfo[i].multircv - IfInfo[i].OLDmultircv );
			free( cmdcopy );
			return;
		}
	}
	free( cmdcopy );
	fprintf(CurrentClient, "0\n" );
}

void printBcastXmitsInfo( const char *cmd ) {
	fprintf(CurrentClient, "Broadcasts Sent\t0\t0\tPackets\n" );
}

void printBcastXmits( const char *cmd ) {

	char	*cmdcopy = strdup( cmd );
	char	*name, *ptr;
	int	i;

	ptr = strchr( cmdcopy, (int) '/' );
	name = ++ptr;
	ptr = strchr( name, (int) '/' );
	*ptr = '\0';

	for( i = 0; i < NetDevCount; i++ ) {
		if( (IfInfo[i].OLDbrdcstxmt > 0)
				&& (strcmp( IfInfo[i].Name, name ) == 0) ) {
			fprintf(CurrentClient, "%ld\n",
				IfInfo[i].brdcstxmt - IfInfo[i].OLDbrdcstxmt );
			free( cmdcopy );
			return;
		}
	}
	free( cmdcopy );
	fprintf(CurrentClient, "0\n" );
}

void printBcastRecvsInfo( const char *cmd ) {
	fprintf(CurrentClient, "Broadcasts Received\t0\t0\tPackets\n" );
}

void printBcastRecvs( const char *cmd ) {

	char	*cmdcopy = strdup( cmd );
	char	*name, *ptr;
	int	i;

	ptr = strchr( cmdcopy, (int) '/' );
	name = ++ptr;
	ptr = strchr( name, (int) '/' );
	*ptr = '\0';

	for( i = 0; i < NetDevCount; i++ ) {
		if( (IfInfo[i].OLDbrdcstrcv > 0)
				&& (strcmp( IfInfo[i].Name, name ) == 0) ) {
			fprintf(CurrentClient, "%ld\n",
				IfInfo[i].brdcstrcv - IfInfo[i].OLDbrdcstrcv );
			free( cmdcopy );
			return;
		}
	}
	free( cmdcopy );
	fprintf(CurrentClient, "0\n" );
}