2
* Copyright (C) 1998-2001 Luca Deri <deri@ntop.org>
3
* Portions by Stefano Suin <stefano@ntop.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "globals-report.h"
25
/* #define PRINT_ALL_ACTIVE_SESSIONS 1 */
29
/* ************************************ */
31
void formatUsageCounter(UsageCounter usageCtr,
32
TrafficCounter topValue
33
/* If this value != 0 then a percentage is printed */
39
/* No percentage is printed */
40
if(snprintf(buf, sizeof(buf), "<TD "TD_BG" ALIGN=RIGHT>%s</TD>",
41
formatPkts(usageCtr.value)) < 0)
42
traceEvent(TRACE_ERROR, "Buffer overflow!");
47
pctg = ((float)usageCtr.value/(float)topValue)*100;
49
if(pctg > 100) pctg = 100; /* This should not happen ! */
51
if(snprintf(buf, sizeof(buf), "<TD "TD_BG" ALIGN=RIGHT>%s [%.0f %%]</TD>",
52
formatPkts(usageCtr.value), pctg) < 0)
53
traceEvent(TRACE_ERROR, "Buffer overflow!");
58
for(i=0; i<MAX_NUM_CONTACTED_PEERS; i++)
59
if((usageCtr.peersIndexes[i] != NO_PEER)
60
&& (usageCtr.peersIndexes[i] != 0 /* Safety check: broadcast */)) {
61
struct hostTraffic *el1;
63
el1 = device[actualReportDeviceId].
64
hash_hostTraffic[checkSessionIdx(usageCtr.peersIndexes[i])];
68
sendString("<TD "TD_BG" ALIGN=LEFT><ul>");
72
sendString(makeHostLink(el1, 0, 0, 0));
77
sendString("</ul></TD>\n");
79
sendString("<TD "TD_BG"> </TD>\n");
82
/* ********************************** */
84
void printTableDoubleEntry(char *buf, int bufLen,
85
char *label, char* color,
86
float totalS, float percentageS,
87
float totalR, float percentageR) {
90
if((totalS == 0) && (totalR == 0)) return;
91
int_perc = (int)percentageS;
93
/* This shouldn't happen */
97
} else if(int_perc > 100) {
104
if(snprintf(buf, bufLen, "<TR %s><TH WIDTH=100 "TH_BG" ALIGN=LEFT>%s</TH>"
105
"<TD WIDTH=100 "TD_BG" ALIGN=RIGHT>%s</TD>"
106
"<TD WIDTH=100 "TD_BG"> </TD>\n",
107
getRowColor(), label, formatKBytes(totalS)) < 0)
108
traceEvent(TRACE_ERROR, "Buffer overflow!");
111
if(snprintf(buf, bufLen, "<TR %s><TH WIDTH=100 "TH_BG" ALIGN=LEFT>%s</TH>"
112
"<TD WIDTH=100 "TD_BG" ALIGN=RIGHT>%s</TD>"
113
"<TD WIDTH=100><IMG ALT=\"100%%\"ALIGN=MIDDLE SRC=/gauge.jpg WIDTH=100 HEIGHT=12></TD>\n",
114
getRowColor(), label, formatKBytes(totalS)) < 0)
115
traceEvent(TRACE_ERROR, "Buffer overflow!");
118
if(snprintf(buf, bufLen, "<TR %s><TH WIDTH=100 "TH_BG" ALIGN=LEFT>%s</TH>"
119
"<TD WIDTH=100 "TD_BG" ALIGN=RIGHT>%s</TD>"
120
"<TD WIDTH=100 "TD_BG"><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=\"100\">"
121
"<TR><TD><IMG ALT=\"%d%%\" ALIGN=MIDDLE SRC=/gauge.jpg WIDTH=\"%d\" HEIGHT=12></TD>"
122
"<TD "TD_BG" ALIGN=CENTER WIDTH=\"%d\">"
123
"<P> </TD></TR></TABLE></TD>\n",
124
getRowColor(), label, formatKBytes(totalS),
125
int_perc, (100*int_perc)/100, (100*(100-int_perc))/100) < 0)
126
traceEvent(TRACE_ERROR, "Buffer overflow!");
131
/* ************************ */
133
if(totalR == 0) percentageR = 0;
135
int_perc = (int)percentageR;
137
/* This shouldn't happen */
141
} else if(int_perc > 100) {
148
if(snprintf(buf, bufLen, "<TD WIDTH=100 "TD_BG" ALIGN=RIGHT>%s</TD>"
149
"<TD WIDTH=100 "TD_BG"> </TD></TR>\n",
150
formatKBytes(totalR)) < 0)
151
traceEvent(TRACE_ERROR, "Buffer overflow!");
154
if(snprintf(buf, bufLen, "<TD WIDTH=100 "TD_BG" ALIGN=RIGHT>%s</TD>"
155
"<TD WIDTH=100><IMG ALIGN=MIDDLE ALT=\"100\" SRC=/gauge.jpg WIDTH=\"100\" HEIGHT=12></TD></TR>\n",
156
formatKBytes(totalR)) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
159
if(snprintf(buf, bufLen, "<TD WIDTH=100 "TD_BG" ALIGN=RIGHT>%s</TD>"
160
"<TD WIDTH=100 "TD_BG"><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=\"100\">"
161
"<TR><TD><IMG ALT=\"%d%%\" ALIGN=MIDDLE SRC=/gauge.jpg WIDTH=\"%d\" HEIGHT=12>"
162
"</TD><TD "TD_BG" ALIGN=CENTER WIDTH=\"%d\">"
163
"<P> </TD></TR></TABLE></TD></TR>\n",
164
formatKBytes(totalR),
165
int_perc, (100*int_perc)/100, (100*(100-int_perc))/100) < 0)
166
traceEvent(TRACE_ERROR, "Buffer overflow!");
172
/* ********************************** */
174
void printTableEntryPercentage(char *buf, int bufLen,
175
char *label, char* label_1,
176
char* label_2, float total,
178
int int_perc = (int)percentage;
180
/* This shouldn't happen */
183
else if(int_perc > 100)
189
if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
190
"<TD ALIGN=CENTER BGCOLOR=\"%s\">%s (100 %%)</TD></TR>\n",
191
getRowColor(), label, COLOR_2, label_2) < 0)
192
traceEvent(TRACE_ERROR, "Buffer overflow!");
194
if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>%s</TD>"
195
"<TD ALIGN=CENTER BGCOLOR=\"%s\">%s (100 %%)</TD></TR>\n",
196
getRowColor(), label, formatKBytes(total), COLOR_2, label_2) < 0)
197
traceEvent(TRACE_ERROR, "Buffer overflow!");
202
if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
203
"<TD ALIGN=CENTER BGCOLOR=\"%s\">%s (100 %%)</TD></TR>\n",
204
getRowColor(), label, COLOR_1, label_1) < 0)
205
traceEvent(TRACE_ERROR, "Buffer overflow!");
207
if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>%s</TD>"
208
"<TD ALIGN=CENTER BGCOLOR=\"%s\">%s (100 %%)</TD></TR>\n",
209
getRowColor(), label, formatKBytes(total), COLOR_1, label_1) < 0)
210
traceEvent(TRACE_ERROR, "Buffer overflow!");
215
if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
216
"<TD "TD_BG"><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=\"100%%\">"
217
"<TR><TD ALIGN=CENTER WIDTH=\"%d%%\" BGCOLOR=\"%s\">"
218
"<P>%s (%.1f %%)</TD><TD ALIGN=CENTER WIDTH=\"%d%%\" BGCOLOR=\"%s\">"
219
"<P>%s (%.1f %%)</TD></TR></TABLE></TD></TR>\n",
220
getRowColor(), label,
222
label_1, percentage, (100-int_perc), COLOR_2,
223
label_2, (100-percentage)) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
225
if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>%s</TD>"
226
"<TD "TD_BG"><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=\"100%%\">"
227
"<TR><TD ALIGN=CENTER WIDTH=\"%d%%\" BGCOLOR=\"%s\">"
228
"<P>%s (%.1f %%)</TD><TD ALIGN=CENTER WIDTH=\"%d%%\" BGCOLOR=\"%s\">"
229
"<P>%s (%.1f %%)</TD></TR></TABLE></TD></TR>\n",
230
getRowColor(), label, formatKBytes(total),
232
label_1, percentage, (100-int_perc), COLOR_2,
233
label_2, (100-percentage)) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
240
/* ******************************* */
242
void printHeader(int reportType, int revertOrder, u_int column) {
244
char *sign, *arrowGif, *arrow[48], *theAnchor[48];
246
char htmlAnchor[64], htmlAnchor1[64];
248
/* printf("->%d<-\n",screenNumber); */
252
arrowGif = " <IMG ALT=\"Ascending order, click to reverse\" SRC=arrow_up.gif BORDER=0>";
255
arrowGif = " <IMG ALT=\"Descending order, click to reverse\" SRC=arrow_down.gif BORDER=0>";
258
memset(buf, 0, sizeof(buf));
261
if((reportType == 0) || (reportType == 1)) {
262
if(reportType == 0) {
263
if(snprintf(htmlAnchor, sizeof(htmlAnchor),
264
"<A HREF=/%s?%s", STR_SORT_DATA_SENT_PROTOS, sign) < 0)
265
traceEvent(TRACE_ERROR, "Buffer overflow!");
266
if(snprintf(htmlAnchor1, sizeof(htmlAnchor1),
267
"<A HREF=/%s?", STR_SORT_DATA_SENT_PROTOS) < 0)
268
traceEvent(TRACE_ERROR, "Buffer overflow!");
270
if(snprintf(htmlAnchor, sizeof(htmlAnchor),
271
"<A HREF=/%s?%s", STR_SORT_DATA_SENT_IP, sign) < 0)
272
traceEvent(TRACE_ERROR, "Buffer overflow!");
273
if(snprintf(htmlAnchor1, sizeof(htmlAnchor1),
274
"<A HREF=/%s?", STR_SORT_DATA_SENT_IP) < 0)
275
traceEvent(TRACE_ERROR, "Buffer overflow!");
277
} else if(reportType == 2) {
278
if(snprintf(htmlAnchor, sizeof(htmlAnchor),
279
"<A HREF=/%s?%s", STR_SORT_DATA_SENT_THPT, sign) < 0)
280
traceEvent(TRACE_ERROR, "Buffer overflow!");
281
if(snprintf(htmlAnchor1, sizeof(htmlAnchor1),
282
"<A HREF=/%s?", STR_SORT_DATA_SENT_THPT) < 0)
283
traceEvent(TRACE_ERROR, "Buffer overflow!");
284
} else if(reportType == 3) {
285
if(snprintf(htmlAnchor, sizeof(htmlAnchor),
286
"<A HREF=/%s?%s", STR_SORT_DATA_SENT_HOST_TRAFFIC, sign) < 0)
287
traceEvent(TRACE_ERROR, "Buffer overflow!");
288
if(snprintf(htmlAnchor1, sizeof(htmlAnchor1),
289
"<A HREF=/%s?", STR_SORT_DATA_SENT_HOST_TRAFFIC) < 0)
290
traceEvent(TRACE_ERROR, "Buffer overflow!");
293
if((reportType == 0) || (reportType == 1)) {
294
if(abs(column) == HOST_DUMMY_IDX_VALUE)
295
{ arrow[0] = arrowGif; theAnchor[0] = htmlAnchor; }
296
else { arrow[0] = ""; theAnchor[0] = htmlAnchor1; }
297
if(abs(column) == DOMAIN_DUMMY_IDX_VALUE)
298
{ arrow[1] = arrowGif; theAnchor[1] = htmlAnchor; }
299
else { arrow[1] = ""; theAnchor[1] = htmlAnchor1;}
301
{ arrow[2] = arrowGif; theAnchor[2] = htmlAnchor; }
302
else { arrow[2] = ""; theAnchor[2] = htmlAnchor1; }
303
sendString("<CENTER>\n");
304
if(snprintf(buf, BUF_SIZE, ""TABLE_ON"<TABLE BORDER=1><TR>"
305
"<TH "TH_BG">%s"HOST_DUMMY_IDX_STR">Host%s</A></TH>\n"
306
"<TH "TH_BG">%s"DOMAIN_DUMMY_IDX_STR">Domain%s</A></TH>"
307
"<TH "TH_BG" COLSPAN=2>%s0>Sent%s</A></TH>\n",
308
theAnchor[0], arrow[0], theAnchor[1], arrow[1],
309
theAnchor[2], arrow[2]) < 0)
310
traceEvent(TRACE_ERROR, "Buffer overflow!");
312
if(abs(column) == HOST_DUMMY_IDX_VALUE)
313
{ arrow[0] = arrowGif; theAnchor[0] = htmlAnchor; }
314
else { arrow[0] = ""; theAnchor[0] = htmlAnchor1; }
315
if(abs(column) == DOMAIN_DUMMY_IDX_VALUE)
316
{ arrow[1] = arrowGif; theAnchor[1] = htmlAnchor; }
317
else { arrow[1] = ""; theAnchor[1] = htmlAnchor1; }
318
sendString("<CENTER>\n");
319
if(snprintf(buf, BUF_SIZE, ""TABLE_ON"<TABLE BORDER=1><TR>"
320
"<TH "TH_BG">%s"HOST_DUMMY_IDX_STR">Host%s</A></TH>"
321
"<TH "TH_BG">%s"DOMAIN_DUMMY_IDX_STR">Domain%s</A></TH>\n\n",
322
theAnchor[0], arrow[0], theAnchor[1], arrow[1]) < 0)
323
traceEvent(TRACE_ERROR, "Buffer overflow!");
328
if((reportType == 0) || (reportType == 1)) {
329
if(reportType == 0) {
330
if(snprintf(htmlAnchor, sizeof(htmlAnchor), "<A HREF=/%s?%s",
331
STR_SORT_DATA_RECEIVED_PROTOS, sign) < 0)
332
traceEvent(TRACE_ERROR, "Buffer overflow!");
333
if(snprintf(htmlAnchor1, sizeof(htmlAnchor1), "<A HREF=/%s?",
334
STR_SORT_DATA_RECEIVED_PROTOS) < 0)
335
traceEvent(TRACE_ERROR, "Buffer overflow!");
337
if(snprintf(htmlAnchor, sizeof(htmlAnchor), "<A HREF=/%s?%s",
338
STR_SORT_DATA_RECEIVED_IP, sign) < 0)
339
traceEvent(TRACE_ERROR, "Buffer overflow!");
340
if(snprintf(htmlAnchor1, sizeof(htmlAnchor1), "<A HREF=/%s?",
341
STR_SORT_DATA_RECEIVED_IP) < 0)
342
traceEvent(TRACE_ERROR, "Buffer overflow!");
344
} else if(reportType == 2) {
345
if(snprintf(htmlAnchor, sizeof(htmlAnchor), "<A HREF=/%s?%s",
346
STR_SORT_DATA_RECEIVED_THPT, sign) < 0)
347
traceEvent(TRACE_ERROR, "Buffer overflow!");
348
if(snprintf(htmlAnchor1, sizeof(htmlAnchor1), "<A HREF=/%s?",
349
STR_SORT_DATA_RECEIVED_THPT) < 0)
350
traceEvent(TRACE_ERROR, "Buffer overflow!");
351
} else if(reportType == 3) {
352
if(snprintf(htmlAnchor, sizeof(htmlAnchor), "<A HREF=/%s?%s",
353
STR_SORT_DATA_RCVD_HOST_TRAFFIC, sign) < 0)
354
traceEvent(TRACE_ERROR, "Buffer overflow!");
355
if(snprintf(htmlAnchor1, sizeof(htmlAnchor1), "<A HREF=/%s?",
356
STR_SORT_DATA_RCVD_HOST_TRAFFIC) < 0)
357
traceEvent(TRACE_ERROR, "Buffer overflow!");
360
if((reportType == 0) || (reportType == 1)) {
361
if(abs(column) == HOST_DUMMY_IDX_VALUE)
362
{ arrow[0] = arrowGif; theAnchor[0] = htmlAnchor; }
363
else { arrow[0] = ""; theAnchor[0] = htmlAnchor1; }
364
if(abs(column) == DOMAIN_DUMMY_IDX_VALUE)
365
{ arrow[1] = arrowGif; theAnchor[1] = htmlAnchor; }
366
else { arrow[1] = ""; theAnchor[1] = htmlAnchor1;}
368
{ arrow[2] = arrowGif; theAnchor[2] = htmlAnchor; }
369
else { arrow[2] = ""; theAnchor[2] = htmlAnchor1; }
370
sendString("<CENTER>\n");
371
if(snprintf(buf, BUF_SIZE, ""TABLE_ON"<TABLE BORDER=1><TR>"
372
"<TH "TH_BG">%s"HOST_DUMMY_IDX_STR">Host%s</A></TH>\n"
373
"<TH "TH_BG">%s"DOMAIN_DUMMY_IDX_STR">Domain%s</A></TH>"
374
"<TH "TH_BG" COLSPAN=2>%s0>Received%s</A></TH>\n",
375
theAnchor[0], arrow[0], theAnchor[1],
376
arrow[1], theAnchor[2], arrow[2]) < 0)
377
traceEvent(TRACE_ERROR, "Buffer overflow!");
379
if(abs(column) == HOST_DUMMY_IDX_VALUE)
380
{ arrow[0] = arrowGif; theAnchor[0] = htmlAnchor; }
381
else { arrow[0] = ""; theAnchor[0] = htmlAnchor1; }
382
if(abs(column) == DOMAIN_DUMMY_IDX_VALUE)
383
{ arrow[1] = arrowGif; theAnchor[1] = htmlAnchor; }
384
else { arrow[1] = ""; theAnchor[1] = htmlAnchor1;}
385
sendString("<CENTER>\n");
386
if(snprintf(buf, BUF_SIZE, ""TABLE_ON"<TABLE BORDER=1><TR>"
387
"<TH "TH_BG">%s"HOST_DUMMY_IDX_STR">Host%s</A></TH>"
388
"<TH "TH_BG">%s"DOMAIN_DUMMY_IDX_STR">Domain%s</A></TH>\n\n",
389
theAnchor[0], arrow[0], theAnchor[1], arrow[1]) < 0)
390
traceEvent(TRACE_ERROR, "Buffer overflow!");
395
if(reportType == 0) {
397
{ arrow[0] = arrowGif; theAnchor[0] = htmlAnchor; }
398
else { arrow[0] = ""; theAnchor[0] = htmlAnchor1; }
400
{ arrow[1] = arrowGif; theAnchor[1] = htmlAnchor; }
401
else { arrow[1] = ""; theAnchor[1] = htmlAnchor1;}
403
{ arrow[2] = arrowGif; theAnchor[2] = htmlAnchor; }
404
else { arrow[2] = ""; theAnchor[2] = htmlAnchor1; }
406
{ arrow[3] = arrowGif; theAnchor[3] = htmlAnchor; }
407
else { arrow[3] = ""; theAnchor[3] = htmlAnchor1; }
409
{ arrow[4] = arrowGif; theAnchor[4] = htmlAnchor; }
410
else { arrow[4] = ""; theAnchor[4] = htmlAnchor1; }
412
{ arrow[5] = arrowGif; theAnchor[5] = htmlAnchor; }
413
else { arrow[5] = ""; theAnchor[5] = htmlAnchor1; }
415
{ arrow[6] = arrowGif; theAnchor[6] = htmlAnchor1; }
416
else { arrow[6] = ""; theAnchor[6] = htmlAnchor; }
418
{ arrow[7] = arrowGif; theAnchor[7] = htmlAnchor; }
419
else { arrow[7] = ""; theAnchor[7] = htmlAnchor1; }
421
{ arrow[8] = arrowGif; theAnchor[8] = htmlAnchor; }
422
else { arrow[8] = ""; theAnchor[8] = htmlAnchor1; }
423
if(abs(column) == 10)
424
{ arrow[9] = arrowGif; theAnchor[9] = htmlAnchor; }
425
else { arrow[9] = ""; theAnchor[9] = htmlAnchor1; }
426
if(abs(column) == 11)
427
{ arrow[10] = arrowGif; theAnchor[10] = htmlAnchor; }
428
else { arrow[10] = ""; theAnchor[10] = htmlAnchor1;}
429
if(abs(column) == 12)
430
{ arrow[11] = arrowGif; theAnchor[11] = htmlAnchor; }
431
else { arrow[11] = "";theAnchor[11] = htmlAnchor1; }
432
if(abs(column) == 13)
433
{ arrow[12] = arrowGif; theAnchor[12] = htmlAnchor; }
434
else { arrow[12] = ""; theAnchor[12] = htmlAnchor1; }
435
if(abs(column) == 14)
436
{ arrow[13] = arrowGif; theAnchor[13] = htmlAnchor; }
437
else { arrow[13] = ""; theAnchor[13] = htmlAnchor1; }
438
if(abs(column) == 15)
439
{ arrow[14] = arrowGif; theAnchor[14] = htmlAnchor; }
440
else { arrow[14] = ""; theAnchor[14] = htmlAnchor1; }
442
if(snprintf(buf, BUF_SIZE, "<TH "TH_BG">%s1>TCP%s</A></TH>"
443
"<TH "TH_BG">%s2>UDP%s</A></TH><TH "TH_BG">%s3>ICMP%s</A></TH>"
444
"<TH "TH_BG">%s4>DLC%s</A></TH><TH "TH_BG">%s5>IPX%s</A>"
445
"</TH><TH "TH_BG">%s6>Decnet%s</A></TH>"
446
"<TH "TH_BG">%s7>(R)ARP%s</A></TH><TH "TH_BG">%s8>AppleTalk%s</A></TH>",
447
theAnchor[0], arrow[0], theAnchor[1], arrow[1],
448
theAnchor[2], arrow[2], theAnchor[3], arrow[3],
449
theAnchor[4], arrow[4], theAnchor[5], arrow[5],
450
theAnchor[6], arrow[6], theAnchor[7], arrow[7]) < 0)
451
traceEvent(TRACE_ERROR, "Buffer overflow!");
453
if(snprintf(buf, BUF_SIZE,
454
"<TH "TH_BG">%s9>OSPF%s</A></TH>"
455
"<TH "TH_BG">%s10>NetBios%s</A></TH>"
456
"<TH "TH_BG">%s11>IGMP%s</A></TH>"
457
"<TH "TH_BG">%s12>OSI%s</A></TH>"
458
"<TH "TH_BG">%s13>QNX%s</A></TH>"
459
"<TH "TH_BG">%s14>STP%s</A></TH>"
460
"<TH "TH_BG">%s15>Other%s</A></TH>",
461
theAnchor[8], arrow[8],
462
theAnchor[9], arrow[9],
463
theAnchor[10], arrow[10],
464
theAnchor[11], arrow[11],
465
theAnchor[12], arrow[12],
466
theAnchor[13], arrow[13],
467
theAnchor[14], arrow[14]) < 0)
468
traceEvent(TRACE_ERROR, "Buffer overflow!");
470
} else if(reportType == 1) {
473
if(abs(column) == 1) {
475
theAnchor[0] = htmlAnchor;
478
theAnchor[0] = htmlAnchor1;
481
#ifdef ENABLE_NAPSTER
482
if(snprintf(buf, BUF_SIZE, "<TH "TH_BG">%s%d>%s%s</A></TH>",
483
theAnchor[0], 1, "Napster", arrow[0]) < 0)
484
traceEvent(TRACE_ERROR, "Buffer overflow!");
488
for(i=0; i<numIpProtosToMonitor; i++) {
489
if(abs(column) == soFar) {
491
theAnchor[0] = htmlAnchor;
494
theAnchor[0] = htmlAnchor1;
496
if(snprintf(buf, BUF_SIZE, "<TH "TH_BG">%s%d>%s%s</A></TH>",
497
theAnchor[0], i+2, protoIPTrafficInfos[i], arrow[0]) < 0)
498
traceEvent(TRACE_ERROR, "Buffer overflow!");
503
if(abs(column) == soFar) {
504
arrow[0] = arrowGif; theAnchor[0] = htmlAnchor;
506
arrow[0] = ""; theAnchor[0] = htmlAnchor1;
508
if(snprintf(buf, BUF_SIZE, "<TH "TH_BG">%s%d>Other IP%s</A></TH>",
509
theAnchor[0], i+2, arrow[0]) < 0)
510
traceEvent(TRACE_ERROR, "Buffer overflow!");
512
} else if(reportType == 2) {
514
if(abs(column) == 1) { arrow[0] = arrowGif; theAnchor[0] = htmlAnchor; }
515
else { arrow[0] = ""; theAnchor[0] = htmlAnchor1; }
516
if(abs(column) == 2) { arrow[1] = arrowGif; theAnchor[1] = htmlAnchor; }
517
else { arrow[1] = ""; theAnchor[1] = htmlAnchor1; }
518
if(abs(column) == 3) { arrow[2] = arrowGif; theAnchor[2] = htmlAnchor; }
519
else { arrow[2] = ""; theAnchor[2] = htmlAnchor1;}
520
if(abs(column) == 4) { arrow[3] = arrowGif; theAnchor[3] = htmlAnchor; }
521
else { arrow[3] = ""; theAnchor[3] = htmlAnchor1;}
522
if(abs(column) == 5) { arrow[4] = arrowGif; theAnchor[4] = htmlAnchor; }
523
else { arrow[4] = ""; theAnchor[4] = htmlAnchor1;}
524
if(abs(column) == 6) { arrow[5] = arrowGif; theAnchor[5] = htmlAnchor; }
525
else { arrow[5] = ""; theAnchor[5] = htmlAnchor1;}
527
if(snprintf(buf, BUF_SIZE, "<TH "TH_BG">%s1>Actual Thpt%s</A></TH>"
528
"<TH "TH_BG">%s2>Avg Thpt%s</A></TH>"
529
"<TH "TH_BG">%s3>Peak Thpt%s</A></TH>"
530
"<TH "TH_BG">%s4>Actual Pkt Thpt%s</A></TH><TH "TH_BG">%s5>Avg Pkt Thpt%s</A></TH>"
531
"<TH "TH_BG">%s6>Peak Pkt Thpt%s</A></TH>",
532
theAnchor[0], arrow[0], theAnchor[1], arrow[1], theAnchor[2], arrow[2],
533
theAnchor[3], arrow[3], theAnchor[4], arrow[4], theAnchor[5], arrow[5]) < 0)
534
traceEvent(TRACE_ERROR, "Buffer overflow!");
536
} else if(reportType == 3) {
537
sendString("<TH "TH_BG">0<br>AM</TH><TH "TH_BG">1<br>AM</TH>"
538
"<TH "TH_BG">2<br>AM</TH><TH "TH_BG">3<br>AM</TH>"
539
"<TH "TH_BG">4<br>AM</TH><TH "TH_BG">5<br>AM</TH><TH "TH_BG">6<br>AM</TH>"
540
"<TH "TH_BG">7<br>AM</TH><TH "TH_BG">8<br>AM</TH><TH "TH_BG">9<br>AM</TH>"
541
"<TH "TH_BG">10<br>AM</TH><TH "TH_BG">11<br>AM</TH><TH "TH_BG">12<br>AM</TH>\n");
542
sendString("<TH "TH_BG">1<br>PM</TH><TH "TH_BG">2<br>PM</TH><TH "TH_BG">3<br>PM</TH>"
543
"<TH "TH_BG">4<br>PM</TH><TH "TH_BG">5<br>PM</TH><TH "TH_BG">6<br>PM</TH>"
544
"<TH "TH_BG">7<br>PM</TH><TH "TH_BG">8<br>PM</TH><TH "TH_BG">9<br>PM</TH>"
545
"<TH "TH_BG">10<br>PM</TH><TH "TH_BG">11<br>PM</TH>\n");
547
sendString("</TR>\n");
550
/* ******************************* */
552
char* getOSFlag(char* osName, int showOsName) {
553
static char tmpStr[96], *flagImg;
555
if(strstr(osName, "Windows") != NULL)
556
flagImg = "<IMG ALT=\"OS: Windows\" ALIGN=MIDDLE SRC=/statsicons/os/windows.gif>";
557
else if(strstr(osName, "IRIX") != NULL)
558
flagImg = "<IMG ALT=\"OS: Irix\" ALIGN=MIDDLE SRC=/statsicons/os/irix.gif>";
559
else if(strstr(osName, "Linux") != NULL)
560
flagImg = "<IMG ALT=\"OS: Linux\" ALIGN=MIDDLE SRC=/statsicons/os/linux.gif>";
561
else if(strstr(osName, "SunOS") != NULL)
562
flagImg = "<IMG ALT=\"OS: SunOS\" ALIGN=MIDDLE SRC=/statsicons/os/sun.gif>";
563
else if(strstr(osName, "Solaris") != NULL)
564
flagImg = "<IMG ALT=\"OS: Solaris\" ALIGN=MIDDLE SRC=/statsicons/os/sun.gif>";
565
else if(strstr(osName, "HP/JETdirect") != NULL)
566
flagImg = "<IMG ALT=\"OS: HP/JetDirect\" ALIGN=MIDDLE SRC=/statsicons/os/hp.gif>";
567
else if(strstr(osName, "Mac") != NULL)
568
flagImg = "<IMG ALT=\"OS: Apple Mac\" ALIGN=MIDDLE SRC=/statsicons/os/mac.gif>";
569
else if(strstr(osName, "Novell") != NULL)
570
flagImg = "<IMG ALT=\"OS: Novell\" ALIGN=MIDDLE SRC=/statsicons/os/novell.gif>";
571
else if((strstr(osName, "BSD") != NULL)
572
|| (strstr(osName, "Unix") != NULL)
573
|| (strstr(osName, "Berkeley") != NULL))
574
flagImg = "<IMG ALT=\"OS: BSD Unix\" ALIGN=MIDDLE SRC=/statsicons/os/bsd.gif>";
575
else if(strstr(osName, "HP-UX") != NULL)
576
flagImg = "<IMG ALT=\"OS: HP-UX\" ALIGN=MIDDLE SRC=/statsicons/os/hp.gif>";
577
else if(strstr(osName, "AIX") != NULL)
578
flagImg = "<IMG ALT=\"OS: AIX\" ALIGN=MIDDLE SRC=/statsicons/os/aix.gif>";
584
strncpy(tmpStr, flagImg, sizeof(tmpStr));
586
strncpy(tmpStr, "", sizeof(tmpStr));
588
if(flagImg != NULL) {
589
if(snprintf(tmpStr, sizeof(tmpStr), "%s [%s]", flagImg, osName) < 0)
590
traceEvent(TRACE_ERROR, "Buffer overflow!");
592
strncpy(tmpStr, osName, sizeof(tmpStr));
598
/* ******************************* */
600
int sortHostFctn(const void *_a, const void *_b) {
601
HostTraffic **a = (HostTraffic **)_a;
602
HostTraffic **b = (HostTraffic **)_b;
604
char *nameA, *nameB, nameA_str[32], nameB_str[32];
606
if((a == NULL) && (b != NULL)) {
607
traceEvent(TRACE_WARNING, "WARNING (1)\n");
609
} else if((a != NULL) && (b == NULL)) {
610
traceEvent(TRACE_WARNING, "WARNING (2)\n");
612
} else if((a == NULL) && (b == NULL)) {
613
traceEvent(TRACE_WARNING, "WARNING (3)\n");
620
accessMutex(&addressResolutionMutex, "sortHostFctn");
622
rc = strcasecmp((*a)->hostSymIpAddress[0] != '\0' ? (*a)->hostSymIpAddress : (*a)->ethAddressString,
623
(*b)->hostSymIpAddress[0] != '\0' ? (*b)->hostSymIpAddress : (*b)->ethAddressString);
625
releaseMutex(&addressResolutionMutex);
630
if((*a)->hostIpAddress.s_addr > (*b)->hostIpAddress.s_addr)
632
else if((*a)->hostIpAddress.s_addr < (*b)->hostIpAddress.s_addr)
636
/* return(strcasecmp((*a)->hostNumIpAddress, (*b)->hostNumIpAddress)); */
639
return(strcasecmp((*a)->ethAddressString, (*b)->ethAddressString));
642
return(strcasecmp(getVendorInfo((*a)->ethAddress, 0),
643
getVendorInfo((*b)->ethAddress, 0)));
646
if((*a)->nbHostName != NULL)
647
nameA = (*a)->nbHostName;
648
else if((*a)->atNodeName != NULL)
649
nameA = (*a)->atNodeName;
650
else if((*a)->atNetwork != 0) {
651
if(snprintf(nameA_str, sizeof(nameA_str), "%d.%d", (*a)->atNetwork, (*a)->atNode) < 0)
652
traceEvent(TRACE_ERROR, "Buffer overflow!");
654
} else if((*a)->ipxHostName != NULL)
655
nameA = (*a)->ipxHostName;
659
if((*b)->nbHostName != NULL)
660
nameB = (*b)->nbHostName;
661
else if((*b)->atNodeName != NULL)
662
nameB = (*b)->atNodeName;
663
else if((*a)->atNetwork != 0) {
664
if(snprintf(nameB_str, sizeof(nameB_str), "%d.%d", (*b)->atNetwork, (*b)->atNode) < 0)
665
traceEvent(TRACE_ERROR, "Buffer overflow!");
667
} else if((*b)->ipxHostName != NULL)
668
nameB = (*b)->ipxHostName;
672
return(strcasecmp(nameA, nameB));
676
if((*a)->actBandwidthUsage < (*b)->actBandwidthUsage)
678
else if ((*a)->actBandwidthUsage > (*b)->actBandwidthUsage)
686
/* ******************************* */
688
int cmpUsersTraffic(const void *_a, const void *_b) {
689
UsersTraffic **a = (UsersTraffic **)_a;
690
UsersTraffic **b = (UsersTraffic **)_b;
691
TrafficCounter sum_a, sum_b;
693
if((a == NULL) && (b != NULL)) {
695
} else if((a != NULL) && (b == NULL)) {
697
} else if((a == NULL) && (b == NULL)) {
701
sum_a = (*a)->bytesSent + (*a)->bytesReceived;
702
sum_b = (*b)->bytesSent + (*b)->bytesReceived;
706
else if (sum_a == sum_b)
712
/* ******************************* */
714
int cmpProcesses(const void *_a, const void *_b) {
715
ProcessInfo **a = (ProcessInfo **)_a;
716
ProcessInfo **b = (ProcessInfo **)_b;
718
if((a == NULL) && (b != NULL)) {
720
} else if((a != NULL) && (b == NULL)) {
722
} else if((a == NULL) && (b == NULL)) {
728
if((*a)->pid == (*b)->pid)
730
else if((*a)->pid < (*b)->pid)
735
return(strcasecmp((*a)->user, (*b)->user));
738
if((*a)->bytesSent == (*b)->bytesSent)
740
else if((*a)->bytesSent < (*b)->bytesSent)
745
if((*a)->bytesReceived == (*b)->bytesReceived)
747
else if((*a)->bytesReceived < (*b)->bytesReceived)
751
default: /* Process name */
752
return(strcasecmp((*a)->command, (*b)->command));
756
/* ******************************* */
758
int cmpFctn(const void *_a, const void *_b) {
759
HostTraffic **a = (HostTraffic **)_a;
760
HostTraffic **b = (HostTraffic **)_b;
761
TrafficCounter a_=0, b_=0;
764
short oldColumnSort, floatCompare=0;
766
if((a == NULL) && (b != NULL)) {
767
traceEvent(TRACE_WARNING, "WARNING (1)\n");
769
} else if((a != NULL) && (b == NULL)) {
770
traceEvent(TRACE_WARNING, "WARNING (2)\n");
772
} else if((a == NULL) && (b == NULL)) {
773
traceEvent(TRACE_WARNING, "WARNING (3)\n");
778
printf("screenNumber=%d, columnSort=%d\n", screenNumber, columnSort);
781
if(columnSort == HOST_DUMMY_IDX_VALUE) {
786
accessMutex(&addressResolutionMutex, "cmpFctn");
789
if((*a)->hostSymIpAddress[0] != '\0') {
792
name1 = (*a)->hostSymIpAddress;
793
name2 = (*b)->hostSymIpAddress;
795
if(name1[0] == '*') name1++;
796
if(name2[0] == '*') name2++;
797
rc = strcasecmp(name1, name2);
799
rc = strcasecmp((*a)->ethAddressString, (*b)->ethAddressString);
802
releaseMutex(&addressResolutionMutex);
805
} else if(columnSort == DOMAIN_DUMMY_IDX_VALUE) {
808
fillDomainName(*a); fillDomainName(*b);
811
traceEvent(TRACE_INFO, "%s='%s'/'%s' - %s='%s'/'%s'\n",
812
(*a)->hostSymIpAddress,
813
(*a)->dotDomainName, (*a)->fullDomainName,
814
(*b)->hostSymIpAddress,
815
(*b)->dotDomainName, (*b)->fullDomainName
818
rc = strcasecmp((*a)->dotDomainName, (*b)->dotDomainName);
820
return(strcasecmp((*a)->fullDomainName, (*b)->fullDomainName));
825
oldColumnSort = columnSort;
827
if(screenNumber == DUMMY_IDX_VALUE) {
836
idx = (screenNumber-MAX_NUM_PROTOS_SCREENS)*3;
839
traceEvent(TRACE_INFO, "idx=%d/columnSort=%d/sortSendMode=%d/screenNumber=%d/numIpProtosToMonitor=%d\n",
840
idx, columnSort, sortSendMode, screenNumber, numIpProtosToMonitor);
846
a_ = (*a)->bytesSent, b_ = (*b)->bytesSent;
848
a_ = (*a)->bytesReceived, b_ = (*b)->bytesReceived;
856
a_ = (*a)->tcpSentLocally+(*a)->tcpSentRemotely;
857
b_ = (*b)->tcpSentLocally+(*b)->tcpSentRemotely;
860
a_ = (*a)->dlcSent, b_ = (*b)->dlcSent;
863
a_ = (*a)->arp_rarpSent, b_ = (*b)->arp_rarpSent;
866
a_ = (*a)->netbiosSent, b_ = (*b)->netbiosSent;
868
case MAX_NUM_PROTOS_SCREENS:
869
fa_ = (*a)->actualSentThpt, fb_ = (*b)->actualSentThpt, floatCompare = 1;
873
if(idx <= numIpProtosToMonitor) {
875
#ifdef ENABLE_NAPSTER
876
if((*a)->napsterStats == NULL)
879
a_ = (*a)->napsterStats->bytesSent;
881
if((*b)->napsterStats == NULL)
884
b_ = (*b)->napsterStats->bytesSent;
889
a_ = (*a)->protoIPTrafficInfos[idx-1].sentLocally
890
+(*a)->protoIPTrafficInfos[idx-1].sentRemotely;
891
b_ = (*b)->protoIPTrafficInfos[idx-1].sentLocally
892
+(*b)->protoIPTrafficInfos[idx-1].sentRemotely;
899
for(i=0; i<numIpProtosToMonitor; i++) {
900
a_ += (*a)->protoIPTrafficInfos[i].sentLocally
901
+(*a)->protoIPTrafficInfos[i].sentRemotely;
902
b_ += (*b)->protoIPTrafficInfos[i].sentLocally
903
+(*b)->protoIPTrafficInfos[i].sentRemotely;
906
if((*a)->bytesSent > a_)
907
a_ = (*a)->bytesSent-a_;
911
if((*b)->bytesSent > b_)
912
b_ = (*b)->bytesSent-b_;
921
a_ = (*a)->tcpReceivedLocally+(*a)->tcpReceivedFromRemote;
922
b_ = (*b)->tcpReceivedLocally+(*b)->tcpReceivedFromRemote;
925
a_ = (*a)->dlcReceived, b_ = (*b)->dlcReceived;
928
a_ = (*a)->arp_rarpReceived, b_ = (*b)->arp_rarpReceived;
931
a_ = (*a)->netbiosReceived, b_ = (*b)->netbiosReceived;
933
case MAX_NUM_PROTOS_SCREENS:
934
fa_ = (*a)->actualRcvdThpt,
935
fb_ = (*b)->actualRcvdThpt, floatCompare = 1;
938
if(idx <= numIpProtosToMonitor) {
940
#ifdef ENABLE_NAPSTER
941
if((*a)->napsterStats == NULL)
944
a_ = (*a)->napsterStats->bytesRcvd;
946
if((*b)->napsterStats == NULL)
949
b_ = (*b)->napsterStats->bytesRcvd;
954
a_ = (*a)->protoIPTrafficInfos[idx-1].receivedLocally
955
+(*a)->protoIPTrafficInfos[idx-1].receivedFromRemote;
956
b_ = (*b)->protoIPTrafficInfos[idx-1].receivedLocally
957
+(*b)->protoIPTrafficInfos[idx-1].receivedFromRemote;
964
for(i=0; i<numIpProtosToMonitor; i++) {
965
a_ += (*a)->protoIPTrafficInfos[i].receivedLocally
966
+(*a)->protoIPTrafficInfos[i].receivedFromRemote;
967
b_ += (*b)->protoIPTrafficInfos[i].receivedLocally
968
+(*b)->protoIPTrafficInfos[i].receivedFromRemote;
971
if((*a)->bytesReceived > a_)
972
a_ = (*a)->bytesReceived-a_;
976
if((*b)->bytesReceived > b_)
977
b_ = (*b)->bytesReceived-b_;
982
traceEvent(TRACE_INFO, "=>%d (%s)<=>%d (%s)<=\n",
983
(int)a_, (*a)->hostSymIpAddress,
984
(int)b_, (*b)->hostSymIpAddress);
995
a_ = (*a)->udpSentLocally +(*a)->udpSentRemotely;
996
b_ = (*b)->udpSentLocally +(*b)->udpSentRemotely;
999
a_ = (*a)->ipxSent, b_ = (*b)->ipxSent;
1002
a_ = (*a)->appletalkSent, b_ = (*b)->appletalkSent;
1005
a_ = (*a)->igmpSent, b_ = (*b)->igmpSent;
1007
case MAX_NUM_PROTOS_SCREENS:
1008
fa_ = (*a)->averageSentThpt,
1009
fb_ = (*b)->averageSentThpt, floatCompare = 1;
1012
if(++idx < numIpProtosToMonitor) {
1013
a_ = (*a)->protoIPTrafficInfos[idx].sentLocally
1014
+(*a)->protoIPTrafficInfos[idx].sentRemotely;
1015
b_ = (*b)->protoIPTrafficInfos[idx].sentLocally
1016
+(*b)->protoIPTrafficInfos[idx].sentRemotely;
1022
for(i=0; i<numIpProtosToMonitor; i++) {
1023
a_ += (*a)->protoIPTrafficInfos[i].sentLocally
1024
+(*a)->protoIPTrafficInfos[i].sentRemotely;
1025
b_ += (*b)->protoIPTrafficInfos[i].sentLocally
1026
+(*b)->protoIPTrafficInfos[i].sentRemotely;
1029
if((*a)->bytesSent > a_)
1030
a_ = (*a)->bytesSent-a_;
1034
if((*b)->bytesSent > b_)
1035
b_ = (*b)->bytesSent-b_;
1041
switch(screenNumber)
1044
a_ = (*a)->udpReceivedLocally +(*a)->udpReceivedFromRemote;
1045
b_ = (*b)->udpReceivedLocally +(*b)->udpReceivedFromRemote;
1048
a_ = (*a)->ipxReceived, b_ = (*b)->ipxReceived;
1051
a_ = (*a)->appletalkReceived, b_ = (*b)->appletalkReceived;
1054
a_ = (*a)->igmpReceived, b_ = (*b)->igmpReceived;
1056
case MAX_NUM_PROTOS_SCREENS:
1057
fa_ = (*a)->averageRcvdThpt,
1058
fb_ = (*b)->averageRcvdThpt, floatCompare = 1;
1061
if(++idx < numIpProtosToMonitor) {
1062
a_ = (*a)->protoIPTrafficInfos[idx].receivedLocally
1063
+(*a)->protoIPTrafficInfos[idx].receivedFromRemote;
1064
b_ = (*b)->protoIPTrafficInfos[idx].receivedLocally
1065
+(*b)->protoIPTrafficInfos[idx].receivedFromRemote;
1071
for(i=0; i<numIpProtosToMonitor; i++) {
1072
a_ += (*a)->protoIPTrafficInfos[i].receivedLocally
1073
+(*a)->protoIPTrafficInfos[i].receivedFromRemote;
1074
b_ += (*b)->protoIPTrafficInfos[i].receivedLocally
1075
+(*b)->protoIPTrafficInfos[i].receivedFromRemote;
1078
if((*a)->bytesReceived > a_)
1079
a_ = (*a)->bytesReceived-a_;
1083
if((*b)->bytesReceived > b_)
1084
b_ = (*b)->bytesReceived-b_;
1093
switch(screenNumber)
1096
a_ = (*a)->icmpSent, b_ = (*b)->icmpSent;
1099
a_ = (*a)->decnetSent, b_ = (*b)->decnetSent;
1102
a_ = (*a)->ospfSent, b_ = (*b)->ospfSent;
1105
a_ = (*a)->osiSent, b_ = (*b)->osiSent;
1108
a_ = (*a)->qnxSent, b_ = (*b)->qnxSent;
1110
case 5: /* MAX_NUM_PROTOS_SCREENS: */
1111
fa_ = (*a)->peakSentThpt,
1112
fb_ = (*b)->peakSentThpt, floatCompare = 1;
1116
if(idx < numIpProtosToMonitor) {
1117
a_ = (*a)->protoIPTrafficInfos[idx].sentLocally
1118
+(*a)->protoIPTrafficInfos[idx].sentRemotely;
1119
b_ = (*b)->protoIPTrafficInfos[idx].sentLocally
1120
+(*b)->protoIPTrafficInfos[idx].sentRemotely;
1126
for(i=0; i<numIpProtosToMonitor; i++) {
1127
a_ += (*a)->protoIPTrafficInfos[i].sentLocally
1128
+(*a)->protoIPTrafficInfos[i].sentRemotely;
1129
b_ += (*b)->protoIPTrafficInfos[i].sentLocally
1130
+(*b)->protoIPTrafficInfos[i].sentRemotely;
1133
if((*a)->bytesSent > a_)
1134
a_ = (*a)->bytesSent-a_;
1138
if((*b)->bytesSent > b_)
1139
b_ = (*b)->bytesSent-b_;
1145
switch(screenNumber)
1148
a_ = (*a)->icmpReceived, b_ = (*b)->icmpReceived;
1151
a_ = (*a)->decnetReceived, b_ = (*b)->decnetReceived;
1154
a_ = (*a)->ospfReceived, b_ = (*b)->ospfReceived;
1157
a_ = (*a)->osiReceived, b_ = (*b)->osiReceived;
1159
case MAX_NUM_PROTOS_SCREENS:
1160
fa_ = (*a)->peakRcvdThpt,
1161
fb_ = (*b)->peakRcvdThpt, floatCompare = 1;
1165
if(idx < numIpProtosToMonitor) {
1166
a_ = (*a)->protoIPTrafficInfos[idx].receivedLocally
1167
+(*a)->protoIPTrafficInfos[idx].receivedFromRemote;
1168
b_ = (*b)->protoIPTrafficInfos[idx].receivedLocally
1169
+(*b)->protoIPTrafficInfos[idx].receivedFromRemote;
1175
for(i=0; i<numIpProtosToMonitor; i++) {
1176
a_ += (*a)->protoIPTrafficInfos[i].receivedLocally
1177
+(*a)->protoIPTrafficInfos[i].receivedFromRemote;
1178
b_ += (*b)->protoIPTrafficInfos[i].receivedLocally
1179
+(*b)->protoIPTrafficInfos[i].receivedFromRemote;
1182
if((*a)->bytesReceived > a_)
1183
a_ = (*a)->bytesReceived-a_;
1187
if((*b)->bytesReceived > b_)
1188
b_ = (*b)->bytesReceived-b_;
1198
switch(screenNumber) {
1200
a_ = (*a)->qnxSent, b_ = (*b)->qnxSent;
1203
fa_ = (*a)->actualSentPktThpt, fb_ = (*b)->actualSentPktThpt, floatCompare = 1;
1207
switch(screenNumber) {
1209
a_ = (*a)->qnxReceived, b_ = (*b)->qnxReceived;
1211
case MAX_NUM_PROTOS_SCREENS:
1212
fa_ = (*a)->actualRcvdPktThpt, fb_ = (*b)->actualRcvdPktThpt, floatCompare = 1;
1218
switch(screenNumber) {
1220
a_ = (*a)->otherSent, b_ = (*b)->otherSent;
1223
a_ = (*a)->stpSent, b_ = (*b)->stpSent;
1225
case MAX_NUM_PROTOS_SCREENS:
1226
fa_ = (*a)->averageSentPktThpt, fb_ = (*b)->averageSentPktThpt, floatCompare = 1;
1230
switch(screenNumber) {
1232
a_ = (*a)->otherReceived, b_ = (*b)->otherReceived;
1235
a_ = (*a)->stpReceived, b_ = (*b)->stpReceived;
1243
fa_ = (*a)->peakSentPktThpt, fb_ = (*b)->peakSentPktThpt, floatCompare = 1;
1245
fa_ = (*a)->peakRcvdPktThpt, fb_ = (*b)->peakRcvdPktThpt, floatCompare = 1;
1248
columnSort = oldColumnSort;
1250
if(floatCompare == 0) {
1253
} else if (a_ > b_) {
1261
} else if (fa_ > fb_) {
1269
/* ******************************* */
1271
int cmpMulticastFctn(const void *_a, const void *_b) {
1272
HostTraffic **a = (HostTraffic **)_a;
1273
HostTraffic **b = (HostTraffic **)_b;
1276
if((a == NULL) && (b != NULL)) {
1277
traceEvent(TRACE_WARNING, "WARNING (1)\n");
1279
} else if((a != NULL) && (b == NULL)) {
1280
traceEvent(TRACE_WARNING, "WARNING (2)\n");
1282
} else if((a == NULL) && (b == NULL)) {
1283
traceEvent(TRACE_WARNING, "WARNING (3)\n");
1287
switch(columnSort) {
1289
if((*a)->pktMulticastSent < (*b)->pktMulticastSent)
1291
else if ((*a)->pktMulticastSent > (*b)->pktMulticastSent)
1295
break; /* NOTREACHED */
1297
if((*a)->bytesMulticastSent < (*b)->bytesMulticastSent)
1299
else if ((*a)->bytesMulticastSent > (*b)->bytesMulticastSent)
1303
break; /* NOTREACHED */
1305
if((*a)->pktMulticastRcvd < (*b)->pktMulticastRcvd)
1307
else if ((*a)->pktMulticastRcvd > (*b)->pktMulticastRcvd)
1311
break; /* NOTREACHED */
1313
if((*a)->bytesMulticastRcvd < (*b)->bytesMulticastRcvd)
1315
else if ((*a)->bytesMulticastRcvd > (*b)->bytesMulticastRcvd)
1319
break; /* NOTREACHED */
1322
#ifdef MULTITHREADED
1323
accessMutex(&addressResolutionMutex, "cmpMulticastFctn");
1326
rc = strcmp((*a)->hostSymIpAddress, /* Host name */
1327
(*b)->hostSymIpAddress);
1328
#ifdef MULTITHREADED
1329
releaseMutex(&addressResolutionMutex);
1335
/* ******************************* */
1337
void getProtocolDataSent(TrafficCounter *c,
1343
switch(screenNumber) {
1345
(*c) = el->tcpSentLocally + el->tcpSentRemotely;
1346
(*d) = el->udpSentLocally + el->udpSentRemotely;
1347
(*e) = el->icmpSent;
1352
(*e) = el->decnetSent;
1355
(*c) = el->arp_rarpSent;
1356
(*d) = el->appletalkSent;
1357
(*e) = el->ospfSent;
1360
(*c) = el->netbiosSent;
1361
(*d) = el->igmpSent;
1366
(*d) = el->otherSent;
1370
idx = (screenNumber-MAX_NUM_PROTOS_SCREENS)*3;
1371
if(idx < numIpProtosToMonitor)
1372
(*c) = el->protoIPTrafficInfos[idx].sentLocally
1373
+ el->protoIPTrafficInfos[idx].sentRemotely;
1378
if(idx < numIpProtosToMonitor)
1379
(*d) = el->protoIPTrafficInfos[idx].sentLocally
1380
+ el->protoIPTrafficInfos[idx].sentRemotely;
1385
if(idx < numIpProtosToMonitor)
1386
(*e) = el->protoIPTrafficInfos[idx].sentLocally
1387
+ el->protoIPTrafficInfos[idx].sentRemotely;
1393
/* ******************************* */
1395
void getProtocolDataReceived(TrafficCounter *c,
1401
switch(screenNumber) {
1403
(*c) = el->tcpReceivedLocally + el->tcpReceivedFromRemote;
1404
(*d) = el->udpReceivedLocally + el->udpReceivedFromRemote;
1405
(*e) = el->icmpReceived;
1408
(*c) = el->dlcReceived;
1409
(*d) = el->ipxReceived;
1410
(*e) = el->decnetReceived;
1413
(*c) = el->arp_rarpReceived;
1414
(*d) = el->appletalkReceived;
1415
(*e) = el->ospfReceived;
1418
(*c) = el->netbiosReceived;
1419
(*d) = el->igmpReceived;
1420
(*e) = el->osiReceived;
1423
(*c) = el->qnxReceived;
1424
(*d) = el->otherReceived;
1428
idx = (screenNumber-MAX_NUM_PROTOS_SCREENS)*3;
1429
if(idx < numIpProtosToMonitor)
1430
(*c) = el->protoIPTrafficInfos[idx].receivedLocally
1431
+ el->protoIPTrafficInfos[idx].receivedFromRemote;
1436
if(idx < numIpProtosToMonitor)
1437
(*d) = el->protoIPTrafficInfos[idx].receivedLocally
1438
+ el->protoIPTrafficInfos[idx].receivedFromRemote;
1443
if(idx < numIpProtosToMonitor)
1444
(*e) = el->protoIPTrafficInfos[idx].receivedLocally
1445
+ el->protoIPTrafficInfos[idx].receivedFromRemote;
1451
/* *********************************** */
1453
static char* getBgPctgColor(float pctg) {
1456
else if(pctg <= 25) /* < 25% */
1457
return("BGCOLOR=#C6EEF7"); /* 25% <=> 75% */
1459
return("BGCOLOR=#C6EFC8"); /* > 75% */
1461
return("BGCOLOR=#FF3118");
1464
/* ******************************* */
1466
void printHostThtpShort(HostTraffic *el, short dataSent) {
1471
for(i=0, tc=0; i<24; i++) {
1473
tc += el->last24HoursBytesSent[i];
1475
tc += el->last24HoursBytesRcvd[i];
1478
for(i=0; i<24; i++) {
1483
pctg = (float)(el->last24HoursBytesSent[i]*100)/(float)tc;
1485
pctg = (float)(el->last24HoursBytesRcvd[i]*100)/(float)tc;
1489
if(snprintf(buf, sizeof(buf), "<TD ALIGN=RIGHT %s> </TD>",
1490
getBgPctgColor(pctg)) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
1495
/* ******************************* */
1497
int cmpHostsFctn(const void *_a, const void *_b) {
1498
struct hostTraffic **a = (struct hostTraffic **)_a;
1499
struct hostTraffic **b = (struct hostTraffic **)_b;
1500
char *name_a, *name_b;
1501
TrafficCounter a_=0, b_=0;
1504
switch(columnSort) {
1505
case 2: /* IP Address */
1506
if((*a)->hostIpAddress.s_addr > (*b)->hostIpAddress.s_addr)
1508
else if((*a)->hostIpAddress.s_addr < (*b)->hostIpAddress.s_addr)
1514
case 3: /* Data Sent */
1515
switch(sortFilter) {
1516
case REMOTE_TO_LOCAL_ACCOUNTING:
1517
a_ = (*a)->bytesSentLocally;
1518
b_ = (*b)->bytesSentLocally;
1520
case LOCAL_TO_REMOTE_ACCOUNTING:
1521
a_ = (*a)->bytesSentRemotely;
1522
b_ = (*b)->bytesSentRemotely;
1524
case LOCAL_TO_LOCAL_ACCOUNTING:
1525
a_ = (*a)->bytesSentLocally;
1526
b_ = (*b)->bytesSentLocally;
1529
if(a_ < b_) return(1); else if (a_ > b_) return(-1); else return(0);
1532
case 4: /* Data Rcvd */
1533
switch(sortFilter) {
1534
case REMOTE_TO_LOCAL_ACCOUNTING:
1535
a_ = (*a)->bytesReceivedLocally;
1536
b_ = (*b)->bytesReceivedLocally;
1538
case LOCAL_TO_REMOTE_ACCOUNTING:
1539
a_ = (*a)->bytesReceivedFromRemote;
1540
b_ = (*b)->bytesReceivedFromRemote;
1542
case LOCAL_TO_LOCAL_ACCOUNTING:
1543
a_ = (*a)->bytesReceivedLocally;
1544
b_ = (*b)->bytesReceivedLocally;
1547
if(a_ < b_) return(1); else if (a_ > b_) return(-1); else return(0);
1550
default: /* Host Name */
1551
#ifdef MULTITHREADED
1552
accessMutex(&addressResolutionMutex, "cmpHostsFctn");
1555
name_a = (*a)->hostSymIpAddress;
1558
traceEvent(TRACE_WARNING, "Warning\n");
1559
if((name_a == NULL) || (strcmp(name_a, "0.0.0.0") == 0)) {
1560
name_a = (*a)->hostNumIpAddress;
1561
if((name_a == NULL) || (name_a[0] == '\0'))
1562
name_a = (*a)->ethAddressString;
1565
name_b = (*b)->hostSymIpAddress;
1568
traceEvent(TRACE_WARNING, "Warning\n");
1569
if((name_b == NULL) || (strcmp(name_b, "0.0.0.0") == 0)) {
1570
name_b = (*b)->hostNumIpAddress;
1571
if((name_b == NULL) || (name_b[0] == '\0'))
1572
name_b = (*b)->ethAddressString;
1575
#ifdef MULTITHREADED
1576
releaseMutex(&addressResolutionMutex);
1579
rc = strcasecmp(name_a, name_b); /* case insensitive */
1585
/* ************************************ */
1587
void printPacketStats(HostTraffic *el) {
1590
char *tableHeader = "<center><TABLE BORDER=0><TR><TD>";
1592
/* *********************** */
1594
if(el->securityHostPkts != NULL) {
1595
if(((el->securityHostPkts->rejectedTCPConnSent.value+
1596
el->securityHostPkts->rejectedTCPConnRcvd.value+
1597
el->securityHostPkts->establishedTCPConnSent.value+
1598
el->securityHostPkts->establishedTCPConnRcvd.value+
1599
el->securityHostPkts->synPktsSent.value+
1600
el->securityHostPkts->synPktsRcvd.value) > 0)) {
1602
if(!headerSent) { printSectionTitle("Packet Statistics"); sendString(tableHeader); headerSent = 1; }
1604
sendString("<CENTER>\n"
1605
""TABLE_ON"<TABLE BORDER=1 WIDTH=100%><TR><TH "TH_BG">TCP Connections</TH>"
1606
"<TH "TH_BG" COLSPAN=2>Directed to</TH>"
1607
"<TH "TH_BG" COLSPAN=2>Received From</TH></TR>\n");
1609
if((el->securityHostPkts->synPktsSent.value+el->securityHostPkts->synPktsRcvd.value) > 0) {
1610
sendString("<TR><TH "TH_BG" ALIGN=LEFT>Attempted</TH>");
1611
formatUsageCounter(el->securityHostPkts->synPktsSent, 0);
1612
formatUsageCounter(el->securityHostPkts->synPktsRcvd, 0);
1613
sendString("</TR>\n");
1616
if((el->securityHostPkts->establishedTCPConnSent.value+el->securityHostPkts->establishedTCPConnRcvd.value) > 0) {
1617
sendString("<TR><TH "TH_BG" ALIGN=LEFT>Established</TH>");
1618
formatUsageCounter(el->securityHostPkts->establishedTCPConnSent, el->securityHostPkts->synPktsSent.value);
1619
formatUsageCounter(el->securityHostPkts->establishedTCPConnRcvd, el->securityHostPkts->synPktsRcvd.value);
1620
sendString("</TR>\n");
1623
if((el->securityHostPkts->rejectedTCPConnSent.value+el->securityHostPkts->rejectedTCPConnRcvd.value) > 0) {
1624
sendString("<TR><TH "TH_BG" ALIGN=LEFT>Rejected</TH>");
1625
formatUsageCounter(el->securityHostPkts->rejectedTCPConnSent, el->securityHostPkts->synPktsSent.value);
1626
formatUsageCounter(el->securityHostPkts->rejectedTCPConnRcvd, el->securityHostPkts->synPktsRcvd.value);
1627
sendString("</TR>\n");
1630
sendString("</TABLE>"TABLE_OFF"<P>\n");
1631
sendString("</CENTER>\n");
1634
/* *********************** */
1636
if((el->securityHostPkts->synPktsSent.value+el->securityHostPkts->synPktsRcvd.value
1637
+el->securityHostPkts->rstAckPktsSent.value+el->securityHostPkts->rstAckPktsRcvd.value
1638
+el->securityHostPkts->rstPktsSent.value+el->securityHostPkts->rstPktsRcvd.value
1639
+el->securityHostPkts->synFinPktsSent.value+el->securityHostPkts->synFinPktsRcvd.value
1640
+el->securityHostPkts->finPushUrgPktsSent.value+el->securityHostPkts->finPushUrgPktsRcvd.value
1641
+el->securityHostPkts->nullPktsSent.value+el->securityHostPkts->nullPktsRcvd.value) > 0) {
1643
if(!headerSent) { printSectionTitle("Packet Statistics"); sendString(tableHeader); headerSent = 1; }
1645
sendString("<CENTER>\n"
1646
""TABLE_ON"<TABLE BORDER=1 WIDTH=100%><TR><TH "TH_BG">TCP Flags</TH>"
1647
"<TH "TH_BG" COLSPAN=2>Pkts Sent</TH>"
1648
"<TH "TH_BG" COLSPAN=2>Pkts Received</TH></TR>\n");
1650
if((el->securityHostPkts->synPktsSent.value+el->securityHostPkts->synPktsRcvd.value) > 0) {
1651
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>SYN</TH>",
1653
traceEvent(TRACE_ERROR, "Buffer overflow!");
1655
formatUsageCounter(el->securityHostPkts->synPktsSent, 0);
1656
formatUsageCounter(el->securityHostPkts->synPktsRcvd, 0);
1657
sendString("</TR>\n");
1660
if((el->securityHostPkts->rstAckPktsSent.value+el->securityHostPkts->rstAckPktsRcvd.value) > 0) {
1661
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>RST|ACK</TH>",
1663
traceEvent(TRACE_ERROR, "Buffer overflow!");
1665
formatUsageCounter(el->securityHostPkts->rstAckPktsSent, 0);
1666
formatUsageCounter(el->securityHostPkts->rstAckPktsRcvd, 0);
1667
sendString("</TR>\n");
1670
if((el->securityHostPkts->rstPktsSent.value+el->securityHostPkts->rstPktsRcvd.value) > 0) {
1671
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>RST</TH>",
1672
getRowColor()) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
1674
formatUsageCounter(el->securityHostPkts->rstPktsSent, 0);
1675
formatUsageCounter(el->securityHostPkts->rstPktsRcvd, 0);
1676
sendString("</TR>\n");
1679
if((el->securityHostPkts->synFinPktsSent.value+el->securityHostPkts->synFinPktsRcvd.value) > 0) {
1680
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>SYN|FIN</TH>",
1681
getRowColor()) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
1683
formatUsageCounter(el->securityHostPkts->synFinPktsSent, 0);
1684
formatUsageCounter(el->securityHostPkts->synFinPktsRcvd, 0);
1685
sendString("</TR>\n");
1688
if((el->securityHostPkts->finPushUrgPktsSent.value+el->securityHostPkts->finPushUrgPktsRcvd.value) > 0) {
1689
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>FIN|PUSH|URG</TH>",
1690
getRowColor()) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
1692
formatUsageCounter(el->securityHostPkts->finPushUrgPktsSent, 0);
1693
formatUsageCounter(el->securityHostPkts->finPushUrgPktsRcvd, 0);
1694
sendString("</TR>\n");
1697
if((el->securityHostPkts->nullPktsSent.value+el->securityHostPkts->nullPktsRcvd.value) > 0) {
1698
sendString("<TR><TH "TH_BG" ALIGN=LEFT>NULL</TH>");
1699
formatUsageCounter(el->securityHostPkts->nullPktsSent, 0);
1700
formatUsageCounter(el->securityHostPkts->nullPktsRcvd, 0);
1701
sendString("</TR>\n");
1704
sendString("</TABLE>"TABLE_OFF"<P>\n");
1705
sendString("</CENTER>\n");
1708
/* *********************** */
1710
if(((el->securityHostPkts->ackScanSent.value+el->securityHostPkts->ackScanRcvd.value
1711
+el->securityHostPkts->xmasScanSent.value+el->securityHostPkts->xmasScanRcvd.value
1712
+el->securityHostPkts->finScanSent.value+el->securityHostPkts->finScanRcvd.value
1713
+el->securityHostPkts->synFinPktsSent.value+el->securityHostPkts->synFinPktsRcvd.value
1714
+el->securityHostPkts->nullScanSent.value+el->securityHostPkts->nullScanRcvd.value
1715
+el->securityHostPkts->udpToClosedPortSent.value
1716
+el->securityHostPkts->udpToClosedPortRcvd.value
1717
+el->securityHostPkts->udpToDiagnosticPortSent.value
1718
+el->securityHostPkts->udpToDiagnosticPortRcvd.value
1719
+el->securityHostPkts->tcpToDiagnosticPortSent.value
1720
+el->securityHostPkts->tcpToDiagnosticPortRcvd.value
1721
+el->securityHostPkts->tinyFragmentSent.value
1722
+el->securityHostPkts->tinyFragmentRcvd.value
1723
+el->securityHostPkts->icmpFragmentSent.value
1724
+el->securityHostPkts->icmpFragmentRcvd.value
1725
+el->securityHostPkts->overlappingFragmentSent.value
1726
+el->securityHostPkts->overlappingFragmentRcvd.value
1727
+el->securityHostPkts->closedEmptyTCPConnSent.value
1728
+el->securityHostPkts->closedEmptyTCPConnRcvd.value
1729
+el->securityHostPkts->malformedPktsSent.value
1730
+el->securityHostPkts->malformedPktsRcvd.value
1733
if(!headerSent) { printSectionTitle("Packet Statistics"); sendString(tableHeader); headerSent = 1; }
1735
sendString("<CENTER>\n"
1736
""TABLE_ON"<TABLE BORDER=1 WIDTH=100%><TR><TH "TH_BG">Anomaly</TH>"
1737
"<TH "TH_BG" COLSPAN=2>Pkts Sent to</TH>"
1738
"<TH "TH_BG" COLSPAN=2>Pkts Received from</TH>"
1741
if((el->securityHostPkts->ackScanSent.value+el->securityHostPkts->ackScanRcvd.value) > 0) {
1742
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>ACK Scan</TH>",
1744
traceEvent(TRACE_ERROR, "Buffer overflow!");
1746
formatUsageCounter(el->securityHostPkts->ackScanSent, 0);
1747
formatUsageCounter(el->securityHostPkts->ackScanRcvd, 0);
1748
sendString("</TR>\n");
1751
if((el->securityHostPkts->xmasScanSent.value+el->securityHostPkts->xmasScanRcvd.value) > 0) {
1752
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>XMAS Scan</TH>",
1754
traceEvent(TRACE_ERROR, "Buffer overflow!");
1756
formatUsageCounter(el->securityHostPkts->xmasScanSent, 0);
1757
formatUsageCounter(el->securityHostPkts->xmasScanRcvd, 0);
1758
sendString("</TR>\n");
1761
if((el->securityHostPkts->finScanSent.value+el->securityHostPkts->finScanRcvd.value) > 0) {
1762
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>FIN Scan</TH>",
1763
getRowColor()) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
1765
formatUsageCounter(el->securityHostPkts->finScanSent, 0);
1766
formatUsageCounter(el->securityHostPkts->finScanRcvd, 0);
1767
sendString("</TR>\n");
1770
if((el->securityHostPkts->nullScanSent.value+el->securityHostPkts->nullScanRcvd.value) > 0) {
1771
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>NULL Scan</TH>",
1772
getRowColor()) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
1774
formatUsageCounter(el->securityHostPkts->nullScanSent, 0);
1775
formatUsageCounter(el->securityHostPkts->nullScanRcvd, 0);
1776
sendString("</TR>\n");
1779
if((el->securityHostPkts->udpToClosedPortSent.value+
1780
el->securityHostPkts->udpToClosedPortRcvd.value) > 0) {
1781
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>UDP Pkt to Closed Port</TH>",
1782
getRowColor()) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
1784
formatUsageCounter(el->securityHostPkts->udpToClosedPortSent, 0);
1785
formatUsageCounter(el->securityHostPkts->udpToClosedPortRcvd, 0);
1786
sendString("</TR>\n");
1789
if((el->securityHostPkts->udpToDiagnosticPortSent.value+
1790
el->securityHostPkts->udpToDiagnosticPortRcvd.value) > 0) {
1791
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>UDP Pkt Disgnostic Port</TH>",
1792
getRowColor()) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
1794
formatUsageCounter(el->securityHostPkts->udpToDiagnosticPortSent, 0);
1795
formatUsageCounter(el->securityHostPkts->udpToDiagnosticPortRcvd, 0);
1796
sendString("</TR>\n");
1799
if((el->securityHostPkts->tcpToDiagnosticPortSent.value+
1800
el->securityHostPkts->tcpToDiagnosticPortRcvd.value) > 0) {
1801
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>TCP Pkt Disgnostic Port</TH>",
1802
getRowColor()) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
1804
formatUsageCounter(el->securityHostPkts->tcpToDiagnosticPortSent, 0);
1805
formatUsageCounter(el->securityHostPkts->tcpToDiagnosticPortRcvd, 0);
1806
sendString("</TR>\n");
1809
if((el->securityHostPkts->tinyFragmentSent.value+
1810
el->securityHostPkts->tinyFragmentRcvd.value) > 0) {
1811
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>Tiny Fragments</TH>",
1812
getRowColor()) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
1814
formatUsageCounter(el->securityHostPkts->tinyFragmentSent, 0);
1815
formatUsageCounter(el->securityHostPkts->tinyFragmentRcvd, 0);
1816
sendString("</TR>\n");
1819
if((el->securityHostPkts->icmpFragmentSent.value+
1820
el->securityHostPkts->icmpFragmentRcvd.value) > 0) {
1821
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>ICMP Fragments</TH>",
1822
getRowColor()) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
1824
formatUsageCounter(el->securityHostPkts->icmpFragmentSent, 0);
1825
formatUsageCounter(el->securityHostPkts->icmpFragmentRcvd, 0);
1826
sendString("</TR>\n");
1829
if((el->securityHostPkts->overlappingFragmentSent.value+
1830
el->securityHostPkts->overlappingFragmentRcvd.value) > 0) {
1831
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>Overlapping Fragments</TH>",
1832
getRowColor()) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
1834
formatUsageCounter(el->securityHostPkts->overlappingFragmentSent, 0);
1835
formatUsageCounter(el->securityHostPkts->overlappingFragmentRcvd, 0);
1836
sendString("</TR>\n");
1839
if((el->securityHostPkts->closedEmptyTCPConnSent.value+
1840
el->securityHostPkts->closedEmptyTCPConnRcvd.value) > 0) {
1841
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>Closed Empty TCP Conn.</TH>",
1842
getRowColor()) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
1844
formatUsageCounter(el->securityHostPkts->closedEmptyTCPConnSent, 0);
1845
formatUsageCounter(el->securityHostPkts->closedEmptyTCPConnRcvd, 0);
1846
sendString("</TR>\n");
1849
if((el->securityHostPkts->malformedPktsSent.value+
1850
el->securityHostPkts->malformedPktsRcvd.value) > 0) {
1851
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>Malformed Pkts</TH>",
1852
getRowColor()) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
1854
formatUsageCounter(el->securityHostPkts->malformedPktsSent, 0);
1855
formatUsageCounter(el->securityHostPkts->malformedPktsRcvd, 0);
1856
sendString("</TR>\n");
1859
sendString("</TABLE>"TABLE_OFF"<P>\n");
1860
sendString("</CENTER>\n");
1864
if(el->arpReqPktsSent+el->arpReplyPktsSent+el->arpReplyPktsRcvd > 0) {
1866
printSectionTitle("Packet Statistics");
1867
sendString(tableHeader);
1871
sendString("<CENTER>\n"
1872
""TABLE_ON"<TABLE BORDER=1 WIDTH=100%><TR>"
1873
"<TH "TH_BG">ARP</TH>"
1874
"<TH "TH_BG">Packet</TH>"
1877
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>Request Sent</TH>"
1878
"<TD "TH_BG" ALIGN=RIGHT>%s</TD></TR>",
1880
formatPkts(el->arpReqPktsSent)) < 0)
1881
traceEvent(TRACE_ERROR, "Buffer overflow!");
1884
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>Reply Rcvd</TH>"
1885
"<TD "TH_BG" ALIGN=RIGHT>%s (%.1f %%)</TD></TR>",
1887
formatPkts(el->arpReplyPktsRcvd),
1888
((el->arpReqPktsSent > 0) ?
1889
(float)((el->arpReplyPktsRcvd*100)/(float)el->arpReqPktsSent) : 0)) < 0)
1890
traceEvent(TRACE_ERROR, "Buffer overflow!");
1893
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>Reply Sent</TH>"
1894
"<TD "TH_BG" ALIGN=RIGHT>%s</TD></TR>",
1896
formatPkts(el->arpReplyPktsSent)) < 0)
1897
traceEvent(TRACE_ERROR, "Buffer overflow!");
1900
sendString("</TABLE>"TABLE_OFF"<P>\n");
1901
sendString("</CENTER>\n");
1904
if(headerSent) { sendString("</TD></TR></TABLE></center>"); }
1907
/* ************************************ */
1909
void printHostFragmentStats(HostTraffic *el) {
1910
TrafficCounter totalSent, totalReceived;
1913
totalSent = el->tcpFragmentsSent + el->udpFragmentsSent + el->icmpFragmentsSent;
1914
totalReceived = el->tcpFragmentsReceived + el->udpFragmentsReceived + el->icmpFragmentsReceived;
1916
if((totalSent == 0) && (totalReceived == 0))
1919
printSectionTitle("IP Fragments Distribution");
1921
sendString("<CENTER>\n"
1922
""TABLE_ON"<TABLE BORDER=1><TR><TH "TH_BG" WIDTH=100>Protocol</TH>"
1923
"<TH "TH_BG" WIDTH=200 COLSPAN=2>Data Sent</TH>"
1924
"<TH "TH_BG" WIDTH=200 COLSPAN=2>Data Received</TH></TR>\n");
1926
printTableDoubleEntry(buf, sizeof(buf), "TCP", COLOR_1, (float)el->tcpFragmentsSent/1024,
1927
100*((float)SD(el->tcpFragmentsSent, totalSent)),
1928
(float)el->tcpFragmentsReceived/1024,
1929
100*((float)SD(el->tcpFragmentsReceived, totalReceived)));
1931
printTableDoubleEntry(buf, sizeof(buf), "UDP", COLOR_1, (float)el->udpFragmentsSent/1024,
1932
100*((float)SD(el->udpFragmentsSent, totalSent)),
1933
(float)el->udpFragmentsReceived/1024,
1934
100*((float)SD(el->udpFragmentsReceived, totalReceived)));
1936
printTableDoubleEntry(buf, sizeof(buf), "ICMP", COLOR_1, (float)el->icmpFragmentsSent/1024,
1937
100*((float)SD(el->icmpFragmentsSent, totalSent)),
1938
(float)el->icmpFragmentsReceived/1024,
1939
100*((float)SD(el->icmpFragmentsReceived, totalReceived)));
1943
if((totalSent > 0) || (totalReceived > 0)) {
1944
if(snprintf(buf, sizeof(buf),
1945
"<TR %s><TH "TH_BG" ALIGN=LEFT>Fragment Distribution</TH>",
1947
traceEvent(TRACE_ERROR, "Buffer overflow!");
1951
if(snprintf(buf, sizeof(buf),
1952
"<TD "TH_BG" ALIGN=RIGHT COLSPAN=2><IMG SRC=hostFragmentDistrib-%s"CHART_FORMAT"?1></TD>",
1953
el->hostNumIpAddress[0] == '\0' ? el->ethAddressString : el->hostNumIpAddress) < 0)
1954
traceEvent(TRACE_ERROR, "Buffer overflow!");
1957
sendString("<TD "TH_BG" ALIGN=RIGHT COLSPAN=2> </TD>");
1960
if(totalReceived > 0) {
1961
if(snprintf(buf, sizeof(buf),
1962
"<TD "TH_BG" ALIGN=RIGHT COLSPAN=2><IMG SRC=hostFragmentDistrib-%s"CHART_FORMAT"></TD>",
1963
el->hostNumIpAddress[0] == '\0' ? el->ethAddressString : el->hostNumIpAddress) < 0)
1964
traceEvent(TRACE_ERROR, "Buffer overflow!");
1967
sendString("<TD "TH_BG" ALIGN=RIGHT COLSPAN=2> </TD>");
1970
sendString("</TD></TR>");
1972
/* ***************************************** */
1974
if(snprintf(buf, sizeof(buf),
1975
"<TR %s><TH "TH_BG" ALIGN=LEFT>IP Fragment Distribution</TH>",
1977
traceEvent(TRACE_ERROR, "Buffer overflow!");
1981
if(snprintf(buf, sizeof(buf),
1982
"<TD "TH_BG" ALIGN=RIGHT COLSPAN=2><IMG SRC=hostTotalFragmentDistrib-%s"CHART_FORMAT"?1></TD>",
1983
el->hostNumIpAddress[0] == '\0' ? el->ethAddressString : el->hostNumIpAddress) < 0)
1984
traceEvent(TRACE_ERROR, "Buffer overflow!");
1987
sendString("<TD "TH_BG" ALIGN=RIGHT COLSPAN=2> </TD>");
1990
if(totalReceived > 0) {
1991
if(snprintf(buf, sizeof(buf),
1992
"<TD "TH_BG" ALIGN=RIGHT COLSPAN=2><IMG SRC=hostTotalFragmentDistrib-%s"CHART_FORMAT"></TD>",
1993
el->hostNumIpAddress[0] == '\0' ? el->ethAddressString : el->hostNumIpAddress) < 0)
1994
traceEvent(TRACE_ERROR, "Buffer overflow!");
1997
sendString("<TD "TH_BG" ALIGN=RIGHT COLSPAN=2> </TD>");
2000
sendString("</TD></TR>");
2005
sendString("</TABLE>"TABLE_OFF"<P>\n");
2006
sendString("</CENTER>\n");
2009
/* ************************************ */
2011
void printHostTrafficStats(HostTraffic *el) {
2013
TrafficCounter totalSent, totalReceived;
2014
TrafficCounter actTotalSent, actTotalReceived;
2017
totalSent = el->tcpSentLocally+el->tcpSentRemotely+el->udpSentLocally+el->udpSentRemotely;
2018
totalSent += el->icmpSent+el->ospfSent+el->igmpSent+el->ipxSent+el->dlcSent+el->arp_rarpSent;
2019
totalSent += el->decnetSent+el->appletalkSent+el->netbiosSent+
2020
el->osiSent+el->qnxSent+el->stpSent+el->otherSent;
2022
totalReceived = el->tcpReceivedLocally+el->tcpReceivedFromRemote;
2023
totalReceived += el->udpReceivedLocally+el->udpReceivedFromRemote;
2024
totalReceived += el->icmpReceived+el->ospfReceived+el->igmpReceived;
2025
totalReceived += el->ipxReceived+el->dlcReceived+el->arp_rarpReceived;
2026
totalReceived += el->decnetReceived+el->appletalkReceived;
2027
totalReceived += el->osiReceived+el->netbiosReceived+el->qnxReceived
2028
+el->stpReceived+el->otherReceived;
2030
actTotalSent = el->tcpSentLocally+el->tcpSentRemotely;
2031
actTotalReceived = el->tcpReceivedLocally+el->tcpReceivedFromRemote;
2033
printHostEvents(el, -1, -1);
2034
printHostHourlyTraffic(el);
2035
printPacketStats(el);
2037
if((totalSent == 0) && (totalReceived == 0))
2040
printSectionTitle("Protocol Distribution");
2042
sendString("<CENTER>\n"
2043
""TABLE_ON"<TABLE BORDER=1><TR><TH "TH_BG" WIDTH=100>Protocol</TH>"
2044
"<TH "TH_BG" WIDTH=200 COLSPAN=2>Data Sent</TH>"
2045
"<TH "TH_BG" WIDTH=200 COLSPAN=2>Data Received</TH></TR>\n");
2047
printTableDoubleEntry(buf, sizeof(buf), "TCP", COLOR_1, (float)actTotalSent/1024,
2048
100*((float)SD(actTotalSent, totalSent)),
2049
(float)actTotalReceived/1024,
2050
100*((float)SD(actTotalReceived, totalReceived)));
2052
actTotalSent = el->udpSentLocally+el->udpSentRemotely;
2053
actTotalReceived = el->udpReceivedLocally+el->udpReceivedFromRemote;
2056
printTableDoubleEntry(buf, sizeof(buf), "UDP", COLOR_1, (float)actTotalSent/1024,
2057
100*((float)SD(actTotalSent, totalSent)),
2058
(float)actTotalReceived/1024,
2059
100*((float)SD(actTotalReceived, totalReceived)));
2061
printTableDoubleEntry(buf, sizeof(buf), "ICMP", COLOR_1, (float)el->icmpSent/1024,
2062
100*((float)SD(el->icmpSent, totalSent)),
2063
(float)el->icmpReceived/1024,
2064
100*((float)SD(el->icmpReceived, totalReceived)));
2066
printTableDoubleEntry(buf, sizeof(buf), "(R)ARP", COLOR_1, (float)el->arp_rarpSent/1024,
2067
100*((float)SD(el->arp_rarpSent, totalSent)),
2068
(float)el->arp_rarpReceived/1024,
2069
100*((float)SD(el->arp_rarpReceived, totalReceived)));
2071
printTableDoubleEntry(buf, sizeof(buf), "DLC", COLOR_1, (float)el->dlcSent/1024,
2072
100*((float)SD(el->dlcSent, totalSent)),
2073
(float)el->dlcReceived/1024,
2074
100*((float)SD(el->dlcReceived, totalReceived)));
2076
printTableDoubleEntry(buf, sizeof(buf), "IPX", COLOR_1, (float)el->ipxSent/1024,
2077
100*((float)SD(el->ipxSent, totalSent)),
2078
(float)el->ipxReceived/1024,
2079
100*((float)SD(el->ipxReceived, totalReceived)));
2081
printTableDoubleEntry(buf, sizeof(buf), "Decnet", COLOR_1, (float)el->decnetSent/1024,
2082
100*((float)SD(el->decnetSent, totalSent)),
2083
(float)el->decnetReceived/1024,
2084
100*((float)SD(el->decnetReceived, totalReceived)));
2086
printTableDoubleEntry(buf, sizeof(buf), "AppleTalk", COLOR_1, (float)el->appletalkSent/1024,
2087
100*((float)SD(el->appletalkSent, totalSent)),
2088
(float)el->appletalkReceived/1024,
2089
100*((float)SD(el->appletalkReceived, totalReceived)));
2091
printTableDoubleEntry(buf, sizeof(buf), "OSPF", COLOR_1, (float)el->ospfSent/1024,
2092
100*((float)SD(el->ospfSent, totalSent)),
2093
(float)el->ospfReceived/1024,
2094
100*((float)SD(el->ospfReceived, totalReceived)));
2096
printTableDoubleEntry(buf, sizeof(buf), "NetBios", COLOR_1, (float)el->netbiosSent/1024,
2097
100*((float)SD(el->netbiosSent, totalSent)),
2098
(float)el->netbiosReceived/1024,
2099
100*((float)SD(el->netbiosReceived, totalReceived)));
2101
printTableDoubleEntry(buf, sizeof(buf), "IGMP", COLOR_1, (float)el->igmpSent/1024,
2102
100*((float)SD(el->igmpSent, totalSent)),
2103
(float)el->igmpReceived/1024,
2104
100*((float)SD(el->igmpReceived, totalReceived)));
2106
printTableDoubleEntry(buf, sizeof(buf), "OSI", COLOR_1, (float)el->osiSent/1024,
2107
100*((float)SD(el->osiSent, totalSent)),
2108
(float)el->osiReceived/1024,
2109
100*((float)SD(el->osiReceived, totalReceived)));
2111
printTableDoubleEntry(buf, sizeof(buf), "QNX", COLOR_1, (float)el->qnxSent/1024,
2112
100*((float)SD(el->qnxSent, totalSent)),
2113
(float)el->qnxReceived/1024,
2114
100*((float)SD(el->qnxReceived, totalReceived)));
2116
printTableDoubleEntry(buf, sizeof(buf), "STP", COLOR_1, (float)el->stpSent/1024,
2117
100*((float)SD(el->stpSent, totalSent)),
2118
(float)el->stpReceived/1024,
2119
100*((float)SD(el->stpReceived, totalReceived)));
2121
printTableDoubleEntry(buf, sizeof(buf), "Other", COLOR_1, (float)el->otherSent/1024,
2122
100*((float)SD(el->otherSent, totalSent)),
2123
(float)el->otherReceived/1024,
2124
100*((float)SD(el->otherReceived, totalReceived)));
2129
totalSent = el->tcpSentLocally+el->tcpSentRemotely+
2130
el->udpSentLocally+el->udpSentRemotely+
2131
el->icmpSent+el->ospfSent+el->igmpSent+el->stpSent+
2132
el->ipxSent+el->osiSent+el->dlcSent+
2133
el->arp_rarpSent+el->decnetSent+el->appletalkSent+
2134
el->netbiosSent+el->qnxSent+el->otherSent;
2136
totalReceived = el->tcpReceivedLocally+el->tcpReceivedFromRemote+
2137
el->udpReceivedLocally+el->udpReceivedFromRemote+
2138
el->icmpReceived+el->ospfReceived+el->igmpReceived+el->stpReceived+
2139
el->ipxReceived+el->osiReceived+el->dlcReceived+
2140
el->arp_rarpReceived+el->decnetReceived+el->appletalkReceived+
2141
el->netbiosReceived+el->qnxReceived+el->otherReceived;
2143
if((totalSent > 0) || (totalReceived > 0)) {
2144
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>Protocol Distribution</TH>",
2146
traceEvent(TRACE_ERROR, "Buffer overflow!");
2150
if(snprintf(buf, sizeof(buf),
2151
"<TD "TH_BG" ALIGN=RIGHT COLSPAN=2><IMG SRC=hostTrafficDistrib-%s"CHART_FORMAT"?1></TD>",
2152
el->hostNumIpAddress[0] == '\0' ? el->ethAddressString : el->hostNumIpAddress) < 0)
2153
traceEvent(TRACE_ERROR, "Buffer overflow!");
2156
sendString("<TD "TH_BG" ALIGN=RIGHT COLSPAN=2> </TD>");
2159
if(totalReceived > 0) {
2160
if(snprintf(buf, sizeof(buf),
2161
"<TD "TH_BG" ALIGN=RIGHT COLSPAN=2><IMG SRC=hostTrafficDistrib-%s"CHART_FORMAT"></TD>",
2162
el->hostNumIpAddress[0] == '\0' ? el->ethAddressString : el->hostNumIpAddress) < 0)
2163
traceEvent(TRACE_ERROR, "Buffer overflow!");
2166
sendString("<TD "TH_BG" ALIGN=RIGHT COLSPAN=2> </TD>");
2170
sendString("</TD></TR>");
2175
#ifndef ENABLE_NAPSTER
2178
if(el->napsterStats == NULL)
2181
a = el->napsterStats->bytesSent, b = el->napsterStats->bytesRcvd;
2184
for(i=0; i<numIpProtosToMonitor; i++) {
2185
a += el->protoIPTrafficInfos[i].sentLocally+
2186
el->protoIPTrafficInfos[i].sentRemotely;
2187
b += el->protoIPTrafficInfos[i].receivedLocally+
2188
el->protoIPTrafficInfos[i].receivedFromRemote;
2191
if((a > 0) && (b > 0)) {
2192
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>IP Distribution</TH>"
2193
"<TD "TH_BG" ALIGN=RIGHT COLSPAN=2><IMG SRC=hostIPTrafficDistrib-%s"CHART_FORMAT"?1>"
2195
"<TD "TH_BG" ALIGN=RIGHT COLSPAN=2><IMG SRC=hostIPTrafficDistrib-%s"CHART_FORMAT">"
2198
el->hostNumIpAddress,
2199
el->hostNumIpAddress) < 0)
2200
traceEvent(TRACE_ERROR, "Buffer overflow!");
2204
sendString("</TABLE>"TABLE_OFF"<P>\n");
2205
sendString("</CENTER>\n");
2208
/* ************************************ */
2210
void printHostContactedPeers(HostTraffic *el) {
2211
u_int numEntries, i;
2214
if((el->pktSent != 0) || (el->pktReceived != 0)) {
2217
for(numEntries = 0, i=0; i<MAX_NUM_CONTACTED_PEERS; i++)
2218
if((el->contactedSentPeers.peersIndexes[i] != NO_PEER)
2219
|| (el->contactedRcvdPeers.peersIndexes[i] != NO_PEER)) {
2225
struct hostTraffic *el1;
2227
printSectionTitle("Last Contacted Peers");
2228
sendString("<CENTER>\n"
2229
"<TABLE BORDER=0 WIDTH=100%%><TR><TD "TD_BG" VALIGN=TOP>\n");
2231
for(numEntries = 0, i=0; i<MAX_NUM_CONTACTED_PEERS; i++)
2232
if(el->contactedSentPeers.peersIndexes[i] != NO_PEER) {
2233
el1 = device[actualReportDeviceId].hash_hostTraffic[
2234
checkSessionIdx(el->contactedSentPeers.peersIndexes[i])];
2237
if(numEntries == 0) {
2238
sendString(""TABLE_ON"<TABLE BORDER=1 VALIGN=TOP WIDTH=100%%>"
2239
"<TR><TH "TH_BG">Receiver Name</TH>"
2240
"<TH "TH_BG">Receiver Address</TH></TR>\n");
2243
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2244
"<TD "TD_BG" ALIGN=CENTER>%s </TD></TR>\n",
2246
makeHostLink(el1, 0, 0, 0),
2247
el1->hostNumIpAddress) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
2255
sendString("</TABLE>"TABLE_OFF"</TD><TD "TD_BG" VALIGN=TOP>\n");
2257
sendString(" </TD><TD "TD_BG">\n");
2259
/* ***************************************************** */
2260
for(numEntries = 0, i=0; i<MAX_NUM_CONTACTED_PEERS; i++)
2261
if(el->contactedRcvdPeers.peersIndexes[i] != NO_PEER) {
2262
el1 = device[actualReportDeviceId].hash_hostTraffic[
2263
checkSessionIdx(el->contactedRcvdPeers.peersIndexes[i])];
2266
if(numEntries == 0) {
2267
sendString(""TABLE_ON"<TABLE BORDER=1 WIDTH=100%%>"
2268
"<TR><TH "TH_BG">Sender Name</TH>"
2269
"<TH "TH_BG">Sender Address</TH></TR>\n");
2272
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2273
"<TD "TD_BG" ALIGN=CENTER>%s </TD></TR>\n",
2275
makeHostLink(el1, 0, 0, 0),
2276
el1->hostNumIpAddress) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
2284
sendString("</TABLE>"TABLE_OFF"\n");
2286
sendString("</TD></TR></TABLE>"TABLE_OFF"<P>\n");
2287
sendString("</CENTER>\n");
2292
/* ************************************ */
2294
/* Function below courtesy of Andreas Pfaller <a.pfaller@pop.gun.de> */
2296
char *getSessionState(IPSession *session) {
2297
switch (session->sessionState) {
2301
return("Rcvd Syn/Ack");
2304
case STATE_FIN1_ACK0:
2305
return("Fin1 Ack0");
2306
case STATE_FIN1_ACK1:
2307
return("Fin1 Ack1");
2308
case STATE_FIN2_ACK0:
2309
return("Fin2 Ack0");
2310
case STATE_FIN2_ACK1:
2311
return("Fin2 Ack1");
2312
case STATE_FIN2_ACK2:
2313
return("Fin2 Ack2");
2320
return("*Unknown*");
2323
/* ************************************ */
2325
void printHostSessions(HostTraffic *el, u_int elIdx) {
2327
IpGlobalSession *scanner=NULL;
2328
char *sessionType=NULL;
2329
u_short numSessions;
2330
u_int idx, i, sessionIdx;
2331
static char _sport[8], _dport[8];
2333
for(sessionIdx=0; sessionIdx<2; sessionIdx++) {
2334
if(sessionIdx == 0) {
2335
if(el->tcpSessionList != NULL) {
2336
printSectionTitle("TCP Session History");
2339
scanner = el->tcpSessionList;
2340
sessionType = "TCP";
2342
if(el->udpSessionList != NULL) {
2343
printSectionTitle("UDP Session History");
2346
scanner = el->udpSessionList;
2347
sessionType = "UDP";
2352
while(scanner != NULL) {
2353
char *whoswho, *svc=NULL, tmpSvc[16];
2355
if(scanner->initiator == CLIENT_ROLE)
2361
svc = getPortByNum((int)(scanner->port), IPPROTO_TCP);
2363
svc = getPortByNum((int)(scanner->port), IPPROTO_UDP);
2366
if(snprintf(tmpSvc, sizeof(tmpSvc), "%d", (int)(scanner->port)) < 0)
2367
traceEvent(TRACE_ERROR, "Buffer overflow!");
2371
if(numSessions == 0) {
2372
sendString("<CENTER>\n");
2373
if(snprintf(buf, sizeof(buf), ""TABLE_ON"<TABLE BORDER=1 WIDTH=\"100%%\">\n<TR>"
2374
"<TH "TH_BG" COLSPAN=2>%s Service</TH>"
2375
"<TH "TH_BG">Role</TH><TH "TH_BG">"
2376
"# Sessions</TH>"
2377
"<TH "TH_BG">Bytes Sent</TH>"
2378
"<TH "TH_BG">Bytes Rcvd</TH>"
2379
"<TH "TH_BG">Last Seen</TH>"
2380
"<TH "TH_BG">First Seen</TH>"
2381
"<TH "TH_BG">Peers</TH></TR>\n",
2382
sessionType) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
2386
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=RIGHT>%s</TH>"
2387
"<TD "TD_BG" ALIGN=CENTER>%d</TD>"
2388
"<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%d"
2389
"</TD><TD "TD_BG" ALIGN=CENTER>%s</TD>"
2390
"<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG">"
2391
"%s</TD><TD "TD_BG">%s</TD>\n",
2392
getRowColor(), svc, scanner->port, whoswho,
2393
(int)scanner->sessionCounter,
2394
formatBytes(scanner->bytesSent, 1),
2395
formatBytes(scanner->bytesReceived, 1),
2396
formatTime(&(scanner->lastSeen), 1),
2397
formatTime(&(scanner->firstSeen), 1)
2398
) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
2402
sendString("<TD "TD_BG"><UL> ");
2403
for(i=0; i < MAX_NUM_CONTACTED_PEERS; i++) {
2404
u_int theIdx = scanner->peers.peersIndexes[i];
2406
if(theIdx != NO_PEER) {
2407
HostTraffic *host = device[actualReportDeviceId].hash_hostTraffic[checkSessionIdx(theIdx)];
2410
sendString("\n<li>");
2411
sendString(makeHostLink(host, 0, 0, 0));
2416
sendString("</UL></TR>\n");
2418
scanner = (IpGlobalSession*)(scanner->next);
2421
if(numSessions > 0) {
2422
sendString("</TABLE>"TABLE_OFF"<P>\n");
2423
sendString("</CENTER>\n");
2426
if(sessionIdx == 0) {
2427
/* Now print currently established TCP sessions (if any) */
2428
for(idx=1, numSessions=0; idx<device[actualReportDeviceId].numTotSessions; idx++)
2429
if((device[actualReportDeviceId].tcpSession[idx] != NULL)
2430
&& ((device[actualReportDeviceId].tcpSession[idx]->initiatorIdx == elIdx)
2431
|| (device[actualReportDeviceId].tcpSession[idx]->remotePeerIdx == elIdx))
2432
#ifndef PRINT_ALL_ACTIVE_SESSIONS
2433
&& (device[actualReportDeviceId].tcpSession[idx]->sessionState == STATE_ACTIVE)
2436
char *sport, *dport, *remotePeer;
2437
TrafficCounter dataSent, dataReceived, retrDataSent, retrDataRcvd;
2438
TrafficCounter fragDataSent, fragDataRcvd;
2439
int retrSentPercentage, retrRcvdPercentage;
2440
char fragStrSent[64], fragStrRcvd[64], *moreSessionInfo;
2442
if(device[actualReportDeviceId].
2443
tcpSession[idx]->remotePeerIdx == NO_PEER) /* This should not happen */
2446
if(numSessions == 0) {
2447
printSectionTitle("Active TCP Sessions");
2448
sendString("<CENTER>\n");
2449
sendString(""TABLE_ON"<TABLE BORDER=1 WIDTH=\"100%%\"><TR>"
2450
"<TH "TH_BG">Local Port</TH>"
2451
"<TH "TH_BG">Remote Peer:Port</TH>"
2452
"<TH "TH_BG">Data Sent</TH>"
2453
#ifdef PRINT_RETRANSMISSION_DATA
2454
"<TH "TH_BG">Retran. Data Sent</TH>"
2456
"<TH "TH_BG">Data Rcvd</TH>"
2457
#ifdef PRINT_RETRANSMISSION_DATA
2458
"<TH "TH_BG">Retran. Data Rcvd</TH>"
2460
"<TH "TH_BG">Window Size</TH>"
2461
"<TH "TH_BG">Active Since</TH>"
2462
"<TH "TH_BG">Last Seen</TH>"
2463
"<TH "TH_BG">Duration</TH>"
2464
"<TH "TH_BG">Latency</TH>"
2465
#ifdef PRINT_ALL_ACTIVE_SESSIONS
2466
"<TH "TH_BG">State</TH>"
2471
if(device[actualReportDeviceId].tcpSession[idx]->initiatorIdx == elIdx) {
2472
sport = getPortByNum(device[actualReportDeviceId].tcpSession[idx]->sport, IPPROTO_TCP);
2473
dport = getPortByNum(device[actualReportDeviceId].tcpSession[idx]->dport, IPPROTO_TCP);
2475
if(snprintf(_sport, sizeof(_sport), "%d",
2476
device[actualReportDeviceId].tcpSession[idx]->sport) < 0)
2477
traceEvent(TRACE_ERROR, "Buffer overflow!");
2482
if(snprintf(_dport, sizeof(_dport), "%d",
2483
device[actualReportDeviceId].tcpSession[idx]->dport) < 0)
2484
traceEvent(TRACE_ERROR, "Buffer overflow!");
2487
remotePeer = makeHostLink(device[actualReportDeviceId].
2488
hash_hostTraffic[checkSessionIdx(device[actualReportDeviceId].
2489
tcpSession[idx]->remotePeerIdx)],
2490
SHORT_FORMAT, 0, 0);
2491
dataSent = device[actualReportDeviceId].tcpSession[idx]->bytesSent;
2492
dataReceived = device[actualReportDeviceId].tcpSession[idx]->bytesReceived;
2493
retrDataSent = device[actualReportDeviceId].tcpSession[idx]->bytesRetranI2R;
2494
retrDataRcvd = device[actualReportDeviceId].tcpSession[idx]->bytesRetranR2I;
2495
fragDataSent = device[actualReportDeviceId].tcpSession[idx]->bytesFragmentedSent;
2496
fragDataRcvd = device[actualReportDeviceId].tcpSession[idx]->bytesFragmentedReceived;
2499
sport = getPortByNum(device[actualReportDeviceId].tcpSession[idx]->dport, IPPROTO_TCP);
2500
dport = getPortByNum(device[actualReportDeviceId].tcpSession[idx]->sport, IPPROTO_TCP);
2502
if(snprintf(_sport, sizeof(_sport), "%d",
2503
device[actualReportDeviceId].tcpSession[idx]->dport) < 0)
2504
traceEvent(TRACE_ERROR, "Buffer overflow!");
2509
if(snprintf(_dport, sizeof(_dport), "%d",
2510
device[actualReportDeviceId].tcpSession[idx]->sport) < 0)
2511
traceEvent(TRACE_ERROR, "Buffer overflow!");
2515
remotePeer = makeHostLink(device[actualReportDeviceId].
2516
hash_hostTraffic[checkSessionIdx(device[actualReportDeviceId].
2517
tcpSession[idx]->initiatorIdx)],
2518
SHORT_FORMAT, 0, 0);
2519
dataSent = device[actualReportDeviceId].tcpSession[idx]->bytesReceived;
2520
dataReceived = device[actualReportDeviceId].tcpSession[idx]->bytesSent;
2521
retrDataSent = device[actualReportDeviceId].tcpSession[idx]->bytesRetranR2I;
2522
retrDataRcvd = device[actualReportDeviceId].tcpSession[idx]->bytesRetranI2R;
2523
fragDataSent = device[actualReportDeviceId].tcpSession[idx]->bytesFragmentedReceived;
2524
fragDataRcvd = device[actualReportDeviceId].tcpSession[idx]->bytesFragmentedSent;
2528
if((actTime < device[actualReportDeviceId].tcpSession[idx]->firstSeen)
2529
|| (device[actualReportDeviceId].tcpSession[idx]->firstSeen == 0))
2530
device[actualReportDeviceId].tcpSession[idx]->firstSeen = actTime;
2532
retrSentPercentage = (int)((float)(retrDataSent*100))/((float)(dataSent+1));
2533
retrRcvdPercentage = (int)((float)(retrDataRcvd*100))/((float)(dataReceived+1));
2535
if(fragDataSent == 0)
2536
fragStrSent[0] = '\0';
2538
if(snprintf(fragStrSent, sizeof(fragStrSent), "(%.1f fragmented)",
2539
(int)((float)(fragDataSent*100))/((float)(dataSent+1))) < 0)
2540
traceEvent(TRACE_ERROR, "Buffer overflow!");
2542
if(fragDataRcvd == 0)
2543
fragStrRcvd[0] = '\0';
2545
if(snprintf(fragStrRcvd, sizeof(fragStrRcvd), "(%.1f fragmented)",
2546
(int)((float)(fragDataRcvd*100))/((float)(dataReceived+1))) < 0)
2547
traceEvent(TRACE_ERROR, "Buffer overflow!");
2550
#ifndef ENABLE_NAPSTER
2551
moreSessionInfo = "";
2553
if(device[actualReportDeviceId].tcpSession[idx]->napsterSession)
2554
moreSessionInfo = " [Napster]";
2556
moreSessionInfo = "";
2559
if(device[actualReportDeviceId].tcpSession[idx]->passiveFtpSession)
2560
moreSessionInfo = " [FTP]";
2562
moreSessionInfo = "";
2564
if(snprintf(buf, sizeof(buf), "<TR %s>"
2565
"<TD "TD_BG" ALIGN=RIGHT>%s%s</TD>"
2566
"<TD "TD_BG" ALIGN=RIGHT>%s:%s</TD>"
2567
"<TD "TD_BG" ALIGN=RIGHT>%s %s</TD>"
2568
#ifdef PRINT_RETRANSMISSION_DATA
2569
"<TD "TD_BG" ALIGN=RIGHT>%s [%d%%]</TD>"
2571
"<TD "TD_BG" ALIGN=RIGHT>%s %s</TD>"
2572
#ifdef PRINT_RETRANSMISSION_DATA
2573
"<TD "TD_BG" ALIGN=RIGHT>%s [%d%%]</TD>"
2576
sport, moreSessionInfo,
2578
formatBytes(dataSent, 1), fragStrSent,
2579
#ifdef PRINT_RETRANSMISSION_DATA
2580
formatBytes(retrDataSent, 1),
2583
formatBytes(dataReceived, 1), fragStrRcvd
2584
#ifdef PRINT_RETRANSMISSION_DATA
2585
, formatBytes(retrDataRcvd, 1),
2588
) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
2592
if(snprintf(buf, sizeof(buf),
2593
"<TD "TD_BG" ALIGN=CENTER NOWRAP>%d:%d</TD>"
2594
"<TD "TD_BG" ALIGN=RIGHT>%s</TD>"
2595
"<TD "TD_BG" ALIGN=RIGHT>%s</TD>"
2596
"<TD "TD_BG" ALIGN=RIGHT>%s</TD>"
2597
"<TD "TD_BG" ALIGN=RIGHT>%s</TD>"
2598
#ifdef PRINT_ALL_ACTIVE_SESSIONS
2599
"<TD "TD_BG" ALIGN=CENTER>%s</TD>"
2602
device[actualReportDeviceId].tcpSession[idx]->minWindow,
2603
device[actualReportDeviceId].tcpSession[idx]->maxWindow,
2604
formatTime(&(device[actualReportDeviceId].tcpSession[idx]->firstSeen), 1),
2605
formatTime(&(device[actualReportDeviceId].tcpSession[idx]->lastSeen), 1),
2606
formatSeconds(actTime-device[actualReportDeviceId].tcpSession[idx]->firstSeen),
2607
formatLatency(device[actualReportDeviceId].tcpSession[idx]->nwLatency,
2608
device[actualReportDeviceId].tcpSession[idx]->sessionState)
2609
#ifdef PRINT_ALL_ACTIVE_SESSIONS
2610
, getSessionState(device[actualReportDeviceId].tcpSession[idx])
2612
) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
2619
if(numSessions > 0) {
2620
sendString("</TABLE>"TABLE_OFF"<P>\n");
2621
sendString("</CENTER>\n");
2627
/* ******************************* */
2636
u_short isHostHealthy(HostTraffic *el) {
2637
u_char riskFactor = 0;
2639
if(hasWrongNetmask(el)) {
2640
if(riskFactor < 1) riskFactor = 1;
2643
if(hasDuplicatedMac(el)) {
2644
if(riskFactor < 2) riskFactor = 2;
2650
/* ************************************ */
2652
static void checkHostHealthness(HostTraffic *el) {
2655
if(hasWrongNetmask(el)
2656
|| hasDuplicatedMac(el)
2658
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s "
2659
"<IMG ALT=\"High Risk\" SRC=/Risk_high.gif> "
2660
"<IMG ALT=\"Medium Risk\" SRC=/Risk_medium.gif> "
2661
"<IMG ALT=\"Low Risk\" SRC=/Risk_low.gif>"
2662
"</TH><TD "TD_BG" ALIGN=RIGHT NOWRAP><OL>", getRowColor(),
2663
"Network Healthness") < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
2666
if(hasWrongNetmask(el))
2667
sendString("<LI><IMG ALT=\"Medium Risk\" SRC=/Risk_medium.gif><A HREF=/help.html#1>"
2668
"Wrong network mask or bridging enabled</A>\n");
2670
if(hasDuplicatedMac(el))
2671
sendString("<LI><IMG ALT=\"High Risk\" SRC=/Risk_high.gif><A HREF=/help.html#2>"
2672
"Duplicated MAC found for this IP address (spoofing?)</A>\n");
2674
sendString("</OL></TD></TR>\n");
2678
/* ************************************ */
2680
void checkHostProvidedServices(HostTraffic *el) {
2684
|| isWorkstation(el)
2685
|| isMasterBrowser(el)
2688
|| nameServerHost(el)
2690
|| isSMTPhost(el) || isIMAPhost(el) || isPOPhost(el)
2691
|| isDirectoryHost(el)
2695
#ifdef ENABLE_NAPSTER
2696
|| isNapsterRedirector(el) || isNapsterServer(el) || isNapsterClient(el)
2698
|| isDHCPClient(el) || isDHCPServer(el)
2700
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2701
"<TD "TD_BG" ALIGN=RIGHT>", getRowColor(),
2702
"Host Type") < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
2705
if(isServer(el)) sendString("Server<br>");
2706
if(isWorkstation(el)) sendString("Workstation<br>");
2707
if(isMasterBrowser(el)) sendString("Master Browser<br>");
2708
if(isPrinter(el)) sendString("Printer <IMG ALT=Printer SRC=printer.gif BORDER=0><br>");
2709
if(isBridgeHost(el)) sendString("Bridge<br>");
2711
if(nameServerHost(el)) sendString(" <IMG ALT=\"DNS Server\" SRC=/dns.gif BORDER=0> Name Server<br>");
2712
if(gatewayHost(el)) sendString("Gateway <IMG ALT=Router SRC=/router.gif BORDER=0> <br>");
2713
if(isSMTPhost(el)) sendString("SMTP Server <IMG ALT=\"Mail Server (SMTP)\" SRC=/mail.gif BORDER=0> <br>");
2714
if(isPOPhost(el)) sendString("POP Server<br>");
2715
if(isIMAPhost(el)) sendString("IMAP Server<br>");
2716
if(isDirectoryHost(el)) sendString("Directory Server<br>");
2717
if(isFTPhost(el)) sendString("FTP Server<br>");
2718
if(isHTTPhost(el)) sendString("HTTP Server<br>");
2719
if(isWINShost(el)) sendString("WINS Server<br>");
2722
#ifdef ENABLE_NAPSTER
2723
if(isNapsterRedirector(el)) sendString("Napster Redirector<br>");
2724
if(isNapsterServer(el)) sendString("Napster Server<br>");
2725
if(isNapsterClient(el)) sendString("Napster Client<br>");
2728
if(isDHCPClient(el)) sendString("BOOTP/DHCP Client <IMG ALT=\"DHCP Client\" SRC=/bulb.gif BORDER=0><br>");
2729
if(isDHCPServer(el)) sendString("BOOTP/DHCP Server <IMG ALT=\"DHCP Server\" SRC=/wheel.gif BORDER=0> <br>");
2730
sendString("</TD></TR>");
2734
/* ************************************ */
2736
void printHostDetailedInfo(HostTraffic *el) {
2737
char buf[BUF_SIZE], buf1[64], sniffedName[MAXDNAME];
2739
TrafficCounter total;
2740
int printedHeader, i;
2741
char *dynIp, *multihomed;
2743
#ifdef MULTITHREADED
2744
accessMutex(&addressResolutionMutex, "printAllSessionsHTML");
2748
if(getSniffedDNSName(el->hostNumIpAddress, sniffedName, sizeof(sniffedName))) {
2749
if(el->hostSymIpAddress[0] == '\0' || strcmp(sniffedName, el->hostSymIpAddress))
2750
snprintf(buf1, sizeof(buf1), " (%s)", sniffedName);
2753
if(el->hostSymIpAddress[0] == '\0') {
2754
if(snprintf(buf, sizeof(buf), "Info about host %s",
2755
el->ethAddressString) < 0)
2756
traceEvent(TRACE_ERROR, "Buffer overflow!");
2758
if(el->hostNumIpAddress[0] == '\0') {
2759
if(snprintf(buf, sizeof(buf), "Info about host %s", el->hostSymIpAddress) < 0)
2760
traceEvent(TRACE_ERROR, "Buffer overflow!");
2762
if(snprintf(buf, sizeof(buf), "Info about host"
2763
" <A HREF=http://%s/>%s %s</A>\n",
2764
el->hostNumIpAddress, el->hostSymIpAddress, buf1) < 0)
2765
traceEvent(TRACE_ERROR, "Buffer overflow!");
2769
#ifdef MULTITHREADED
2770
releaseMutex(&addressResolutionMutex);
2773
printHTMLheader(buf, 0);
2774
sendString("<CENTER>\n");
2775
sendString("<P>"TABLE_ON"<TABLE BORDER=1 WIDTH=\"100%%\">\n");
2777
if(el->hostNumIpAddress[0] != '\0') {
2778
char *countryIcon, *hostType;
2780
#ifdef MULTITHREADED
2781
accessMutex(&addressResolutionMutex, "printAllSessions-2");
2784
/* Courtesy of Roberto De Luca <deluca@tandar.cnea.gov.ar> */
2785
if(strcmp(el->hostNumIpAddress, el->hostSymIpAddress) != 0) {
2786
#ifdef MULTITHREADED
2787
releaseMutex(&addressResolutionMutex);
2789
countryIcon = getHostCountryIconURL(el);
2791
#ifdef MULTITHREADED
2792
releaseMutex(&addressResolutionMutex);
2797
if(broadcastHost(el)) hostType = "broadcast";
2798
else if(multicastHost(el)) hostType = "multicast";
2799
else hostType = "unicast";
2801
if(isDHCPClient(el))
2806
if(isMultihomed(el) && (!broadcastHost(el)))
2807
multihomed = " - multihomed <IMG ALT=\"Multihomed Host SRC=/multihomed.gif BORDER=0>";
2811
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2812
"<TD "TD_BG" ALIGN=RIGHT>%s %s [%s%s%s]",
2815
el->hostNumIpAddress,
2816
countryIcon, hostType, dynIp, multihomed) < 0)
2817
traceEvent(TRACE_ERROR, "Buffer overflow!");
2820
sendString("</TD></TR>\n");
2822
if(isMultihomed(el) && (!broadcastHost(el))) {
2825
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD ALIGN=RIGHT><OL>",
2826
getRowColor(), "Multihomed Addresses") < 0)
2827
traceEvent(TRACE_ERROR, "Buffer overflow!");
2830
for(elIdx=1; elIdx<device[actualReportDeviceId].actualHashSize; elIdx++) {
2831
HostTraffic *theHost;
2833
if(elIdx == otherHostEntryIdx) continue;
2835
theHost = device[actualReportDeviceId].hash_hostTraffic[elIdx];
2837
if((theHost != NULL)
2839
&& (memcmp(theHost->ethAddress, el->ethAddress, ETHERNET_ADDRESS_LEN) == 0)) {
2840
if(snprintf(buf, sizeof(buf), "<LI><A HREF=/%s.html>%s</A>",
2841
theHost->hostNumIpAddress, theHost->hostNumIpAddress) < 0)
2842
traceEvent(TRACE_ERROR, "Buffer overflow!");
2847
sendString("</TD></TR>");
2850
if(el->dhcpStats != NULL) {
2851
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>",
2852
getRowColor(), "DHCP Information") < 0)
2853
traceEvent(TRACE_ERROR, "Buffer overflow!");
2856
sendString("<TD "TD_BG"><TABLE BORDER WIDTH=100%%>\n");
2858
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2859
"<TD ALIGN=RIGHT COLSPAN=2>%s</TD></TR>\n", getRowColor(), "DHCP Server",
2860
_intoa(el->dhcpStats->dhcpServerIpAddress, buf1, sizeof(buf1))) < 0)
2861
traceEvent(TRACE_ERROR, "Buffer overflow!");
2864
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2865
"<TD ALIGN=RIGHT COLSPAN=2>%s</TD></TR>\n", getRowColor(), "Previous IP Address",
2866
_intoa(el->dhcpStats->previousIpAddress, buf1, sizeof(buf1))) < 0)
2867
traceEvent(TRACE_ERROR, "Buffer overflow!");
2870
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2871
"<TD ALIGN=RIGHT COLSPAN=2>%s</TD></TR>\n",
2872
getRowColor(), "Address Assigned on",
2873
formatTime(&(el->dhcpStats->assignTime), 1)) < 0)
2874
traceEvent(TRACE_ERROR, "Buffer overflow!");
2877
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2878
"<TD ALIGN=RIGHT COLSPAN=2>%s</TD></TR>\n",
2879
getRowColor(), "To be Renewed Before",
2880
formatTime(&(el->dhcpStats->renewalTime), 1)) < 0)
2881
traceEvent(TRACE_ERROR, "Buffer overflow!");
2884
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2885
"<TD ALIGN=RIGHT COLSPAN=2>%s</TD></TR>\n",
2886
getRowColor(), "Lease Ends on",
2887
formatTime(&(el->dhcpStats->leaseTime), 1)) < 0)
2888
traceEvent(TRACE_ERROR, "Buffer overflow!");
2892
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>DHCP Packets</TH>"
2893
"<TH "TH_BG" ALIGN=CENTER>Sent</TH><TH "TH_BG" ALIGN=RIGHT>Rcvd</TH></TR>\n",
2895
traceEvent(TRACE_ERROR, "Buffer overflow!");
2898
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2899
"<TD ALIGN=RIGHT>%s</TD><TD ALIGN=RIGHT>%s</TD></TR>\n",
2900
getRowColor(), "DHCP Discover",
2901
formatPkts(el->dhcpStats->dhcpMsgSent[DHCP_DISCOVER_MSG]),
2902
formatPkts(el->dhcpStats->dhcpMsgRcvd[DHCP_DISCOVER_MSG])) < 0)
2903
traceEvent(TRACE_ERROR, "Buffer overflow!");
2906
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2907
"<TD ALIGN=RIGHT>%s</TD><TD ALIGN=RIGHT>%s</TD></TR>\n",
2908
getRowColor(), "DHCP Offer",
2909
formatPkts(el->dhcpStats->dhcpMsgSent[DHCP_OFFER_MSG]),
2910
formatPkts(el->dhcpStats->dhcpMsgRcvd[DHCP_OFFER_MSG])) < 0)
2911
traceEvent(TRACE_ERROR, "Buffer overflow!");
2914
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2915
"<TD ALIGN=RIGHT>%s</TD><TD ALIGN=RIGHT>%s</TD></TR>\n",
2916
getRowColor(), "DHCP Request",
2917
formatPkts(el->dhcpStats->dhcpMsgSent[DHCP_REQUEST_MSG]),
2918
formatPkts(el->dhcpStats->dhcpMsgRcvd[DHCP_REQUEST_MSG])) < 0)
2919
traceEvent(TRACE_ERROR, "Buffer overflow!");
2922
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2923
"<TD ALIGN=RIGHT>%s</TD><TD ALIGN=RIGHT>%s</TD></TR>\n",
2924
getRowColor(), "DHCP Decline",
2925
formatPkts(el->dhcpStats->dhcpMsgSent[DHCP_DECLINE_MSG]),
2926
formatPkts(el->dhcpStats->dhcpMsgRcvd[DHCP_DECLINE_MSG])) < 0)
2927
traceEvent(TRACE_ERROR, "Buffer overflow!");
2930
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2931
"<TD ALIGN=RIGHT>%s</TD><TD ALIGN=RIGHT>%s</TD></TR>\n",
2932
getRowColor(), "DHCP Ack",
2933
formatPkts(el->dhcpStats->dhcpMsgSent[DHCP_ACK_MSG]),
2934
formatPkts(el->dhcpStats->dhcpMsgRcvd[DHCP_ACK_MSG])) < 0)
2935
traceEvent(TRACE_ERROR, "Buffer overflow!");
2938
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2939
"<TD ALIGN=RIGHT>%s</TD><TD ALIGN=RIGHT>%s</TD></TR>\n",
2940
getRowColor(), "DHCP Nack",
2941
formatPkts(el->dhcpStats->dhcpMsgSent[DHCP_NACK_MSG]),
2942
formatPkts(el->dhcpStats->dhcpMsgRcvd[DHCP_NACK_MSG])) < 0)
2943
traceEvent(TRACE_ERROR, "Buffer overflow!");
2946
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2947
"<TD ALIGN=RIGHT>%s</TD><TD ALIGN=RIGHT>%s</TD></TR>\n",
2948
getRowColor(), "DHCP Release",
2949
formatPkts(el->dhcpStats->dhcpMsgSent[DHCP_RELEASE_MSG]),
2950
formatPkts(el->dhcpStats->dhcpMsgRcvd[DHCP_RELEASE_MSG])) < 0)
2951
traceEvent(TRACE_ERROR, "Buffer overflow!");
2955
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2956
"<TD ALIGN=RIGHT>%s</TD><TD ALIGN=RIGHT>%s</TD></TR>\n",
2957
getRowColor(), "DHCP Inform",
2958
formatPkts(el->dhcpStats->dhcpMsgSent[DHCP_INFORM_MSG]),
2959
formatPkts(el->dhcpStats->dhcpMsgRcvd[DHCP_INFORM_MSG])) < 0)
2960
traceEvent(TRACE_ERROR, "Buffer overflow!");
2964
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2965
"<TD ALIGN=RIGHT>%s</TD><TD ALIGN=RIGHT>%s</TD></TR>\n",
2966
getRowColor(), "DHCP Unknown Msg",
2967
formatPkts(el->dhcpStats->dhcpMsgSent[DHCP_UNKNOWN_MSG]),
2968
formatPkts(el->dhcpStats->dhcpMsgRcvd[DHCP_UNKNOWN_MSG])) < 0)
2969
traceEvent(TRACE_ERROR, "Buffer overflow!");
2972
sendString("</TABLE></TD></TR>\n");
2976
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
2977
"<TD "TD_BG" ALIGN=RIGHT>"
2978
"%s - %s [%s]</TD></TR>\n",
2980
"First/Last Seen",
2981
formatTime(&(el->firstSeen), 1),
2982
formatTime(&(el->lastSeen), 1),
2983
formatSeconds(el->lastSeen - el->firstSeen)) < 0)
2984
traceEvent(TRACE_ERROR, "Buffer overflow!");
2987
if(el->fullDomainName && (el->fullDomainName[0] != '\0')) {
2988
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
2991
"Domain", el->fullDomainName) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
2995
if((el->ethAddressString[0] != '\0')
2996
&& strcmp(el->ethAddressString, "00:00:00:00:00:00")
2997
&& strcmp(el->ethAddressString, "00:01:02:03:04:05") /* dummy address */) {
3000
if(isMultihomed(el)) {
3001
char *symMacAddr, symLink[32];
3004
symMacAddr = etheraddr_string(el->ethAddress);
3005
strcpy(symLink, symMacAddr);
3006
for(i=0; symLink[i] != '\0'; i++)
3007
if(symLink[i] == ':')
3010
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3011
"<A HREF=%s.html>%s</A>%s</TD></TR>\n",
3012
getRowColor(), "Main Host MAC Address",
3013
symLink, symMacAddr,
3014
separator /* it avoids empty cells not to be rendered */) < 0)
3015
traceEvent(TRACE_ERROR, "Buffer overflow!");
3019
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3021
getRowColor(), "MAC Address <IMG ALT=\"Network Interface Card (NIC)\" SRC=/card.gif BORDER=0>",
3022
el->ethAddressString,
3023
separator /* it avoids empty cells not to be rendered */) < 0)
3024
traceEvent(TRACE_ERROR, "Buffer overflow!");
3028
vendorName = getVendorInfo(el->ethAddress, 1);
3029
if(vendorName[0] != '\0') {
3030
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3032
getRowColor(), "Nw Board Vendor",
3034
separator /* it avoids empty cells not to be rendered */) < 0)
3035
traceEvent(TRACE_ERROR, "Buffer overflow!");
3040
if(((el->lastEthAddress[0] != 0)
3041
|| (el->lastEthAddress[1] != 0)
3042
|| (el->lastEthAddress[2] != 0)
3043
|| (el->lastEthAddress[3] != 0)
3044
|| (el->lastEthAddress[4] != 0)
3045
|| (el->lastEthAddress[5] != 0) /* The address isn't empty */)
3046
&& (memcmp(el->lastEthAddress, el->ethAddress, ETHERNET_ADDRESS_LEN) != 0)) {
3047
/* Different MAC addresses */
3048
char *symMacAddr, symLink[32];
3051
symMacAddr = etheraddr_string(el->lastEthAddress);
3052
strcpy(symLink, symMacAddr);
3053
for(i=0; symLink[i] != '\0'; i++)
3054
if(symLink[i] == ':')
3057
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3058
"<A HREF=%s.html>%s</A>%s</TD></TR>\n",
3059
getRowColor(), "Last MAC Address/Router <IMG ALT=\"Network Interface Card (NIC)/Router\" SRC=/card.gif BORDER=0>",
3060
symLink, symMacAddr,
3061
separator /* it avoids empty cells not to be rendered */) < 0)
3062
traceEvent(TRACE_ERROR, "Buffer overflow!");
3066
if(el->hostNumIpAddress[0] != '\0') {
3069
if((el->osName != NULL) && (el->osName[0] != '\0')) {
3070
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3072
getRowColor(), "OS Name",
3073
getOSFlag(el->osName, 1),
3074
separator /* it avoids empty cells not to be rendered */) < 0)
3075
traceEvent(TRACE_ERROR, "Buffer overflow!");
3080
if((el->nbHostName != NULL) && (el->nbDomainName != NULL)) {
3081
if(el->nbAccountName) {
3082
if(el->nbDomainName != NULL) {
3083
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3084
"%s@%s [domain %s] (%s) %s</TD></TR>\n",
3085
getRowColor(), "NetBios Name",
3086
el->nbAccountName, el->nbHostName, el->nbDomainName,
3087
getNbNodeType(el->nbNodeType),
3088
el->nbDescr ? el->nbDescr : "") < 0)
3089
traceEvent(TRACE_ERROR, "Buffer overflow!");
3091
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3092
"%s@%s (%s) %s</TD></TR>\n",
3093
getRowColor(), "NetBios Name",
3094
el->nbAccountName, el->nbHostName,
3095
getNbNodeType(el->nbNodeType),
3096
el->nbDescr ? el->nbDescr : "") < 0)
3097
traceEvent(TRACE_ERROR, "Buffer overflow!");
3100
if(el->nbDomainName != NULL) {
3101
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3102
"%s [domain %s] (%s) %s</TD></TR>\n",
3103
getRowColor(), "NetBios Name",
3104
el->nbHostName, el->nbDomainName,
3105
getNbNodeType(el->nbNodeType),
3106
el->nbDescr ? el->nbDescr : "") < 0)
3107
traceEvent(TRACE_ERROR, "Buffer overflow!");
3109
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3110
"%s (%s) %s</TD></TR>\n",
3111
getRowColor(), "NetBios Name",
3113
getNbNodeType(el->nbNodeType),
3114
el->nbDescr ? el->nbDescr : "") < 0)
3115
traceEvent(TRACE_ERROR, "Buffer overflow!");
3120
} else if(el->nbHostName != NULL) {
3121
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3122
"%s (%s) %s</TD></TR>\n",
3123
getRowColor(), "NetBios Name",
3124
el->nbHostName, getNbNodeType(el->nbNodeType),
3125
el->nbDescr ? el->nbDescr : "") < 0)
3126
traceEvent(TRACE_ERROR, "Buffer overflow!");
3130
if(el->atNetwork != 0) {
3131
char *nodeName = el->atNodeName;
3133
if(nodeName == NULL) nodeName = "";
3135
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3137
getRowColor(), "AppleTalk Name",
3138
nodeName) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
3141
if(el->atNodeType[0] != NULL) {
3145
for(i=0; i<MAX_NODE_TYPES; i++)
3146
if(el->atNodeType[i] == NULL)
3149
if(i > 0) sendString("/");
3150
sendString(el->atNodeType[i]);
3153
sendString(") ");
3156
if(snprintf(buf, sizeof(buf), "[%d.%d]</TD></TR>\n",
3157
el->atNetwork, el->atNode) < 0)
3158
traceEvent(TRACE_ERROR, "Buffer overflow!");
3162
if(el->ipxHostName != NULL) {
3165
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
3166
"<TD "TD_BG" ALIGN=RIGHT>"
3167
"%s [", getRowColor(), "IPX Name",
3168
el->ipxHostName) < 0)
3169
traceEvent(TRACE_ERROR, "Buffer overflow!");
3172
for(i=0; i<el->numIpxNodeTypes; i++) {
3173
if(i>0) sendString("/");
3174
sendString(getSAPInfo(el->ipxNodeType[i], 1));
3177
sendString("]</TD></TR>\n");
3180
if(!multicastHost(el)) {
3181
if(subnetPseudoLocalHost(el)) {
3182
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3183
"%s</TD></TR>\n", getRowColor(),
3184
"Host Location",
3185
"Local (inside specified/local subnet)") < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
3187
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3188
"%s</TD></TR>\n", getRowColor(),
3189
"Host Location",
3190
"Remote (outside specified/local subnet)") < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
3195
if(el->minTTL > 0) {
3196
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3197
"%d:%d hops</TD></TR>\n",
3198
getRowColor(), "IP TTL (Time to Live)",
3199
el->minTTL, el->maxTTL) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
3203
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3204
"%s/%s Pkts/%s Retran. Pkts [%d%%]</TD></TR>\n",
3205
getRowColor(), "Total Data Sent",
3206
formatBytes(el->bytesSent, 1), formatPkts(el->pktSent),
3207
formatPkts(el->pktDuplicatedAckSent),
3208
(int)(((float)el->pktDuplicatedAckSent*100)/(float)(el->pktSent+1))
3209
) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
3212
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3213
"%s Pkts</TD></TR>\n",
3214
getRowColor(), "Broadcast Pkts Sent",
3215
formatPkts(el->pktBroadcastSent)) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
3218
if(el->routedTraffic != NULL) {
3219
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3220
"%s/%s Pkts</TD></TR>\n",
3221
getRowColor(), "Routed Traffic",
3222
formatBytes(el->routedTraffic->routedBytes, 1),
3223
formatPkts(el->routedTraffic->routedPkts)) < 0)
3224
traceEvent(TRACE_ERROR, "Buffer overflow!");
3228
if((el->pktMulticastSent > 0) || (el->pktMulticastRcvd > 0)) {
3229
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3230
"Sent %s/%s Pkts -"
3231
" Rcvd %s/%s Pkts</TD></TR>\n",
3232
getRowColor(), "Multicast Traffic",
3233
formatBytes(el->bytesMulticastSent, 1),
3234
formatPkts(el->pktMulticastSent),
3235
formatBytes(el->bytesMulticastRcvd, 1),
3236
formatPkts(el->pktMulticastRcvd)
3237
) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
3241
if(el->bytesSent == 0)
3244
percentage = 100 - (((float)el->bytesSentRemotely*100)/el->bytesSent);
3246
if(el->hostNumIpAddress[0] != '\0') {
3247
printTableEntryPercentage(buf, sizeof(buf), "Data Sent Stats",
3248
"Local", "Remote", -1, percentage);
3251
if(el->bytesSent > 0) {
3252
percentage = (((float)el->ipBytesSent*100)/el->bytesSent);
3253
printTableEntryPercentage(buf, sizeof(buf), "IP vs. Non-IP Sent",
3254
"IP", "Non-IP", -1, percentage);
3257
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3258
"%s/%s Pkts/%s Retran. Pkts [%d%%]</TD></TR>\n",
3259
getRowColor(), "Total Data Rcvd",
3260
formatBytes(el->bytesReceived, 1), formatPkts(el->pktReceived),
3261
formatPkts(el->pktDuplicatedAckRcvd),
3262
(int)((float)(el->pktDuplicatedAckRcvd*100)/(float)(el->pktReceived+1))) < 0)
3263
traceEvent(TRACE_ERROR, "Buffer overflow!");
3266
if(el->bytesReceived == 0)
3269
percentage = 100 - (((float)el->bytesReceivedFromRemote*100)/el->bytesReceived);
3271
if(el->hostNumIpAddress[0] != '\0')
3272
printTableEntryPercentage(buf, sizeof(buf), "Data Received Stats",
3273
"Local", "Remote", -1, percentage);
3275
if(el->bytesReceived > 0) {
3276
percentage = (((float)el->ipBytesReceived*100)/el->bytesReceived);
3277
printTableEntryPercentage(buf, sizeof(buf), "IP vs. Non-IP Received",
3278
"IP", "Non-IP", -1, percentage);
3281
total = el->pktSent+el->pktReceived;
3283
percentage = ((float)el->pktSent*100)/((float)total);
3284
printTableEntryPercentage(buf, sizeof(buf), "Sent vs. Rcvd Pkts",
3285
"Sent", "Rcvd", -1, percentage);
3288
total = el->bytesSent+el->bytesReceived;
3290
percentage = ((float)el->bytesSent*100)/((float)total);
3291
printTableEntryPercentage(buf, sizeof(buf), "Sent vs. Rcvd Data",
3292
"Sent", "Rcvd", -1, percentage);
3295
/* ******************** */
3298
for(i=0; i<MAX_NUM_CONTACTED_PEERS; i++) {
3299
if(el->contactedRouters.peersIndexes[i] != NO_PEER) {
3300
int routerIdx = el->contactedRouters.peersIndexes[i];
3301
HostTraffic *router = device[actualReportDeviceId].hash_hostTraffic[checkSessionIdx(routerIdx)];
3303
if(router != NULL) {
3304
if(!printedHeader) {
3305
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>"
3306
"Used Subnet Routers</TH><TD "TD_BG" ALIGN=RIGHT>\n",
3308
traceEvent(TRACE_ERROR, "Buffer overflow!");
3313
if(printedHeader > 1) sendString("<BR>");
3315
if(snprintf(buf, sizeof(buf), "%s\n", makeHostLink(router, SHORT_FORMAT, 0, 0)) < 0)
3316
traceEvent(TRACE_ERROR, "Buffer overflow!");
3322
checkHostProvidedServices(el);
3324
/* **************************** */
3327
Albert Chin-A-Young <china@thewrittenword.com>
3329
if(printedHeader > 1)
3330
sendString("</OL></TD></TR>\n");
3332
if((el->hostNumIpAddress[0] != '\0')
3333
&& (!subnetPseudoLocalHost(el))
3334
&& (!multicastHost(el))
3335
&& (!privateIPAddress(el))
3336
&& (mapperURL[0] > 0)) {
3337
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT>%s</TH><TD "TD_BG" ALIGN=RIGHT>"
3338
"<IMG SRC=\"%s?host=%s\" WIDTH=320 HEIGHT=200></TD></TR>\n",
3340
"Host Physical Location",
3341
mapperURL, el->hostNumIpAddress) < 0)
3342
traceEvent(TRACE_ERROR, "Buffer overflow!");
3346
checkHostHealthness(el);
3348
sendString("</TABLE>"TABLE_OFF"<P>\n");
3349
sendString("</CENTER>\n");
3352
/* ************************************ */
3354
void printServiceStats(char* svcName, ServiceStats* ss,
3355
short printSentStats) {
3357
TrafficCounter tot, tot1;
3358
float f1, f2, f3, f4;
3361
if(printSentStats) {
3362
tot = ss->numLocalReqSent+ss->numRemoteReqSent;
3367
f1 = (ss->numLocalReqSent*100)/tot;
3368
f2 = (ss->numRemoteReqSent*100)/tot;
3371
tot1 = ss->numPositiveReplRcvd+ss->numNegativeReplRcvd;
3375
f3 = (ss->numPositiveReplRcvd*100)/tot1;
3376
f4 = (ss->numNegativeReplRcvd*100)/tot1;
3379
if((tot > 0) || (tot1 > 0)) {
3380
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG">%s</TH>"
3381
"<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
3382
"<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
3383
"<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
3384
"<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
3385
"<TD "TD_BG" ALIGN=CENTER>%s - %s</TD><TD "TD_BG" ALIGN=CENTER>%s - %s</TD>"
3387
getRowColor(), svcName,
3388
formatPkts(ss->numLocalReqSent), f1,
3389
formatPkts(ss->numRemoteReqSent), f2,
3390
formatPkts(ss->numPositiveReplRcvd), f3,
3391
formatPkts(ss->numNegativeReplRcvd), f4,
3392
formatMicroSeconds(ss->fastestMicrosecLocalReqMade),
3393
formatMicroSeconds(ss->slowestMicrosecLocalReqMade),
3394
formatMicroSeconds(ss->fastestMicrosecRemoteReqMade),
3395
formatMicroSeconds(ss->slowestMicrosecRemoteReqMade)
3396
) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
3400
tot = ss->numLocalReqRcvd+ss->numRemoteReqRcvd;
3405
f1 = (ss->numLocalReqRcvd*100)/tot;
3406
f2 = (ss->numRemoteReqRcvd*100)/tot;
3409
tot1 = ss->numPositiveReplSent+ss->numNegativeReplSent;
3413
f3 = (ss->numPositiveReplSent*100)/tot1;
3414
f4 = (ss->numNegativeReplSent*100)/tot1;
3417
if((tot > 0) || (tot1 > 0)) {
3418
if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG">%s</TH>"
3419
"<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
3420
"<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
3421
"<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
3422
"<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
3423
"<TD "TD_BG" ALIGN=CENTER>%s - %s</TD><TD "TD_BG" ALIGN=CENTER>%s - %s</TD>"
3425
getRowColor(), svcName,
3426
formatPkts(ss->numLocalReqRcvd), f1,
3427
formatPkts(ss->numRemoteReqRcvd), f2,
3428
formatPkts(ss->numPositiveReplSent), f3,
3429
formatPkts(ss->numNegativeReplSent), f4,
3430
formatMicroSeconds(ss->fastestMicrosecLocalReqServed),
3431
formatMicroSeconds(ss->slowestMicrosecLocalReqServed),
3432
formatMicroSeconds(ss->fastestMicrosecRemoteReqServed),
3433
formatMicroSeconds(ss->slowestMicrosecRemoteReqServed)
3434
) < 0) traceEvent(TRACE_ERROR, "Buffer overflow!");
3441
/* ************************************ */
3443
#ifdef ENABLE_NAPSTER
3444
static void printNapsterStats(HostTraffic *el) {
3446
printSectionTitle("Napster Stats");
3448
sendString("<CENTER>"TABLE_ON"<TABLE BORDER=1>\n");
3449
sendString("<TR><TH "TH_BG" ALIGN=LEFT># Connections Requested</TH><TD ALIGN=RIGHT>");
3450
sendString(formatPkts(el->napsterStats->numConnectionsRequested));
3451
sendString("</TD></TR>\n");
3452
sendString("<TR><TH "TH_BG" ALIGN=LEFT># Connections Served</TH><TD ALIGN=RIGHT>");
3453
sendString(formatPkts(el->napsterStats->numConnectionsServed));
3454
sendString("</TD></TR>\n");
3455
sendString("<TR><TH "TH_BG" ALIGN=LEFT># Search Requested</TH><TD ALIGN=RIGHT>");
3456
sendString(formatPkts(el->napsterStats->numSearchSent));
3457
sendString("</TD></TR>\n");
3458
sendString("<TR><TH "TH_BG" ALIGN=LEFT># Search Served</TH><TD ALIGN=RIGHT>");
3459
sendString(formatPkts(el->napsterStats->numSearchRcvd));
3460
sendString("</TD></TR>\n");
3461
sendString("<TR><TH "TH_BG" ALIGN=LEFT># Downloads Requested</TH><TD ALIGN=RIGHT>");
3462
sendString(formatPkts(el->napsterStats->numDownloadsRequested));
3463
sendString("</TD></TR>\n");
3464
sendString("<TR><TH "TH_BG" ALIGN=LEFT># Downloads Served</TH><TD ALIGN=RIGHT>");
3465
sendString(formatPkts(el->napsterStats->numDownloadsServed));
3466
sendString("</TD></TR>\n");
3467
sendString("<TR><TH "TH_BG" ALIGN=LEFT>Data Sent</TH><TD ALIGN=RIGHT>");
3468
sendString(formatBytes(el->napsterStats->bytesSent, 1));
3469
sendString("</TD></TR>\n");
3470
sendString("<TR><TH "TH_BG" ALIGN=LEFT>Data Received</TH><TD ALIGN=RIGHT>");
3471
sendString(formatBytes(el->napsterStats->bytesRcvd, 1));
3472
sendString("</TD></TR>\n");
3474
sendString("</TABLE>"TABLE_OFF"</CENTER>\n");
3478
/* ************************************ */
3480
void printHostUsedServices(HostTraffic *el) {
3483
#ifdef ENABLE_NAPSTER
3484
if(el->napsterStats != NULL)
3485
printNapsterStats(el);
3488
if((el->dnsStats == NULL) && (el->httpStats == NULL))
3494
tot += el->dnsStats->numLocalReqSent+el->dnsStats->numRemoteReqSent;
3497
tot += el->httpStats->numLocalReqSent+el->httpStats->numRemoteReqSent;
3500
printSectionTitle("IP Service Stats: Client Role");
3501
sendString("<CENTER>\n");
3502
sendString(""TABLE_ON"<TABLE BORDER=1 WIDTH=100%%>\n<TR>"
3503
"<TH "TH_BG"> </TH>"
3504
"<TH "TH_BG" COLSPAN=2># Loc. Req. Sent</TH>"
3505
"<TH "TH_BG" COLSPAN=2># Rem. Req. Sent</TH>"
3506
"<TH "TH_BG" COLSPAN=2># Pos. Reply Rcvd</TH>"
3507
"<TH "TH_BG" COLSPAN=2># Neg. Reply Rcvd</TH>"
3508
"<TH "TH_BG">Local RndTrip</TH>"
3509
"<TH "TH_BG">Remote RndTrip</TH>"
3512
if(el->dnsStats) printServiceStats("DNS", el->dnsStats, 1);
3513
if(el->httpStats) printServiceStats("HTTP", el->httpStats, 1);
3515
sendString("</TABLE>"TABLE_OFF"\n");
3516
sendString("</CENTER>\n");
3524
tot += el->dnsStats->numLocalReqRcvd+el->dnsStats->numRemoteReqRcvd;
3527
tot += el->httpStats->numLocalReqRcvd+el->httpStats->numRemoteReqRcvd;
3530
printSectionTitle("IP Service Stats: Server Role");
3531
sendString("<CENTER>\n");
3532
sendString("<P>"TABLE_ON"<TABLE BORDER=1 WIDTH=100%%>\n<TR>"
3533
"<TH "TH_BG"> </TH>"
3534
"<TH "TH_BG" COLSPAN=2># Loc. Req. Rcvd</TH>"
3535
"<TH "TH_BG" COLSPAN=2># Rem. Req. Rcvd</TH>"
3536
"<TH "TH_BG" COLSPAN=2># Pos. Reply Sent</TH>"
3537
"<TH "TH_BG" COLSPAN=2># Neg. Reply Sent</TH>"
3538
"<TH "TH_BG">Local RndTrip</TH>"
3539
"<TH "TH_BG">Remote RndTrip</TH>"
3542
if(el->dnsStats) printServiceStats("DNS", el->dnsStats, 0);
3543
if(el->httpStats) printServiceStats("HTTP", el->httpStats, 0);
3545
sendString("</TABLE>"TABLE_OFF"\n");
3546
sendString("</CENTER>\n");
3550
/* ********************************** */
3552
void printTableEntry(char *buf, int bufLen,
3553
char *label, char* color,
3554
float total, float percentage) {
3557
if(total == 0) return;
3559
int_perc = (int)percentage;
3561
/* This shouldn't happen */
3565
} else if(int_perc > 100) {
3572
if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT WIDTH=150>%s</TH>"
3573
"<TD "TD_BG" ALIGN=RIGHT WIDTH=100>%s</TD>"
3574
"<TD "TD_BG" WIDTH=250> </TD></TR>\n",
3575
getRowColor(), label, formatKBytes(total)) < 0)
3576
traceEvent(TRACE_ERROR, "Buffer overflow!");
3579
if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT WIDTH=150>%s</TH>"
3580
"<TD "TD_BG" ALIGN=RIGHT WIDTH=100>%s</TD>"
3581
"<TD ALIGN=CENTER WIDTH=250><IMG ALT=\"100%%\" ALIGN=MIDDLE SRC=/gauge.jpg WIDTH=\"250\" HEIGHT=12>"
3583
getRowColor(), label, formatKBytes(total)) < 0)
3584
traceEvent(TRACE_ERROR, "Buffer overflow!");
3587
if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT WIDTH=150>%s</TH>"
3588
"<TD "TD_BG" ALIGN=RIGHT WIDTH=100>%s</TD>"
3589
"<TD "TD_BG" WIDTH=250><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=\"250\">"
3590
"<TR><TD><IMG ALIGN=MIDDLE ALT=\"%d%%\" SRC=/gauge.jpg WIDTH=\"%d\" HEIGHT=12>"
3591
"</TD><TD "TD_BG" ALIGN=CENTER WIDTH=\"%d\" %s>"
3592
"<P> </TD></TR></TABLE></TD></TR>\n",
3593
getRowColor(), label, formatKBytes(total),
3594
int_perc, (250*int_perc)/100,
3595
(250*(100-int_perc))/100, getActualRowColor()) < 0)
3596
traceEvent(TRACE_ERROR, "Buffer overflow!");
3602
/* ************************ */
3604
char* buildHTMLBrowserWindowsLabel(int i, int j) {
3605
static char buf[BUF_SIZE];
3606
int idx = i*device[actualReportDeviceId].numHosts + j;
3608
#ifdef MULTITHREADED
3609
accessMutex(&addressResolutionMutex, "buildHTMLBrowserWindowsLabel");
3612
if((device[actualReportDeviceId].ipTrafficMatrix[idx] == NULL)
3613
|| ((device[actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent == 0)
3614
&& (device[actualReportDeviceId].ipTrafficMatrix[idx]->bytesReceived == 0)))
3616
else if ((device[actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent > 0)
3617
&& (device[actualReportDeviceId].ipTrafficMatrix[idx]->bytesReceived == 0)) {
3618
if(snprintf(buf, sizeof(buf), "(%s->%s)=%s",
3619
device[actualReportDeviceId].ipTrafficMatrixHosts[i]->hostSymIpAddress,
3620
device[actualReportDeviceId].ipTrafficMatrixHosts[j]->hostSymIpAddress,
3621
formatBytes(device[actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent, 1)) < 0)
3622
traceEvent(TRACE_ERROR, "Buffer overflow!");
3623
} else if ((device[actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent == 0)
3624
&& (device[actualReportDeviceId].ipTrafficMatrix[idx]->bytesReceived > 0)) {
3625
if(snprintf(buf, sizeof(buf), "(%s->%s)=%s",
3626
device[actualReportDeviceId].ipTrafficMatrixHosts[j]->hostSymIpAddress,
3627
device[actualReportDeviceId].ipTrafficMatrixHosts[i]->hostSymIpAddress,
3628
formatBytes(device[actualReportDeviceId].ipTrafficMatrix[idx]->bytesReceived, 1)) < 0)
3629
traceEvent(TRACE_ERROR, "Buffer overflow!");
3631
if(snprintf(buf, sizeof(buf), "(%s->%s)=%s, (%s->%s)=%s",
3632
device[actualReportDeviceId].ipTrafficMatrixHosts[i]->hostSymIpAddress,
3633
device[actualReportDeviceId].ipTrafficMatrixHosts[j]->hostSymIpAddress,
3634
formatBytes(device[actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent, 1),
3635
device[actualReportDeviceId].ipTrafficMatrixHosts[j]->hostSymIpAddress,
3636
device[actualReportDeviceId].ipTrafficMatrixHosts[i]->hostSymIpAddress,
3637
formatBytes(device[actualReportDeviceId].ipTrafficMatrix[idx]->bytesReceived, 1)) < 0)
3638
traceEvent(TRACE_ERROR, "Buffer overflow!");
3641
#ifdef MULTITHREADED
3642
releaseMutex(&addressResolutionMutex);
3648
/* ************************ */
3650
int cmpEventsFctn(const void *_a, const void *_b) {
3651
EventMsg **a = (EventMsg**)_a;
3652
EventMsg **b = (EventMsg**)_b;
3654
switch(columnSort) {
3655
case 0: /* Event Time */
3656
if((*a)->eventTime > (*b)->eventTime)
3658
else if((*a)->eventTime < (*b)->eventTime)
3663
case 1: /* Severity */
3664
if((*a)->severity > (*b)->severity)
3666
else if((*a)->severity < (*b)->severity)
3671
case 2: /* Rule Id */
3672
if((*a)->ruleId > (*b)->ruleId)
3674
else if((*a)->ruleId < (*b)->ruleId)
3684
/* *********************************** */
3686
void printHostHourlyTrafficEntry(HostTraffic *el, int i,
3687
TrafficCounter tcSent,
3688
TrafficCounter tcRcvd) {
3692
if(snprintf(buf, BUF_SIZE, "<TD "TD_BG" ALIGN=RIGHT>%s</TD>",
3693
formatBytes(el->last24HoursBytesSent[i], 0)) < 0)
3694
traceEvent(TRACE_ERROR, "Buffer overflow!");
3697
pctg = (float)(el->last24HoursBytesSent[i]*100)/(float)tcSent;
3700
if(snprintf(buf, BUF_SIZE, "<TD ALIGN=RIGHT %s>%.1f %%</TD>",
3701
getBgPctgColor(pctg), pctg) < 0)
3702
traceEvent(TRACE_ERROR, "Buffer overflow!");
3704
if(snprintf(buf, BUF_SIZE, "<TD "TD_BG" ALIGN=RIGHT>%s</TD>",
3705
formatBytes(el->last24HoursBytesRcvd[i], 0)) < 0)
3706
traceEvent(TRACE_ERROR, "Buffer overflow!");
3709
pctg = (float)(el->last24HoursBytesRcvd[i]*100)/(float)tcRcvd;
3713
if(snprintf(buf, BUF_SIZE, "<TD ALIGN=RIGHT %s>%.1f %%</TD></TR>",
3714
getBgPctgColor(pctg), pctg) < 0)
3715
traceEvent(TRACE_ERROR, "Buffer overflow!");
3719
/* ************************************ */
3721
char* getNbNodeType(char nodeType) {
3725
return("Workstation");
3731
return(""); /* NOTREACHED */
3734
#endif /* MICRO_NTOP */
3736
/* ********************************** */
3738
void printFlagedWarning(char *text) {
3741
snprintf(buf, BUF_SIZE,
3743
"<P><IMG ALT=Warning SRC=/warning.gif>\n"
3744
"<P><FONT COLOR=\"#FF0000\" SIZE=+1>%s</FONT>\n"
3745
"</CENTER>\n", text);
3749
/* ********************************** */
3751
void printSectionTitle(char *text) {
3754
snprintf(buf, BUF_SIZE,
3756
"<H1><FONT FACE=\"Helvetica, Arial, Sans Serif\">%s</FONT></H1><P>\n"
3757
"</CENTER>\n", text);