~ubuntu-branches/ubuntu/natty/ntop/natty

« back to all changes in this revision

Viewing changes to reportUtils.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2005-01-30 21:59:13 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050130215913-xc3ke963bw49b3k4
Tags: 2:3.0-5
* Updated README.Debian file so users will understand what to do at
  install, closes: #291794, #287802.
* Updated ntop init script to give better output.
* Also changed log directory from /var/lib/ntop to /var/log/ntop,
  closes: #252352.
* Quoted the interface list to allow whitespace, closes: #267248.
* Added a couple of logcheck ignores, closes: #269321, #269319.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 1998-2004 Luca Deri <deri@ntop.org>
 
3
 *
 
4
 *                          http://www.ntop.org/
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
#include "ntop.h"
 
22
#include "globals-report.h"
 
23
 
 
24
typedef struct osInfo {
 
25
  char *name, *link;
 
26
} OsInfo;
 
27
 
 
28
typedef struct osNumInfo {
 
29
  char *name;
 
30
  unsigned short num;
 
31
} OsNumInfo;
 
32
 
 
33
static OsInfo osInfos[] = {
 
34
  { "Windows",       CONST_IMG_OS_WINDOWS },
 
35
  { "IRIX",          CONST_IMG_OS_IRIX },
 
36
  { "Linux",         CONST_IMG_OS_LINUX },
 
37
  { "SunOS",         CONST_IMG_OS_SUNOS },
 
38
  { "Solaris",       CONST_IMG_OS_SOLARIS },
 
39
  { "HP/JETdirect",  CONST_IMG_OS_HP_JETDIRET },
 
40
  { "Mac",           CONST_IMG_OS_MAC },
 
41
  { "Novell",        CONST_IMG_OS_NOVELL },
 
42
  { "BSD",           CONST_IMG_OS_BSD },
 
43
  { "Unix",          CONST_IMG_OS_UNIX },
 
44
  { "Berkeley",      CONST_IMG_OS_BERKELEY },
 
45
  { "HP-UX",         CONST_IMG_OS_HP_UX },
 
46
  { "AIX",           CONST_IMG_OS_AIX },
 
47
  { "Cisco",         CONST_IMG_OS_CISCO },
 
48
  NULL
 
49
};
 
50
 
 
51
/* ************************* */
 
52
 
 
53
void *mallocAndInitWithReportWarn(int sz, char *from) {
 
54
  void *tmpTable;
 
55
 
 
56
  tmpTable = malloc(sz);
 
57
 
 
58
  if (tmpTable == NULL) {
 
59
    traceEvent(CONST_TRACE_ERROR, "Unable to allocate temporary table (%d) for %s", sz, from);
 
60
    traceEvent(CONST_TRACE_INFO,  "User warned, continuing without generating report");
 
61
    printFlagedWarning("SORRY: <i>An internal error does not allow creation of this report.</i>");
 
62
  } else {
 
63
    memset (tmpTable, 0, sz);
 
64
  }
 
65
 
 
66
  return tmpTable;
 
67
}
 
68
 
 
69
/* ************************************ */
 
70
 
 
71
void formatUsageCounter(UsageCounter usageCtr,
 
72
                        Counter topValue,
 
73
                        /* If this value != 0 then a percentage is printed */
 
74
                        int actualDeviceId) {
 
75
  char buf[LEN_GENERAL_WORK_BUFFER], formatBuf[32], hostLinkBuf[LEN_GENERAL_WORK_BUFFER];
 
76
  int i, sendHeader=0;
 
77
  HostTraffic *el;
 
78
 
 
79
  if(topValue == 0) {
 
80
    /* No percentage is printed */
 
81
    if(snprintf(buf, sizeof(buf), "<TD "TD_BG" ALIGN=RIGHT>%s</TD>",
 
82
                formatPkts(usageCtr.value.value, formatBuf, sizeof(formatBuf))) < 0)
 
83
      BufferTooShort();
 
84
    sendString(buf);
 
85
  } else {
 
86
    float pctg;
 
87
 
 
88
    pctg = ((float)usageCtr.value.value/(float)topValue)*100;
 
89
 
 
90
    if(pctg > 100) pctg = 100; /* This should not happen ! */
 
91
 
 
92
    if(snprintf(buf, sizeof(buf), "<TD "TD_BG" ALIGN=RIGHT>%s&nbsp;[%.0f&nbsp;%%]</TD>",
 
93
                formatPkts(usageCtr.value.value, formatBuf, sizeof(formatBuf)), pctg) < 0)
 
94
      BufferTooShort();
 
95
    sendString(buf);
 
96
  }
 
97
 
 
98
  for(i=0; i<MAX_NUM_CONTACTED_PEERS; i++) {
 
99
      HostTraffic tmpEl;
 
100
 
 
101
      if(!emptySerial(&usageCtr.peersSerials[i])) {
 
102
          if((el = quickHostLink(usageCtr.peersSerials[i], myGlobals.actualReportDeviceId, &tmpEl)) != NULL) {
 
103
        if(!sendHeader) {
 
104
          sendString("<TD "TD_BG" ALIGN=LEFT><ul>");
 
105
          sendHeader = 1;
 
106
        }
 
107
 
 
108
        sendString("\n<li>");
 
109
        sendString(makeHostLink(el, 0, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)));
 
110
      } else
 
111
          traceEvent(CONST_TRACE_WARNING, "Unable to find host serial - host skipped");
 
112
    }
 
113
  }
 
114
 
 
115
  if(sendHeader)
 
116
    sendString("</ul></TD>\n");
 
117
  else
 
118
    sendString("<TD "TD_BG">&nbsp;</TD>\n");
 
119
}
 
120
 
 
121
/* ********************************** */
 
122
 
 
123
void printTableDoubleEntry(char *buf, int bufLen,
 
124
                           char *label, char* color,
 
125
                           float totalS, float percentageS,
 
126
                           float totalR, float percentageR) {
 
127
  int int_perc;
 
128
  char formatBuf[32];
 
129
 
 
130
  if((totalS == 0) && (totalR == 0)) return;
 
131
 
 
132
  if(percentageS < 0.5) {
 
133
    int_perc = 0;
 
134
    percentageS = 0;
 
135
  } else if(percentageS > 99.5) {
 
136
    int_perc = 100;
 
137
    percentageS = 100;
 
138
  } else {
 
139
    int_perc = (int) percentageS + 0.5;
 
140
  }
 
141
 
 
142
  switch(int_perc) {
 
143
  case 0:
 
144
    if(snprintf(buf, bufLen, "<TR "TR_ON" %s><TH WIDTH=100 "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
145
           "<TD WIDTH=100 "TD_BG" ALIGN=RIGHT>%s</TD>"
 
146
           "<TD WIDTH=100 "TD_BG">&nbsp;</TD>\n",
 
147
           getRowColor(), label, formatKBytes(totalS, formatBuf, sizeof(formatBuf))) < 0)
 
148
      BufferTooShort();
 
149
    break;
 
150
  case 100:
 
151
    if(snprintf(buf, bufLen, "<TR "TR_ON" %s><TH WIDTH=100 "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
152
                "<TD WIDTH=100 "TD_BG" ALIGN=RIGHT>%s</TD>"
 
153
                "<TD WIDTH=100><IMG ALT=\"100%%\"ALIGN=MIDDLE SRC=\"/gauge.jpg\" WIDTH=100 HEIGHT=12></TD>\n",
 
154
                getRowColor(), label, formatKBytes(totalS, formatBuf, sizeof(formatBuf))) < 0)
 
155
      BufferTooShort();
 
156
    break;
 
157
  default:
 
158
    if(snprintf(buf, bufLen, "<TR "TR_ON" %s><TH WIDTH=100 "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
159
                "<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 "TR_ON"><TD><IMG  ALT=\"%d%%\" ALIGN=MIDDLE SRC=\"/gauge.jpg\" WIDTH=\"%d\" HEIGHT=12></TD>"
 
162
                "<TD "TD_BG" ALIGN=CENTER WIDTH=\"%d\">"
 
163
                "<P>&nbsp;</TD></TR></TABLE>"TABLE_OFF"</TD>\n",
 
164
                getRowColor(), label, formatKBytes(totalS, formatBuf, sizeof(formatBuf)),
 
165
                int_perc, (100*int_perc)/100, (100*(100-int_perc))/100) < 0)
 
166
      BufferTooShort();
 
167
  }
 
168
 
 
169
  sendString(buf);
 
170
 
 
171
  /* ************************ */
 
172
 
 
173
  if(totalR == 0) percentageR = 0;
 
174
 
 
175
  if(percentageR < 0.5) {
 
176
    int_perc = 0;
 
177
    percentageR = 0;
 
178
  } else if(percentageR > 99.5) {
 
179
    int_perc = 100;
 
180
    percentageR = 100;
 
181
  } else {
 
182
    int_perc = (int) percentageR + 0.5;
 
183
  }
 
184
 
 
185
  switch(int_perc) {
 
186
  case 0:
 
187
    if(snprintf(buf, bufLen, "<TD WIDTH=100 "TD_BG" ALIGN=RIGHT>%s</TD>"
 
188
                "<TD WIDTH=100 "TD_BG">&nbsp;</TD></TR>\n",
 
189
                formatKBytes(totalR, formatBuf, sizeof(formatBuf))) < 0)
 
190
      BufferTooShort();
 
191
    break;
 
192
  case 100:
 
193
    if(snprintf(buf, bufLen, "<TD WIDTH=100 "TD_BG" ALIGN=RIGHT>%s</TD>"
 
194
                "<TD WIDTH=100><IMG ALIGN=MIDDLE ALT=\"100\" SRC=\"/gauge.jpg\" WIDTH=\"100\" HEIGHT=12></TD></TR>\n",
 
195
                formatKBytes(totalR, formatBuf, sizeof(formatBuf))) < 0) BufferTooShort();
 
196
    break;
 
197
  default:
 
198
    if(snprintf(buf, bufLen, "<TD WIDTH=100 "TD_BG" ALIGN=RIGHT>%s</TD>"
 
199
                "<TD  WIDTH=100 "TD_BG"><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=\"100\">"
 
200
                "<TR "TR_ON"><TD><IMG ALT=\"%d%%\" ALIGN=MIDDLE SRC=\"/gauge.jpg\" WIDTH=\"%d\" HEIGHT=12>"
 
201
                "</TD><TD "TD_BG" ALIGN=CENTER WIDTH=\"%d\">"
 
202
                "<P>&nbsp;</TD></TR></TABLE></TD></TR>\n",
 
203
                formatKBytes(totalR, formatBuf, sizeof(formatBuf)),
 
204
                int_perc, (100*int_perc)/100, (100*(100-int_perc))/100) < 0)
 
205
      BufferTooShort();
 
206
  }
 
207
 
 
208
  sendString(buf);
 
209
}
 
210
 
 
211
/* ********************************** */
 
212
 
 
213
void printTableEntryPercentage(char *buf, int bufLen,
 
214
                               char *label, char* label_1,
 
215
                               char* label_2, float total,
 
216
                               float percentage) {
 
217
  int int_perc;
 
218
  char formatBuf[32];
 
219
 
 
220
  if(percentage < 0.5)
 
221
    int_perc = 0;
 
222
  else if(percentage > 99.5)
 
223
    int_perc = 100;
 
224
  else
 
225
    int_perc = (int) (percentage + 0.5);
 
226
 
 
227
  switch(int_perc) {
 
228
  case 0:
 
229
    if(total == -1) {
 
230
      if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
231
                  "<TD "TD_BG"><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=\"100%%\">"
 
232
                  "<TR>"
 
233
                  "<TD ALIGN=LEFT WIDTH=\"10%%\" BGCOLOR=\"%s\">%s 0&nbsp;%%</TD>"
 
234
                  "<TD><TABLE BORDER=1 CELLPADDING=1 CELLSPACING=0 WIDTH=\"100%%\"><TR>"
 
235
                  "<TD ALIGN=CENTER WIDTH=\"100%%\" BGCOLOR=\"%s\">&nbsp;</TD>"
 
236
                  "</TR></TABLE></TD>"
 
237
                  "<TD ALIGN=RIGHT WIDTH=\"10%%\" BGCOLOR=\"%s\">%s 100&nbsp;%%</TD></TR></TABLE></TD></TR>\n",
 
238
                  getRowColor(), label,
 
239
                  CONST_COLOR_1, label_1,
 
240
                  CONST_COLOR_2,
 
241
                  CONST_COLOR_2, label_2) < 0)
 
242
        BufferTooShort();
 
243
    } else {
 
244
      if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
245
                  "<TD "TD_BG" ALIGN=RIGHT>%s</TD>"
 
246
                  "<TD "TD_BG"><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=\"100%%\">"
 
247
                  "<TR>"
 
248
                  "<TD ALIGN=LEFT WIDTH=\"10%%\"  BGCOLOR=\"%s\">%s 0&nbsp;%%</TD>"
 
249
                  "<TD><TABLE BORDER=1 CELLPADDING=1 CELLSPACING=0 WIDTH=\"100%%\"><TR>"
 
250
                  "<TD ALIGN=CENTER WIDTH=\"100%%\" BGCOLOR=\"%s\">&nbsp;</TD>"
 
251
                  "</TR></TABLE></TD>"
 
252
                  "<TD ALIGN=RIGHT WIDTH=\"10%%\" BGCOLOR=\"%s\">%s 100&nbsp;%%</TD></TR></TABLE></TD></TR>\n",
 
253
                  getRowColor(), label,
 
254
                  formatKBytes(total, formatBuf, sizeof(formatBuf)),
 
255
                  CONST_COLOR_1, label_1,
 
256
                  CONST_COLOR_2,
 
257
                  CONST_COLOR_1, label_2) < 0)
 
258
        BufferTooShort();
 
259
    }
 
260
    break;
 
261
  case 100:
 
262
    if(total == -1) {
 
263
      if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
264
             "<TD "TD_BG"><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=\"100%%\">"
 
265
             "<TR>"
 
266
             "<TD ALIGN=LEFT WIDTH=\"10%%\" BGCOLOR=\"%s\">%s 100&nbsp;%%</TD>"
 
267
             "<TD><TABLE BORDER=1 CELLPADDING=1 CELLSPACING=0 WIDTH=\"100%%\"><TR>"
 
268
             "<TD ALIGN=CENTER WIDTH=\"100%%\" BGCOLOR=\"%s\">&nbsp;</TD>"
 
269
             "</TR></TABLE></TD>"
 
270
             "<TD ALIGN=RIGHT WIDTH=\"10%%\" BGCOLOR=\"%s\">%s 0&nbsp;%%</TD></TR></TABLE></TD></TR>\n",
 
271
             getRowColor(), label,
 
272
             CONST_COLOR_1, label_1,
 
273
             CONST_COLOR_1,
 
274
             CONST_COLOR_2, label_2) < 0)
 
275
        BufferTooShort();
 
276
    } else {
 
277
      if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
278
                  "<TD "TD_BG" ALIGN=RIGHT>%s</TD>"
 
279
                  "<TD "TD_BG"><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=\"100%%\">"
 
280
                  "<TR>"
 
281
                  "<TD ALIGN=LEFT WIDTH=\"10%%\" BGCOLOR=\"%s\">%s 100&nbsp;%%</TD>"
 
282
                  "<TD><TABLE BORDER=1 CELLPADDING=1 CELLSPACING=0 WIDTH=\"100%%\"><TR>"
 
283
                  "<TD ALIGN=CENTER WIDTH=\"100%%\" BGCOLOR=\"%s\">&nbsp;</TD>"
 
284
                  "</TR></TABLE></TD>"
 
285
                  "<TD ALIGN=RIGHT WIDTH=\"10%%\" BGCOLOR=\"%s\">%s 0&nbsp;%%</TD></TR></TABLE></TD></TR>\n",
 
286
                  getRowColor(), label,
 
287
                  formatKBytes(total, formatBuf, sizeof(formatBuf)),
 
288
                  CONST_COLOR_1, label_1, CONST_COLOR_1,
 
289
                  CONST_COLOR_2, label_2) < 0)
 
290
        BufferTooShort();
 
291
    }
 
292
    break;
 
293
  default:
 
294
    if(total == -1) {
 
295
      if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
296
             "<TD "TD_BG"><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=\"100%%\">"
 
297
             "<TR>"
 
298
             "<TD ALIGN=LEFT WIDTH=\"10%%\" BGCOLOR=\"%s\">%s %.1f&nbsp;%%</TD>"
 
299
             "<TD><TABLE BORDER=1 CELLPADDING=1 CELLSPACING=0 WIDTH=\"100%%\"><TR>"
 
300
             "<TD ALIGN=CENTER WIDTH=\"%d%%\" BGCOLOR=\"%s\">&nbsp;</TD>"
 
301
             "<TD ALIGN=CENTER WIDTH=\"%d%%\" BGCOLOR=\"%s\">&nbsp;</TD>"
 
302
             "</TR></TABLE></TD>"
 
303
             "<TD ALIGN=RIGHT WIDTH=\"10%%\" BGCOLOR=\"%s\">%s %.1f&nbsp;%%</TD></TR></TABLE></TD></TR>\n",
 
304
             getRowColor(), label,
 
305
             CONST_COLOR_1, label_1, percentage,
 
306
             int_perc, CONST_COLOR_1,
 
307
             (100-int_perc), CONST_COLOR_2,
 
308
             CONST_COLOR_2, label_2, (100-percentage)) < 0)
 
309
         BufferTooShort();
 
310
    } else {
 
311
      if(snprintf(buf, bufLen, "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>%s</TD>"
 
312
                  "<TD "TD_BG"><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=\"100%%\">"
 
313
                  "<TR><TD ALIGN=LEFT WIDTH=\"10%%\" BGCOLOR=\"%s\">%s %.1f&nbsp;%%</TD>"
 
314
                  "<TD><TABLE BORDER=1 CELLPADDING=1 CELLSPACING=0 WIDTH=\"100%%\"><TR>"
 
315
                  "<TD ALIGN=CENTER WIDTH=\"%d%%\" BGCOLOR=\"%s\">&nbsp;</TD>"
 
316
                  "<TD ALIGN=CENTER WIDTH=\"%d%%\" BGCOLOR=\"%s\">&nbsp;</TD>"
 
317
                  "</TR></TABLE></TD>"
 
318
                  "<TD ALIGN=RIGHT WIDTH=\"10%%\" BGCOLOR=\"%s\">%s %.1f&nbsp;%%</TD></TR></TABLE></TD></TR>\n",
 
319
                  getRowColor(), label, formatKBytes(total, formatBuf, sizeof(formatBuf)),
 
320
                  CONST_COLOR_1, label_1, percentage,
 
321
                  int_perc, CONST_COLOR_1,
 
322
                  (100-int_perc), CONST_COLOR_2,
 
323
                  CONST_COLOR_2, label_2, (100-percentage)) < 0)
 
324
        BufferTooShort();
 
325
    }
 
326
  }
 
327
 
 
328
  sendString(buf);
 
329
}
 
330
 
 
331
/* ******************************* */
 
332
 
 
333
void printFooterHostLink(void) {
 
334
  ;
 
335
}
 
336
 
 
337
/* ******************************* */
 
338
 
 
339
static void printFooterTrafficPct(void) {
 
340
    char buf[LEN_GENERAL_WORK_BUFFER];
 
341
 
 
342
    if (snprintf(buf, sizeof(buf),
 
343
                 "<P><TABLE BORDER=0 "TABLE_DEFAULTS">"
 
344
                   "<TR>"
 
345
                     "<TD COLSPAN=4>The percentage value is - for a given host - the traffic for that host "
 
346
                     "during that hour divided by the total traffic for that host for the last 24 hours.</TD>"
 
347
                   "</TR>"
 
348
                   "<TR>"
 
349
                     "<TD ALIGN=CENTER NOWRAP "TD_BG" WIDTH=20%%> 0%% </TD>"
 
350
                     "<TD ALIGN=CENTER NOWRAP "CONST_CONST_PCTG_LOW_COLOR" WIDTH=20%%>  0%% to %d%% </TD>"
 
351
                     "<TD ALIGN=CENTER NOWRAP "CONST_CONST_PCTG_MID_COLOR" WIDTH=20%%> %d%% to %d%% </TD>"
 
352
                     "<TD ALIGN=CENTER NOWRAP "CONST_PCTG_HIGH_COLOR" WIDTH=20%%> &gt;%d%% to 100%% </TD>"
 
353
                   "</TR>"
 
354
                 "</TABLE>\n",
 
355
                 CONST_PCTG_LOW, CONST_PCTG_LOW, CONST_PCTG_MID, CONST_PCTG_MID) < 0)
 
356
 
 
357
        BufferTooShort();
 
358
    sendString(buf);
 
359
}
 
360
 
 
361
/* ******************************* */
 
362
 
 
363
void printFooter(int reportType) {
 
364
  switch(reportType) {
 
365
    case TRAFFIC_STATS:
 
366
        break;
 
367
    case SORT_DATA_RECEIVED_PROTOS:
 
368
    case SORT_DATA_SENT_PROTOS:
 
369
    case SORT_DATA_PROTOS:
 
370
    case SORT_DATA_RECEIVED_IP:
 
371
    case SORT_DATA_SENT_IP:
 
372
    case SORT_DATA_IP:
 
373
    case SORT_DATA_RCVD_HOST_TRAFFIC:
 
374
    case SORT_DATA_SENT_HOST_TRAFFIC:
 
375
    case SORT_DATA_RECEIVED_THPT:
 
376
    case SORT_DATA_SENT_THPT:
 
377
    case SORT_DATA_THPT:
 
378
    case SORT_DATA_HOST_TRAFFIC:
 
379
      break;
 
380
  }
 
381
 
 
382
  sendString("<CENTER>\n");
 
383
 
 
384
  switch(reportType) {
 
385
    case TRAFFIC_STATS:
 
386
        break;
 
387
    case SORT_DATA_RECEIVED_PROTOS:
 
388
    case SORT_DATA_RECEIVED_IP:
 
389
    case SORT_DATA_SENT_PROTOS:
 
390
    case SORT_DATA_SENT_IP:
 
391
    case SORT_DATA_PROTOS:
 
392
    case SORT_DATA_IP:
 
393
        printFooterHostLink();
 
394
        break;
 
395
 
 
396
    case SORT_DATA_RCVD_HOST_TRAFFIC:
 
397
    case SORT_DATA_SENT_HOST_TRAFFIC:
 
398
    case SORT_DATA_HOST_TRAFFIC:
 
399
        printFooterHostLink();
 
400
        printFooterTrafficPct();
 
401
        break;
 
402
 
 
403
    case SORT_DATA_RECEIVED_THPT:
 
404
    case SORT_DATA_SENT_THPT:
 
405
    case SORT_DATA_THPT:
 
406
        printFooterHostLink();
 
407
        sendString("<i><P>Peak values are the maximum value for any 10 second interval."
 
408
                   "<br>Average values are recomputed each 60 seconds, using values "
 
409
                   "accumulated since this run of ntop was started.</P>\n");
 
410
        sendString("<P>Note: Both values are reset each time ntop is restarted.</P></i>\n");
 
411
        break;
 
412
  }
 
413
 
 
414
  sendString("</CENTER>\n");
 
415
}
 
416
 
 
417
/* ******************************* */
 
418
 
 
419
void printHeader(int reportType, int revertOrder, u_int column,
 
420
                 HostsDisplayPolicy showHostsMode,
 
421
                 LocalityDisplayPolicy showLocalityMode) {
 
422
  char buf[LEN_GENERAL_WORK_BUFFER];
 
423
  char *sign, *arrowGif, *arrow[128], *theAnchor[128], *url=NULL;
 
424
  int i, soFar=2, idx, j, hourId;
 
425
  char htmlAnchor[128], htmlAnchor1[128], theLink[128];
 
426
  ProtocolsList *protoList;
 
427
  char theDate[8];
 
428
  struct tm t;
 
429
  char hours[][24] = {"12<BR>AM", "1<BR>AM", "2<BR>AM", "3<BR>AM", "4<BR>AM", "5<BR>AM", "6<BR>AM",
 
430
                      "7<BR>AM", "8<BR>AM", "9<BR>AM", "10<BR>AM", "11<BR>AM", "12<BR>PM", "1<BR>PM",
 
431
                      "2<BR>PM", "3<BR>PM", "4<BR>PM", "5<BR>PM", "6<BR>PM", "7<BR>PM", "8<BR>PM",
 
432
                      "9<BR>PM", "10<BR>PM", "11<BR>PM"};
 
433
 
 
434
  /* printf("->%d<-\n",showHostsMode); */
 
435
 
 
436
  strftime(theDate, 8, CONST_TOD_HOUR_TIMESPEC, localtime_r(&myGlobals.actTime, &t));
 
437
  hourId = atoi(theDate);
 
438
  
 
439
  memset(arrow, 0, sizeof(arrow));
 
440
  memset(theAnchor, 0, sizeof(theAnchor));
 
441
  memset(htmlAnchor, 0, sizeof(htmlAnchor));
 
442
  memset(htmlAnchor1, 0, sizeof(htmlAnchor1));
 
443
 
 
444
  if(revertOrder) {
 
445
    sign = "";
 
446
    arrowGif = "&nbsp;" CONST_IMG_ARROW_UP;
 
447
  } else {
 
448
    sign = "-";
 
449
    arrowGif = "&nbsp;" CONST_IMG_ARROW_DOWN;
 
450
  }
 
451
 
 
452
  memset(buf, 0, sizeof(buf));
 
453
 
 
454
  switch(reportType) {
 
455
  case TRAFFIC_STATS:               url = CONST_TRAFFIC_STATS_HTML;               break;
 
456
  case SORT_DATA_PROTOS:            url = CONST_SORT_DATA_PROTOS_HTML;            break;
 
457
  case SORT_DATA_IP:                url = CONST_SORT_DATA_IP_HTML;                break;
 
458
  case SORT_DATA_THPT:              url = CONST_SORT_DATA_THPT_HTML;              break;
 
459
  case SORT_DATA_HOST_TRAFFIC:      url = CONST_SORT_DATA_HOST_TRAFFIC_HTML;      break;
 
460
  }
 
461
 
 
462
  if(snprintf(htmlAnchor, sizeof(htmlAnchor),
 
463
              "<A HREF=\"/%s?showH=%d&amp;showL=%d&amp;col=%s",
 
464
              url, showHostsMode, showLocalityMode, sign) < 0)
 
465
    BufferTooShort();
 
466
  if(snprintf(htmlAnchor1, sizeof(htmlAnchor1),
 
467
              "<A HREF=\"/%s?showH=%d&amp;showL=%d&amp;col=",
 
468
              url, showHostsMode, showLocalityMode) < 0)
 
469
    BufferTooShort();
 
470
 
 
471
  if(abs(column) == FLAG_HOST_DUMMY_IDX) {
 
472
    arrow[0] = arrowGif; theAnchor[0] = htmlAnchor;
 
473
  } else {
 
474
    arrow[0] = ""; theAnchor[0] = htmlAnchor1;
 
475
  }
 
476
 
 
477
  if(abs(column) == FLAG_DOMAIN_DUMMY_IDX) {
 
478
    arrow[1] = arrowGif; theAnchor[1] = htmlAnchor;
 
479
  } else {
 
480
    arrow[1] = "";  theAnchor[1] = htmlAnchor1;
 
481
  }
 
482
 
 
483
  if(abs(column) == 0) {
 
484
    arrow[2] = arrowGif; theAnchor[2] = htmlAnchor;
 
485
  } else {
 
486
    arrow[2] = ""; theAnchor[2] = htmlAnchor1;
 
487
  }
 
488
 
 
489
  if(snprintf(theLink, sizeof(theLink), "/%s?col=%s%d&amp;showL=%d&amp;showH=", url,
 
490
           revertOrder ? "-" : "", column, showLocalityMode) < 0)
 
491
    BufferTooShort();
 
492
 
 
493
  sendString("<CENTER><TABLE WIDTH=100%% BORDER=0 "TABLE_DEFAULTS"><TR><TD ALIGN=LEFT>");
 
494
 
 
495
  switch(showHostsMode) {
 
496
  case showOnlyLocalHosts:
 
497
    if(snprintf(buf, sizeof(buf), 
 
498
              "<b>Hosts:</b> [ <A HREF=\"%s0\">All</A> ]&nbsp;"
 
499
              "[<B> Local Only </B>]&nbsp;"
 
500
              "[ <A HREF=\"%s2\">Remote Only</A> ]&nbsp;</TD>",
 
501
              theLink, theLink) < 0)
 
502
      BufferTooShort();
 
503
    break;
 
504
  case showOnlyRemoteHosts:
 
505
    if(snprintf(buf, sizeof(buf), 
 
506
             "<b>Hosts:</b> [ <A HREF=\"%s0\">All</A> ]&nbsp;"
 
507
             "[ <A HREF=\"%s1\">Local Only</A> ]&nbsp;"
 
508
             "[<B> Remote Only </B>]&nbsp;</TD>",
 
509
             theLink, theLink) < 0)
 
510
      BufferTooShort();
 
511
    break;
 
512
  default:
 
513
    if(snprintf(buf, sizeof(buf), 
 
514
             "<b>Hosts:</b> [<B> All </B>]&nbsp;"
 
515
             "[ <A HREF=\"%s1\">Local Only</A> ]&nbsp;"
 
516
             "[ <A HREF=\"%s2\">Remote Only</A> ]&nbsp;</TD>",
 
517
             theLink, theLink) < 0)
 
518
      BufferTooShort();
 
519
    break;
 
520
  }
 
521
  sendString(buf);
 
522
 
 
523
  if(reportType != TRAFFIC_STATS) {
 
524
    switch(showLocalityMode) {
 
525
    case showSentReceived:
 
526
      if(snprintf(buf, sizeof(buf), "<TD ALIGN=right>"
 
527
             "<b>Data:</b> [<b> All </b>]&nbsp;"
 
528
             "[ <a href=\"%s?col=%s%d&showH=%d&showL=1\">Sent Only</a> ]&nbsp;"
 
529
             "[ <a href=\"%s?col=%s%d&showH=%d&showL=2\">Received Only</a> ]&nbsp;",
 
530
             url, revertOrder ? "-" : "", column, showHostsMode,
 
531
             url, revertOrder ? "-" : "", column, showHostsMode) < 0)
 
532
        BufferTooShort();
 
533
      break;
 
534
    case showOnlySent:
 
535
      if(snprintf(buf, sizeof(buf), "<TD ALIGN=right>"
 
536
             "<b>Data:</b> [ <a href=\"%s?col=%s%d&showH=%d&showL=0\">All</a> ]&nbsp;"
 
537
             "[<b> Sent Only </b>]&nbsp;"
 
538
             "[ <a href=\"%s?col=%s%d&showH=%d&showL=2\">Received Only</a> ]&nbsp;",
 
539
             url, revertOrder ? "-" : "", column, showHostsMode,
 
540
             url, revertOrder ? "-" : "", column, showHostsMode) < 0)
 
541
        BufferTooShort();
 
542
      break;
 
543
    default:
 
544
      if(snprintf(buf, sizeof(buf), "<TD ALIGN=right>"
 
545
             "<b>Data:</b> [ <a href=\"%s?col=%s%d&showH=%d&showL=0\">All</a> ]&nbsp;"
 
546
             "[ <a href=\"%s?col=%s%d&showH=%d&showL=1\">Sent Only</a> ]&nbsp;"
 
547
             "[<b> Received Only </b>]&nbsp;",
 
548
             url, revertOrder ? "-" : "", column, showHostsMode,
 
549
             url, revertOrder ? "-" : "", column, showHostsMode) < 0)
 
550
        BufferTooShort();
 
551
      break;
 
552
    }
 
553
    sendString(buf);
 
554
    sendString("</TD></TR></TABLE></CENTER><p>");
 
555
  }
 
556
 
 
557
  switch(reportType) {
 
558
  case SORT_DATA_RECEIVED_PROTOS:
 
559
  case SORT_DATA_SENT_PROTOS:
 
560
  case SORT_DATA_PROTOS:
 
561
    sendString("<CENTER>\n");
 
562
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS"><TR "TR_ON" "DARK_BG">"
 
563
                "<TH "TH_BG">%s"FLAG_HOST_DUMMY_IDX_STR"\">Host%s</A></TH>\n"
 
564
                "<TH "TH_BG">%s"FLAG_DOMAIN_DUMMY_IDX_STR"\">Domain%s</A></TH>"
 
565
                "<TH "TH_BG" COLSPAN=2>%s0\">Data%s</A></TH>\n",
 
566
                theAnchor[0], arrow[0], theAnchor[1], arrow[1],
 
567
                theAnchor[2], arrow[2]) < 0)
 
568
      BufferTooShort();
 
569
    sendString(buf);
 
570
 
 
571
    for(i=0; i<=15; i++)
 
572
      if(abs(column) == i+1)  { arrow[i] = arrowGif; theAnchor[i] = htmlAnchor; } else { arrow[i] = ""; theAnchor[i] = htmlAnchor1;  }
 
573
 
 
574
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, "<TH "TH_BG">%s1\">TCP%s</A></TH>"
 
575
                "<TH "TH_BG">%s2\">UDP%s</A></TH><TH "TH_BG">%s3\">ICMP%s</A></TH>""<TH "TH_BG">%s4\">ICMPv6%s</A></TH>"
 
576
                "<TH "TH_BG">%s5\">DLC%s</A></TH><TH "TH_BG">%s6\">IPX%s</A>"
 
577
                "</TH><TH "TH_BG">%s7\">Decnet%s</A></TH>"
 
578
                "<TH "TH_BG">%s8\">(R)ARP%s</A></TH><TH "TH_BG">%s9\">AppleTalk%s</A></TH>",
 
579
                theAnchor[0], arrow[0], theAnchor[1], arrow[1],
 
580
                theAnchor[2], arrow[2], theAnchor[3], arrow[3],
 
581
                theAnchor[4], arrow[4],
 
582
                theAnchor[5], arrow[5], theAnchor[6], arrow[6],
 
583
                theAnchor[7], arrow[7], theAnchor[8], arrow[8]) < 0)
 
584
      BufferTooShort();
 
585
    sendString(buf);
 
586
 
 
587
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER,
 
588
                "<TH "TH_BG">%s11\">NetBios%s</A></TH>"
 
589
                "<TH "TH_BG">%s13\">OSI%s</A></TH>"
 
590
                "<TH "TH_BG">%s14\">IPv6%s</A></TH>"
 
591
                "<TH "TH_BG">%s15\">STP%s</A></TH>",
 
592
                theAnchor[10], arrow[10],
 
593
                theAnchor[12], arrow[12],
 
594
                theAnchor[13], arrow[13],
 
595
                theAnchor[14], arrow[14]) < 0)
 
596
      BufferTooShort();
 
597
    sendString(buf);
 
598
 
 
599
    protoList = myGlobals.ipProtosList, idx=0;
 
600
    while(protoList != NULL) {
 
601
 
 
602
      if(abs(column) == BASE_PROTOS_IDX+idx) {
 
603
        arrow[BASE_PROTOS_IDX+idx] = arrowGif;
 
604
        theAnchor[BASE_PROTOS_IDX+idx] = htmlAnchor;
 
605
      } else {
 
606
        arrow[BASE_PROTOS_IDX+idx] = "";
 
607
        theAnchor[BASE_PROTOS_IDX+idx] = htmlAnchor1;
 
608
      }
 
609
 
 
610
      if(snprintf(buf, sizeof(buf), "<TH "TH_BG">%s%d\">%s%s</A></TH>",
 
611
                  theAnchor[BASE_PROTOS_IDX+idx], BASE_PROTOS_IDX+idx,
 
612
                  protoList->protocolName, arrow[BASE_PROTOS_IDX+idx]) < 0)
 
613
        BufferTooShort();
 
614
      sendString(buf);
 
615
 
 
616
      idx++, protoList = protoList->next;
 
617
    }
 
618
 
 
619
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER,
 
620
                "<TH "TH_BG">%s16\">Other%s</A></TH>",
 
621
                theAnchor[15], arrow[15]) < 0)
 
622
      BufferTooShort();
 
623
    sendString(buf);
 
624
    break;
 
625
 
 
626
  case SORT_DATA_RECEIVED_IP:
 
627
  case SORT_DATA_SENT_IP:
 
628
  case SORT_DATA_IP:
 
629
    sendString("<CENTER>\n");
 
630
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS"><TR "TR_ON" "DARK_BG">"
 
631
                "<TH "TH_BG">%s"FLAG_HOST_DUMMY_IDX_STR"\">Host%s</A></TH>\n"
 
632
                "<TH "TH_BG">%s"FLAG_DOMAIN_DUMMY_IDX_STR"\">Domain%s</A></TH>"
 
633
                "<TH "TH_BG" COLSPAN=2>%s0\">Data%s</A></TH>\n",
 
634
                theAnchor[0], arrow[0], theAnchor[1], arrow[1],
 
635
                theAnchor[2], arrow[2]) < 0)
 
636
      BufferTooShort();
 
637
    sendString(buf);
 
638
    if(abs(column) == 1) {
 
639
      arrow[0] = arrowGif;
 
640
      theAnchor[0] = htmlAnchor;
 
641
    } else {
 
642
      arrow[0] = "";
 
643
      theAnchor[0] = htmlAnchor1;
 
644
    }
 
645
 
 
646
    for(i=0; i<myGlobals.numIpProtosToMonitor; i++) {
 
647
      if(abs(column) == soFar) {
 
648
        arrow[0] = arrowGif;
 
649
        theAnchor[0] = htmlAnchor;
 
650
      } else {
 
651
        arrow[0] = "";
 
652
        theAnchor[0] = htmlAnchor1;
 
653
      }
 
654
      if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, "<TH "TH_BG">%s%d\">%s%s</A></TH>",
 
655
                  theAnchor[0], i+2, myGlobals.protoIPTrafficInfos[i], arrow[0]) < 0)
 
656
        BufferTooShort();
 
657
      sendString(buf);
 
658
      soFar++;
 
659
    }
 
660
 
 
661
    if(abs(column) == soFar) {
 
662
      arrow[0] = arrowGif; theAnchor[0] = htmlAnchor;
 
663
    } else {
 
664
      arrow[0] = "";  theAnchor[0] = htmlAnchor1;
 
665
    }
 
666
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, "<TH "TH_BG">%s%d\">Other&nbsp;IP%s</A></TH>",
 
667
                theAnchor[0], i+2, arrow[0]) < 0)
 
668
      BufferTooShort();
 
669
    sendString(buf);
 
670
    break;
 
671
 
 
672
  case SORT_DATA_RCVD_HOST_TRAFFIC:
 
673
  case SORT_DATA_SENT_HOST_TRAFFIC:
 
674
  case SORT_DATA_HOST_TRAFFIC:
 
675
    sendString("<CENTER>\n");
 
676
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS"><TR "DARK_BG">"
 
677
                "<TH "TH_BG">%s"FLAG_HOST_DUMMY_IDX_STR"\">Host%s</A></TH>"
 
678
                "<TH "TH_BG">%s"FLAG_DOMAIN_DUMMY_IDX_STR"\">Domain%s</A></TH>\n",
 
679
                theAnchor[0], arrow[0], theAnchor[1], arrow[1]) < 0)
 
680
      BufferTooShort();
 
681
    sendString(buf);
 
682
    j = hourId;
 
683
    for (i = 0; i < 24; i++) {
 
684
        j = j % 24;
 
685
        if (snprintf (buf, sizeof(buf), "<TH "TH_BG">%s</TH>\n", hours[j]) < 0)
 
686
            BufferTooShort();
 
687
        sendString (buf);
 
688
        if (!j) {
 
689
            j = 23;
 
690
        }
 
691
        else {
 
692
            j--;
 
693
        }
 
694
    }
 
695
    break;
 
696
  case SORT_DATA_RECEIVED_THPT:
 
697
  case SORT_DATA_SENT_THPT:
 
698
  case SORT_DATA_THPT:
 
699
    sendString("<CENTER>\n");
 
700
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS"><TR "TR_ON" "DARK_BG">"
 
701
                "<TH "TH_BG" ROWSPAN=\"2\">%s"FLAG_HOST_DUMMY_IDX_STR"\">Host%s</A></TH>"
 
702
                "<TH "TH_BG" ROWSPAN=\"2\">%s"FLAG_DOMAIN_DUMMY_IDX_STR"\">Domain%s</A></TH>\n\n",
 
703
                theAnchor[0], arrow[0], theAnchor[1], arrow[1]) < 0)
 
704
      BufferTooShort();
 
705
    sendString(buf);
 
706
 
 
707
    updateThpt(0);
 
708
    if(abs(column) == 1) { arrow[0] = arrowGif; theAnchor[0] = htmlAnchor; }
 
709
    else { arrow[0] = ""; theAnchor[0] = htmlAnchor1;  }
 
710
    if(abs(column) == 2) { arrow[1] = arrowGif; theAnchor[1] = htmlAnchor; }
 
711
    else { arrow[1] = ""; theAnchor[1] = htmlAnchor1; }
 
712
    if(abs(column) == 3) { arrow[2] = arrowGif; theAnchor[2] = htmlAnchor; }
 
713
    else { arrow[2] = "";  theAnchor[2] = htmlAnchor1;}
 
714
    if(abs(column) == 4) { arrow[3] = arrowGif; theAnchor[3] = htmlAnchor; }
 
715
    else { arrow[3] = "";  theAnchor[3] = htmlAnchor1;}
 
716
    if(abs(column) == 5) { arrow[4] = arrowGif; theAnchor[4] = htmlAnchor; }
 
717
    else { arrow[4] = "";  theAnchor[4] = htmlAnchor1;}
 
718
    if(abs(column) == 6) { arrow[5] = arrowGif; theAnchor[5] = htmlAnchor; }
 
719
    else { arrow[5] = "";  theAnchor[5] = htmlAnchor1;}
 
720
 
 
721
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, "<TH "TH_BG" COLSPAN=\"3\" ALIGN=CENTER>Data</TH>"
 
722
                "<TH "TH_BG" COLSPAN=\"3\" ALIGN=CENTER>Packets</TH>"
 
723
                "</TR><TR "TR_ON" "DARK_BG">") < 0)
 
724
      BufferTooShort();
 
725
    sendString(buf);
 
726
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, "<TH "TH_BG">%s1\">Current%s</A></TH>"
 
727
                "<TH "TH_BG">%s2\">Avg%s</A></TH>"
 
728
                "<TH "TH_BG">%s3\">Peak%s</A></TH>"
 
729
                "<TH "TH_BG">%s4\">Current%s</A></TH><TH "TH_BG">%s5\">Avg%s</A></TH>"
 
730
                "<TH "TH_BG">%s6\">Peak%s</A></TH>",
 
731
                theAnchor[0], arrow[0], theAnchor[1], arrow[1], theAnchor[2], arrow[2],
 
732
                theAnchor[3], arrow[3], theAnchor[4], arrow[4], theAnchor[5], arrow[5]) < 0)
 
733
      BufferTooShort();
 
734
    sendString(buf);
 
735
    break;
 
736
  case TRAFFIC_STATS:
 
737
    sendString("<CENTER>\n");
 
738
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS"><TR "TR_ON" "DARK_BG">"
 
739
                "<TH "TH_BG">%s"FLAG_HOST_DUMMY_IDX_STR"\">Host%s</A></TH>"
 
740
                "<TH "TH_BG">%s"FLAG_DOMAIN_DUMMY_IDX_STR"\">Domain%s</A></TH>\n\n",
 
741
                theAnchor[0], arrow[0], theAnchor[1], arrow[1]) < 0)
 
742
      BufferTooShort();
 
743
    sendString(buf);
 
744
    break;
 
745
  }
 
746
 
 
747
  sendString("</TR>\n");
 
748
}
 
749
 
 
750
/* ******************************* */
 
751
 
 
752
char* getOSFlag(HostTraffic *el, char *elOsName, int showOsName, char *tmpStr, int tmpStrLen) {
 
753
  /* Lengthen tmpString buffer - to handle long name given by nmap for Win2k
 
754
     Courtesy of Marcel Hauser <marcel_hauser@gmx.ch> */
 
755
  char *flagImg = "";
 
756
  char *theOsName;
 
757
  int i;
 
758
 
 
759
  if((el == NULL) && (elOsName == NULL)) return("");
 
760
 
 
761
  tmpStr[0] = '\0';
 
762
 
 
763
  if(elOsName != NULL)
 
764
    theOsName = elOsName;
 
765
  else {
 
766
    if(el->fingerprint == NULL)   return("");
 
767
    if(el->fingerprint[0] != ':') setHostFingerprint(el);
 
768
    if(el->fingerprint[0] != ':') return("");
 
769
    theOsName = &el->fingerprint[1];
 
770
  }
 
771
 
 
772
  if(theOsName[0] == '\0') return("");
 
773
 
 
774
  flagImg = NULL;
 
775
 
 
776
  for(i=0; osInfos[i].link != NULL; i++) {
 
777
    if(strstr(theOsName, osInfos[i].name) != NULL) {
 
778
      flagImg = osInfos[i].link;
 
779
      break;
 
780
    }
 
781
  }
 
782
 
 
783
  if(!showOsName) {
 
784
    if(flagImg != NULL)
 
785
      if(snprintf(tmpStr, tmpStrLen, "%s", flagImg) < 0)
 
786
        BufferTooShort();
 
787
    else
 
788
      tmpStr[0] = '\0';
 
789
  } else {
 
790
    if(flagImg != NULL) {
 
791
      if(snprintf(tmpStr, tmpStrLen, "%s&nbsp;[%s]", flagImg, theOsName) < 0)
 
792
        BufferTooShort();
 
793
    } else {
 
794
      if(snprintf(tmpStr, tmpStrLen, "%s", theOsName) < 0)
 
795
        BufferTooShort();
 
796
    }
 
797
  }
 
798
 
 
799
  return(tmpStr);
 
800
}
 
801
 
 
802
/* ******************************* */
 
803
 
 
804
int sortHostFctn(const void *_a, const void *_b) {
 
805
  HostTraffic **a = (HostTraffic **)_a;
 
806
  HostTraffic **b = (HostTraffic **)_b;
 
807
  int rc, n_a, n_b;
 
808
  char *nameA, *nameB, nameA_str[32], nameB_str[32];
 
809
 
 
810
  if((a == NULL) && (b != NULL)) {
 
811
    traceEvent(CONST_TRACE_WARNING, "sortHostFctn() error (1)");
 
812
    return(1);
 
813
  } else if((a != NULL) && (b == NULL)) {
 
814
    traceEvent(CONST_TRACE_WARNING, "sortHostFctn() error (2)");
 
815
    return(-1);
 
816
  } else if((a == NULL) && (b == NULL)) {
 
817
    traceEvent(CONST_TRACE_WARNING, "sortHostFctn() error (3)");
 
818
    return(0);
 
819
  }
 
820
 
 
821
  switch(myGlobals.columnSort) {
 
822
  case 1:
 
823
    rc=cmpFctnResolvedName(a, b);
 
824
    return(rc);
 
825
    break;
 
826
  case 2:
 
827
      if (isFcHost ((*a)) && isFcHost ((*b))) {
 
828
          if((*a)->hostFcAddress.domain > (*b)->hostFcAddress.domain)
 
829
              return(1);
 
830
          else if ((*a)->hostFcAddress.domain < (*b)->hostFcAddress.domain)
 
831
              return (-1);
 
832
          else {
 
833
              if ((*a)->hostFcAddress.area > (*b)->hostFcAddress.area)
 
834
                  return (1);
 
835
              else if ((*a)->hostFcAddress.area < (*b)->hostFcAddress.area)
 
836
                  return (-1);
 
837
              else {
 
838
                  if ((*a)->hostFcAddress.port > (*b)->hostFcAddress.port)
 
839
                      return (1);
 
840
                  else if ((*a)->hostFcAddress.port < (*b)->hostFcAddress.port)
 
841
                      return (-1);
 
842
                  else
 
843
                      return (0);
 
844
              }
 
845
          }
 
846
      }
 
847
      else {
 
848
          rc = addrcmp(&(*a)->hostIpAddress,&(*b)->hostIpAddress);
 
849
          return(rc);
 
850
      }
 
851
    break;
 
852
  case 3:
 
853
      if (isFcHost ((*a)) && isFcHost ((*b))) {
 
854
          n_a = (*a)->vsanId, n_b = (*b)->vsanId;
 
855
          return ((n_a < n_b) ? -1 : (n_a > n_b) ? 1 : 0);
 
856
      }
 
857
      else {
 
858
          return(strcasecmp((*a)->ethAddressString, (*b)->ethAddressString));
 
859
      }
 
860
  case 5:
 
861
      if (isFcHost ((*a)) && isFcHost ((*b))) {
 
862
          return(strcasecmp(getVendorInfo(&((*a)->pWWN.str[2]), 0),
 
863
                            getVendorInfo(&((*b)->pWWN.str[2]), 0)));
 
864
      }
 
865
      else {
 
866
          return(strcasecmp(getVendorInfo((*a)->ethAddress, 0),
 
867
                            getVendorInfo((*b)->ethAddress, 0)));
 
868
      }
 
869
      break;
 
870
  case 6:
 
871
    if((*a)->nonIPTraffic == NULL) {
 
872
      nameA = "";
 
873
    } else {
 
874
    if((*a)->nonIPTraffic->nbHostName != NULL)
 
875
      nameA = (*a)->nonIPTraffic->nbHostName;
 
876
    else if((*a)->nonIPTraffic->atNodeName != NULL)
 
877
      nameA = (*a)->nonIPTraffic->atNodeName;
 
878
    else if((*a)->nonIPTraffic->atNetwork != 0) {
 
879
      if(snprintf(nameA_str, sizeof(nameA_str), "%d.%d",
 
880
                  (*a)->nonIPTraffic->atNetwork, (*a)->nonIPTraffic->atNode) < 0)
 
881
        BufferTooShort();
 
882
      nameA = nameA_str;
 
883
    } else if((*a)->nonIPTraffic->ipxHostName != NULL)
 
884
      nameA = (*a)->nonIPTraffic->ipxHostName;
 
885
    else
 
886
      nameA = "";
 
887
    }
 
888
 
 
889
    if((*b)->nonIPTraffic == NULL) {
 
890
      nameB = "";
 
891
    } else {
 
892
    if((*b)->nonIPTraffic->nbHostName != NULL)
 
893
      nameB = (*b)->nonIPTraffic->nbHostName;
 
894
    else if((*b)->nonIPTraffic->atNodeName != NULL)
 
895
      nameB = (*b)->nonIPTraffic->atNodeName;
 
896
    else if((*b)->nonIPTraffic->atNetwork != 0) {
 
897
      if(snprintf(nameB_str, sizeof(nameB_str), "%d.%d",
 
898
                  (*b)->nonIPTraffic->atNetwork, (*b)->nonIPTraffic->atNode) < 0)
 
899
        BufferTooShort();
 
900
      nameB = nameB_str;
 
901
    } else if((*b)->nonIPTraffic->ipxHostName != NULL)
 
902
      nameB = (*b)->nonIPTraffic->ipxHostName;
 
903
    else
 
904
      nameB = "";
 
905
    }
 
906
 
 
907
    return(strcasecmp(nameA, nameB));
 
908
    break;
 
909
  case 7:
 
910
    n_a = guessHops(*a);
 
911
    n_b = guessHops(*b);
 
912
 
 
913
    if(n_a < n_b)
 
914
      return(1);
 
915
    else if(n_a > n_b)
 
916
      return(-1);
 
917
    else
 
918
      return(0);
 
919
    break;
 
920
  case 8:
 
921
    n_a = (*a)->totContactedSentPeers+(*a)->totContactedRcvdPeers;
 
922
    n_b = (*b)->totContactedSentPeers+(*b)->totContactedRcvdPeers;
 
923
 
 
924
    if(n_a < n_b)
 
925
      return(1);
 
926
    else if(n_a > n_b)
 
927
      return(-1);
 
928
    else
 
929
      return(0);
 
930
    break;
 
931
  case 9:
 
932
    n_a = (*a)->lastSeen-(*a)->firstSeen;
 
933
    n_b = (*b)->lastSeen-(*b)->firstSeen;
 
934
 
 
935
    if(n_a < n_b)
 
936
      return(1);
 
937
    else if(n_a > n_b)
 
938
      return(-1);
 
939
    else
 
940
      return(0);
 
941
    break;
 
942
  case 10:
 
943
    n_a = (*a)->hostAS, n_b = (*b)->hostAS;
 
944
 
 
945
    if(n_a < n_b)
 
946
      return(1);
 
947
    else if(n_a > n_b)
 
948
      return(-1);
 
949
    else
 
950
      return(0);
 
951
    break;
 
952
  case 11:
 
953
    n_a = (*a)->vlanId, n_b = (*b)->vlanId;
 
954
 
 
955
    if(n_a < n_b)
 
956
      return(1);
 
957
    else if(n_a > n_b)
 
958
      return(-1);
 
959
    else
 
960
      return(0);
 
961
    break;
 
962
  case FLAG_DOMAIN_DUMMY_IDX:
 
963
    rc=cmpFctnLocationName(a, b);
 
964
    return(rc);
 
965
    break;
 
966
  case 4:
 
967
  default:
 
968
    if((*a)->actBandwidthUsage < (*b)->actBandwidthUsage)
 
969
      return(1);
 
970
    else if ((*a)->actBandwidthUsage > (*b)->actBandwidthUsage)
 
971
      return(-1);
 
972
    else
 
973
      return(0);
 
974
    break;
 
975
  }
 
976
}
 
977
 
 
978
/* ******************************* */
 
979
 
 
980
int cmpUsersTraffic(const void *_a, const void *_b) {
 
981
  UsersTraffic **a = (UsersTraffic **)_a;
 
982
  UsersTraffic **b = (UsersTraffic **)_b;
 
983
  Counter sum_a, sum_b;
 
984
 
 
985
  if((a == NULL) && (b != NULL)) {
 
986
    return(1);
 
987
  } else if((a != NULL) && (b == NULL)) {
 
988
    return(-1);
 
989
  } else if((a == NULL) && (b == NULL)) {
 
990
    return(0);
 
991
  }
 
992
 
 
993
  sum_a = (*a)->bytesSent + (*a)->bytesRcvd;
 
994
  sum_b = (*b)->bytesSent + (*b)->bytesRcvd;
 
995
 
 
996
  if(sum_a > sum_b)
 
997
    return(-1);
 
998
  else if (sum_a == sum_b)
 
999
    return(0);
 
1000
  else
 
1001
    return(1);
 
1002
}
 
1003
 
 
1004
/* ******************************* */
 
1005
 
 
1006
int cmpProcesses(const void *_a, const void *_b) {
 
1007
  ProcessInfo **a = (ProcessInfo **)_a;
 
1008
  ProcessInfo **b = (ProcessInfo **)_b;
 
1009
 
 
1010
  if((a == NULL) && (b != NULL)) {
 
1011
    return(1);
 
1012
  } else if((a != NULL) && (b == NULL)) {
 
1013
    return(-1);
 
1014
  } else if((a == NULL) && (b == NULL)) {
 
1015
    return(0);
 
1016
  }
 
1017
 
 
1018
  switch(myGlobals.columnSort) {
 
1019
  case 2: /* PID */
 
1020
    if((*a)->pid == (*b)->pid)
 
1021
      return(0);
 
1022
    else if((*a)->pid < (*b)->pid)
 
1023
      return(1);
 
1024
    else return(-1);
 
1025
    break;
 
1026
  case 3: /* User */
 
1027
    return(strcasecmp((*a)->user, (*b)->user));
 
1028
    break;
 
1029
  case 4: /* Sent */
 
1030
    if((*a)->bytesSent.value == (*b)->bytesSent.value)
 
1031
      return(0);
 
1032
    else if((*a)->bytesSent.value < (*b)->bytesSent.value)
 
1033
      return(1);
 
1034
    else return(-1);
 
1035
    break;
 
1036
  case 5: /* Rcvd */
 
1037
    if((*a)->bytesRcvd.value == (*b)->bytesRcvd.value)
 
1038
      return(0);
 
1039
    else if((*a)->bytesRcvd.value < (*b)->bytesRcvd.value)
 
1040
      return(1);
 
1041
    else return(-1);
 
1042
    break;
 
1043
  default: /* Process name */
 
1044
    return(strcasecmp((*a)->command, (*b)->command));
 
1045
  }
 
1046
}
 
1047
 
 
1048
/* ******************************* */
 
1049
 
 
1050
static int cmpOSFctn(const void *_a, const void *_b) {
 
1051
  OsNumInfo *a = (OsNumInfo *)_a;
 
1052
  OsNumInfo *b = (OsNumInfo *)_b;
 
1053
 
 
1054
  if(a->num < b->num)
 
1055
    return(1);
 
1056
  else
 
1057
    return(-1);
 
1058
}
 
1059
 
 
1060
/* ******************************* */
 
1061
 
 
1062
int cmpFctn(const void *_a, const void *_b) {
 
1063
  HostTraffic **a = (HostTraffic **)_a;
 
1064
  HostTraffic **b = (HostTraffic **)_b;
 
1065
  Counter a_=0, b_=0, a_val, b_val;
 
1066
  float fa_=0, fb_=0;
 
1067
  short floatCompare=0, columnProtoId;
 
1068
 
 
1069
  if((a == NULL) && (b != NULL)) {
 
1070
    traceEvent(CONST_TRACE_WARNING, "cmpFctn() error (1)");
 
1071
    return(1);
 
1072
  } else if((a != NULL) && (b == NULL)) {
 
1073
    traceEvent(CONST_TRACE_WARNING, "cmpFctn() error (2)");
 
1074
    return(-1);
 
1075
  } else if((a == NULL) && (b == NULL)) {
 
1076
    traceEvent(CONST_TRACE_WARNING, "cmpFctn() error (3)");
 
1077
    return(0);
 
1078
  }
 
1079
  if((*a == NULL) && (*b != NULL)) {
 
1080
    traceEvent(CONST_TRACE_WARNING, "cmpFctn() error (4)");
 
1081
    return(1);
 
1082
  } else if((*a != NULL) && (*b == NULL)) {
 
1083
    traceEvent(CONST_TRACE_WARNING, "cmpFctn() error (5)");
 
1084
    return(-1);
 
1085
  } else if((*a == NULL) && (*b == NULL)) {
 
1086
    traceEvent(CONST_TRACE_WARNING, "cmpFctn() error (6)");
 
1087
    return(0);
 
1088
  }
 
1089
 
 
1090
  if(myGlobals.columnSort == FLAG_HOST_DUMMY_IDX) {
 
1091
    return(cmpFctnResolvedName(a, b));
 
1092
  } else if(myGlobals.columnSort == FLAG_DOMAIN_DUMMY_IDX) {
 
1093
    int rc;
 
1094
 
 
1095
    fillDomainName(*a); fillDomainName(*b);
 
1096
 
 
1097
#ifdef DEBUG
 
1098
    traceEvent(CONST_TRACE_INFO, "%s='%s'/'%s' - %s='%s'/'%s'",
 
1099
           (*a)->hostResolvedName,
 
1100
           (*a)->ip2ccValue, (*a)->dnsDomainValue,
 
1101
           (*b)->hostResolvedName,
 
1102
           (*b)->ip2ccValue, (*b)->dnsDomainValue
 
1103
           );
 
1104
#endif
 
1105
 
 
1106
    rc=cmpFctnLocationName(a, b);
 
1107
    return(rc);
 
1108
  }
 
1109
 
 
1110
#ifdef DEBUG
 
1111
  traceEvent(CONST_TRACE_INFO,
 
1112
             "reportKind=%d/columnSort=%d/numIpProtosToMonitor=%d\n",
 
1113
             myGlobals.reportKind, myGlobals.columnSort,
 
1114
             myGlobals.numIpProtosToMonitor);
 
1115
#endif
 
1116
 
 
1117
  switch(myGlobals.reportKind) {
 
1118
  case SORT_DATA_RECEIVED_PROTOS:
 
1119
    switch(myGlobals.columnSort) {
 
1120
    case 0:
 
1121
      a_ = (*a)->bytesRcvd.value, b_ = (*b)->bytesRcvd.value;
 
1122
      break;
 
1123
    case 1:
 
1124
      a_ = (*a)->tcpRcvdLoc.value + (*a)->tcpRcvdFromRem.value;
 
1125
      b_ = (*b)->tcpRcvdLoc.value + (*b)->tcpRcvdFromRem.value;
 
1126
      break;
 
1127
    case 2:
 
1128
      a_ = (*a)->udpRcvdLoc.value + (*a)->udpRcvdFromRem.value;
 
1129
      b_ = (*b)->udpRcvdLoc.value + (*b)->udpRcvdFromRem.value;
 
1130
      break;
 
1131
    case 3:
 
1132
      a_ = (*a)->icmpRcvd.value, b_ = (*b)->icmpRcvd.value;
 
1133
      break;
 
1134
    case 4:
 
1135
      a_ = (*a)->icmp6Rcvd.value, b_ = (*b)->icmp6Rcvd.value;
 
1136
      break;
 
1137
    case 5:
 
1138
      a_ = (*a)->dlcRcvd.value, b_ = (*b)->dlcRcvd.value;
 
1139
      break;
 
1140
    case 6:
 
1141
      a_ = (*a)->ipxRcvd.value, b_ = (*b)->ipxRcvd.value;
 
1142
      break;
 
1143
    case 7:
 
1144
      a_ = (*a)->decnetRcvd.value, b_ = (*b)->decnetRcvd.value;
 
1145
      break;
 
1146
    case 8:
 
1147
      a_ = (*a)->arp_rarpRcvd.value, b_ = (*b)->arp_rarpRcvd.value;
 
1148
      break;
 
1149
    case 9:
 
1150
      a_ = (*a)->appletalkRcvd.value, b_ = (*b)->appletalkRcvd.value;
 
1151
      break;
 
1152
    case 11:
 
1153
      a_ = (*a)->netbiosRcvd.value, b_ = (*b)->netbiosRcvd.value;
 
1154
      break;
 
1155
    case 13:
 
1156
      a_ = (*a)->osiRcvd.value, b_ = (*b)->osiRcvd.value;
 
1157
      break;
 
1158
    case 14:
 
1159
      a_ = (*a)->ipv6Rcvd.value, b_ = (*b)->ipv6Rcvd.value;
 
1160
      break;
 
1161
    case 15:
 
1162
      a_ = (*a)->stpRcvd.value, b_ = (*b)->stpRcvd.value;
 
1163
      break;
 
1164
    case 16:
 
1165
      a_ = (*a)->otherRcvd.value, b_ = (*b)->otherRcvd.value;
 
1166
      break;
 
1167
    default:
 
1168
      if((myGlobals.columnSort >= BASE_PROTOS_IDX)
 
1169
         && (myGlobals.columnSort < (BASE_PROTOS_IDX+myGlobals.numIpProtosList))) {
 
1170
        a_ = (*a)->ipProtosList[myGlobals.columnSort-BASE_PROTOS_IDX].rcvd.value,
 
1171
          b_ = (*b)->ipProtosList[myGlobals.columnSort-BASE_PROTOS_IDX].rcvd.value;
 
1172
      }
 
1173
      break;
 
1174
    }
 
1175
    break;
 
1176
  case SORT_DATA_RECEIVED_IP:
 
1177
    columnProtoId = myGlobals.columnSort - 1;
 
1178
    if((columnProtoId != -1) && (columnProtoId <= myGlobals.numIpProtosToMonitor)) {
 
1179
      if(columnProtoId <= 0) {
 
1180
        a_ = b_ = 0;
 
1181
      } else {
 
1182
        a_ = (*a)->protoIPTrafficInfos[columnProtoId-1].rcvdLoc.value+
 
1183
          (*a)->protoIPTrafficInfos[columnProtoId-1].rcvdFromRem.value;
 
1184
        b_ = (*b)->protoIPTrafficInfos[columnProtoId-1].rcvdLoc.value+
 
1185
          (*b)->protoIPTrafficInfos[columnProtoId-1].rcvdFromRem.value;
 
1186
      }
 
1187
    } else {
 
1188
      a_ = (*a)->ipBytesRcvd.value, b_ = (*b)->ipBytesRcvd.value;
 
1189
 
 
1190
      if(myGlobals.numIpProtosToMonitor == (columnProtoId-1)) {
 
1191
        /* other IP */
 
1192
        int i;
 
1193
 
 
1194
        for(i=0; i<myGlobals.numIpProtosToMonitor; i++) {
 
1195
          a_val = ((*a)->protoIPTrafficInfos[i].rcvdLoc.value
 
1196
                   +(*a)->protoIPTrafficInfos[i].rcvdFromRem.value);
 
1197
          b_val = ((*b)->protoIPTrafficInfos[i].rcvdLoc.value
 
1198
                   +(*b)->protoIPTrafficInfos[i].rcvdFromRem.value);
 
1199
 
 
1200
          /* Better be safe... */
 
1201
          if(a_ > a_val) a_ -= a_val; else a_ = 0;
 
1202
          if(b_ > b_val) b_ -= b_val; else b_ = 0;
 
1203
        }
 
1204
      }
 
1205
    }
 
1206
    break;
 
1207
  case SORT_DATA_RECEIVED_THPT:
 
1208
    switch(myGlobals.columnSort) {
 
1209
    case 1:
 
1210
      fa_ = (*a)->actualRcvdThpt, fb_ = (*b)->actualRcvdThpt, floatCompare = 1;
 
1211
      break;
 
1212
    case 2:
 
1213
      fa_ = (*a)->averageRcvdThpt, fb_ = (*b)->averageRcvdThpt, floatCompare = 1;
 
1214
      break;
 
1215
    case 3:
 
1216
      fa_ = (*a)->peakRcvdThpt, fb_ = (*b)->peakRcvdThpt, floatCompare = 1;
 
1217
      break;
 
1218
    case 4:
 
1219
      fa_ = (*a)->actualRcvdPktThpt, fb_ = (*b)->actualRcvdPktThpt, floatCompare = 1;
 
1220
      break;
 
1221
    case 5:
 
1222
      fa_ = (*a)->averageRcvdPktThpt, fb_ = (*b)->averageRcvdPktThpt, floatCompare = 1;
 
1223
      break;
 
1224
    case 6:
 
1225
      fa_ = (*a)->peakRcvdPktThpt, fb_ = (*b)->peakRcvdPktThpt, floatCompare = 1;
 
1226
      break;
 
1227
    }
 
1228
    break;
 
1229
  case SORT_DATA_RCVD_HOST_TRAFFIC:
 
1230
  case SORT_DATA_SENT_HOST_TRAFFIC:
 
1231
  case SORT_DATA_HOST_TRAFFIC:
 
1232
    /* Nothing */
 
1233
    break;
 
1234
  case SORT_DATA_SENT_PROTOS:
 
1235
    switch(myGlobals.columnSort) {
 
1236
    case 0:
 
1237
      a_ = (*a)->bytesSent.value, b_ = (*b)->bytesSent.value;
 
1238
      break;
 
1239
    case 1:
 
1240
      a_ = (*a)->tcpSentLoc.value + (*a)->tcpSentRem.value;
 
1241
      b_ = (*b)->tcpSentLoc.value + (*b)->tcpSentRem.value;
 
1242
      break;
 
1243
    case 2:
 
1244
      a_ = (*a)->udpSentLoc.value + (*a)->udpSentRem.value;
 
1245
      b_ = (*b)->udpSentLoc.value + (*b)->udpSentRem.value;
 
1246
      break;
 
1247
    case 3:
 
1248
      a_ = (*a)->icmpSent.value, b_ = (*b)->icmpSent.value;
 
1249
      break;
 
1250
    case 4:
 
1251
      a_ = (*a)->icmp6Sent.value, b_ = (*b)->icmp6Sent.value;
 
1252
      break;
 
1253
    case 5:
 
1254
      a_ = (*a)->dlcSent.value, b_ = (*b)->dlcSent.value;
 
1255
      break;
 
1256
    case 6:
 
1257
      a_ = (*a)->ipxSent.value, b_ = (*b)->ipxSent.value;
 
1258
      break;
 
1259
    case 7:
 
1260
      a_ = (*a)->decnetSent.value, b_ = (*b)->decnetSent.value;
 
1261
      break;
 
1262
    case 8:
 
1263
      a_ = (*a)->arp_rarpSent.value, b_ = (*b)->arp_rarpSent.value;
 
1264
      break;
 
1265
    case 9:
 
1266
      a_ = (*a)->appletalkSent.value, b_ = (*b)->appletalkSent.value;
 
1267
      break;
 
1268
    case 11:
 
1269
      a_ = (*a)->netbiosSent.value, b_ = (*b)->netbiosSent.value;
 
1270
      break;
 
1271
    case 13:
 
1272
      a_ = (*a)->osiSent.value, b_ = (*b)->osiSent.value;
 
1273
      break;
 
1274
    case 14:
 
1275
      a_ = (*a)->ipv6Sent.value, b_ = (*b)->ipv6Sent.value;
 
1276
      break;
 
1277
    case 15:
 
1278
      a_ = (*a)->stpSent.value, b_ = (*b)->stpSent.value;
 
1279
      break;
 
1280
    case 16:
 
1281
      a_ = (*a)->otherSent.value, b_ = (*b)->otherSent.value;
 
1282
      break;
 
1283
    default:
 
1284
      if((myGlobals.columnSort >= BASE_PROTOS_IDX)
 
1285
         && (myGlobals.columnSort < (BASE_PROTOS_IDX+myGlobals.numIpProtosList))) {
 
1286
        a_ = (*a)->ipProtosList[myGlobals.columnSort-BASE_PROTOS_IDX].sent.value,
 
1287
          b_ = (*b)->ipProtosList[myGlobals.columnSort-BASE_PROTOS_IDX].sent.value;
 
1288
      }
 
1289
      break;
 
1290
    }
 
1291
    break;
 
1292
  case SORT_DATA_SENT_IP:
 
1293
    columnProtoId = myGlobals.columnSort - 1;
 
1294
    if((columnProtoId != -1) && (columnProtoId <= myGlobals.numIpProtosToMonitor)) {
 
1295
      if(columnProtoId <= 0) {
 
1296
        a_ = b_ = 0;
 
1297
      } else {
 
1298
        a_ = (*a)->protoIPTrafficInfos[columnProtoId-1].sentLoc.value
 
1299
          +(*a)->protoIPTrafficInfos[columnProtoId-1].sentRem.value;
 
1300
        b_ = (*b)->protoIPTrafficInfos[columnProtoId-1].sentLoc.value
 
1301
          +(*b)->protoIPTrafficInfos[columnProtoId-1].sentRem.value;
 
1302
      }
 
1303
    } else {
 
1304
      a_ = (*a)->ipBytesSent.value, b_ = (*b)->ipBytesSent.value;
 
1305
 
 
1306
      if(myGlobals.numIpProtosToMonitor == (columnProtoId-1)) {
 
1307
        /* other IP */
 
1308
        int i;
 
1309
 
 
1310
        for(i=0; i<myGlobals.numIpProtosToMonitor; i++) {
 
1311
          a_val = ((*a)->protoIPTrafficInfos[i].sentLoc.value
 
1312
                   +(*a)->protoIPTrafficInfos[i].sentRem.value);
 
1313
          b_val = ((*b)->protoIPTrafficInfos[i].sentLoc.value
 
1314
                   +(*b)->protoIPTrafficInfos[i].sentRem.value);
 
1315
 
 
1316
          /* Better be safe... */
 
1317
          if(a_ > a_val) a_ -= a_val; else a_ = 0;
 
1318
          if(b_ > b_val) b_ -= b_val; else b_ = 0;
 
1319
        }
 
1320
      }
 
1321
    }
 
1322
    break;
 
1323
  case SORT_DATA_SENT_THPT:
 
1324
    switch(myGlobals.columnSort) {
 
1325
    case 1:
 
1326
      fa_ = (*a)->actualSentThpt, fb_ = (*b)->actualSentThpt, floatCompare = 1;
 
1327
      break;
 
1328
    case 2:
 
1329
      fa_ = (*a)->averageSentThpt, fb_ = (*b)->averageSentThpt, floatCompare = 1;
 
1330
      break;
 
1331
    case 3:
 
1332
      fa_ = (*a)->peakSentThpt, fb_ = (*b)->peakSentThpt, floatCompare = 1;
 
1333
      break;
 
1334
    case 4:
 
1335
      fa_ = (*a)->actualSentPktThpt, fb_ = (*b)->actualSentPktThpt, floatCompare = 1;
 
1336
      break;
 
1337
    case 5:
 
1338
      fa_ = (*a)->averageSentPktThpt, fb_ = (*b)->averageSentPktThpt, floatCompare = 1;
 
1339
      break;
 
1340
    case 6:
 
1341
      fa_ = (*a)->peakSentPktThpt, fb_ = (*b)->peakSentPktThpt, floatCompare = 1;
 
1342
      break;
 
1343
    }
 
1344
    break;
 
1345
  case TRAFFIC_STATS:
 
1346
    /* Nothing */
 
1347
    break;
 
1348
  case SORT_DATA_PROTOS:
 
1349
    switch(myGlobals.columnSort) {
 
1350
    case 0:
 
1351
      a_ = (*a)->bytesRcvd.value+(*a)->bytesSent.value, b_ = (*b)->bytesRcvd.value+(*b)->bytesSent.value;
 
1352
      break;
 
1353
    case 1:
 
1354
      a_ = (*a)->tcpRcvdLoc.value + (*a)->tcpRcvdFromRem.value +
 
1355
           (*a)->tcpSentLoc.value + (*a)->tcpSentRem.value;
 
1356
      b_ = (*b)->tcpRcvdLoc.value + (*b)->tcpRcvdFromRem.value +
 
1357
           (*b)->tcpSentLoc.value + (*b)->tcpSentRem.value;
 
1358
      break;
 
1359
    case 2:
 
1360
      a_ = (*a)->udpRcvdLoc.value + (*a)->udpRcvdFromRem.value +
 
1361
           (*a)->udpSentLoc.value + (*a)->udpSentRem.value;
 
1362
      b_ = (*b)->udpRcvdLoc.value + (*b)->udpRcvdFromRem.value +
 
1363
           (*b)->udpSentLoc.value + (*b)->udpSentRem.value;
 
1364
      break;
 
1365
    case 3:
 
1366
      a_ = (*a)->icmpRcvd.value+(*a)->icmpSent.value, b_ = (*b)->icmpRcvd.value+(*b)->icmpSent.value;
 
1367
      break;
 
1368
    case 4:
 
1369
      a_ = (*a)->icmp6Rcvd.value+(*a)->icmp6Sent.value, b_ = (*b)->icmp6Rcvd.value+(*b)->icmp6Sent.value;
 
1370
      break;
 
1371
    case 5:
 
1372
      a_ = (*a)->dlcRcvd.value+(*a)->dlcSent.value, b_ = (*b)->dlcRcvd.value+(*b)->dlcSent.value;
 
1373
      break;
 
1374
    case 6:
 
1375
      a_ = (*a)->ipxRcvd.value+(*a)->ipxSent.value, b_ = (*b)->ipxRcvd.value+(*b)->ipxSent.value;
 
1376
      break;
 
1377
    case 7:
 
1378
      a_ = (*a)->decnetRcvd.value+(*a)->decnetSent.value, b_ = (*b)->decnetRcvd.value+(*b)->decnetSent.value;
 
1379
      break;
 
1380
    case 8:
 
1381
      a_ = (*a)->arp_rarpRcvd.value+(*a)->arp_rarpSent.value;
 
1382
      b_ = (*b)->arp_rarpRcvd.value+(*b)->arp_rarpSent.value;
 
1383
      break;
 
1384
    case 9:
 
1385
      a_ = (*a)->appletalkRcvd.value+(*a)->appletalkSent.value;
 
1386
      b_ = (*b)->appletalkRcvd.value+(*b)->appletalkSent.value;
 
1387
      break;
 
1388
    case 11:
 
1389
      a_ = (*a)->netbiosRcvd.value+(*a)->netbiosSent.value;
 
1390
      b_ = (*b)->netbiosRcvd.value+(*b)->netbiosSent.value;
 
1391
      break;
 
1392
    case 13:
 
1393
      a_ = (*a)->osiRcvd.value+(*a)->osiSent.value, b_ = (*b)->osiRcvd.value+(*b)->osiSent.value;
 
1394
      break;
 
1395
    case 14:
 
1396
      a_ = (*a)->ipv6Rcvd.value+(*a)->ipv6Sent.value, b_ = (*b)->ipv6Rcvd.value+(*b)->ipv6Sent.value;
 
1397
      break;
 
1398
    case 15:
 
1399
      a_ = (*a)->stpRcvd.value+(*a)->stpSent.value, b_ = (*b)->stpRcvd.value+(*b)->stpSent.value;
 
1400
      break;
 
1401
    case 16:
 
1402
      a_ = (*a)->otherRcvd.value+(*a)->otherSent.value, b_ = (*b)->otherRcvd.value+(*b)->otherSent.value;
 
1403
      break;
 
1404
    default:
 
1405
      if((myGlobals.columnSort >= BASE_PROTOS_IDX)
 
1406
         && (myGlobals.columnSort < (BASE_PROTOS_IDX+myGlobals.numIpProtosList))) {
 
1407
        a_ = (*a)->ipProtosList[myGlobals.columnSort-BASE_PROTOS_IDX].sent.value
 
1408
          +(*a)->ipProtosList[myGlobals.columnSort-BASE_PROTOS_IDX].rcvd.value;
 
1409
        b_ = (*b)->ipProtosList[myGlobals.columnSort-BASE_PROTOS_IDX].sent.value
 
1410
          +(*b)->ipProtosList[myGlobals.columnSort-BASE_PROTOS_IDX].rcvd.value;
 
1411
      }
 
1412
      break;
 
1413
    }
 
1414
    break;
 
1415
  case SORT_DATA_IP:
 
1416
    columnProtoId = myGlobals.columnSort - 1;
 
1417
    if((columnProtoId != -1) && (columnProtoId <= myGlobals.numIpProtosToMonitor)) {
 
1418
      if(columnProtoId <= 0) {
 
1419
        a_ = b_ = 0;
 
1420
      } else {
 
1421
        a_ = (*a)->protoIPTrafficInfos[columnProtoId-1].rcvdLoc.value+
 
1422
          (*a)->protoIPTrafficInfos[columnProtoId-1].rcvdFromRem.value+
 
1423
          (*a)->protoIPTrafficInfos[columnProtoId-1].sentLoc.value+
 
1424
          (*a)->protoIPTrafficInfos[columnProtoId-1].sentRem.value;
 
1425
        b_ = (*b)->protoIPTrafficInfos[columnProtoId-1].rcvdLoc.value+
 
1426
          (*b)->protoIPTrafficInfos[columnProtoId-1].rcvdFromRem.value+
 
1427
          (*b)->protoIPTrafficInfos[columnProtoId-1].sentLoc.value+
 
1428
          (*b)->protoIPTrafficInfos[columnProtoId-1].sentRem.value;
 
1429
      }
 
1430
    } else {
 
1431
      a_ = (*a)->ipBytesRcvd.value+(*a)->ipBytesSent.value;
 
1432
      b_ = (*b)->ipBytesRcvd.value+(*b)->ipBytesSent.value;
 
1433
 
 
1434
      if(myGlobals.numIpProtosToMonitor == (columnProtoId-1)) {
 
1435
        /* other IP */
 
1436
        int i;
 
1437
 
 
1438
        for(i=0; i<myGlobals.numIpProtosToMonitor; i++) {
 
1439
          a_val = ((*a)->protoIPTrafficInfos[i].rcvdLoc.value
 
1440
                   +(*a)->protoIPTrafficInfos[i].rcvdFromRem.value
 
1441
                   +(*a)->protoIPTrafficInfos[i].sentLoc.value
 
1442
                   +(*a)->protoIPTrafficInfos[i].sentRem.value);
 
1443
          b_val = ((*b)->protoIPTrafficInfos[i].rcvdLoc.value
 
1444
                   +(*b)->protoIPTrafficInfos[i].rcvdFromRem.value
 
1445
                   +(*b)->protoIPTrafficInfos[i].sentLoc.value
 
1446
                   +(*b)->protoIPTrafficInfos[i].sentRem.value);
 
1447
 
 
1448
          /* Better be safe... */
 
1449
          if(a_ > a_val) a_ -= a_val; else a_ = 0;
 
1450
          if(b_ > b_val) b_ -= b_val; else b_ = 0;
 
1451
        }
 
1452
      }
 
1453
    }
 
1454
    break;
 
1455
  case SORT_DATA_THPT:
 
1456
    switch(myGlobals.columnSort) {
 
1457
    case 1:
 
1458
      fa_ = (*a)->actualTThpt;
 
1459
      fb_ = (*b)->actualTThpt;
 
1460
      floatCompare = 1;
 
1461
      break;
 
1462
    case 2:
 
1463
      fa_ = (*a)->averageTThpt;
 
1464
      fb_ = (*b)->averageTThpt;
 
1465
      floatCompare = 1;
 
1466
      break;
 
1467
    case 3:
 
1468
      fa_ = (*a)->peakTThpt;
 
1469
      fb_ = (*b)->peakTThpt;
 
1470
      floatCompare = 1;
 
1471
      break;
 
1472
    case 4:
 
1473
      fa_ = (*a)->actualTPktThpt;
 
1474
      fb_ = (*b)->actualTPktThpt;
 
1475
      floatCompare = 1;
 
1476
      break;
 
1477
    case 5:
 
1478
      fa_ = (*a)->averageTPktThpt;
 
1479
      fb_ = (*b)->averageTPktThpt;
 
1480
      floatCompare = 1;
 
1481
      break;
 
1482
    case 6:
 
1483
      fa_ = (*a)->peakTPktThpt;
 
1484
      fb_ = (*b)->peakTPktThpt;
 
1485
      floatCompare = 1;
 
1486
      break;
 
1487
    }
 
1488
    break;
 
1489
  }
 
1490
 
 
1491
  /*
 
1492
    traceEvent(CONST_TRACE_INFO, "%s=%u - %s=%u",
 
1493
    (*a)->hostResolvedName, (unsigned long)a_,
 
1494
    (*b)->hostResolvedName, (unsigned long)b_);
 
1495
  */
 
1496
 
 
1497
  if(floatCompare == 0) {
 
1498
    if(a_ < b_) {
 
1499
      return(1);
 
1500
    } else if (a_ > b_) {
 
1501
      return(-1);
 
1502
    } else {
 
1503
      return(0);
 
1504
    }
 
1505
  } else {
 
1506
    if(fa_ < fb_) {
 
1507
      return(1);
 
1508
    } else if (fa_ > fb_) {
 
1509
      return(-1);
 
1510
    } else {
 
1511
      return(0);
 
1512
    }
 
1513
  }
 
1514
}
 
1515
 
 
1516
/* ******************************* */
 
1517
 
 
1518
int cmpMulticastFctn(const void *_a, const void *_b) {
 
1519
  HostTraffic **a = (HostTraffic **)_a;
 
1520
  HostTraffic **b = (HostTraffic **)_b;
 
1521
  int rc;
 
1522
 
 
1523
  if((a == NULL) && (b != NULL)) {
 
1524
    traceEvent(CONST_TRACE_WARNING, "cmpMulticastFctn() error (1)");
 
1525
    return(1);
 
1526
  } else if((a != NULL) && (b == NULL)) {
 
1527
    traceEvent(CONST_TRACE_WARNING, "cmpMulticastFctn() error (2)");
 
1528
    return(-1);
 
1529
  } else if((a == NULL) && (b == NULL)) {
 
1530
    traceEvent(CONST_TRACE_WARNING, "cmpMulticastFctn() error (3)");
 
1531
    return(0);
 
1532
  }
 
1533
 
 
1534
  switch(myGlobals.columnSort) {
 
1535
  case 2:
 
1536
    if((*a)->pktMulticastSent.value < (*b)->pktMulticastSent.value)
 
1537
      return(1);
 
1538
    else if ((*a)->pktMulticastSent.value > (*b)->pktMulticastSent.value)
 
1539
      return(-1);
 
1540
    else
 
1541
      return(0);
 
1542
    break; /* NOTREACHED */
 
1543
  case 3:
 
1544
    if((*a)->bytesMulticastSent.value < (*b)->bytesMulticastSent.value)
 
1545
      return(1);
 
1546
    else if ((*a)->bytesMulticastSent.value > (*b)->bytesMulticastSent.value)
 
1547
      return(-1);
 
1548
    else
 
1549
      return(0);
 
1550
    break; /* NOTREACHED */
 
1551
  case 4:
 
1552
    if((*a)->pktMulticastRcvd.value < (*b)->pktMulticastRcvd.value)
 
1553
      return(1);
 
1554
    else if ((*a)->pktMulticastRcvd.value > (*b)->pktMulticastRcvd.value)
 
1555
      return(-1);
 
1556
    else
 
1557
      return(0);
 
1558
    break; /* NOTREACHED */
 
1559
  case 5:
 
1560
    if((*a)->bytesMulticastRcvd.value < (*b)->bytesMulticastRcvd.value)
 
1561
      return(1);
 
1562
    else if ((*a)->bytesMulticastRcvd.value > (*b)->bytesMulticastRcvd.value)
 
1563
      return(-1);
 
1564
    else
 
1565
      return(0);
 
1566
    break; /* NOTREACHED */
 
1567
 
 
1568
  default:
 
1569
    rc=cmpFctnResolvedName(a, b);
 
1570
    return(rc);
 
1571
  }
 
1572
}
 
1573
 
 
1574
/* *********************************** */
 
1575
 
 
1576
static char* getBgPctgColor(float pctg) {
 
1577
  if(pctg == 0)
 
1578
    return(TD_BG);
 
1579
  else if(pctg <= CONST_PCTG_LOW)     /* < 25%       */
 
1580
    return(CONST_CONST_PCTG_LOW_COLOR);
 
1581
  else if(pctg <= CONST_PCTG_MID)     /* 25% <=> 75% */
 
1582
    return(CONST_CONST_PCTG_MID_COLOR);
 
1583
  else                          /* > 75%       */
 
1584
    return(CONST_PCTG_HIGH_COLOR);
 
1585
}
 
1586
 
 
1587
/* ******************************* */
 
1588
 
 
1589
void printHostThtpShort(HostTraffic *el, int reportType, u_int hourId)
 
1590
{
 
1591
  int i, j;
 
1592
  Counter tc;
 
1593
  char buf[64];
 
1594
 
 
1595
  if(el->trafficDistribution == NULL) return;
 
1596
 
 
1597
  for(i=0, tc=0; i<24; i++) {
 
1598
    switch(reportType) {
 
1599
        case SORT_DATA_RCVD_HOST_TRAFFIC:
 
1600
          tc += el->trafficDistribution->last24HoursBytesRcvd[i].value;
 
1601
          break;
 
1602
    case SORT_DATA_SENT_HOST_TRAFFIC:
 
1603
      tc += el->trafficDistribution->last24HoursBytesSent[i].value;
 
1604
      break;
 
1605
    case SORT_DATA_HOST_TRAFFIC:
 
1606
    case TRAFFIC_STATS:
 
1607
      tc += el->trafficDistribution->last24HoursBytesRcvd[i].value +
 
1608
        el->trafficDistribution->last24HoursBytesSent[i].value;
 
1609
      break;
 
1610
    }
 
1611
  }
 
1612
 
 
1613
  j = hourId;
 
1614
  for(i=0; i<24; i++) {
 
1615
    float pctg=0;
 
1616
 
 
1617
    j = j % 24;
 
1618
    if(tc > 0) {
 
1619
      switch(reportType) {
 
1620
      case SORT_DATA_RCVD_HOST_TRAFFIC:
 
1621
        pctg = (float)(el->trafficDistribution->last24HoursBytesRcvd[j].value*100)/(float)tc;
 
1622
        break;
 
1623
      case SORT_DATA_SENT_HOST_TRAFFIC:
 
1624
        pctg = (float)(el->trafficDistribution->last24HoursBytesSent[j].value*100)/(float)tc;
 
1625
        break;
 
1626
      case SORT_DATA_HOST_TRAFFIC:
 
1627
      case TRAFFIC_STATS:
 
1628
        pctg = ( (float)(el->trafficDistribution->last24HoursBytesRcvd[j].value*100) +
 
1629
                 (float)(el->trafficDistribution->last24HoursBytesSent[j].value*100) ) / (float)tc;
 
1630
        break;
 
1631
      }
 
1632
    }
 
1633
 
 
1634
    if(snprintf(buf, sizeof(buf), "<TD "TD_BG" ALIGN=RIGHT %s>&nbsp;</TD>",
 
1635
                getBgPctgColor(pctg)) < 0) BufferTooShort();
 
1636
    sendString(buf);
 
1637
    if (!j) {
 
1638
        j = 23;
 
1639
    }
 
1640
    else {
 
1641
        j--;
 
1642
    }
 
1643
  }
 
1644
}
 
1645
 
 
1646
/* ******************************* */
 
1647
 
 
1648
int cmpHostsFctn(const void *_a, const void *_b) {
 
1649
  struct hostTraffic **a = (struct hostTraffic **)_a;
 
1650
  struct hostTraffic **b = (struct hostTraffic **)_b;
 
1651
  char *name_a, *name_b;
 
1652
  Counter a_=0, b_=0;
 
1653
 
 
1654
  switch(myGlobals.columnSort) {
 
1655
  case 2: /* IP Address */
 
1656
      if(isFcHost ((*a)) && isFcHost ((*b))) {
 
1657
          return (memcmp (((u_int8_t *)&(*a)->hostFcAddress), ((u_int8_t *)&(*b)->hostFcAddress),
 
1658
                          LEN_FC_ADDRESS));
 
1659
      }
 
1660
      else {
 
1661
          return (addrcmp(&(*a)->hostIpAddress,&(*b)->hostIpAddress));
 
1662
      }
 
1663
      break;
 
1664
 
 
1665
  case 3: /* Data Sent */
 
1666
      if (isFcHost ((*a)) && isFcHost ((*b))) {
 
1667
          a_ = (*a)->fcBytesSent.value;
 
1668
          b_ = (*b)->fcBytesSent.value;
 
1669
      }
 
1670
      else {
 
1671
          switch(myGlobals.sortFilter) {
 
1672
          case FLAG_REMOTE_TO_LOCAL_ACCOUNTING:
 
1673
              a_ = (*a)->bytesSentLoc.value;
 
1674
              b_ = (*b)->bytesSentLoc.value;
 
1675
              break;
 
1676
          case FLAG_LOCAL_TO_REMOTE_ACCOUNTING:
 
1677
              a_ = (*a)->bytesSentRem.value;
 
1678
              b_ = (*b)->bytesSentRem.value;
 
1679
              break;
 
1680
          case FLAG_LOCAL_TO_LOCAL_ACCOUNTING:
 
1681
              a_ = (*a)->bytesSentLoc.value;
 
1682
              b_ = (*b)->bytesSentLoc.value;
 
1683
              break;
 
1684
          }
 
1685
      }
 
1686
      if(a_ < b_) return(1); else if (a_ > b_) return(-1); else return(0);
 
1687
      break;
 
1688
 
 
1689
  case 4: /* Data Rcvd */
 
1690
      if (isFcHost ((*a)) && isFcHost ((*b))) {
 
1691
          a_ = (*a)->fcBytesRcvd.value;
 
1692
          b_ = (*b)->fcBytesRcvd.value;
 
1693
      }
 
1694
      else {
 
1695
          switch(myGlobals.sortFilter) {
 
1696
          case FLAG_REMOTE_TO_LOCAL_ACCOUNTING:
 
1697
              a_ = (*a)->bytesRcvdLoc.value;
 
1698
              b_ = (*b)->bytesRcvdLoc.value;
 
1699
              break;
 
1700
          case FLAG_LOCAL_TO_REMOTE_ACCOUNTING:
 
1701
              a_ = (*a)->bytesRcvdFromRem.value;
 
1702
              b_ = (*b)->bytesRcvdFromRem.value;
 
1703
              break;
 
1704
          case FLAG_LOCAL_TO_LOCAL_ACCOUNTING:
 
1705
              a_ = (*a)->bytesRcvdLoc.value;
 
1706
              b_ = (*b)->bytesRcvdLoc.value;
 
1707
              break;
 
1708
          }
 
1709
      }
 
1710
      if(a_ < b_) return(1); else if (a_ > b_) return(-1); else return(0);
 
1711
      break;
 
1712
 
 
1713
  case 5: /* VSAN */
 
1714
      if (isFcHost ((*a)) && isFcHost ((*b))) {
 
1715
          a_ = (*a)->vsanId, b_ = (*b)->vsanId;
 
1716
          return ((a_ < b_) ? -1 : (a_ > b_) ? 1 : 0);
 
1717
      }
 
1718
      break;
 
1719
 
 
1720
  default: /* Host Name */
 
1721
    return(cmpFctnResolvedName(a, b));
 
1722
  }
 
1723
}
 
1724
 
 
1725
/* ************************************ */
 
1726
 
 
1727
void printPacketStats(HostTraffic *el, int actualDeviceId) {
 
1728
  char buf[LEN_GENERAL_WORK_BUFFER];
 
1729
  char formatBuf[32];
 
1730
  int headerSent = 0;
 
1731
  char *tableHeader = "<center><TABLE BORDER=0 "TABLE_DEFAULTS"><TR><TD>";
 
1732
 
 
1733
  /* *********************** */
 
1734
 
 
1735
  if(el->secHostPkts != NULL) {
 
1736
    if(((el->secHostPkts->rejectedTCPConnSent.value.value+
 
1737
         el->secHostPkts->rejectedTCPConnRcvd.value.value+
 
1738
         el->secHostPkts->establishedTCPConnSent.value.value+
 
1739
         el->secHostPkts->establishedTCPConnRcvd.value.value+
 
1740
         el->secHostPkts->synPktsSent.value.value+
 
1741
         el->secHostPkts->synPktsRcvd.value.value) > 0)) {
 
1742
 
 
1743
      if(!headerSent) { printSectionTitle("Packet Statistics"); sendString(tableHeader); headerSent = 1; }
 
1744
 
 
1745
      sendString("<CENTER>\n"
 
1746
                 ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\"><TR "TR_ON" "DARK_BG"><TH "TH_BG">TCP Connections</TH>"
 
1747
                 "<TH "TH_BG" COLSPAN=2>Directed to</TH>"
 
1748
                 "<TH "TH_BG" COLSPAN=2>Rcvd From</TH></TR>\n");
 
1749
 
 
1750
      if((el->secHostPkts->synPktsSent.value.value+el->secHostPkts->synPktsRcvd.value.value) > 0) {
 
1751
        sendString("<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT "DARK_BG">Attempted</TH>");
 
1752
        formatUsageCounter(el->secHostPkts->synPktsSent, 0, actualDeviceId);
 
1753
        formatUsageCounter(el->secHostPkts->synPktsRcvd, 0, actualDeviceId);
 
1754
        sendString("</TR>\n");
 
1755
      }
 
1756
 
 
1757
      if((el->secHostPkts->establishedTCPConnSent.value.value+el->secHostPkts->establishedTCPConnRcvd.value.value) > 0) {
 
1758
        sendString("<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT "DARK_BG">Established</TH>");
 
1759
        formatUsageCounter(el->secHostPkts->establishedTCPConnSent, el->secHostPkts->synPktsSent.value.value, actualDeviceId);
 
1760
        formatUsageCounter(el->secHostPkts->establishedTCPConnRcvd, el->secHostPkts->synPktsRcvd.value.value, actualDeviceId);
 
1761
        sendString("</TR>\n");
 
1762
      }
 
1763
 
 
1764
      if((el->secHostPkts->terminatedTCPConnServer.value.value + el->secHostPkts->terminatedTCPConnClient.value.value) > 0) {
 
1765
        sendString("<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT "DARK_BG">Terminated</TH>");
 
1766
        formatUsageCounter(el->secHostPkts->terminatedTCPConnServer, 0, actualDeviceId);
 
1767
        formatUsageCounter(el->secHostPkts->terminatedTCPConnClient, 0, actualDeviceId);
 
1768
        sendString("</TR>\n");
 
1769
      }
 
1770
 
 
1771
      if((el->secHostPkts->rejectedTCPConnSent.value.value+el->secHostPkts->rejectedTCPConnRcvd.value.value) > 0) {
 
1772
        sendString("<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT "DARK_BG">Rejected</TH>");
 
1773
        formatUsageCounter(el->secHostPkts->rejectedTCPConnSent, el->secHostPkts->synPktsSent.value.value, actualDeviceId);
 
1774
        formatUsageCounter(el->secHostPkts->rejectedTCPConnRcvd, el->secHostPkts->synPktsRcvd.value.value, actualDeviceId);
 
1775
        sendString("</TR>\n");
 
1776
      }
 
1777
 
 
1778
      sendString("</TABLE>"TABLE_OFF"<P>\n");
 
1779
      sendString("</CENTER>\n");
 
1780
    }
 
1781
 
 
1782
    /* *********************** */
 
1783
 
 
1784
    if((el->secHostPkts->synPktsSent.value.value+el->secHostPkts->synPktsRcvd.value.value
 
1785
        +el->secHostPkts->rstAckPktsSent.value.value+el->secHostPkts->rstAckPktsRcvd.value.value
 
1786
        +el->secHostPkts->rstPktsSent.value.value+el->secHostPkts->rstPktsRcvd.value.value
 
1787
        +el->secHostPkts->synFinPktsSent.value.value+el->secHostPkts->synFinPktsRcvd.value.value
 
1788
        +el->secHostPkts->finPushUrgPktsSent.value.value+el->secHostPkts->finPushUrgPktsRcvd.value.value
 
1789
        +el->secHostPkts->nullPktsSent.value.value+el->secHostPkts->nullPktsRcvd.value.value) > 0) {
 
1790
 
 
1791
      if(!headerSent) { printSectionTitle("Packet Statistics"); sendString(tableHeader); headerSent = 1; }
 
1792
 
 
1793
      sendString("<CENTER>\n"
 
1794
                 ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\"><TR "TR_ON" "DARK_BG"><TH "TH_BG">TCP Flags</TH>"
 
1795
                 "<TH "TH_BG" COLSPAN=2>Pkts&nbsp;Sent</TH>"
 
1796
                 "<TH "TH_BG" COLSPAN=2>Pkts&nbsp;Rcvd</TH></TR>\n");
 
1797
 
 
1798
      if((el->secHostPkts->synPktsSent.value.value+el->secHostPkts->synPktsRcvd.value.value) > 0) {
 
1799
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">SYN</TH>",
 
1800
                    getRowColor()) < 0)
 
1801
          BufferTooShort();
 
1802
        sendString(buf);
 
1803
        formatUsageCounter(el->secHostPkts->synPktsSent, 0, actualDeviceId);
 
1804
        formatUsageCounter(el->secHostPkts->synPktsRcvd, 0, actualDeviceId);
 
1805
        sendString("</TR>\n");
 
1806
      }
 
1807
 
 
1808
      if((el->secHostPkts->rstAckPktsSent.value.value+el->secHostPkts->rstAckPktsRcvd.value.value) > 0) {
 
1809
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">RST|ACK</TH>",
 
1810
                    getRowColor()) < 0)
 
1811
          BufferTooShort();
 
1812
        sendString(buf);
 
1813
        formatUsageCounter(el->secHostPkts->rstAckPktsSent, 0, actualDeviceId);
 
1814
        formatUsageCounter(el->secHostPkts->rstAckPktsRcvd, 0, actualDeviceId);
 
1815
        sendString("</TR>\n");
 
1816
      }
 
1817
 
 
1818
      if((el->secHostPkts->rstPktsSent.value.value+el->secHostPkts->rstPktsRcvd.value.value) > 0) {
 
1819
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">RST</TH>",
 
1820
                    getRowColor()) < 0) BufferTooShort();
 
1821
        sendString(buf);
 
1822
        formatUsageCounter(el->secHostPkts->rstPktsSent, 0, actualDeviceId);
 
1823
        formatUsageCounter(el->secHostPkts->rstPktsRcvd, 0, actualDeviceId);
 
1824
        sendString("</TR>\n");
 
1825
      }
 
1826
 
 
1827
      if((el->secHostPkts->synFinPktsSent.value.value+el->secHostPkts->synFinPktsRcvd.value.value) > 0) {
 
1828
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">SYN|FIN</TH>",
 
1829
                    getRowColor()) < 0) BufferTooShort();
 
1830
        sendString(buf);
 
1831
        formatUsageCounter(el->secHostPkts->synFinPktsSent, 0, actualDeviceId);
 
1832
        formatUsageCounter(el->secHostPkts->synFinPktsRcvd, 0, actualDeviceId);
 
1833
        sendString("</TR>\n");
 
1834
      }
 
1835
 
 
1836
      if((el->secHostPkts->finPushUrgPktsSent.value.value+el->secHostPkts->finPushUrgPktsRcvd.value.value) > 0) {
 
1837
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">FIN|PUSH|URG</TH>",
 
1838
                    getRowColor()) < 0) BufferTooShort();
 
1839
        sendString(buf);
 
1840
        formatUsageCounter(el->secHostPkts->finPushUrgPktsSent, 0, actualDeviceId);
 
1841
        formatUsageCounter(el->secHostPkts->finPushUrgPktsRcvd, 0, actualDeviceId);
 
1842
        sendString("</TR>\n");
 
1843
      }
 
1844
 
 
1845
      if((el->secHostPkts->nullPktsSent.value.value+el->secHostPkts->nullPktsRcvd.value.value) > 0) {
 
1846
        sendString("<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT "DARK_BG">NULL</TH>");
 
1847
        formatUsageCounter(el->secHostPkts->nullPktsSent, 0, actualDeviceId);
 
1848
        formatUsageCounter(el->secHostPkts->nullPktsRcvd, 0, actualDeviceId);
 
1849
        sendString("</TR>\n");
 
1850
      }
 
1851
 
 
1852
      sendString("</TABLE>"TABLE_OFF"<P>\n");
 
1853
      sendString("</CENTER>\n");
 
1854
    }
 
1855
 
 
1856
    /* *********************** */
 
1857
 
 
1858
    if(((el->secHostPkts->ackXmasFinSynNullScanSent.value.value+el->secHostPkts->ackXmasFinSynNullScanRcvd.value.value
 
1859
         +el->secHostPkts->udpToClosedPortSent.value.value
 
1860
         +el->secHostPkts->udpToClosedPortRcvd.value.value
 
1861
         +el->secHostPkts->udpToDiagnosticPortSent.value.value
 
1862
         +el->secHostPkts->udpToDiagnosticPortRcvd.value.value
 
1863
         +el->secHostPkts->tcpToDiagnosticPortSent.value.value
 
1864
         +el->secHostPkts->tcpToDiagnosticPortRcvd.value.value
 
1865
         +el->secHostPkts->tinyFragmentSent.value.value
 
1866
         +el->secHostPkts->tinyFragmentRcvd.value.value
 
1867
         +el->secHostPkts->icmpFragmentSent.value.value
 
1868
         +el->secHostPkts->icmpFragmentRcvd.value.value
 
1869
         +el->secHostPkts->overlappingFragmentSent.value.value
 
1870
         +el->secHostPkts->overlappingFragmentRcvd.value.value
 
1871
         +el->secHostPkts->closedEmptyTCPConnSent.value.value
 
1872
         +el->secHostPkts->closedEmptyTCPConnRcvd.value.value
 
1873
         +el->secHostPkts->icmpPortUnreachSent.value.value
 
1874
         +el->secHostPkts->icmpPortUnreachRcvd.value.value
 
1875
         +el->secHostPkts->icmpHostNetUnreachSent.value.value
 
1876
         +el->secHostPkts->icmpHostNetUnreachRcvd.value.value
 
1877
         +el->secHostPkts->icmpProtocolUnreachSent.value.value
 
1878
         +el->secHostPkts->icmpProtocolUnreachRcvd.value.value
 
1879
         +el->secHostPkts->icmpAdminProhibitedSent.value.value
 
1880
         +el->secHostPkts->icmpAdminProhibitedRcvd.value.value
 
1881
         +el->secHostPkts->malformedPktsSent.value.value
 
1882
         +el->secHostPkts->malformedPktsRcvd.value.value
 
1883
         ) > 0)) {
 
1884
 
 
1885
      if(!headerSent) { printSectionTitle("Packet Statistics"); sendString(tableHeader); headerSent = 1; }
 
1886
 
 
1887
      sendString("<CENTER>\n"
 
1888
                 ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\"><TR "TR_ON" "DARK_BG"><TH "TH_BG">Anomaly</TH>"
 
1889
                 "<TH "TH_BG" COLSPAN=2>Pkts&nbsp;Sent&nbsp;to</TH>"
 
1890
                 "<TH "TH_BG" COLSPAN=2>Pkts&nbsp;Rcvd&nbsp;from</TH>"
 
1891
                 "</TR>\n");
 
1892
 
 
1893
      if((el->secHostPkts->ackXmasFinSynNullScanSent.value.value+el->secHostPkts->ackXmasFinSynNullScanRcvd.value.value) > 0) {
 
1894
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">ACK/XMAS/SYN/FIN/NULL Scan</TH>",
 
1895
                    getRowColor()) < 0)
 
1896
          BufferTooShort();
 
1897
        sendString(buf);
 
1898
        formatUsageCounter(el->secHostPkts->ackXmasFinSynNullScanSent, 0, actualDeviceId);
 
1899
        formatUsageCounter(el->secHostPkts->ackXmasFinSynNullScanRcvd, 0, actualDeviceId);
 
1900
        sendString("</TR>\n");
 
1901
      }
 
1902
 
 
1903
      if((el->secHostPkts->udpToClosedPortSent.value.value+
 
1904
          el->secHostPkts->udpToClosedPortRcvd.value.value) > 0) {
 
1905
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">UDP Pkt to Closed Port</TH>",
 
1906
                    getRowColor()) < 0) BufferTooShort();
 
1907
        sendString(buf);
 
1908
        formatUsageCounter(el->secHostPkts->udpToClosedPortSent, 0, actualDeviceId);
 
1909
        formatUsageCounter(el->secHostPkts->udpToClosedPortRcvd, 0, actualDeviceId);
 
1910
        sendString("</TR>\n");
 
1911
      }
 
1912
 
 
1913
      if((el->secHostPkts->udpToDiagnosticPortSent.value.value+
 
1914
          el->secHostPkts->udpToDiagnosticPortRcvd.value.value) > 0) {
 
1915
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">UDP Pkt Disgnostic Port</TH>",
 
1916
                    getRowColor()) < 0) BufferTooShort();
 
1917
        sendString(buf);
 
1918
        formatUsageCounter(el->secHostPkts->udpToDiagnosticPortSent, 0, actualDeviceId);
 
1919
        formatUsageCounter(el->secHostPkts->udpToDiagnosticPortRcvd, 0, actualDeviceId);
 
1920
        sendString("</TR>\n");
 
1921
      }
 
1922
 
 
1923
      if((el->secHostPkts->tcpToDiagnosticPortSent.value.value+
 
1924
          el->secHostPkts->tcpToDiagnosticPortRcvd.value.value) > 0) {
 
1925
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">TCP Pkt Disgnostic Port</TH>",
 
1926
                    getRowColor()) < 0) BufferTooShort();
 
1927
        sendString(buf);
 
1928
        formatUsageCounter(el->secHostPkts->tcpToDiagnosticPortSent, 0, actualDeviceId);
 
1929
        formatUsageCounter(el->secHostPkts->tcpToDiagnosticPortRcvd, 0, actualDeviceId);
 
1930
        sendString("</TR>\n");
 
1931
      }
 
1932
 
 
1933
      if((el->secHostPkts->tinyFragmentSent.value.value+
 
1934
          el->secHostPkts->tinyFragmentRcvd.value.value) > 0) {
 
1935
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">Tiny Fragments</TH>",
 
1936
                    getRowColor()) < 0) BufferTooShort();
 
1937
        sendString(buf);
 
1938
        formatUsageCounter(el->secHostPkts->tinyFragmentSent, 0, actualDeviceId);
 
1939
        formatUsageCounter(el->secHostPkts->tinyFragmentRcvd, 0, actualDeviceId);
 
1940
        sendString("</TR>\n");
 
1941
      }
 
1942
 
 
1943
      if((el->secHostPkts->icmpFragmentSent.value.value+
 
1944
          el->secHostPkts->icmpFragmentRcvd.value.value) > 0) {
 
1945
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">ICMP Fragments</TH>",
 
1946
                    getRowColor()) < 0) BufferTooShort();
 
1947
        sendString(buf);
 
1948
        formatUsageCounter(el->secHostPkts->icmpFragmentSent, 0, actualDeviceId);
 
1949
        formatUsageCounter(el->secHostPkts->icmpFragmentRcvd, 0, actualDeviceId);
 
1950
        sendString("</TR>\n");
 
1951
      }
 
1952
 
 
1953
      if((el->secHostPkts->overlappingFragmentSent.value.value+
 
1954
          el->secHostPkts->overlappingFragmentRcvd.value.value) > 0) {
 
1955
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">Overlapping Fragments</TH>",
 
1956
                    getRowColor()) < 0) BufferTooShort();
 
1957
        sendString(buf);
 
1958
        formatUsageCounter(el->secHostPkts->overlappingFragmentSent, 0, actualDeviceId);
 
1959
        formatUsageCounter(el->secHostPkts->overlappingFragmentRcvd, 0, actualDeviceId);
 
1960
        sendString("</TR>\n");
 
1961
      }
 
1962
 
 
1963
      if((el->secHostPkts->closedEmptyTCPConnSent.value.value+
 
1964
          el->secHostPkts->closedEmptyTCPConnRcvd.value.value) > 0) {
 
1965
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">Closed Empty TCP Conn.</TH>",
 
1966
                    getRowColor()) < 0) BufferTooShort();
 
1967
        sendString(buf);
 
1968
        formatUsageCounter(el->secHostPkts->closedEmptyTCPConnSent, 0, actualDeviceId);
 
1969
        formatUsageCounter(el->secHostPkts->closedEmptyTCPConnRcvd, 0, actualDeviceId);
 
1970
        sendString("</TR>\n");
 
1971
      }
 
1972
 
 
1973
 
 
1974
      if((el->secHostPkts->icmpPortUnreachSent.value.value+
 
1975
          el->secHostPkts->icmpPortUnreachRcvd.value.value) > 0) {
 
1976
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">ICMP Port Unreachable</TH>",
 
1977
                    getRowColor()) < 0) BufferTooShort();
 
1978
        sendString(buf);
 
1979
        formatUsageCounter(el->secHostPkts->icmpPortUnreachSent, 0, actualDeviceId);
 
1980
        formatUsageCounter(el->secHostPkts->icmpPortUnreachRcvd, 0, actualDeviceId);
 
1981
        sendString("</TR>\n");
 
1982
      }
 
1983
 
 
1984
      if((el->secHostPkts->icmpHostNetUnreachSent.value.value+
 
1985
          el->secHostPkts->icmpHostNetUnreachRcvd.value.value) > 0) {
 
1986
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">ICMP Net Unreachable</TH>",
 
1987
                    getRowColor()) < 0) BufferTooShort();
 
1988
        sendString(buf);
 
1989
        formatUsageCounter(el->secHostPkts->icmpHostNetUnreachSent, 0, actualDeviceId);
 
1990
        formatUsageCounter(el->secHostPkts->icmpHostNetUnreachRcvd, 0, actualDeviceId);
 
1991
        sendString("</TR>\n");
 
1992
      }
 
1993
 
 
1994
      if((el->secHostPkts->icmpProtocolUnreachSent.value.value+
 
1995
          el->secHostPkts->icmpProtocolUnreachRcvd.value.value) > 0) {
 
1996
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">ICMP Protocol Unreachable</TH>",
 
1997
                    getRowColor()) < 0) BufferTooShort();
 
1998
        sendString(buf);
 
1999
        formatUsageCounter(el->secHostPkts->icmpProtocolUnreachSent, 0, actualDeviceId);
 
2000
        formatUsageCounter(el->secHostPkts->icmpProtocolUnreachRcvd, 0, actualDeviceId);
 
2001
        sendString("</TR>\n");
 
2002
      }
 
2003
 
 
2004
      if((el->secHostPkts->icmpAdminProhibitedSent.value.value+
 
2005
          el->secHostPkts->icmpAdminProhibitedRcvd.value.value) > 0) {
 
2006
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">ICMP Administratively Prohibited</TH>",
 
2007
                    getRowColor()) < 0) BufferTooShort();
 
2008
        sendString(buf);
 
2009
        formatUsageCounter(el->secHostPkts->icmpAdminProhibitedSent, 0, actualDeviceId);
 
2010
        formatUsageCounter(el->secHostPkts->icmpAdminProhibitedRcvd, 0, actualDeviceId);
 
2011
        sendString("</TR>\n");
 
2012
      }
 
2013
 
 
2014
      if((el->secHostPkts->malformedPktsSent.value.value+
 
2015
          el->secHostPkts->malformedPktsRcvd.value.value) > 0) {
 
2016
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">Malformed Pkts</TH>",
 
2017
                    getRowColor()) < 0) BufferTooShort();
 
2018
        sendString(buf);
 
2019
        formatUsageCounter(el->secHostPkts->malformedPktsSent, 0, actualDeviceId);
 
2020
        formatUsageCounter(el->secHostPkts->malformedPktsRcvd, 0, actualDeviceId);
 
2021
        sendString("</TR>\n");
 
2022
      }
 
2023
 
 
2024
      sendString("</TABLE>"TABLE_OFF"<P>\n");
 
2025
      sendString("</CENTER>\n");
 
2026
    }
 
2027
  }
 
2028
 
 
2029
  if(el->arpReqPktsSent.value+el->arpReplyPktsSent.value+el->arpReplyPktsRcvd.value > 0) {
 
2030
    if(!headerSent) {
 
2031
      printSectionTitle("Packet Statistics");
 
2032
      sendString(tableHeader);
 
2033
      headerSent = 1;
 
2034
    }
 
2035
 
 
2036
    sendString("<CENTER>\n"
 
2037
               ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\"><TR "TR_ON" "DARK_BG">"
 
2038
               "<TH "TH_BG">ARP</TH>"
 
2039
               "<TH "TH_BG">Packet</TH>"
 
2040
               "</TR>\n");
 
2041
 
 
2042
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT>Request Sent</TH>"
 
2043
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2044
                getRowColor(),
 
2045
                formatPkts(el->arpReqPktsSent.value, formatBuf, sizeof(formatBuf))) < 0)
 
2046
      BufferTooShort();
 
2047
    sendString(buf);
 
2048
 
 
2049
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT>Reply Rcvd</TH>"
 
2050
                "<TD "TD_BG" ALIGN=RIGHT>%s (%.1f %%)</TD></TR>",
 
2051
                getRowColor(),
 
2052
                formatPkts(el->arpReplyPktsRcvd.value, formatBuf, sizeof(formatBuf)),
 
2053
                ((el->arpReqPktsSent.value > 0) ?
 
2054
                (float)((el->arpReplyPktsRcvd.value*100)/(float)el->arpReqPktsSent.value) : 0)) < 0)
 
2055
      BufferTooShort();
 
2056
    sendString(buf);
 
2057
 
 
2058
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT>Reply Sent</TH>"
 
2059
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2060
                getRowColor(),
 
2061
                formatPkts(el->arpReplyPktsSent.value, formatBuf, sizeof(formatBuf))) < 0)
 
2062
      BufferTooShort();
 
2063
    sendString(buf);
 
2064
 
 
2065
    sendString("</TABLE>"TABLE_OFF"<P>\n");
 
2066
    sendString("</CENTER>\n");
 
2067
  }
 
2068
 
 
2069
  if(headerSent) { sendString("</TD></TR></TABLE>"TABLE_OFF"</CENTER>"); }
 
2070
}
 
2071
 
 
2072
/* ************************************ */
 
2073
 
 
2074
void printHostFragmentStats(HostTraffic *el, int actualDeviceId) {
 
2075
  Counter totalSent, totalRcvd;
 
2076
  char buf[LEN_GENERAL_WORK_BUFFER];
 
2077
  char linkName[LEN_GENERAL_WORK_BUFFER/2];
 
2078
  int i;
 
2079
 
 
2080
  totalSent = el->tcpFragmentsSent.value + el->udpFragmentsSent.value + el->icmpFragmentsSent.value;
 
2081
  totalRcvd = el->tcpFragmentsRcvd.value + el->udpFragmentsRcvd.value + el->icmpFragmentsRcvd.value;
 
2082
 
 
2083
 if((totalSent == 0) && (totalRcvd == 0))
 
2084
    return;
 
2085
 
 
2086
  printSectionTitle("IP Fragments Distribution");
 
2087
 
 
2088
  sendString("<CENTER>\n"
 
2089
             ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS"><TR "DARK_BG"><TH "TH_BG" WIDTH=100>Protocol</TH>"
 
2090
             "<TH "TH_BG" WIDTH=200 COLSPAN=2>Data&nbsp;Sent</TH>"
 
2091
             "<TH "TH_BG" WIDTH=200 COLSPAN=2>Data&nbsp;Rcvd</TH></TR>\n");
 
2092
 
 
2093
  printTableDoubleEntry(buf, sizeof(buf), "TCP", CONST_COLOR_1, (float)el->tcpFragmentsSent.value/1024,
 
2094
                        100*((float)SD(el->tcpFragmentsSent.value, totalSent)),
 
2095
                        (float)el->tcpFragmentsRcvd.value/1024,
 
2096
                        100*((float)SD(el->tcpFragmentsRcvd.value, totalRcvd)));
 
2097
 
 
2098
  printTableDoubleEntry(buf, sizeof(buf), "UDP", CONST_COLOR_1, (float)el->udpFragmentsSent.value/1024,
 
2099
                        100*((float)SD(el->udpFragmentsSent.value, totalSent)),
 
2100
                        (float)el->udpFragmentsRcvd.value/1024,
 
2101
                        100*((float)SD(el->udpFragmentsRcvd.value, totalRcvd)));
 
2102
 
 
2103
  printTableDoubleEntry(buf, sizeof(buf), "ICMP", CONST_COLOR_1, (float)el->icmpFragmentsSent.value/1024,
 
2104
                        100*((float)SD(el->icmpFragmentsSent.value, totalSent)),
 
2105
                        (float)el->icmpFragmentsRcvd.value/1024,
 
2106
                        100*((float)SD(el->icmpFragmentsRcvd.value, totalRcvd)));
 
2107
 
 
2108
  {
 
2109
    if((totalSent > 0) || (totalRcvd > 0)) {
 
2110
      if(snprintf(buf, sizeof(buf),
 
2111
                  "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT>Fragment Distribution</TH>",
 
2112
                  getRowColor()) < 0)
 
2113
        BufferTooShort();
 
2114
      sendString(buf);
 
2115
 
 
2116
      if(el->hostNumIpAddress[0] != '\0') {
 
2117
        strncpy(linkName, el->hostNumIpAddress, sizeof(linkName));
 
2118
      } else {
 
2119
        strncpy(linkName, el->ethAddressString, sizeof(linkName));
 
2120
      }
 
2121
 
 
2122
      /* For Ethernet and IPv6 addresses */
 
2123
      urlFixupToRFC1945Inplace(linkName);
 
2124
 
 
2125
      if(totalSent > 0) {
 
2126
        if(snprintf(buf, sizeof(buf),
 
2127
                    "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2 BGCOLOR=white>"
 
2128
                    "<IMG SRC=hostFragmentDistrib-%s"CHART_FORMAT"?1 ALT=\"Sent Fragment Distribution for %s\"></TD>",
 
2129
                    linkName, el->hostNumIpAddress[0] == '\0' ?  el->ethAddressString : el->hostNumIpAddress) < 0)
 
2130
          BufferTooShort();
 
2131
        sendString(buf);
 
2132
      } else {
 
2133
        sendString("<TD "TD_BG" ALIGN=RIGHT COLSPAN=2>&nbsp;</TD>");
 
2134
      }
 
2135
 
 
2136
      if(totalRcvd > 0) {
 
2137
        if(snprintf(buf, sizeof(buf),
 
2138
                    "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2 BGCOLOR=white>"
 
2139
                    "<IMG SRC=hostFragmentDistrib-%s"CHART_FORMAT" ALT=\"Received Fragment Distribution for %s\"></TD>",
 
2140
                    linkName, el->hostNumIpAddress[0] == '\0' ?  el->ethAddressString : el->hostNumIpAddress) < 0)
 
2141
          BufferTooShort();
 
2142
        sendString(buf);
 
2143
      } else {
 
2144
        sendString("<TD "TD_BG" ALIGN=RIGHT COLSPAN=2>&nbsp;</TD>");
 
2145
      }
 
2146
 
 
2147
      sendString("</TD></TR>");
 
2148
 
 
2149
      /* ***************************************** */
 
2150
 
 
2151
      if(snprintf(buf, sizeof(buf),
 
2152
                  "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT>IP Fragment Distribution</TH>",
 
2153
                  getRowColor()) < 0)
 
2154
        BufferTooShort();
 
2155
      sendString(buf);
 
2156
 
 
2157
      if(totalSent > 0) {
 
2158
        if(snprintf(buf, sizeof(buf),
 
2159
                    "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2 BGCOLOR=white>"
 
2160
                    "<IMG SRC=hostTotalFragmentDistrib-%s"CHART_FORMAT"?1 ALT=\"Sent IP Fragment Distribution for %s\"></TD>",
 
2161
                    linkName, el->hostNumIpAddress[0] == '\0' ?  el->ethAddressString : el->hostNumIpAddress) < 0)
 
2162
          BufferTooShort();
 
2163
        sendString(buf);
 
2164
      } else {
 
2165
        sendString("<TD "TD_BG" ALIGN=RIGHT COLSPAN=2>&nbsp;</TD>");
 
2166
      }
 
2167
 
 
2168
      if(totalRcvd > 0) {
 
2169
        if(snprintf(buf, sizeof(buf),
 
2170
                    "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2 BGCOLOR=white>"
 
2171
                    "<IMG SRC=hostTotalFragmentDistrib-%s"CHART_FORMAT" ALT=\"Received IP Fragment Distribution for %s\"></TD>",
 
2172
                    linkName, el->hostNumIpAddress[0] == '\0' ?  el->ethAddressString : el->hostNumIpAddress) < 0)
 
2173
          BufferTooShort();
 
2174
        sendString(buf);
 
2175
      } else {
 
2176
        sendString("<TD "TD_BG" ALIGN=RIGHT COLSPAN=2>&nbsp;</TD>");
 
2177
      }
 
2178
 
 
2179
      sendString("</TD></TR>");
 
2180
    }
 
2181
  }
 
2182
 
 
2183
  sendString("</TABLE>"TABLE_OFF"<P>\n");
 
2184
  sendString("</CENTER>\n");
 
2185
}
 
2186
 
 
2187
/* ************************************ */
 
2188
 
 
2189
static char* sap2name(u_int16_t proto, char *sap, int sap_len) {
 
2190
  switch(proto) {
 
2191
  case SAP_NULL:
 
2192
    if(snprintf(sap, sap_len, "NULL LSAP") < 0)
 
2193
      BufferTooShort();
 
2194
    break;
 
2195
  case SAP_LLC_SLMGMT:
 
2196
    if(snprintf(sap, sap_len, "LLC Sub-Layer Management") < 0)
 
2197
      BufferTooShort();
 
2198
    break;
 
2199
  case SAP_SNA_PATHCTRL:
 
2200
    if(snprintf(sap, sap_len, "SNA Path Control") < 0)
 
2201
      BufferTooShort();
 
2202
    break;
 
2203
  case SAP_IP:
 
2204
    if(snprintf(sap, sap_len, "TCP/IP") < 0)
 
2205
      BufferTooShort();
 
2206
    break;
 
2207
  case SAP_SNA1:
 
2208
    if(snprintf(sap, sap_len, "SNA") < 0)
 
2209
      BufferTooShort();
 
2210
    break;
 
2211
  case SAP_SNA2:
 
2212
    if(snprintf(sap, sap_len, "SNA") < 0)
 
2213
      BufferTooShort();
 
2214
    break;
 
2215
  case SAP_PROWAY_NM_INIT:
 
2216
    if(snprintf(sap, sap_len, "PROWAY (IEC955) Network Management and Initialization") < 0)
 
2217
      BufferTooShort();
 
2218
    break;
 
2219
  case SAP_TI:
 
2220
    if(snprintf(sap, sap_len, "Texas Instruments") < 0)
 
2221
      BufferTooShort();
 
2222
    break;
 
2223
  case SAP_BPDU:
 
2224
    if(snprintf(sap, sap_len, "Spanning Tree BPDU") < 0)
 
2225
      BufferTooShort();
 
2226
    break;
 
2227
  case SAP_RS511:
 
2228
    if(snprintf(sap, sap_len, "EIA RS-511 Manufacturing Message Service") < 0)
 
2229
      BufferTooShort();
 
2230
    break;
 
2231
  case SAP_X25:
 
2232
    if(snprintf(sap, sap_len, "ISO 8208 (X.25 over 802.2)") < 0)
 
2233
      BufferTooShort();
 
2234
    break;
 
2235
  case 0x7F:
 
2236
    if(snprintf(sap, sap_len, "ISO 802.2") < 0)
 
2237
      BufferTooShort();
 
2238
    break;
 
2239
  case SAP_XNS:
 
2240
    if(snprintf(sap, sap_len, "XNS") < 0)
 
2241
      BufferTooShort();
 
2242
    break;
 
2243
  case SAP_BACNET:
 
2244
    if(snprintf(sap, sap_len, "BACnet") < 0)
 
2245
      BufferTooShort();
 
2246
    break;
 
2247
  case SAP_NESTAR:
 
2248
    if(snprintf(sap, sap_len, "Nestar") < 0)
 
2249
      BufferTooShort();
 
2250
    break;
 
2251
  case SAP_PROWAY_ASLM:
 
2252
    if(snprintf(sap, sap_len, "PROWAY (IEC955) Active Station List Maintenance") < 0)
 
2253
      BufferTooShort();
 
2254
    break;
 
2255
  case SAP_ARP:
 
2256
    if(snprintf(sap, sap_len, "ARP") < 0)
 
2257
      BufferTooShort();
 
2258
    break;
 
2259
  case SAP_SNAP:
 
2260
    if(snprintf(sap, sap_len, "SNAP") < 0)
 
2261
      BufferTooShort();
 
2262
    break;
 
2263
  case SAP_VINES1:
 
2264
  case SAP_VINES2:
 
2265
    if(snprintf(sap, sap_len, "Banyan Vines") < 0)
 
2266
      BufferTooShort();
 
2267
    break;
 
2268
  case SAP_NETWARE:
 
2269
    if(snprintf(sap, sap_len, "NetWare") < 0)
 
2270
      BufferTooShort();
 
2271
    break;
 
2272
  case SAP_NETBIOS:
 
2273
    if(snprintf(sap, sap_len, "NetBIOS") < 0)
 
2274
      BufferTooShort();
 
2275
    break;
 
2276
  case SAP_IBMNM:
 
2277
    if(snprintf(sap, sap_len, "IBM Net Management") < 0)
 
2278
      BufferTooShort();
 
2279
    break;
 
2280
  case SAP_HPEXT:
 
2281
    if(snprintf(sap, sap_len, "HP Extended LLC") < 0)
 
2282
      BufferTooShort();
 
2283
    break;
 
2284
  case SAP_UB:
 
2285
    if(snprintf(sap, sap_len, "Ungermann-Bass") < 0)
 
2286
      BufferTooShort();
 
2287
    break;
 
2288
  case SAP_RPL:
 
2289
    if(snprintf(sap, sap_len, "Remote Program Load") < 0)
 
2290
      BufferTooShort();
 
2291
    break;
 
2292
  case SAP_OSINL:
 
2293
    if(snprintf(sap, sap_len, "ISO Network Layer") < 0)
 
2294
      BufferTooShort();
 
2295
    break;
 
2296
  case SAP_GLOBAL:
 
2297
    if(snprintf(sap, sap_len, "Global LSAP") < 0)
 
2298
      BufferTooShort();
 
2299
    break;
 
2300
  default:
 
2301
    if(snprintf(sap, sap_len, "0x%X", proto) < 0)
 
2302
      BufferTooShort();
 
2303
    break;
 
2304
  }
 
2305
 
 
2306
  return(sap);
 
2307
}
 
2308
 
 
2309
/* ************************************ */
 
2310
 
 
2311
static void printUnknownProto(UnknownProto proto) {
 
2312
  char buf[64];
 
2313
 
 
2314
  switch(proto.protoType) {
 
2315
  case 1:
 
2316
    if(snprintf(buf, sizeof(buf), "<li>Ethernet Type: 0x%04X\n", proto.proto.ethType) < 0)
 
2317
      BufferTooShort();
 
2318
    break;
 
2319
  case 2:
 
2320
    if(snprintf(buf, sizeof(buf), "<li>SAP: DSAP=0x%02X/SSAP=0x%02X\n",
 
2321
             proto.proto.sapType.dsap, proto.proto.sapType.ssap) < 0)
 
2322
      BufferTooShort();
 
2323
    break;
 
2324
  case 3:
 
2325
    if(snprintf(buf, sizeof(buf), "<li>IP Protocol: 0x%d\n", proto.proto.ipType) < 0)
 
2326
      BufferTooShort();
 
2327
    break;
 
2328
  default:
 
2329
    return;
 
2330
  }
 
2331
 
 
2332
  sendString(buf);
 
2333
}
 
2334
 
 
2335
/* ************************************ */
 
2336
 
 
2337
void printHostTrafficStats(HostTraffic *el, int actualDeviceId) {
 
2338
  Counter totalSent, totalRcvd;
 
2339
  Counter actTotalSent, actTotalRcvd;
 
2340
  char buf[LEN_GENERAL_WORK_BUFFER];
 
2341
  char linkName[LEN_GENERAL_WORK_BUFFER/2];
 
2342
  int i, idx;
 
2343
  ProtocolsList *protoList;
 
2344
 
 
2345
  totalSent = el->tcpSentLoc.value+el->tcpSentRem.value+el->udpSentLoc.value+el->udpSentRem.value;
 
2346
  totalSent += el->icmpSent.value+el->icmp6Sent.value+el->ipxSent.value+el->dlcSent.value+el->arp_rarpSent.value;
 
2347
  totalSent +=  el->decnetSent.value+el->appletalkSent.value+el->netbiosSent.value+
 
2348
    el->osiSent.value+el->ipv6Sent.value+el->stpSent.value+el->otherSent.value;
 
2349
 
 
2350
  totalRcvd = el->tcpRcvdLoc.value+el->tcpRcvdFromRem.value;
 
2351
  totalRcvd += el->udpRcvdLoc.value+el->udpRcvdFromRem.value;
 
2352
  totalRcvd += el->icmpRcvd.value+el->icmp6Rcvd.value;
 
2353
  totalRcvd += el->ipxRcvd.value+el->dlcRcvd.value+el->arp_rarpRcvd.value;
 
2354
  totalRcvd += el->decnetRcvd.value+el->appletalkRcvd.value;
 
2355
  totalRcvd += el->osiRcvd.value+el->netbiosRcvd.value+el->ipv6Rcvd.value
 
2356
    +el->stpRcvd.value+el->otherRcvd.value;
 
2357
 
 
2358
  protoList = myGlobals.ipProtosList;
 
2359
  idx = 0;
 
2360
 
 
2361
  while(protoList != NULL) {
 
2362
    totalSent += el->ipProtosList[idx].sent.value;
 
2363
    totalRcvd += el->ipProtosList[idx].rcvd.value;
 
2364
    idx++, protoList = protoList->next;
 
2365
  }
 
2366
 
 
2367
  actTotalSent = el->tcpSentLoc.value+el->tcpSentRem.value;
 
2368
  actTotalRcvd = el->tcpRcvdLoc.value+el->tcpRcvdFromRem.value;
 
2369
 
 
2370
  printHostHourlyTraffic(el);
 
2371
  printPacketStats(el, actualDeviceId);
 
2372
 
 
2373
  if((totalSent == 0) && (totalRcvd == 0))
 
2374
    return;
 
2375
 
 
2376
  printSectionTitle("Protocol Distribution");
 
2377
 
 
2378
  sendString("<CENTER>\n"
 
2379
             ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=80%%><TR "DARK_BG"><TH "TH_BG" WIDTH=100>Protocol</TH>"
 
2380
             "<TH "TH_BG" WIDTH=200 COLSPAN=2>Data&nbsp;Sent</TH>"
 
2381
             "<TH "TH_BG" WIDTH=200 COLSPAN=2>Data&nbsp;Rcvd</TH></TR>\n");
 
2382
 
 
2383
  printTableDoubleEntry(buf, sizeof(buf), "TCP", CONST_COLOR_1, (float)actTotalSent/1024,
 
2384
                        100*((float)SD(actTotalSent, totalSent)),
 
2385
                        (float)actTotalRcvd/1024,
 
2386
                        100*((float)SD(actTotalRcvd, totalRcvd)));
 
2387
 
 
2388
  actTotalSent = el->udpSentLoc.value+el->udpSentRem.value;
 
2389
  actTotalRcvd = el->udpRcvdLoc.value+el->udpRcvdFromRem.value;
 
2390
 
 
2391
  printTableDoubleEntry(buf, sizeof(buf), "UDP", CONST_COLOR_1, (float)actTotalSent/1024,
 
2392
                        100*((float)SD(actTotalSent, totalSent)),
 
2393
                        (float)actTotalRcvd/1024,
 
2394
                        100*((float)SD(actTotalRcvd, totalRcvd)));
 
2395
 
 
2396
  printTableDoubleEntry(buf, sizeof(buf), "ICMP", CONST_COLOR_1, (float)el->icmpSent.value/1024,
 
2397
                        100*((float)SD(el->icmpSent.value, totalSent)),
 
2398
                        (float)el->icmpRcvd.value/1024,
 
2399
                        100*((float)SD(el->icmpRcvd.value, totalRcvd)));
 
2400
 
 
2401
  printTableDoubleEntry(buf, sizeof(buf), "ICMPv6", CONST_COLOR_1, (float)el->icmp6Sent.value/1024,
 
2402
                        100*((float)SD(el->icmp6Sent.value, totalSent)),
 
2403
                        (float)el->icmp6Rcvd.value/1024,
 
2404
                        100*((float)SD(el->icmp6Rcvd.value, totalRcvd)));
 
2405
 
 
2406
  printTableDoubleEntry(buf, sizeof(buf), "(R)ARP", CONST_COLOR_1, (float)el->arp_rarpSent.value/1024,
 
2407
                        100*((float)SD(el->arp_rarpSent.value, totalSent)),
 
2408
                        (float)el->arp_rarpRcvd.value/1024,
 
2409
                        100*((float)SD(el->arp_rarpRcvd.value, totalRcvd)));
 
2410
 
 
2411
  printTableDoubleEntry(buf, sizeof(buf), "DLC", CONST_COLOR_1, (float)el->dlcSent.value/1024,
 
2412
                        100*((float)SD(el->dlcSent.value, totalSent)),
 
2413
                        (float)el->dlcRcvd.value/1024,
 
2414
                        100*((float)SD(el->dlcRcvd.value, totalRcvd)));
 
2415
 
 
2416
  printTableDoubleEntry(buf, sizeof(buf), "IPX", CONST_COLOR_1, (float)el->ipxSent.value/1024,
 
2417
                        100*((float)SD(el->ipxSent.value, totalSent)),
 
2418
                        (float)el->ipxRcvd.value/1024,
 
2419
                        100*((float)SD(el->ipxRcvd.value, totalRcvd)));
 
2420
 
 
2421
  printTableDoubleEntry(buf, sizeof(buf), "Decnet", CONST_COLOR_1, (float)el->decnetSent.value/1024,
 
2422
                        100*((float)SD(el->decnetSent.value, totalSent)),
 
2423
                        (float)el->decnetRcvd.value/1024,
 
2424
                        100*((float)SD(el->decnetRcvd.value, totalRcvd)));
 
2425
 
 
2426
  printTableDoubleEntry(buf, sizeof(buf), "AppleTalk", CONST_COLOR_1, (float)el->appletalkSent.value/1024,
 
2427
                        100*((float)SD(el->appletalkSent.value, totalSent)),
 
2428
                        (float)el->appletalkRcvd.value/1024,
 
2429
                        100*((float)SD(el->appletalkRcvd.value, totalRcvd)));
 
2430
 
 
2431
  printTableDoubleEntry(buf, sizeof(buf), "NetBios", CONST_COLOR_1, (float)el->netbiosSent.value/1024,
 
2432
                        100*((float)SD(el->netbiosSent.value, totalSent)),
 
2433
                        (float)el->netbiosRcvd.value/1024,
 
2434
                        100*((float)SD(el->netbiosRcvd.value, totalRcvd)));
 
2435
 
 
2436
  printTableDoubleEntry(buf, sizeof(buf), "OSI", CONST_COLOR_1, (float)el->osiSent.value/1024,
 
2437
                        100*((float)SD(el->osiSent.value, totalSent)),
 
2438
                        (float)el->osiRcvd.value/1024,
 
2439
                        100*((float)SD(el->osiRcvd.value, totalRcvd)));
 
2440
 
 
2441
  printTableDoubleEntry(buf, sizeof(buf), "IPv6", CONST_COLOR_1, (float)el->ipv6Sent.value/1024,
 
2442
                        100*((float)SD(el->ipv6Sent.value, totalSent)),
 
2443
                        (float)el->ipv6Rcvd.value/1024,
 
2444
                        100*((float)SD(el->ipv6Rcvd.value, totalRcvd)));
 
2445
 
 
2446
  printTableDoubleEntry(buf, sizeof(buf), "STP", CONST_COLOR_1, (float)el->stpSent.value/1024,
 
2447
                        100*((float)SD(el->stpSent.value, totalSent)),
 
2448
                        (float)el->stpRcvd.value/1024,
 
2449
                        100*((float)SD(el->stpRcvd.value, totalRcvd)));
 
2450
 
 
2451
  {
 
2452
    protoList = myGlobals.ipProtosList;
 
2453
    idx = 0;
 
2454
 
 
2455
    while(protoList != NULL) {
 
2456
      printTableDoubleEntry(buf, sizeof(buf), protoList->protocolName, CONST_COLOR_1,
 
2457
                            (float)el->ipProtosList[idx].sent.value/1024,
 
2458
                            100*((float)SD(el->ipProtosList[idx].sent.value, totalSent)),
 
2459
                            (float)el->ipProtosList[idx].rcvd.value/1024,
 
2460
                            100*((float)SD(el->ipProtosList[idx].rcvd.value, totalRcvd)));
 
2461
      idx++, protoList = protoList->next;
 
2462
    }
 
2463
  }
 
2464
 
 
2465
  printTableDoubleEntry(buf, sizeof(buf), "Other (Non IP)", CONST_COLOR_1, (float)el->otherSent.value/1024,
 
2466
                        100*((float)SD(el->otherSent.value, totalSent)),
 
2467
                        (float)el->otherRcvd.value/1024,
 
2468
                        100*((float)SD(el->otherRcvd.value, totalRcvd)));
 
2469
 
 
2470
  {
 
2471
    totalSent = el->tcpSentLoc.value+el->tcpSentRem.value+
 
2472
      el->udpSentLoc.value+el->udpSentRem.value+
 
2473
      el->icmpSent.value+el->icmp6Sent.value+el->stpSent.value+
 
2474
      el->ipxSent.value+el->osiSent.value+el->dlcSent.value+
 
2475
      el->arp_rarpSent.value+el->decnetSent.value+el->appletalkSent.value+
 
2476
      el->netbiosSent.value+el->ipv6Sent.value+el->otherSent.value;
 
2477
 
 
2478
    totalRcvd = el->tcpRcvdLoc.value+el->tcpRcvdFromRem.value+
 
2479
      el->udpRcvdLoc.value+el->udpRcvdFromRem.value+
 
2480
      el->icmpRcvd.value+el->icmp6Rcvd.value+el->stpRcvd.value+
 
2481
      el->ipxRcvd.value+el->osiRcvd.value+el->dlcRcvd.value+
 
2482
      el->arp_rarpRcvd.value+el->decnetRcvd.value+el->appletalkRcvd.value+
 
2483
      el->netbiosRcvd.value+el->ipv6Rcvd.value+el->otherRcvd.value;
 
2484
 
 
2485
    protoList = myGlobals.ipProtosList;
 
2486
    idx = 0;
 
2487
 
 
2488
    while(protoList != NULL) {
 
2489
      totalSent += el->ipProtosList[idx].sent.value;
 
2490
      totalRcvd += el->ipProtosList[idx].rcvd.value;
 
2491
      idx++, protoList = protoList->next;
 
2492
    }
 
2493
 
 
2494
    if((totalSent > 0) || (totalRcvd > 0)) {
 
2495
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">Protocol Distribution</TH>",
 
2496
                  getRowColor()) < 0)
 
2497
        BufferTooShort();
 
2498
      sendString(buf);
 
2499
 
 
2500
      if(el->hostNumIpAddress[0] != '\0') {
 
2501
        strncpy(linkName, el->hostNumIpAddress, sizeof(linkName));
 
2502
      } else {
 
2503
        strncpy(linkName, el->ethAddressString, sizeof(linkName));
 
2504
      }
 
2505
 
 
2506
      /* For Ethernet and Ipv6 addresses */
 
2507
      urlFixupToRFC1945Inplace(linkName);
 
2508
 
 
2509
      if(totalSent > 0) {
 
2510
        if(snprintf(buf, sizeof(buf),
 
2511
                    "<TD WIDTH=250 "TD_BG" ALIGN=RIGHT COLSPAN=2 BGCOLOR=white>"
 
2512
                    "<IMG SRC=\"hostTrafficDistrib-%s"CHART_FORMAT"?1\" "
 
2513
                    "ALT=\"Sent Traffic Distribution for %s\"></TD>",
 
2514
                    linkName,
 
2515
                    el->hostNumIpAddress[0] == '\0' ?  el->ethAddressString : el->hostNumIpAddress) < 0)
 
2516
          BufferTooShort();
 
2517
        sendString(buf);
 
2518
      } else {
 
2519
        sendString("<TD width=250 "TD_BG" ALIGN=RIGHT COLSPAN=2 WIDTH=250>&nbsp;</TD>");
 
2520
      }
 
2521
 
 
2522
      if(totalRcvd > 0) {
 
2523
        if(snprintf(buf, sizeof(buf),
 
2524
                    "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2 BGCOLOR=white><IMG SRC=hostTrafficDistrib-"
 
2525
                    "%s"CHART_FORMAT" ALT=\"Received Traffic Distribution for %s\"></TD>",
 
2526
                    linkName,
 
2527
                    el->hostNumIpAddress[0] == '\0' ?  el->ethAddressString : el->hostNumIpAddress) < 0)
 
2528
          BufferTooShort();
 
2529
        sendString(buf);
 
2530
      } else {
 
2531
        sendString("<TD "TD_BG" ALIGN=RIGHT COLSPAN=2 WIDTH=250>&nbsp;</TD>");
 
2532
      }
 
2533
 
 
2534
      sendString("</TD></TR>");
 
2535
 
 
2536
      if((el->tcpSentLoc.value+el->tcpSentRem.value+el->udpSentLoc.value+el->udpSentRem.value
 
2537
          +el->tcpRcvdLoc.value+el->tcpRcvdFromRem.value+el->udpRcvdLoc.value+el->udpRcvdFromRem.value) > 0) {
 
2538
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">IP Distribution</TH>",
 
2539
                    getRowColor()) < 0)
 
2540
          BufferTooShort();
 
2541
        sendString(buf);
 
2542
 
 
2543
        if((el->tcpSentLoc.value+el->tcpSentRem.value+el->udpSentLoc.value+el->udpSentRem.value) > 0) {
 
2544
          if(snprintf(buf, sizeof(buf),
 
2545
                      "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2 BGCOLOR=white>"
 
2546
                      "<IMG SRC=\"hostIPTrafficDistrib-%s"CHART_FORMAT"?1\" ALT=\"Sent IP Traffic Distribution for %s\"></TD>",
 
2547
                      linkName, el->hostNumIpAddress) < 0)
 
2548
            BufferTooShort();
 
2549
          sendString(buf);
 
2550
        } else
 
2551
          sendString("<TD "TD_BG" COLSPAN=2 WIDTH=250>&nbsp;</TD>");
 
2552
 
 
2553
        if((el->tcpRcvdLoc.value+el->tcpRcvdFromRem.value+el->udpRcvdLoc.value+el->udpRcvdFromRem.value) > 0) {
 
2554
          if(snprintf(buf, sizeof(buf),
 
2555
                      "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2 BGCOLOR=white><IMG SRC=hostIPTrafficDistrib-"
 
2556
                      "%s"CHART_FORMAT" ALT=\"Received IP Traffic Distribution for %s\"></TD></TR>",
 
2557
                      linkName, el->hostNumIpAddress) < 0)
 
2558
            BufferTooShort();
 
2559
          sendString(buf);
 
2560
        } else
 
2561
          sendString("<TD "TD_BG" COLSPAN=2 WIDTH=250>&nbsp;</TD>");
 
2562
 
 
2563
        sendString("</TR>");
 
2564
      }
 
2565
    }
 
2566
  }
 
2567
 
 
2568
  sendString("</TABLE>"TABLE_OFF"<P>\n");
 
2569
  sendString("</CENTER>\n");
 
2570
 
 
2571
  /* ************************************** */
 
2572
 
 
2573
  if(el->nonIpProtoTrafficInfos != NULL) {
 
2574
    NonIpProtoTrafficInfo *nonIp = el->nonIpProtoTrafficInfos;
 
2575
 
 
2576
    printSectionTitle("Non IP Protocol Distribution");
 
2577
 
 
2578
    sendString("<CENTER>\n"
 
2579
               ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS"><TR "DARK_BG" "DARK_BG"><TH "TH_BG" WIDTH=100>Protocol</TH>"
 
2580
               "<TH "TH_BG" WIDTH=200 COLSPAN=2>Data&nbsp;Sent</TH>"
 
2581
               "<TH "TH_BG" WIDTH=200 COLSPAN=2>Data&nbsp;Rcvd</TH></TR>\n");
 
2582
 
 
2583
    while(nonIp != NULL) {
 
2584
      char buf1[64];
 
2585
 
 
2586
      printTableDoubleEntry(buf, sizeof(buf), sap2name(nonIp->protocolId, buf1, sizeof(buf1)),
 
2587
                            CONST_COLOR_1, (float)nonIp->sentBytes.value/1024,
 
2588
                            100*((float)SD(nonIp->sentBytes.value, el->otherSent.value)),
 
2589
                            (float)nonIp->rcvdBytes.value/1024,
 
2590
                            100*((float)SD(nonIp->rcvdBytes.value, el->otherRcvd.value)));
 
2591
 
 
2592
      nonIp = nonIp->next;
 
2593
    }
 
2594
 
 
2595
    sendString("</TABLE>"TABLE_OFF"<P>\n");
 
2596
    sendString("</CENTER>\n");
 
2597
  }
 
2598
 
 
2599
 /* ************************************** */
 
2600
 
 
2601
  if(el->unknownProtoSent || el->unknownProtoRcvd) {
 
2602
    printSectionTitle("Unknown Protocols");
 
2603
 
 
2604
    sendString("<CENTER>\n"
 
2605
               ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS"><TR "DARK_BG">"
 
2606
               "<TH "TH_BG" WIDTH=200>Data&nbsp;Sent</TH>"
 
2607
               "<TH "TH_BG" WIDTH=200>Data&nbsp;Rcvd</TH></TR>\n");
 
2608
 
 
2609
    if(el->unknownProtoSent == NULL) {
 
2610
      sendString("<TR><TH "TH_BG">&nbsp;</TH>");
 
2611
    } else {
 
2612
      sendString("<TR><TH "TH_BG" ALIGN=LEFT>");
 
2613
      for(i=0; i<MAX_NUM_UNKNOWN_PROTOS; i++)
 
2614
        printUnknownProto(el->unknownProtoSent[i]);
 
2615
      sendString("&nbsp;</TH>");
 
2616
    }
 
2617
 
 
2618
    if(el->unknownProtoRcvd == NULL) {
 
2619
      sendString("<TH "TH_BG">&nbsp;</TH></TR>");
 
2620
    } else {
 
2621
      sendString("<TH "TH_BG" ALIGN=LEFT>");
 
2622
      for(i=0; i<MAX_NUM_UNKNOWN_PROTOS; i++)
 
2623
        printUnknownProto(el->unknownProtoRcvd[i]);
 
2624
      sendString("&nbsp;</TH></TR>");
 
2625
    }
 
2626
 
 
2627
    sendString("</TABLE>"TABLE_OFF"<P>\n");
 
2628
    sendString("</CENTER>\n");
 
2629
  }
 
2630
}
 
2631
 
 
2632
/* ************************************ */
 
2633
 
 
2634
#ifdef INET6
 
2635
void printIcmpv6Stats(HostTraffic *el) {
 
2636
  char buf[LEN_GENERAL_WORK_BUFFER], formatBuf[32], formatBuf1[32];
 
2637
 
 
2638
  sendString("<CENTER>\n<H1>ICMPv6 Traffic</H1><p>\n");
 
2639
  sendString("<TABLE BORDER=1 "TABLE_DEFAULTS">\n");
 
2640
  sendString("<TR "TR_ON" "DARK_BG"><th>Type</th>"
 
2641
             "<TH "TH_BG" ALIGN=LEFT>Pkt&nbsp;Sent</TH>"
 
2642
             "<TH "TH_BG" ALIGN=LEFT>Pkt&nbsp;Rcvd</TH></TR>\n");
 
2643
 
 
2644
  if(el->icmpInfo->icmpMsgSent[ICMP6_ECHO_REQUEST].value+el->icmpInfo->icmpMsgRcvd[ICMP6_ECHO_REQUEST].value > 0) {
 
2645
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Echo Request</TH>"
 
2646
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2647
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP6_ECHO_REQUEST].value, formatBuf, sizeof(formatBuf)),
 
2648
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP6_ECHO_REQUEST].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2649
      BufferTooShort();
 
2650
    sendString(buf);
 
2651
  }
 
2652
 
 
2653
  if(el->icmpInfo->icmpMsgSent[ICMP6_ECHO_REPLY].value+el->icmpInfo->icmpMsgRcvd[ICMP6_ECHO_REPLY].value > 0) {
 
2654
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Echo Reply</TH>"
 
2655
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2656
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP6_ECHO_REPLY].value, formatBuf, sizeof(formatBuf)),
 
2657
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP6_ECHO_REPLY].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2658
      BufferTooShort();
 
2659
    sendString(buf);
 
2660
  }
 
2661
 
 
2662
  if(el->icmpInfo->icmpMsgSent[ICMP6_DST_UNREACH].value+el->icmpInfo->icmpMsgRcvd[ICMP6_DST_UNREACH].value > 0) {
 
2663
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Unreach</TH>"
 
2664
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2665
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP6_DST_UNREACH].value, formatBuf, sizeof(formatBuf)),
 
2666
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP6_DST_UNREACH].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2667
      BufferTooShort();
 
2668
    sendString(buf);
 
2669
  }
 
2670
 
 
2671
  if(el->icmpInfo->icmpMsgSent[ND_REDIRECT].value+el->icmpInfo->icmpMsgRcvd[ND_REDIRECT].value > 0) {
 
2672
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Redirect</TH>"
 
2673
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2674
                formatPkts(el->icmpInfo->icmpMsgSent[ND_REDIRECT].value, formatBuf, sizeof(formatBuf)),
 
2675
                formatPkts(el->icmpInfo->icmpMsgRcvd[ND_REDIRECT].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2676
      BufferTooShort();
 
2677
    sendString(buf);
 
2678
  }
 
2679
 
 
2680
  if(el->icmpInfo->icmpMsgSent[ND_ROUTER_ADVERT].value+el->icmpInfo->icmpMsgRcvd[ND_ROUTER_ADVERT].value > 0) {
 
2681
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Router Advertisement</TH>"
 
2682
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2683
                formatPkts(el->icmpInfo->icmpMsgSent[ND_ROUTER_ADVERT].value, formatBuf, sizeof(formatBuf)),
 
2684
                formatPkts(el->icmpInfo->icmpMsgRcvd[ND_ROUTER_ADVERT].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2685
      BufferTooShort();
 
2686
    sendString(buf);
 
2687
  }
 
2688
 
 
2689
  if(el->icmpInfo->icmpMsgSent[ND_ROUTER_SOLICIT].value+el->icmpInfo->icmpMsgRcvd[ND_ROUTER_SOLICIT].value > 0) {
 
2690
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Router solicitation</TH>"
 
2691
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2692
                formatPkts(el->icmpInfo->icmpMsgSent[ND_ROUTER_SOLICIT].value, formatBuf, sizeof(formatBuf)),
 
2693
                formatPkts(el->icmpInfo->icmpMsgRcvd[ND_ROUTER_SOLICIT].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2694
      BufferTooShort();
 
2695
    sendString(buf);
 
2696
  }
 
2697
 
 
2698
  if(el->icmpInfo->icmpMsgSent[ND_NEIGHBOR_SOLICIT].value+el->icmpInfo->icmpMsgRcvd[ND_NEIGHBOR_SOLICIT].value > 0) {
 
2699
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Neighbor solicitation</TH>"
 
2700
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2701
                formatPkts(el->icmpInfo->icmpMsgSent[ND_NEIGHBOR_SOLICIT].value, formatBuf, sizeof(formatBuf)),
 
2702
                formatPkts(el->icmpInfo->icmpMsgRcvd[ND_NEIGHBOR_SOLICIT].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2703
      BufferTooShort();
 
2704
    sendString(buf);
 
2705
  }
 
2706
 
 
2707
  if(el->icmpInfo->icmpMsgSent[ND_NEIGHBOR_ADVERT].value+el->icmpInfo->icmpMsgRcvd[ND_NEIGHBOR_ADVERT].value > 0) {
 
2708
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Neighbor advertisment</TH>"
 
2709
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2710
                formatPkts(el->icmpInfo->icmpMsgSent[ND_NEIGHBOR_ADVERT].value, formatBuf, sizeof(formatBuf)),
 
2711
                formatPkts(el->icmpInfo->icmpMsgRcvd[ND_NEIGHBOR_ADVERT].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2712
      BufferTooShort();
 
2713
    sendString(buf);
 
2714
  }
 
2715
  sendString("</TABLE>"TABLE_OFF"</CENTER>\n");
 
2716
}
 
2717
#endif
 
2718
 
 
2719
/* ******************************************** */
 
2720
 
 
2721
void printIcmpv4Stats(HostTraffic *el) {
 
2722
  char buf[LEN_GENERAL_WORK_BUFFER];
 
2723
  char formatBuf[32], formatBuf1[32];
 
2724
 
 
2725
  sendString("<CENTER>\n<H1>ICMP Traffic</H1><p>\n");
 
2726
  sendString("<TABLE BORDER=1 "TABLE_DEFAULTS">\n");
 
2727
  sendString("<TR "TR_ON" "DARK_BG"><th>Type</th>"
 
2728
             "<TH "TH_BG" ALIGN=LEFT>Pkt&nbsp;Sent</TH>"
 
2729
             "<TH "TH_BG" ALIGN=LEFT>Pkt&nbsp;Rcvd</TH></TR>\n");
 
2730
 
 
2731
  if(el->icmpInfo->icmpMsgSent[ICMP_ECHO].value+el->icmpInfo->icmpMsgRcvd[ICMP_ECHO].value > 0) {
 
2732
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Echo Request</TH>"
 
2733
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2734
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP_ECHO].value, formatBuf, sizeof(formatBuf)),
 
2735
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP_ECHO].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2736
      BufferTooShort();
 
2737
    sendString(buf);
 
2738
  }
 
2739
 
 
2740
  if(el->icmpInfo->icmpMsgSent[ICMP_ECHOREPLY].value+el->icmpInfo->icmpMsgRcvd[ICMP_ECHOREPLY].value > 0) {
 
2741
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Echo Reply</TH>"
 
2742
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2743
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP_ECHOREPLY].value, formatBuf, sizeof(formatBuf)),
 
2744
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP_ECHOREPLY].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2745
      BufferTooShort();
 
2746
    sendString(buf);
 
2747
  }
 
2748
 
 
2749
  if(el->icmpInfo->icmpMsgSent[ICMP_UNREACH].value+el->icmpInfo->icmpMsgRcvd[ICMP_UNREACH].value > 0) {
 
2750
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Unreach</TH>"
 
2751
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2752
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP_UNREACH].value, formatBuf, sizeof(formatBuf)),
 
2753
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP_UNREACH].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2754
      BufferTooShort();
 
2755
    sendString(buf);
 
2756
  }
 
2757
 
 
2758
  if(el->icmpInfo->icmpMsgSent[ICMP_REDIRECT].value+el->icmpInfo->icmpMsgRcvd[ICMP_REDIRECT].value > 0) {
 
2759
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Redirect</TH>"
 
2760
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2761
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP_REDIRECT].value, formatBuf, sizeof(formatBuf)),
 
2762
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP_REDIRECT].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2763
      BufferTooShort();
 
2764
    sendString(buf);
 
2765
  }
 
2766
 
 
2767
   if(el->icmpInfo->icmpMsgSent[ICMP_ROUTERADVERT].value+el->icmpInfo->icmpMsgRcvd[ICMP_ROUTERADVERT].value > 0) {
 
2768
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Router Advertisement</TH>"
 
2769
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2770
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP_ROUTERADVERT].value, formatBuf, sizeof(formatBuf)),
 
2771
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP_ROUTERADVERT].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2772
      BufferTooShort();
 
2773
    sendString(buf);
 
2774
  }
 
2775
 
 
2776
   if(el->icmpInfo->icmpMsgSent[ICMP_TIMXCEED].value+el->icmpInfo->icmpMsgRcvd[ICMP_TIMXCEED].value > 0) {
 
2777
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Time Exceeded</TH>"
 
2778
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2779
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP_TIMXCEED].value, formatBuf, sizeof(formatBuf)),
 
2780
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP_TIMXCEED].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2781
      BufferTooShort();
 
2782
    sendString(buf);
 
2783
  }
 
2784
 
 
2785
  if(el->icmpInfo->icmpMsgSent[ICMP_PARAMPROB].value+el->icmpInfo->icmpMsgRcvd[ICMP_PARAMPROB].value > 0) {
 
2786
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Parameter Problem</TH>"
 
2787
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2788
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP_PARAMPROB].value, formatBuf, sizeof(formatBuf)),
 
2789
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP_PARAMPROB].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2790
      BufferTooShort();
 
2791
    sendString(buf);
 
2792
  }
 
2793
 
 
2794
  if(el->icmpInfo->icmpMsgSent[ICMP_MASKREQ].value+el->icmpInfo->icmpMsgRcvd[ICMP_MASKREQ].value > 0) {
 
2795
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Network Mask Request</TH>"
 
2796
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2797
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP_MASKREQ].value, formatBuf, sizeof(formatBuf)),
 
2798
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP_MASKREQ].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2799
      BufferTooShort();
 
2800
    sendString(buf);
 
2801
  }
 
2802
 
 
2803
  if(el->icmpInfo->icmpMsgSent[ICMP_MASKREPLY].value+el->icmpInfo->icmpMsgRcvd[ICMP_MASKREPLY].value > 0) {
 
2804
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Network Mask Reply</TH>"
 
2805
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2806
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP_MASKREPLY].value, formatBuf, sizeof(formatBuf)),
 
2807
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP_MASKREPLY].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2808
      BufferTooShort();
 
2809
    sendString(buf);
 
2810
  }
 
2811
 
 
2812
  if(el->icmpInfo->icmpMsgSent[ICMP_SOURCE_QUENCH].value+el->icmpInfo->icmpMsgRcvd[ICMP_SOURCE_QUENCH].value > 0) {
 
2813
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Source Quench</TH>"
 
2814
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2815
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP_SOURCE_QUENCH].value, formatBuf, sizeof(formatBuf)),
 
2816
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP_SOURCE_QUENCH].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2817
      BufferTooShort();
 
2818
    sendString(buf);
 
2819
  }
 
2820
 
 
2821
  if(el->icmpInfo->icmpMsgSent[ICMP_TIMESTAMP].value+el->icmpInfo->icmpMsgRcvd[ICMP_TIMESTAMP].value > 0) {
 
2822
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Timestamp</TH>"
 
2823
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2824
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP_TIMESTAMP].value, formatBuf, sizeof(formatBuf)),
 
2825
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP_TIMESTAMP].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2826
      BufferTooShort();
 
2827
    sendString(buf);
 
2828
  }
 
2829
 
 
2830
  if(el->icmpInfo->icmpMsgSent[ICMP_INFO_REQUEST].value+el->icmpInfo->icmpMsgRcvd[ICMP_INFO_REQUEST].value > 0) {
 
2831
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Info Request</TH>"
 
2832
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2833
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP_INFO_REQUEST].value, formatBuf, sizeof(formatBuf)),
 
2834
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP_INFO_REQUEST].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2835
      BufferTooShort();
 
2836
    sendString(buf);
 
2837
  }
 
2838
 
 
2839
  if(el->icmpInfo->icmpMsgSent[ICMP_INFO_REPLY].value+el->icmpInfo->icmpMsgRcvd[ICMP_INFO_REPLY].value > 0) {
 
2840
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON"><TH "TH_BG" ALIGN=LEFT>Info Reply</TH>"
 
2841
                "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>",
 
2842
                formatPkts(el->icmpInfo->icmpMsgSent[ICMP_INFO_REPLY].value, formatBuf, sizeof(formatBuf)),
 
2843
                formatPkts(el->icmpInfo->icmpMsgRcvd[ICMP_INFO_REPLY].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
2844
      BufferTooShort();
 
2845
    sendString(buf);
 
2846
  }
 
2847
 
 
2848
  /************ ICMPv6 info*********************/
 
2849
 
 
2850
  sendString("</TABLE>"TABLE_OFF"</CENTER>\n");
 
2851
}
 
2852
 
 
2853
/* ************************************ */
 
2854
 
 
2855
void printHostIcmpStats(HostTraffic *el){
 
2856
  int family;
 
2857
 
 
2858
  if(el->icmpInfo == NULL) return;
 
2859
  family = el->hostIpAddress.hostFamily;
 
2860
  if (family == AF_INET)
 
2861
    printIcmpv4Stats(el);
 
2862
#ifdef INET6
 
2863
  else if (family == AF_INET6)
 
2864
    printIcmpv6Stats(el);
 
2865
#endif
 
2866
}
 
2867
 
 
2868
/* ************************************ */
 
2869
 
 
2870
void printHostHTTPVirtualHosts(HostTraffic *el, int actualDeviceId) {
 
2871
  char buf[LEN_GENERAL_WORK_BUFFER];
 
2872
  char formatBuf[32], formatBuf1[32];
 
2873
 
 
2874
  if((el->protocolInfo != NULL) && (el->protocolInfo->httpVirtualHosts != NULL)) {
 
2875
    VirtualHostList *list = el->protocolInfo->httpVirtualHosts;
 
2876
 
 
2877
    printSectionTitle("HTTP Virtual Hosts Traffic");
 
2878
    sendString("<CENTER>\n<TABLE BORDER=0 "TABLE_DEFAULTS"><TR><TD "TD_BG" VALIGN=TOP>\n");
 
2879
 
 
2880
    sendString(""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\">"
 
2881
               "<TR "TR_ON" "DARK_BG"><TH "TH_BG">Virtual Host</TH>"
 
2882
               "<TH "TH_BG">Sent</TH><TH "TH_BG">Rcvd</TH></TR>\n");
 
2883
 
 
2884
    while(list != NULL) {
 
2885
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
2886
                  "<TD "TD_BG" ALIGN=CENTER>%s&nbsp;</TD>"
 
2887
                  "<TD "TD_BG" ALIGN=CENTER>%s&nbsp;</TD></TR>\n",
 
2888
                  getRowColor(), list->virtualHostName,
 
2889
                  formatBytes(list->bytesSent.value, 1, formatBuf, sizeof(formatBuf)),
 
2890
                  formatBytes(list->bytesRcvd.value, 1, formatBuf1, sizeof(formatBuf1))) < 0)
 
2891
        BufferTooShort();
 
2892
      sendString(buf);
 
2893
      list = list->next;
 
2894
    }
 
2895
    sendString("</TABLE>"TABLE_OFF"\n");
 
2896
    sendString("<H5>NOTE: The above table is not updated in realtime but when connections are terminated.</H5>\n");
 
2897
    sendString("</CENTER><P>\n");
 
2898
  }
 
2899
}
 
2900
 
 
2901
/* ************************************ */
 
2902
 
 
2903
HostTraffic* quickHostLink(HostSerial theSerial, int deviceId, HostTraffic *el) {
 
2904
  HostTraffic *theEntry = NULL;
 
2905
  int found = 0, type;
 
2906
  FcNameServerCacheEntry *fcnsEntry;
 
2907
 
 
2908
  if(cmpSerial(&theSerial, &myGlobals.broadcastEntry->hostSerial)) {
 
2909
    memcpy(el, myGlobals.broadcastEntry, sizeof(HostTraffic));
 
2910
    return(el);
 
2911
  } else if(cmpSerial(&theSerial, &myGlobals.otherHostEntry->hostSerial)) {
 
2912
    memcpy(el, myGlobals.otherHostEntry, sizeof(HostTraffic));
 
2913
    return(0);
 
2914
  }
 
2915
 
 
2916
  memset(el, 0, sizeof(HostTraffic));
 
2917
  copySerial(&el->hostSerial, &theSerial);
 
2918
 
 
2919
  if((theSerial.serialType == SERIAL_IPV4) ||
 
2920
     (theSerial.serialType == SERIAL_IPV6)){
 
2921
    /* IP */
 
2922
    char sniffedName[MAXDNAME];
 
2923
    char buf[LEN_GENERAL_WORK_BUFFER];
 
2924
 
 
2925
    addrcpy(&el->hostIpAddress,&theSerial.value.ipAddress);
 
2926
    strncpy(el->hostNumIpAddress,
 
2927
            _addrtostr(&el->hostIpAddress, buf, sizeof(buf)),
 
2928
            sizeof(el->hostNumIpAddress));
 
2929
    if(myGlobals.numericFlag == 0) {
 
2930
      fetchAddressFromCache(el->hostIpAddress, el->hostResolvedName, &type);
 
2931
 
 
2932
      if(strcmp(el->hostResolvedName, el->hostNumIpAddress) == 0) {
 
2933
        if(getSniffedDNSName(el->hostNumIpAddress, sniffedName, sizeof(sniffedName))) {
 
2934
          int i;
 
2935
 
 
2936
          for(i=0; i<strlen(sniffedName); i++) if(isupper(sniffedName[i])) tolower(sniffedName[i]);
 
2937
          setResolvedName(el, sniffedName, FLAG_HOST_SYM_ADDR_TYPE_IP);
 
2938
        }
 
2939
      }
 
2940
    }
 
2941
  } else if (theSerial.serialType == SERIAL_FC) {
 
2942
    memcpy ((u_int8_t *)&el->hostFcAddress,
 
2943
            (u_int8_t *)&theSerial.value.fcSerial.fcAddress,
 
2944
            LEN_FC_ADDRESS);
 
2945
    sprintf (el->hostNumFcAddress, "%02x.%02x.%02x", el->hostFcAddress.domain,
 
2946
             el->hostFcAddress.area, el->hostFcAddress.port);
 
2947
    setResolvedName(el, el->hostNumFcAddress, FLAG_HOST_SYM_ADDR_TYPE_FC);
 
2948
//TODO ? FC_NUM????
 
2949
    el->vsanId = theSerial.value.fcSerial.vsanId;
 
2950
    
 
2951
    fcnsEntry = findFcHostNSCacheEntry (&el->hostFcAddress, el->vsanId);
 
2952
    if (fcnsEntry != NULL) {
 
2953
        setResolvedName(el, fcnsEntry->alias, FLAG_HOST_SYM_ADDR_TYPE_FC);
 
2954
        memcpy ((u_int8_t *)el->pWWN.str, (u_int8_t *)fcnsEntry->pWWN.str,
 
2955
                LEN_WWN_ADDRESS);
 
2956
    }
 
2957
    
 
2958
  } else {
 
2959
    /* MAC */
 
2960
    char *ethAddr;
 
2961
    char etherbuf[LEN_ETHERNET_ADDRESS_DISPLAY];
 
2962
 
 
2963
    memcpy(el->ethAddress, theSerial.value.ethAddress, LEN_ETHERNET_ADDRESS);
 
2964
    ethAddr = etheraddr_string(el->ethAddress, etherbuf);
 
2965
    strncpy(el->ethAddressString, ethAddr, sizeof(el->ethAddressString));
 
2966
    if (el->hostIpAddress.hostFamily == AF_INET)
 
2967
      el->hostIp4Address.s_addr = 0x1234; /* dummy */
 
2968
  }
 
2969
 
 
2970
  return(el);
 
2971
}
 
2972
 
 
2973
/* ************************************ */
 
2974
 
 
2975
void printHostContactedPeers(HostTraffic *el, int actualDeviceId) {
 
2976
  u_int i, titleSent = 0;
 
2977
  char buf[LEN_GENERAL_WORK_BUFFER], hostLinkBuf[LEN_GENERAL_WORK_BUFFER];
 
2978
  HostTraffic tmpEl;
 
2979
 
 
2980
  if (isFcHost (el)) {
 
2981
      printFcHostContactedPeers (el, actualDeviceId);
 
2982
      return;
 
2983
  }
 
2984
  
 
2985
  if((el->pktSent.value != 0) || (el->pktRcvd.value != 0)) {
 
2986
      int ok =0;
 
2987
 
 
2988
    for(i=0; i<MAX_NUM_CONTACTED_PEERS; i++)
 
2989
        if((!emptySerial(&el->contactedSentPeers.peersSerials[i])
 
2990
            && (!cmpSerial(&el->contactedSentPeers.peersSerials[i], &myGlobals.otherHostEntry->hostSerial))
 
2991
           || (!emptySerial(&el->contactedRcvdPeers.peersSerials[i])
 
2992
               && (!cmpSerial(&el->contactedRcvdPeers.peersSerials[i], &myGlobals.otherHostEntry->hostSerial))))) {
 
2993
          ok = 1;
 
2994
          break;
 
2995
        }
 
2996
 
 
2997
    if(ok) {
 
2998
      HostTraffic *el2;
 
2999
      int numEntries;
 
3000
 
 
3001
      for(numEntries = 0, i=0; i<MAX_NUM_CONTACTED_PEERS; i++)
 
3002
          if(!emptySerial(&el->contactedSentPeers.peersSerials[i])
 
3003
             && (!cmpSerial(&el->contactedSentPeers.peersSerials[i], &myGlobals.otherHostEntry->hostSerial))) {
 
3004
              if((el2 = quickHostLink(el->contactedSentPeers.peersSerials[i],
 
3005
                                      myGlobals.actualReportDeviceId, &tmpEl)) != NULL) {
 
3006
                  if(numEntries == 0) {
 
3007
                      printSectionTitle("Last Contacted Peers");
 
3008
                      titleSent = 1;
 
3009
                      sendString("<CENTER>\n<TABLE BORDER=0 "TABLE_DEFAULTS"><TR><TD "TD_BG" VALIGN=TOP>\n");
 
3010
 
 
3011
                      sendString(""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\">"
 
3012
                                 "<TR "TR_ON" "DARK_BG"><TH "TH_BG">Sent To</TH>"
 
3013
                                 "<TH "TH_BG">IP Address</TH></TR>\n");
 
3014
                  }
 
3015
 
 
3016
                  if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3017
                              "<TD "TD_BG" ALIGN=RIGHT>%s&nbsp;</TD></TR>\n",
 
3018
                              getRowColor(), makeHostLink(el2, 0, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)),
 
3019
                              el2->hostNumIpAddress) < 0)
 
3020
                      BufferTooShort();
 
3021
 
 
3022
                  sendString(buf);
 
3023
                  numEntries++;
 
3024
              }
 
3025
          }
 
3026
 
 
3027
      if(numEntries > 0) {
 
3028
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">Total Contacts</TH>"
 
3029
                    "<TD "TD_BG" ALIGN=RIGHT "DARK_BG">%lu</TD></TR>\n",
 
3030
                    getRowColor(), (unsigned long)el->totContactedSentPeers) < 0)
 
3031
          BufferTooShort();
 
3032
       sendString(buf);
 
3033
 
 
3034
       sendString("</TABLE>"TABLE_OFF"</TD><TD "TD_BG" VALIGN=TOP>\n");
 
3035
      } else
 
3036
        sendString("&nbsp;</TD><TD "TD_BG">\n");
 
3037
 
 
3038
      /* ***************************************************** */
 
3039
 
 
3040
      for(numEntries = 0, i=0; i<MAX_NUM_CONTACTED_PEERS; i++)
 
3041
          if((!emptySerial(&el->contactedRcvdPeers.peersSerials[i]))
 
3042
             && (!cmpSerial(&el->contactedRcvdPeers.peersSerials[i], &myGlobals.otherHostEntry->hostSerial))) {
 
3043
 
 
3044
            if((el2 = quickHostLink(el->contactedRcvdPeers.peersSerials[i],
 
3045
                                        myGlobals.actualReportDeviceId, &tmpEl)) != NULL) {
 
3046
              if(numEntries == 0) {
 
3047
                  if(!titleSent) printSectionTitle("Last Contacted Peers");
 
3048
                sendString("<CENTER>"TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS">"
 
3049
                           "<TR "TR_ON" "DARK_BG"><TH "TH_BG">Received From</TH>"
 
3050
                           "<TH "TH_BG">IP Address</TH></TR>\n");
 
3051
              }
 
3052
 
 
3053
              if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3054
                          "<TD "TD_BG" ALIGN=RIGHT>%s&nbsp;</TD></TR>\n",
 
3055
                          getRowColor(), makeHostLink(el2, 0, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)),
 
3056
                          el2->hostNumIpAddress) < 0)
 
3057
                BufferTooShort();
 
3058
 
 
3059
              sendString(buf);
 
3060
              numEntries++;
 
3061
            }
 
3062
          }
 
3063
 
 
3064
      if(numEntries > 0) {
 
3065
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">Total Contacts</TH>"
 
3066
                    "<TD "TD_BG" ALIGN=RIGHT "DARK_BG">%lu</TD></TR>\n",
 
3067
                    getRowColor(), (unsigned long)el->totContactedRcvdPeers) < 0)
 
3068
          BufferTooShort();
 
3069
        sendString(buf);
 
3070
 
 
3071
        sendString("</TABLE>"TABLE_OFF"\n");
 
3072
      }
 
3073
 
 
3074
      sendString("</TD></TR></TABLE>"TABLE_OFF"<P>\n");
 
3075
      sendString("</CENTER>\n");
 
3076
    } /* ok */
 
3077
  }
 
3078
}
 
3079
 
 
3080
/* ************************************ */
 
3081
 
 
3082
/* Function below courtesy of Andreas Pfaller <apfaller@yahoo.com.au> */
 
3083
 
 
3084
char *getSessionState(IPSession *session) {
 
3085
  switch (session->sessionState) {
 
3086
  case FLAG_STATE_SYN:
 
3087
    return("Sent&nbsp;Syn");
 
3088
  case FLAG_FLAG_STATE_SYN_ACK:
 
3089
    return("Rcvd&nbsp;Syn/Ack");
 
3090
  case FLAG_STATE_ACTIVE:
 
3091
    return("Active");
 
3092
  case FLAG_STATE_FIN1_ACK0:
 
3093
    return("Fin1&nbsp;Ack0");
 
3094
  case FLAG_STATE_FIN1_ACK1:
 
3095
    return("Fin1&nbsp;Ack1");
 
3096
  case FLAG_STATE_FIN2_ACK0:
 
3097
    return("Fin2&nbsp;Ack0");
 
3098
  case FLAG_STATE_FIN2_ACK1:
 
3099
    return("Fin2&nbsp;Ack1");
 
3100
  case FLAG_STATE_FIN2_ACK2:
 
3101
    return("Fin2&nbsp;Ack2");
 
3102
  case FLAG_STATE_TIMEOUT:
 
3103
    return("Timeout");
 
3104
  case FLAG_STATE_END:
 
3105
    return("End");
 
3106
  }
 
3107
 
 
3108
 return("*Unknown*");
 
3109
}
 
3110
 
 
3111
/* ************************************ */
 
3112
 
 
3113
void printHostSessions(HostTraffic *el, int actualDeviceId) {
 
3114
  printActiveTCPSessions(actualDeviceId, 0, el);
 
3115
}
 
3116
 
 
3117
/* ******************************* */
 
3118
/*
 
3119
   Return codes:
 
3120
 
 
3121
   OK          0
 
3122
   Minor       1
 
3123
   Warning     2
 
3124
   Error       3!
 
3125
*/
 
3126
 
 
3127
u_short isHostHealthy(HostTraffic *el) {
 
3128
 
 
3129
  if((hasDuplicatedMac(el)) ||
 
3130
     (hasSentIpDataOnZeroPort(el)))
 
3131
    return(3);
 
3132
 
 
3133
  if(hasWrongNetmask(el))
 
3134
    return(2);
 
3135
 
 
3136
  if((el->totContactedSentPeers > CONTACTED_PEERS_THRESHOLD)
 
3137
     || (el->totContactedRcvdPeers > CONTACTED_PEERS_THRESHOLD)) {
 
3138
    /* Mail/DNS/HTTP server usually touch many hosts */
 
3139
    if(!(isSMTPhost(el) || nameServerHost(el) || isHTTPhost(el))) {
 
3140
      return(2);
 
3141
    }
 
3142
  }
 
3143
 
 
3144
  if((el->secHostPkts != NULL)
 
3145
     && ((el->secHostPkts->nullPktsSent.value.value > 0)
 
3146
         || (el->secHostPkts->synFinPktsSent.value.value > 0)
 
3147
         || (el->secHostPkts->ackXmasFinSynNullScanSent.value.value > 0)
 
3148
         || (el->secHostPkts->tinyFragmentSent.value.value > 0)
 
3149
         || (el->secHostPkts->icmpFragmentSent.value.value > 0)
 
3150
         || (el->secHostPkts->overlappingFragmentSent.value.value > 0)
 
3151
         || (el->secHostPkts->malformedPktsRcvd.value.value > 0))) {
 
3152
    return(2);
 
3153
  }
 
3154
 
 
3155
  if((el->secHostPkts != NULL)
 
3156
     && ((el->secHostPkts->rstPktsRcvd.value.value > 0)
 
3157
         || (el->secHostPkts->rejectedTCPConnRcvd.value.value > 0)
 
3158
         || (el->secHostPkts->udpToClosedPortRcvd.value.value > 0)
 
3159
         || (el->secHostPkts->udpToDiagnosticPortSent.value.value > 0)
 
3160
         || (el->secHostPkts->closedEmptyTCPConnSent.value.value > 0)
 
3161
         || (el->secHostPkts->icmpPortUnreachRcvd.value.value > 0)
 
3162
         || (el->secHostPkts->icmpHostNetUnreachRcvd.value.value > 0)
 
3163
         || (el->secHostPkts->icmpProtocolUnreachRcvd.value.value > 0)
 
3164
         || (el->secHostPkts->icmpAdminProhibitedRcvd.value.value > 0))) {
 
3165
    return(1);
 
3166
  }
 
3167
 
 
3168
  return(0);
 
3169
}
 
3170
 
 
3171
/* ************************************ */
 
3172
 
 
3173
static void checkHostHealthness(HostTraffic *el) {
 
3174
  char buf[LEN_GENERAL_WORK_BUFFER];
 
3175
 
 
3176
  if(hasWrongNetmask(el)
 
3177
     || hasDuplicatedMac(el)
 
3178
     || hasSentIpDataOnZeroPort(el)
 
3179
     || (el->totContactedSentPeers > CONTACTED_PEERS_THRESHOLD) || (el->totContactedRcvdPeers > CONTACTED_PEERS_THRESHOLD)
 
3180
     || ((el->secHostPkts != NULL)
 
3181
         && ((el->secHostPkts->nullPktsSent.value.value > 0)
 
3182
             || (el->secHostPkts->synFinPktsSent.value.value > 0)
 
3183
             || (el->secHostPkts->rstPktsRcvd.value.value > 0)
 
3184
             || (el->secHostPkts->ackXmasFinSynNullScanSent.value.value > 0)
 
3185
             || (el->secHostPkts->rejectedTCPConnRcvd.value.value > 0)
 
3186
             || (el->secHostPkts->udpToClosedPortRcvd.value.value > 0)
 
3187
             || (el->secHostPkts->udpToDiagnosticPortSent.value.value > 0)
 
3188
             || (el->secHostPkts->tinyFragmentSent.value.value > 0)
 
3189
             || (el->secHostPkts->icmpFragmentSent.value.value > 0)
 
3190
             || (el->secHostPkts->overlappingFragmentSent.value.value > 0)
 
3191
             || (el->secHostPkts->closedEmptyTCPConnSent.value.value > 0)
 
3192
             || (el->secHostPkts->icmpPortUnreachRcvd.value.value > 0)
 
3193
             || (el->secHostPkts->icmpHostNetUnreachRcvd.value.value > 0)
 
3194
             || (el->secHostPkts->icmpProtocolUnreachRcvd.value.value > 0)
 
3195
             || (el->secHostPkts->icmpAdminProhibitedRcvd.value.value > 0)
 
3196
             || (el->secHostPkts->malformedPktsRcvd.value.value > 0)))) {
 
3197
    if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s "
 
3198
                CONST_IMG_HIGH_RISK 
 
3199
                CONST_IMG_MEDIUM_RISK 
 
3200
                CONST_IMG_LOW_RISK 
 
3201
                "</TH><TD "TD_BG" ALIGN=RIGHT NOWRAP><OL>", getRowColor(),
 
3202
                "Host Healthness (Risk Flags)") < 0) BufferTooShort();
 
3203
    sendString(buf);
 
3204
 
 
3205
    if(hasDuplicatedMac(el))
 
3206
      sendString("<LI>" CONST_IMG_HIGH_RISK "<A HREF=/" CONST_NTOP_HELP_HTML "#2>"
 
3207
                 "Duplicated MAC found for this IP address (spoofing?)</A>\n");
 
3208
 
 
3209
    if(hasSentIpDataOnZeroPort(el))
 
3210
      sendString("<LI>" CONST_IMG_HIGH_RISK "<A HREF=/" CONST_NTOP_HELP_HTML "#3>"
 
3211
                 "Traffic on suspicious IP ports</A>\n");
 
3212
 
 
3213
    if(hasWrongNetmask(el))
 
3214
      sendString("<LI>" CONST_IMG_MEDIUM_RISK "<A HREF=/" CONST_NTOP_HELP_HTML "#1>"
 
3215
                 "Wrong network mask or bridging enabled</A>\n");
 
3216
 
 
3217
    if((el->totContactedSentPeers > CONTACTED_PEERS_THRESHOLD)
 
3218
       || (el->totContactedRcvdPeers > CONTACTED_PEERS_THRESHOLD)) {
 
3219
      sendString("<LI>" CONST_IMG_MEDIUM_RISK "<A HREF=/" CONST_NTOP_HELP_HTML "#4>"
 
3220
                 "Suspicious activities: too many host contacts</A>\n");
 
3221
    }
 
3222
 
 
3223
    if((el->secHostPkts != NULL)
 
3224
       && ((el->secHostPkts->nullPktsSent.value.value > 0)
 
3225
           || (el->secHostPkts->synFinPktsSent.value.value > 0)
 
3226
           || (el->secHostPkts->ackXmasFinSynNullScanSent.value.value > 0)
 
3227
           || (el->secHostPkts->tinyFragmentSent.value.value > 0)
 
3228
           || (el->secHostPkts->icmpFragmentSent.value.value > 0)
 
3229
           || (el->secHostPkts->overlappingFragmentSent.value.value > 0)
 
3230
           || (el->secHostPkts->malformedPktsRcvd.value.value > 0))) {
 
3231
      sendString("<LI>" CONST_IMG_MEDIUM_RISK "<A HREF=/" CONST_NTOP_HELP_HTML "#5>"
 
3232
                 "Unexpected packets (e.g. traffic to closed port or connection reset)</A>:<br>\n");
 
3233
      if(el->secHostPkts->synFinPktsSent.value.value > 0) sendString("[Sent: syn-fin]&nbsp;");
 
3234
      if(el->secHostPkts->ackXmasFinSynNullScanSent.value.value > 0) sendString("[Sent: xmas]&nbsp;");
 
3235
      if(el->secHostPkts->tinyFragmentSent.value.value > 0) sendString("[Sent: Tiny frag]&nbsp;");
 
3236
      if(el->secHostPkts->icmpFragmentSent.value.value > 0) sendString("[Sent: icmp frag]&nbsp;");
 
3237
      if(el->secHostPkts->overlappingFragmentSent.value.value > 0) sendString("[Sent: overlapfrag]&nbsp;");
 
3238
      if(el->secHostPkts->malformedPktsRcvd.value.value > 0) sendString("[Rcvd: malformed]&nbsp;");
 
3239
    }
 
3240
 
 
3241
    if((el->secHostPkts != NULL)
 
3242
       && ((el->secHostPkts->rejectedTCPConnRcvd.value.value > 0)
 
3243
           || (el->secHostPkts->udpToClosedPortRcvd.value.value > 0)
 
3244
           || (el->secHostPkts->udpToDiagnosticPortSent.value.value > 0)
 
3245
           || (el->secHostPkts->rstPktsRcvd.value.value > 0)
 
3246
           || (el->secHostPkts->closedEmptyTCPConnSent.value.value > 0)
 
3247
           || (el->secHostPkts->icmpPortUnreachRcvd.value.value > 0)
 
3248
           || (el->secHostPkts->icmpHostNetUnreachRcvd.value.value > 0)
 
3249
           || (el->secHostPkts->icmpProtocolUnreachRcvd.value.value > 0)
 
3250
           || (el->secHostPkts->icmpAdminProhibitedRcvd.value.value > 0))) {
 
3251
      sendString("<LI>" CONST_IMG_LOW_RISK "<A HREF=/" CONST_NTOP_HELP_HTML "#6>"
 
3252
                 "Unexpected packets (e.g. traffic to closed port or connection reset)</A>:<br>\n");
 
3253
      if(el->secHostPkts->rejectedTCPConnRcvd.value.value > 0) sendString("[Rcvd: rejected]&nbsp;");
 
3254
      if(el->secHostPkts->udpToClosedPortRcvd.value.value > 0) sendString("[Sent: udp to closed]&nbsp;");
 
3255
      if(el->secHostPkts->udpToDiagnosticPortSent.value.value > 0) sendString("[Sent: udp to diag]&nbsp;");
 
3256
      if(el->secHostPkts->rstPktsRcvd.value.value > 0) sendString("[Rcvd: rst]&nbsp;");
 
3257
      if(el->secHostPkts->closedEmptyTCPConnSent.value.value > 0) sendString("[Sent: closed-empty]&nbsp;");
 
3258
      if(el->secHostPkts->icmpPortUnreachRcvd.value.value > 0) sendString("[Rcvd: port unreac]&nbsp;");
 
3259
      if(el->secHostPkts->icmpHostNetUnreachRcvd.value.value > 0) sendString("[Rcvd: hostnet unreac]&nbsp;");
 
3260
      if(el->secHostPkts->icmpProtocolUnreachRcvd.value.value > 0) sendString("[Rcvd: proto unreac]&nbsp;");
 
3261
      if(el->secHostPkts->icmpAdminProhibitedRcvd.value.value > 0) sendString("[Rcvd: admin prohib]&nbsp;");
 
3262
    }
 
3263
 
 
3264
    sendString("</OL></TD></TR>\n");
 
3265
  }
 
3266
}
 
3267
 
 
3268
/* ************************************ */
 
3269
 
 
3270
static void printUserList(HostTraffic *el) {
 
3271
  char buf[LEN_GENERAL_WORK_BUFFER];
 
3272
  UserList *list = el->protocolInfo->userList;
 
3273
  int num = 0;
 
3274
 
 
3275
  while(list != NULL) {
 
3276
    if(num > 0) sendString("<br>");
 
3277
 
 
3278
    if(snprintf(buf, sizeof(buf), "%s&nbsp;[", list->userName) < 0)
 
3279
      BufferTooShort();
 
3280
    sendString(buf);
 
3281
 
 
3282
    if(FD_ISSET(BITFLAG_POP_USER, &(list->userFlags))) sendString("&nbsp;POP&nbsp;");
 
3283
    if(FD_ISSET(BITFLAG_IMAP_USER, &(list->userFlags))) sendString("&nbsp;IMAP&nbsp;");
 
3284
    if(FD_ISSET(BITFLAG_SMTP_USER, &(list->userFlags))) sendString("&nbsp;SMTP&nbsp;");
 
3285
    if(FD_ISSET(BITFLAG_P2P_USER, &(list->userFlags))) sendString("&nbsp;P2P&nbsp;");
 
3286
    if(FD_ISSET(BITFLAG_FTP_USER, &(list->userFlags))) sendString("&nbsp;FTP&nbsp;");
 
3287
    if(FD_ISSET(BITFLAG_MESSENGER_USER, &(list->userFlags))) sendString("&nbsp;MSG&nbsp;");
 
3288
 
 
3289
    sendString("]\n");
 
3290
    list = list->next;
 
3291
    num++;
 
3292
  }
 
3293
}
 
3294
 
 
3295
/* ************************************ */
 
3296
 
 
3297
void checkHostProvidedServices(HostTraffic *el) {
 
3298
  char buf[LEN_GENERAL_WORK_BUFFER];
 
3299
 
 
3300
  if(isServer(el)
 
3301
     || isWorkstation(el)
 
3302
     || isMasterBrowser(el)
 
3303
     || isPrinter(el)
 
3304
     || isBridgeHost(el)
 
3305
     || nameServerHost(el) || isNtpServer(el)
 
3306
     || gatewayHost(el)
 
3307
     || isSMTPhost(el) || isIMAPhost(el) || isPOPhost(el)
 
3308
     || isDirectoryHost(el)
 
3309
     || isFTPhost(el)
 
3310
     || isHTTPhost(el)
 
3311
     || isWINShost(el)
 
3312
     || isDHCPClient(el) || isDHCPServer(el)
 
3313
     ) {
 
3314
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3315
                "<TD "TD_BG" ALIGN=RIGHT>", getRowColor(), "Host Type") < 0) BufferTooShort();
 
3316
    sendString(buf);
 
3317
 
 
3318
    if(isServer(el))           sendString("Server<BR>\n");
 
3319
    if(isWorkstation(el))      sendString("Workstation<BR>\n");
 
3320
    if(isMasterBrowser(el))    sendString("Master Browser<BR>\n");
 
3321
 
 
3322
    if(isPrinter(el))          sendString("Printer&nbsp;" CONST_IMG_PRINTER "<BR>\n");
 
3323
    if(isBridgeHost(el))       sendString("Layer-2 Switch/Bridge&nbsp;" CONST_IMG_BRIDGE "<BR>\n");
 
3324
 
 
3325
    if(nameServerHost(el))     sendString("Name Server&nbsp;" CONST_IMG_DNS_SERVER "<BR>\n");
 
3326
    if(isNtpServer(el))        sendString("NTP Server&nbsp;" CONST_IMG_NTP_SERVER "<BR>\n");
 
3327
    if(gatewayHost(el))        sendString("Gateway/Router&nbsp;" CONST_IMG_ROUTER "<BR>\n");
 
3328
    if(isSMTPhost(el))         sendString("SMTP (Mail) Server&nbsp;" CONST_IMG_SMTP_SERVER "<BR>\n");
 
3329
    if(isPOPhost(el))          sendString("POP Server&nbsp;" CONST_IMG_POP_SERVER "<BR>\n");
 
3330
    if(isIMAPhost(el))         sendString("IMAP Server&nbsp;" CONST_IMG_IMAP_SERVER "<BR>\n");
 
3331
    if(isDirectoryHost(el))    sendString("Directory Server&nbsp;" CONST_IMG_DIRECTORY_SERVER " <BR>\n");
 
3332
    if(isFTPhost(el))          sendString("FTP Server&nbsp;" CONST_IMG_FTP_SERVER "<BR>\n");
 
3333
    if(isHTTPhost(el))         sendString("HTTP Server&nbsp;" CONST_IMG_HTTP_SERVER "<BR>\n");
 
3334
    if(isWINShost(el))         sendString("WINS Server<BR>\n");
 
3335
 
 
3336
    if(isDHCPClient(el))       sendString("BOOTP/DHCP Client&nbsp;" CONST_IMG_DHCP_CLIENT "<BR>\n");
 
3337
    if(isDHCPServer(el))       sendString("BOOTP/DHCP Server&nbsp;" CONST_IMG_DHCP_SERVER "<BR>\n");
 
3338
 
 
3339
    sendString("</TD></TR>");
 
3340
  }
 
3341
}
 
3342
 
 
3343
/* ************************************ */
 
3344
 
 
3345
void printHostDetailedInfo(HostTraffic *el, int actualDeviceId) {
 
3346
  char buf[LEN_GENERAL_WORK_BUFFER], buf1[64], buf2[128], sniffedName[MAXDNAME], osBuf[128];
 
3347
  float percentage;
 
3348
  Counter total;
 
3349
  int printedHeader, i;
 
3350
  char *dynIp, *multihomed;
 
3351
  u_short as=0;
 
3352
  HostTraffic *theHost, tmpEl;
 
3353
  char formatBuf[32], formatBuf1[32], formatBuf2[32], hostLinkBuf[LEN_GENERAL_WORK_BUFFER];
 
3354
 
 
3355
  accessAddrResMutex("printAllSessionsHTML");
 
3356
 
 
3357
  buf1[0]=0;
 
3358
  if(getSniffedDNSName(el->hostNumIpAddress, sniffedName, sizeof(sniffedName))) {
 
3359
    if(el->hostResolvedName[0] == '\0' || strcmp(sniffedName, el->hostResolvedName))
 
3360
      if(snprintf(buf1, sizeof(buf1), " (%s)", sniffedName) < 0)
 
3361
        BufferTooShort();
 
3362
  }
 
3363
 
 
3364
  if((el->hostResolvedName[0] != '\0') && (strcmp(el->hostResolvedName, el->hostNumIpAddress))) {
 
3365
    if(snprintf(buf, sizeof(buf), "Info about "
 
3366
                " <A HREF=\"http://%s/\" TARGET=\"_blank\" "
 
3367
                "TITLE=\"Link to web server on host, IF available\">%s %s</A>\n",
 
3368
                el->hostResolvedName,
 
3369
                el->hostResolvedName, buf1) < 0)
 
3370
      BufferTooShort();
 
3371
 
 
3372
    if(snprintf(buf2, sizeof(buf2), "Info about %s", el->hostResolvedName) < 0)
 
3373
      BufferTooShort();
 
3374
  } else if(el->hostNumIpAddress[0] != '\0') {
 
3375
    if(snprintf(buf, sizeof(buf), "Info about "
 
3376
                " <A HREF=\"http://%s%s%s/\" TARGET=\"_blank\" "
 
3377
                "TITLE=\"Link to web server on host, if available\">%s %s</A>\n",
 
3378
                el->hostIpAddress.hostFamily == AF_INET6 ? "[" : "",
 
3379
                el->hostNumIpAddress,
 
3380
                el->hostIpAddress.hostFamily == AF_INET6 ? "]" : "",
 
3381
                el->hostNumIpAddress, buf1) < 0)
 
3382
      BufferTooShort();
 
3383
 
 
3384
    if(snprintf(buf2, sizeof(buf2), "Info about %s", el->hostNumIpAddress) < 0)
 
3385
      BufferTooShort();
 
3386
  } else {
 
3387
    if(snprintf(buf, sizeof(buf), "Info about %s", el->ethAddressString) < 0)
 
3388
      BufferTooShort();
 
3389
 
 
3390
    if(snprintf(buf2, sizeof(buf2), "Info about %s", el->ethAddressString) < 0)
 
3391
      BufferTooShort();
 
3392
  }
 
3393
 
 
3394
  releaseAddrResMutex();
 
3395
  printHTMLheader(buf2, buf, 0);
 
3396
  sendString("<CENTER>\n<P>"TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=80%%>\n");
 
3397
 
 
3398
  if(el->hostNumIpAddress[0] != '\0') {
 
3399
    char *countryIcon, *hostType;
 
3400
 
 
3401
    accessAddrResMutex("printAllSessions-2");
 
3402
 
 
3403
    countryIcon = getHostCountryIconURL(el);
 
3404
 
 
3405
    if(broadcastHost(el)) hostType = "broadcast";
 
3406
    else if(multicastHost(el)) hostType = "multicast";
 
3407
    else hostType = "unicast";
 
3408
 
 
3409
    if(isDHCPClient(el))
 
3410
      dynIp = "/dynamic";
 
3411
    else
 
3412
      dynIp = "";
 
3413
 
 
3414
    if(isMultihomed(el) && (!broadcastHost(el)))
 
3415
      multihomed = "&nbsp;-&nbsp;multihomed&nbsp;" CONST_IMG_MULTIHOMED;
 
3416
    else
 
3417
      multihomed = "";
 
3418
 
 
3419
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3420
                "<TD "TD_BG" ALIGN=RIGHT>%s&nbsp;%s&nbsp;[%s%s%s]",
 
3421
                getRowColor(),
 
3422
                "IP&nbsp;Address",
 
3423
                el->hostNumIpAddress,
 
3424
                countryIcon, hostType, dynIp, multihomed) < 0)
 
3425
      BufferTooShort();
 
3426
    sendString(buf);
 
3427
 
 
3428
    sendString("</TD></TR>\n");
 
3429
 
 
3430
    if(isMultihomed(el) && (!broadcastHost(el))) {
 
3431
      if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD ALIGN=RIGHT>&nbsp;<OL>",
 
3432
                  getRowColor(), "Multihomed Addresses") < 0)
 
3433
        BufferTooShort();
 
3434
      sendString(buf);
 
3435
 
 
3436
      for(theHost=getFirstHost(actualDeviceId);
 
3437
          theHost != NULL; theHost = getNextHost(actualDeviceId, theHost)) {
 
3438
        if((theHost != el)
 
3439
           && (memcmp(theHost->ethAddress, el->ethAddress, LEN_ETHERNET_ADDRESS) == 0)) {
 
3440
          if(snprintf(buf, sizeof(buf), "<LI><A HREF=/%s.html>%s</A>",
 
3441
                      theHost->hostNumIpAddress, theHost->hostNumIpAddress) < 0)
 
3442
            BufferTooShort();
 
3443
          sendString(buf);
 
3444
        }
 
3445
      } /* for */
 
3446
 
 
3447
      sendString("</TD></TR>");
 
3448
    }
 
3449
 
 
3450
    if((el->protocolInfo != NULL) && (el->protocolInfo->dhcpStats != NULL)) {
 
3451
      if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>",
 
3452
                  getRowColor(), "DHCP Information") < 0)
 
3453
        BufferTooShort();
 
3454
      sendString(buf);
 
3455
 
 
3456
      sendString("<TD "TD_BG"><TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\">\n");
 
3457
 
 
3458
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3459
                  "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2>%s</TD></TR>\n", getRowColor(), "DHCP Server",
 
3460
                  _intoa(el->protocolInfo->dhcpStats->dhcpServerIpAddress, buf1, sizeof(buf1))) < 0)
 
3461
        BufferTooShort();
 
3462
      sendString(buf);
 
3463
 
 
3464
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3465
                  "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2>%s</TD></TR>\n", getRowColor(), "Previous IP Address",
 
3466
                  _intoa(el->protocolInfo->dhcpStats->previousIpAddress, buf1, sizeof(buf1))) < 0)
 
3467
        BufferTooShort();
 
3468
      sendString(buf);
 
3469
 
 
3470
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3471
                  "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2>%s</TD></TR>\n",
 
3472
                  getRowColor(), "Address Assigned on",
 
3473
                  formatTime(&(el->protocolInfo->dhcpStats->assignTime), formatBuf, sizeof(formatBuf))) < 0)
 
3474
        BufferTooShort();
 
3475
      sendString(buf);
 
3476
 
 
3477
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3478
                  "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2>%s</TD></TR>\n",
 
3479
                  getRowColor(), "To be Renewed Before",
 
3480
                  formatTime(&(el->protocolInfo->dhcpStats->renewalTime), formatBuf, sizeof(formatBuf))) < 0)
 
3481
        BufferTooShort();
 
3482
      sendString(buf);
 
3483
 
 
3484
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3485
                  "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2>%s</TD></TR>\n",
 
3486
                  getRowColor(), "Lease Ends on",
 
3487
                  formatTime(&(el->protocolInfo->dhcpStats->leaseTime), formatBuf, sizeof(formatBuf))) < 0)
 
3488
        BufferTooShort();
 
3489
      sendString(buf);
 
3490
 
 
3491
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">DHCP Packets</TH>"
 
3492
                  "<TH "TH_BG" ALIGN=CENTER "DARK_BG">Sent</TH><TH "TH_BG" ALIGN=RIGHT "DARK_BG">Rcvd</TH></TR>\n",
 
3493
                  getRowColor()) < 0)
 
3494
        BufferTooShort();
 
3495
      sendString(buf);
 
3496
 
 
3497
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3498
                  "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>\n",
 
3499
                  getRowColor(), "DHCP Discover",
 
3500
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgSent[FLAG_DHCP_DISCOVER_MSG].value, formatBuf, sizeof(formatBuf)),
 
3501
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgRcvd[FLAG_DHCP_DISCOVER_MSG].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
3502
        BufferTooShort();
 
3503
      sendString(buf);
 
3504
 
 
3505
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3506
                  "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>\n",
 
3507
                  getRowColor(), "DHCP Offer",
 
3508
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgSent[FLAG_DHCP_OFFER_MSG].value, formatBuf, sizeof(formatBuf)),
 
3509
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgRcvd[FLAG_DHCP_OFFER_MSG].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
3510
        BufferTooShort();
 
3511
      sendString(buf);
 
3512
 
 
3513
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3514
                  "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>\n",
 
3515
                  getRowColor(), "DHCP Request",
 
3516
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgSent[FLAG_DHCP_REQUEST_MSG].value, formatBuf, sizeof(formatBuf)),
 
3517
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgRcvd[FLAG_DHCP_REQUEST_MSG].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
3518
        BufferTooShort();
 
3519
      sendString(buf);
 
3520
 
 
3521
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3522
                  "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>\n",
 
3523
                  getRowColor(), "DHCP Decline",
 
3524
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgSent[FLAG_DHCP_DECLINE_MSG].value, formatBuf, sizeof(formatBuf)),
 
3525
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgRcvd[FLAG_DHCP_DECLINE_MSG].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
3526
        BufferTooShort();
 
3527
      sendString(buf);
 
3528
 
 
3529
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3530
                  "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>\n",
 
3531
                  getRowColor(), "DHCP Ack",
 
3532
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgSent[FLAG_DHCP_ACK_MSG].value, formatBuf, sizeof(formatBuf)),
 
3533
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgRcvd[FLAG_DHCP_ACK_MSG].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
3534
        BufferTooShort();
 
3535
      sendString(buf);
 
3536
 
 
3537
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3538
                  "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>\n",
 
3539
                  getRowColor(), "DHCP Nack",
 
3540
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgSent[FLAG_DHCP_NACK_MSG].value, formatBuf, sizeof(formatBuf)),
 
3541
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgRcvd[FLAG_DHCP_NACK_MSG].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
3542
        BufferTooShort();
 
3543
      sendString(buf);
 
3544
 
 
3545
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3546
                  "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>\n",
 
3547
                  getRowColor(), "DHCP Release",
 
3548
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgSent[FLAG_DHCP_RELEASE_MSG].value, formatBuf, sizeof(formatBuf)),
 
3549
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgRcvd[FLAG_DHCP_RELEASE_MSG].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
3550
        BufferTooShort();
 
3551
      sendString(buf);
 
3552
 
 
3553
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3554
                  "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>\n",
 
3555
                  getRowColor(), "DHCP Inform",
 
3556
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgSent[FLAG_DHCP_INFORM_MSG].value, formatBuf, sizeof(formatBuf)),
 
3557
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgRcvd[FLAG_DHCP_INFORM_MSG].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
3558
        BufferTooShort();
 
3559
      sendString(buf);
 
3560
 
 
3561
 
 
3562
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3563
                  "<TD "TD_BG" ALIGN=RIGHT>%s</TD><TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>\n",
 
3564
                  getRowColor(), "DHCP Unknown Msg",
 
3565
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgSent[FLAG_DHCP_UNKNOWN_MSG].value, formatBuf, sizeof(formatBuf)),
 
3566
                  formatPkts(el->protocolInfo->dhcpStats->dhcpMsgRcvd[FLAG_DHCP_UNKNOWN_MSG].value, formatBuf1, sizeof(formatBuf1))) < 0)
 
3567
        BufferTooShort();
 
3568
      sendString(buf);
 
3569
 
 
3570
      sendString("</TABLE>"TABLE_OFF"</TD></TR>\n");
 
3571
    }
 
3572
  }
 
3573
 
 
3574
  if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3575
              "<TD "TD_BG" ALIGN=RIGHT>"
 
3576
              "%s&nbsp;&nbsp;-&nbsp;&nbsp;%s&nbsp;[%s]</TD></TR>\n",
 
3577
              getRowColor(),
 
3578
              "First/Last&nbsp;Seen",
 
3579
              formatTime(&(el->firstSeen), formatBuf, sizeof(formatBuf)),
 
3580
              formatTime(&(el->lastSeen), formatBuf1, sizeof(formatBuf1)),
 
3581
              formatSeconds(el->lastSeen - el->firstSeen, formatBuf2, sizeof(formatBuf2))) < 0)
 
3582
    BufferTooShort();
 
3583
  sendString(buf);
 
3584
 
 
3585
  if(el->hostAS != 0) {
 
3586
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3587
                "<A HREF=\"http://ws.arin.net/cgi-bin/whois.pl?queryinput=AS%d\">%d</A></TD></TR>\n",
 
3588
                getRowColor(), "Autonomous System", el->hostAS, el->hostAS) < 0) BufferTooShort();
 
3589
    sendString(buf);
 
3590
  }
 
3591
 
 
3592
  if(el->dnsDomainValue && (el->dnsDomainValue[0] != '\0')) {
 
3593
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3594
                "%s</TD></TR>\n", getRowColor(),
 
3595
                "Domain", el->dnsDomainValue) < 0) BufferTooShort();
 
3596
    sendString(buf);
 
3597
  }
 
3598
 
 
3599
  if((el->ethAddressString[0] != '\0')
 
3600
     && strcmp(el->ethAddressString, "00:00:00:00:00:00")
 
3601
     && strcmp(el->ethAddressString, "00:01:02:03:04:05") /* dummy address */) {
 
3602
    char *vendorName;
 
3603
 
 
3604
    if(isMultihomed(el)) {
 
3605
      char *symMacAddr, symLink[32];
 
3606
      char etherbuf[LEN_ETHERNET_ADDRESS_DISPLAY];
 
3607
 
 
3608
      symMacAddr = etheraddr_string(el->ethAddress, etherbuf);
 
3609
      strcpy(symLink, symMacAddr);
 
3610
      urlFixupToRFC1945Inplace(symLink);
 
3611
 
 
3612
      if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3613
                  "<A HREF=%s.html>%s</A>%s</TD></TR>\n",
 
3614
                  getRowColor(), "Main Host MAC Address",
 
3615
                  symLink, symMacAddr,
 
3616
                  myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
3617
        BufferTooShort();
 
3618
      sendString(buf);
 
3619
 
 
3620
    } else {
 
3621
      if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3622
                  "%s%s</TD></TR>\n",
 
3623
                  getRowColor(), "MAC&nbsp;Address <IMG ALT=\"Network Interface Card (NIC)\" SRC=/card.gif BORDER=0 "TABLE_DEFAULTS">",
 
3624
                  el->ethAddressString,
 
3625
                  myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
3626
        BufferTooShort();
 
3627
      sendString(buf);
 
3628
    }
 
3629
 
 
3630
    vendorName = getVendorInfo(el->ethAddress, 1);
 
3631
    if(vendorName[0] != '\0') {
 
3632
      if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT NOWRAP>%s%s</TD></TR>\n",
 
3633
                  getRowColor(), "Nw&nbsp;Board&nbsp;Vendor",
 
3634
                  vendorName,
 
3635
                  myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
3636
        BufferTooShort();
 
3637
      sendString(buf);
 
3638
    }
 
3639
  }
 
3640
 
 
3641
  if(((el->lastEthAddress[0] != 0)
 
3642
      || (el->lastEthAddress[1] != 0)
 
3643
      || (el->lastEthAddress[2] != 0)
 
3644
      || (el->lastEthAddress[3] != 0)
 
3645
      || (el->lastEthAddress[4] != 0)
 
3646
      || (el->lastEthAddress[5] != 0) /* The address isn't empty */)
 
3647
     && (memcmp(el->lastEthAddress, el->ethAddress, LEN_ETHERNET_ADDRESS) != 0)) {
 
3648
    /* Different MAC addresses */
 
3649
    char *symMacAddr, symLink[32], shortBuf[64];
 
3650
    char etherbuf[LEN_ETHERNET_ADDRESS_DISPLAY];
 
3651
 
 
3652
    symMacAddr = etheraddr_string(el->lastEthAddress, etherbuf);
 
3653
    strcpy(symLink, symMacAddr);
 
3654
    urlFixupToRFC1945Inplace(symLink);
 
3655
 
 
3656
    if(!myGlobals.dontTrustMACaddr) {
 
3657
      if(snprintf(shortBuf, sizeof(shortBuf), "<A HREF=%s.html>%s</A>", symLink, symMacAddr) < 0)
 
3658
        BufferTooShort();
 
3659
    } else {
 
3660
      strcpy(shortBuf, symMacAddr);
 
3661
    }
 
3662
 
 
3663
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3664
                "%s"
 
3665
                "%s</TD></TR>\n",
 
3666
                getRowColor(),
 
3667
                "Last MAC Address/Router <IMG ALT=\"Network Interface Card (NIC)/Router\" SRC=/card.gif BORDER=0 "TABLE_DEFAULTS">",
 
3668
                shortBuf,
 
3669
                myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
3670
      BufferTooShort();
 
3671
    sendString(buf);
 
3672
  }
 
3673
 
 
3674
  if(el->hostNumIpAddress[0] != '\0') {
 
3675
    setHostFingerprint(el);
 
3676
 
 
3677
    if((el->fingerprint != NULL) && (el->fingerprint[0] == ':') && (strlen(el->fingerprint) > 2)) {
 
3678
      if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3679
                  "%s%s</TD></TR>\n",
 
3680
                  getRowColor(), "OS&nbsp;Name",
 
3681
                  getOSFlag(el, NULL, 1, osBuf, sizeof(osBuf)),
 
3682
                  myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
3683
        BufferTooShort();
 
3684
      sendString(buf);
 
3685
    }
 
3686
  }
 
3687
 
 
3688
  if((as = getHostAS(el)) != 0) {
 
3689
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3690
                "%d</TD></TR>\n", getRowColor(), "Origin&nbsp;AS", as) < 0)
 
3691
      BufferTooShort();
 
3692
    sendString(buf);
 
3693
  }
 
3694
 
 
3695
  if(el->vlanId != -1) {
 
3696
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3697
                "%d</TD></TR>\n", getRowColor(), "VLAN&nbsp;Id", el->vlanId) < 0)
 
3698
      BufferTooShort();
 
3699
      sendString(buf);
 
3700
  }
 
3701
 
 
3702
  if(el->nonIPTraffic) {
 
3703
    if((el->nonIPTraffic->nbHostName != NULL) || (el->nonIPTraffic->nbDomainName != NULL)) {
 
3704
      if(el->nonIPTraffic->nbAccountName) {
 
3705
        if(el->nonIPTraffic->nbDomainName != NULL) {
 
3706
          if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3707
                      "%s@%s&nbsp;[domain %s] (%s) %s</TD></TR>\n",
 
3708
                      getRowColor(), "NetBios&nbsp;Name",
 
3709
                      el->nonIPTraffic->nbAccountName, el->nonIPTraffic->nbHostName, el->nonIPTraffic->nbDomainName,
 
3710
                      getNbNodeType(el->nonIPTraffic->nbNodeType),
 
3711
                      el->nonIPTraffic->nbDescr ? el->nonIPTraffic->nbDescr : "") < 0)
 
3712
            BufferTooShort();
 
3713
        } else {
 
3714
          if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3715
                      "%s@%s (%s) %s</TD></TR>\n",
 
3716
                      getRowColor(), "NetBios&nbsp;Name",
 
3717
                      el->nonIPTraffic->nbAccountName, el->nonIPTraffic->nbHostName,
 
3718
                      getNbNodeType(el->nonIPTraffic->nbNodeType),
 
3719
                      el->nonIPTraffic->nbDescr ? el->nonIPTraffic->nbDescr : "") < 0)
 
3720
            BufferTooShort();
 
3721
        }
 
3722
      } else {
 
3723
        if(el->nonIPTraffic->nbDomainName != NULL) {
 
3724
          if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3725
                      "%s&nbsp;[domain %s] (%s) %s</TD></TR>\n",
 
3726
                      getRowColor(), "NetBios&nbsp;Name",
 
3727
                      el->nonIPTraffic->nbHostName != NULL ? el->nonIPTraffic->nbHostName : "",
 
3728
                      el->nonIPTraffic->nbDomainName,
 
3729
                      getNbNodeType(el->nonIPTraffic->nbNodeType),
 
3730
                      el->nonIPTraffic->nbDescr ? el->nonIPTraffic->nbDescr : "") < 0)
 
3731
            BufferTooShort();
 
3732
        } else {
 
3733
          if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3734
                      "%s (%s) %s</TD></TR>\n",
 
3735
                      getRowColor(), "NetBios&nbsp;Name",
 
3736
                      el->nonIPTraffic->nbHostName,
 
3737
                      getNbNodeType(el->nonIPTraffic->nbNodeType),
 
3738
                      el->nonIPTraffic->nbDescr ? el->nonIPTraffic->nbDescr : "") < 0)
 
3739
            BufferTooShort();
 
3740
        }
 
3741
      }
 
3742
 
 
3743
      sendString(buf);
 
3744
    } else if(el->nonIPTraffic->nbHostName != NULL) {
 
3745
      if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3746
                  "%s&nbsp;(%s) %s</TD></TR>\n",
 
3747
                  getRowColor(), "NetBios&nbsp;Name",
 
3748
                  el->nonIPTraffic->nbHostName, getNbNodeType(el->nonIPTraffic->nbNodeType),
 
3749
                  el->nonIPTraffic->nbDescr ? el->nonIPTraffic->nbDescr : "") < 0)
 
3750
        BufferTooShort();
 
3751
      sendString(buf);
 
3752
    }
 
3753
 
 
3754
    if(el->nonIPTraffic->atNetwork != 0) {
 
3755
      char *nodeName = el->nonIPTraffic->atNodeName;
 
3756
 
 
3757
      if(nodeName == NULL) nodeName = "";
 
3758
 
 
3759
      if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3760
                  "%s&nbsp;\n",
 
3761
                  getRowColor(), "AppleTalk&nbsp;Name",
 
3762
                  nodeName) < 0) BufferTooShort();
 
3763
      sendString(buf);
 
3764
 
 
3765
      if(el->nonIPTraffic->atNodeType[0] != NULL) {
 
3766
        sendString("(");
 
3767
        for(i=0; i<MAX_NODE_TYPES; i++)
 
3768
          if(el->nonIPTraffic->atNodeType[i] == NULL)
 
3769
            break;
 
3770
          else {
 
3771
            if(i > 0) sendString("/");
 
3772
            sendString(el->nonIPTraffic->atNodeType[i]);
 
3773
          }
 
3774
 
 
3775
        sendString(")&nbsp;");
 
3776
      }
 
3777
 
 
3778
      if(snprintf(buf, sizeof(buf), "[%d.%d]</TD></TR>\n",
 
3779
                  el->nonIPTraffic->atNetwork, el->nonIPTraffic->atNode) < 0)
 
3780
        BufferTooShort();
 
3781
      sendString(buf);
 
3782
    }
 
3783
 
 
3784
    if(el->nonIPTraffic->ipxHostName != NULL) {
 
3785
      if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
3786
                  "<TD "TD_BG" ALIGN=RIGHT>"
 
3787
                  "%s&nbsp;[", getRowColor(), "IPX&nbsp;Name",
 
3788
                  el->nonIPTraffic->ipxHostName) < 0)
 
3789
        BufferTooShort();
 
3790
      sendString(buf);
 
3791
 
 
3792
      for(i=0; i<el->nonIPTraffic->numIpxNodeTypes; i++) {
 
3793
        if(i>0) sendString("/");
 
3794
        sendString(getSAPInfo(el->nonIPTraffic->ipxNodeType[i], 1));
 
3795
      }
 
3796
 
 
3797
      sendString("]</TD></TR>\n");
 
3798
    }
 
3799
  }
 
3800
 
 
3801
  if(!multicastHost(el)) {
 
3802
    if(subnetPseudoLocalHost(el)) {
 
3803
      if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3804
                  "%s</TD></TR>\n", getRowColor(),
 
3805
                  "Host&nbsp;Location",
 
3806
                  "Local (inside specified/local subnet)") < 0)
 
3807
        BufferTooShort();
 
3808
    } else {
 
3809
      if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3810
                  "%s</TD></TR>\n", getRowColor(),
 
3811
                  "Host&nbsp;Location",
 
3812
                  "Remote (outside specified/local subnet)") < 0)
 
3813
        BufferTooShort();
 
3814
    }
 
3815
    sendString(buf);
 
3816
  }
 
3817
 
 
3818
  if(el->minTTL > 0) {
 
3819
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3820
                "%d:%d&nbsp;[~%d&nbsp;hop(s)]</TD></TR>\n",
 
3821
                getRowColor(), "IP&nbsp;TTL&nbsp;(Time to Live)",
 
3822
                el->minTTL, el->maxTTL, guessHops(el)) < 0) BufferTooShort();
 
3823
    sendString(buf);
 
3824
  }
 
3825
 
 
3826
  if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s"
 
3827
              "</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3828
              "%s/%s Pkts/%s Retran. Pkts [%d%%]</TD></TR>\n",
 
3829
              getRowColor(), "Total&nbsp;Data&nbsp;Sent",
 
3830
              formatBytes(el->bytesSent.value, 1, formatBuf, sizeof(formatBuf)),
 
3831
              formatPkts(el->pktSent.value, formatBuf1, sizeof(formatBuf1)),
 
3832
              formatPkts(el->pktDuplicatedAckSent.value, formatBuf2, sizeof(formatBuf2)),
 
3833
              (int)(((float)el->pktDuplicatedAckSent.value*100)/(float)(el->pktSent.value+1))
 
3834
              ) < 0) BufferTooShort();
 
3835
  sendString(buf);
 
3836
 
 
3837
  if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3838
              "%s Pkts</TD></TR>\n",
 
3839
              getRowColor(), "Broadcast&nbsp;Pkts&nbsp;Sent",
 
3840
              formatPkts(el->pktBroadcastSent.value, formatBuf, sizeof(formatBuf))) < 0) BufferTooShort();
 
3841
  sendString(buf);
 
3842
 
 
3843
  if(el->routedTraffic != NULL) {
 
3844
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3845
                "%s/%s Pkts</TD></TR>\n",
 
3846
                getRowColor(), "Routed Traffic",
 
3847
                formatBytes(el->routedTraffic->routedBytes.value, 1, formatBuf, sizeof(formatBuf)),
 
3848
                formatPkts(el->routedTraffic->routedPkts.value, formatBuf1, sizeof(formatBuf1))) < 0)
 
3849
      BufferTooShort();
 
3850
    sendString(buf);
 
3851
  }
 
3852
 
 
3853
  if((el->pktMulticastSent.value > 0) || (el->pktMulticastRcvd.value > 0)) {
 
3854
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>",
 
3855
                getRowColor(), "Multicast&nbsp;Traffic") < 0) BufferTooShort();
 
3856
    sendString(buf);
 
3857
 
 
3858
    if(el->pktMulticastSent.value > 0) {
 
3859
      if(snprintf(buf, sizeof(buf), "Sent&nbsp;%s/%s&nbsp;Pkts&nbsp;-",
 
3860
                  formatBytes(el->bytesMulticastSent.value, 1, formatBuf, sizeof(formatBuf)),
 
3861
                  formatPkts(el->pktMulticastSent.value, formatBuf1, sizeof(formatBuf1))) < 0) BufferTooShort();
 
3862
      sendString(buf);
 
3863
    }
 
3864
 
 
3865
    if(el->pktMulticastRcvd.value > 0) {
 
3866
      if(snprintf(buf, sizeof(buf), "Rcvd&nbsp;%s/%s&nbsp;Pkts",
 
3867
                  formatBytes(el->bytesMulticastRcvd.value, 1, formatBuf, sizeof(formatBuf)),
 
3868
                  formatPkts(el->pktMulticastRcvd.value, formatBuf1, sizeof(formatBuf1))) < 0) BufferTooShort();
 
3869
      sendString(buf);
 
3870
    }
 
3871
 
 
3872
    sendString("</TD></TR>\n");
 
3873
  }
 
3874
 
 
3875
  if(el->bytesSent.value == 0)
 
3876
    percentage = 0;
 
3877
  else
 
3878
    percentage = 100 - (((float)el->bytesSentRem.value*100)/el->bytesSent.value);
 
3879
 
 
3880
  if(el->hostNumIpAddress[0] != '\0') {
 
3881
    printTableEntryPercentage(buf, sizeof(buf), "Data&nbsp;Sent&nbsp;Stats",
 
3882
                              "Local", "Rem", -1, percentage);
 
3883
 
 
3884
    if(el->bytesSent.value > 0) {
 
3885
      percentage = (((float)el->ipBytesSent.value*100)/el->bytesSent.value);
 
3886
      printTableEntryPercentage(buf, sizeof(buf), "IP&nbsp;vs.&nbsp;Non-IP&nbsp;Sent",
 
3887
                                "IP", "Non-IP", -1, percentage);
 
3888
    }
 
3889
  }
 
3890
 
 
3891
  if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s"
 
3892
              "</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3893
              "%s/%s Pkts/%s Retran. Pkts [%d%%]</TD></TR>\n",
 
3894
              getRowColor(), "Total&nbsp;Data&nbsp;Rcvd",
 
3895
              formatBytes(el->bytesRcvd.value, 1, formatBuf, sizeof(formatBuf)),
 
3896
              formatPkts(el->pktRcvd.value, formatBuf1, sizeof(formatBuf1)),
 
3897
              formatPkts(el->pktDuplicatedAckRcvd.value, formatBuf2, sizeof(formatBuf2)),
 
3898
              (int)((float)(el->pktDuplicatedAckRcvd.value*100)/(float)(el->pktRcvd.value+1))) < 0)
 
3899
    BufferTooShort();
 
3900
  sendString(buf);
 
3901
 
 
3902
  if(el->bytesRcvd.value == 0)
 
3903
    percentage = 0;
 
3904
  else
 
3905
    percentage = 100 - (((float)el->bytesRcvdFromRem.value*100)/el->bytesRcvd.value);
 
3906
 
 
3907
    if(el->hostNumIpAddress[0] != '\0')
 
3908
      printTableEntryPercentage(buf, sizeof(buf), "Data&nbsp;Rcvd&nbsp;Stats",
 
3909
                                "Local", "Rem", -1, percentage);
 
3910
 
 
3911
  if(el->bytesRcvd.value > 0) {
 
3912
    percentage = (((float)el->ipBytesRcvd.value*100)/el->bytesRcvd.value);
 
3913
    printTableEntryPercentage(buf, sizeof(buf), "IP&nbsp;vs.&nbsp;Non-IP&nbsp;Rcvd",
 
3914
                              "IP", "Non-IP", -1, percentage);
 
3915
  }
 
3916
 
 
3917
  total = el->pktSent.value+el->pktRcvd.value;
 
3918
  if(total > 0) {
 
3919
    percentage = ((float)el->pktSent.value*100)/((float)total);
 
3920
    printTableEntryPercentage(buf, sizeof(buf), "Sent&nbsp;vs.&nbsp;Rcvd&nbsp;Pkts",
 
3921
                              "Sent", "Rcvd", -1, percentage);
 
3922
  }
 
3923
 
 
3924
  total = el->bytesSent.value+el->bytesRcvd.value;
 
3925
  if(total > 0) {
 
3926
    percentage = ((float)el->bytesSent.value*100)/((float)total);
 
3927
    printTableEntryPercentage(buf, sizeof(buf), "Sent&nbsp;vs.&nbsp;Rcvd&nbsp;Data",
 
3928
                              "Sent", "Rcvd", -1, percentage);
 
3929
  }
 
3930
 
 
3931
  /* ******************** */
 
3932
 
 
3933
  printedHeader=0;
 
3934
  for(i=0; i<MAX_NUM_CONTACTED_PEERS; i++) {
 
3935
      if(!emptySerial(&el->contactedRouters.peersSerials[i])) {
 
3936
          HostSerial routerIdx = el->contactedRouters.peersSerials[i];
 
3937
 
 
3938
      if(!emptySerial(&routerIdx)) {
 
3939
        HostTraffic *router = quickHostLink(routerIdx, myGlobals.actualReportDeviceId, &tmpEl);
 
3940
 
 
3941
        if(router != NULL) {
 
3942
          if(!printedHeader) {
 
3943
            if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">"
 
3944
                        "Used&nbsp;Subnet&nbsp;Routers</TH><TD "TD_BG" ALIGN=RIGHT>\n",
 
3945
                        getRowColor()) < 0)
 
3946
              BufferTooShort();
 
3947
            sendString(buf);
 
3948
          }
 
3949
          printedHeader++;
 
3950
 
 
3951
          if(printedHeader > 1) sendString("<BR>");
 
3952
 
 
3953
          if(snprintf(buf, sizeof(buf), "%s\n",
 
3954
                      makeHostLink(router, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0,
 
3955
                                   hostLinkBuf, sizeof(hostLinkBuf))) < 0)
 
3956
            BufferTooShort();
 
3957
          sendString(buf);
 
3958
        }
 
3959
      }
 
3960
    }
 
3961
  }
 
3962
 
 
3963
  checkHostProvidedServices(el);
 
3964
 
 
3965
  /*
 
3966
    Fix courtesy of
 
3967
    Albert Chin-A-Young <china@thewrittenword.com>
 
3968
  */
 
3969
  if(printedHeader > 1)
 
3970
    sendString("</OL></TD></TR>\n");
 
3971
 
 
3972
  /* **************************** */
 
3973
 
 
3974
  if((el->protocolInfo) && (el->protocolInfo->userList != NULL)) {
 
3975
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">"
 
3976
                "Known&nbsp;Users&nbsp;" CONST_IMG_HAS_USERS "</TH><TD "TD_BG" ALIGN=RIGHT>\n",
 
3977
                getRowColor()) < 0)
 
3978
      BufferTooShort();
 
3979
    sendString(buf);
 
3980
 
 
3981
    printUserList(el);
 
3982
    sendString("<br>\n</TD></TR>\n");
 
3983
  }
 
3984
 
 
3985
  /* **************************** */
 
3986
 
 
3987
  if((el->hostNumIpAddress[0] != '\0')
 
3988
     && (!subnetPseudoLocalHost(el))
 
3989
     && (!multicastHost(el))
 
3990
     && (!privateIPAddress(el))) {
 
3991
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3992
                "[ <A HREF=\"http://www.radb.net/cgi-bin/radb/whois.cgi?obj=%s\">Whois</A> ]</TD></TR>\n",
 
3993
                getRowColor(), "Further Host Information", el->hostNumIpAddress) < 0)
 
3994
      BufferTooShort();
 
3995
    sendString(buf);
 
3996
 
 
3997
    if(myGlobals.mapperURL) {
 
3998
      if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
3999
                  "<IMG SRC=\"%s?host=%s\" alt=\"map of host location\" WIDTH=320 HEIGHT=200></TD></TR>\n",
 
4000
                  getRowColor(),
 
4001
                  "Host Physical Location",
 
4002
                  myGlobals.mapperURL, el->hostNumIpAddress) < 0)
 
4003
      BufferTooShort();
 
4004
      sendString(buf);
 
4005
    }
 
4006
  }
 
4007
 
 
4008
  /* RRD */
 
4009
  if(el->hostNumIpAddress[0] != '\0') {
 
4010
    struct stat statbuf;
 
4011
    char *key;
 
4012
 
 
4013
    if((!myGlobals.dontTrustMACaddr) && subnetPseudoLocalHost(el) 
 
4014
       && (el->ethAddressString[0] != '\0') /* Really safe in case a host that was supposed to be local isn't really so*/)
 
4015
      key = el->ethAddressString;
 
4016
    else
 
4017
      key = el->hostNumIpAddress;
 
4018
 
 
4019
    /* Do NOT add a '/' at the end of the path because Win32 will complain about it */
 
4020
    if(snprintf(buf, sizeof(buf), "%s/interfaces/%s/hosts/%s",
 
4021
             myGlobals.rrdPath != NULL ? myGlobals.rrdPath : ".",
 
4022
             myGlobals.device[myGlobals.actualReportDeviceId].humanFriendlyName,
 
4023
             dotToSlash(key)) < 0)
 
4024
      BufferTooShort();
 
4025
 
 
4026
    if(stat(buf, &statbuf) == 0) {
 
4027
      if(snprintf(buf, sizeof(buf),
 
4028
                  "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">Historical Data</TH>\n"
 
4029
                  "<TD "TD_BG" ALIGN=\"right\">"
 
4030
                  "[ <a href=\"/" CONST_PLUGINS_HEADER 
 
4031
                  "rrdPlugin?action=list&amp;key=interfaces/%s/hosts/%s&amp;title=host%%20%s\">"
 
4032
                  "<img valign=\"top\" border=\"0\" src=\"/graph.gif\""
 
4033
                  " alt=\"view rrd graphs of historical data for this host\"></a> ]"
 
4034
                  "</TD></TR>\n",
 
4035
                  getRowColor(),
 
4036
                  myGlobals.device[myGlobals.actualReportDeviceId].humanFriendlyName,
 
4037
                  dotToSlash(key),
 
4038
                  el->hostResolvedName[0] != '\0' ? el->hostResolvedName : el->hostNumIpAddress) < 0)
 
4039
        BufferTooShort();
 
4040
      sendString(buf);
 
4041
    }
 
4042
  }
 
4043
 
 
4044
  checkHostHealthness(el);
 
4045
 
 
4046
  sendString("</TABLE>"TABLE_OFF"<P>\n");
 
4047
  sendString("</CENTER>\n");
 
4048
}
 
4049
 
 
4050
/* ************************************ */
 
4051
 
 
4052
void printServiceStats(char* svcName, ServiceStats* ss,
 
4053
                       short printSentStats) {
 
4054
  char buf[LEN_GENERAL_WORK_BUFFER];
 
4055
  Counter tot, tot1;
 
4056
  float f1, f2, f3, f4;
 
4057
  char formatBuf[32], formatBuf1[32], formatBuf2[32], formatBuf3[32], formatBuf4[32],
 
4058
    formatBuf5[32], formatBuf6[32], formatBuf7[32];
 
4059
 
 
4060
  if(ss != NULL) {
 
4061
    if(printSentStats) {
 
4062
      tot = ss->numLocalReqSent.value+ss->numRemReqSent.value;
 
4063
 
 
4064
      if(tot == 0)
 
4065
        f1 = f2 = 0;
 
4066
      else {
 
4067
        f1 = (ss->numLocalReqSent.value*100)/tot;
 
4068
        f2 = (ss->numRemReqSent.value*100)/tot;
 
4069
      }
 
4070
 
 
4071
      tot1 = ss->numPositiveReplRcvd.value+ss->numNegativeReplRcvd.value;
 
4072
      if(tot1 == 0)
 
4073
        f3 = f4 = 0;
 
4074
      else {
 
4075
        f3 = (ss->numPositiveReplRcvd.value*100)/tot1;
 
4076
        f4 = (ss->numNegativeReplRcvd.value*100)/tot1;
 
4077
      }
 
4078
 
 
4079
      if((tot > 0) || (tot1 > 0)) {
 
4080
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" "DARK_BG">%s</TH>"
 
4081
                    "<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
 
4082
                    "<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
 
4083
                    "<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
 
4084
                    "<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
 
4085
                    "<TD "TD_BG" ALIGN=CENTER>%s - %s</TD><TD "TD_BG" ALIGN=CENTER>%s - %s</TD>"
 
4086
                    "</TR>\n",
 
4087
                    getRowColor(), svcName,
 
4088
                    formatPkts(ss->numLocalReqSent.value, formatBuf, sizeof(formatBuf)), f1,
 
4089
                    formatPkts(ss->numRemReqSent.value, formatBuf1, sizeof(formatBuf1)), f2,
 
4090
                    formatPkts(ss->numPositiveReplRcvd.value, formatBuf2, sizeof(formatBuf2)), f3,
 
4091
                    formatPkts(ss->numNegativeReplRcvd.value, formatBuf3, sizeof(formatBuf3)), f4,
 
4092
                    formatMicroSeconds(ss->fastestMicrosecLocalReqMade, formatBuf4, sizeof(formatBuf4)),
 
4093
                    formatMicroSeconds(ss->slowestMicrosecLocalReqMade, formatBuf5, sizeof(formatBuf5)),
 
4094
                    formatMicroSeconds(ss->fastestMicrosecRemReqMade, formatBuf6, sizeof(formatBuf6)),
 
4095
                    formatMicroSeconds(ss->slowestMicrosecRemReqMade, formatBuf7, sizeof(formatBuf7))
 
4096
                    ) < 0) BufferTooShort();
 
4097
        sendString(buf);
 
4098
      }
 
4099
    } else {
 
4100
      tot = ss->numLocalReqRcvd.value+ss->numRemReqRcvd.value;
 
4101
 
 
4102
      if(tot == 0)
 
4103
        f1 = f2 = 0;
 
4104
      else {
 
4105
        f1 = (ss->numLocalReqRcvd.value*100)/tot;
 
4106
        f2 = (ss->numRemReqRcvd.value*100)/tot;
 
4107
      }
 
4108
 
 
4109
      tot1 = ss->numPositiveReplSent.value+ss->numNegativeReplSent.value;
 
4110
      if(tot1 == 0)
 
4111
        f3 = f4 = 0;
 
4112
      else {
 
4113
        f3 = (ss->numPositiveReplSent.value*100)/tot1;
 
4114
        f4 = (ss->numNegativeReplSent.value*100)/tot1;
 
4115
      }
 
4116
 
 
4117
      if((tot > 0) || (tot1 > 0)) {
 
4118
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG">%s</TH>"
 
4119
                "<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
 
4120
                "<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
 
4121
                "<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
 
4122
                "<TD "TD_BG" ALIGN=CENTER>%s</TD><TD "TD_BG" ALIGN=CENTER>%.1f%%</TD>"
 
4123
                "<TD "TD_BG" ALIGN=CENTER>%s - %s</TD><TD "TD_BG" ALIGN=CENTER>%s - %s</TD>"
 
4124
                "</TR>\n",
 
4125
                getRowColor(), svcName,
 
4126
                formatPkts(ss->numLocalReqRcvd.value, formatBuf, sizeof(formatBuf)), f1,
 
4127
                formatPkts(ss->numRemReqRcvd.value, formatBuf1, sizeof(formatBuf1)), f2,
 
4128
                formatPkts(ss->numPositiveReplSent.value, formatBuf2, sizeof(formatBuf2)), f3,
 
4129
                formatPkts(ss->numNegativeReplSent.value, formatBuf3, sizeof(formatBuf3)), f4,
 
4130
                formatMicroSeconds(ss->fastestMicrosecLocalReqServed, formatBuf4, sizeof(formatBuf4)),
 
4131
                formatMicroSeconds(ss->slowestMicrosecLocalReqServed, formatBuf5, sizeof(formatBuf5)),
 
4132
                formatMicroSeconds(ss->fastestMicrosecRemReqServed, formatBuf6, sizeof(formatBuf6)),
 
4133
                formatMicroSeconds(ss->slowestMicrosecRemReqServed, formatBuf7, sizeof(formatBuf7))
 
4134
                ) < 0) BufferTooShort();
 
4135
        sendString(buf);
 
4136
      }
 
4137
    }
 
4138
  }
 
4139
}
 
4140
 
 
4141
/* ************************************ */
 
4142
 
 
4143
void printHostUsedServices(HostTraffic *el, int actualDeviceId) {
 
4144
  Counter tot;
 
4145
 
 
4146
  if((el->protocolInfo == NULL)
 
4147
     || ((el->protocolInfo->dnsStats == NULL) && (el->protocolInfo->httpStats == NULL)))
 
4148
    return;
 
4149
 
 
4150
  tot = 0;
 
4151
 
 
4152
  if(el->protocolInfo->dnsStats)
 
4153
    tot += el->protocolInfo->dnsStats->numLocalReqSent.value + el->protocolInfo->dnsStats->numRemReqSent.value;
 
4154
 
 
4155
  if(el->protocolInfo->httpStats)
 
4156
    tot += el->protocolInfo->httpStats->numLocalReqSent.value + el->protocolInfo->httpStats->numRemReqSent.value;
 
4157
 
 
4158
  if(tot > 0) {
 
4159
    printSectionTitle("IP&nbsp;Service&nbsp;Stats:&nbsp;Client&nbsp;Role");
 
4160
    sendString("<CENTER>\n");
 
4161
    sendString(""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\">\n<TR "TR_ON" "DARK_BG">"
 
4162
               "<TH "TH_BG">&nbsp;</TH>"
 
4163
               "<TH "TH_BG" COLSPAN=2>#&nbsp;Loc.&nbsp;Req.&nbsp;Sent</TH>"
 
4164
               "<TH "TH_BG" COLSPAN=2>#&nbsp;Rem.&nbsp;Req.&nbsp;Sent</TH>"
 
4165
               "<TH "TH_BG" COLSPAN=2>#&nbsp;Pos.&nbsp;Reply&nbsp;Rcvd</TH>"
 
4166
               "<TH "TH_BG" COLSPAN=2>#&nbsp;Neg.&nbsp;Reply&nbsp;Rcvd</TH>"
 
4167
               "<TH "TH_BG">Local&nbsp;RndTrip</TH>"
 
4168
               "<TH "TH_BG">Rem&nbsp;RndTrip</TH>"
 
4169
               "</TR>\n");
 
4170
 
 
4171
    if(el->protocolInfo->dnsStats)  printServiceStats("DNS", el->protocolInfo->dnsStats, 1);
 
4172
    if(el->protocolInfo->httpStats) printServiceStats("HTTP", el->protocolInfo->httpStats, 1);
 
4173
 
 
4174
    sendString("</TABLE>"TABLE_OFF"\n");
 
4175
    sendString("</CENTER>\n");
 
4176
  }
 
4177
 
 
4178
  /* ************ */
 
4179
 
 
4180
  tot = 0;
 
4181
 
 
4182
  if(el->protocolInfo->dnsStats)
 
4183
    tot += el->protocolInfo->dnsStats->numLocalReqRcvd.value+el->protocolInfo->dnsStats->numRemReqRcvd.value;
 
4184
 
 
4185
  if(el->protocolInfo->httpStats)
 
4186
    tot += el->protocolInfo->httpStats->numLocalReqRcvd.value+el->protocolInfo->httpStats->numRemReqRcvd.value;
 
4187
 
 
4188
  if(tot > 0) {
 
4189
    printSectionTitle("IP&nbsp;Service&nbsp;Stats:&nbsp;Server&nbsp;Role");
 
4190
    sendString("<CENTER>\n");
 
4191
    sendString("<P>"TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\">\n<TR "TR_ON" "DARK_BG">"
 
4192
               "<TH "TH_BG">&nbsp;</TH>"
 
4193
               "<TH "TH_BG" COLSPAN=2>#&nbsp;Loc.&nbsp;Req.&nbsp;Rcvd</TH>"
 
4194
               "<TH "TH_BG" COLSPAN=2>#&nbsp;Rem.&nbsp;Req.&nbsp;Rcvd</TH>"
 
4195
               "<TH "TH_BG" COLSPAN=2>#&nbsp;Pos.&nbsp;Reply&nbsp;Sent</TH>"
 
4196
               "<TH "TH_BG" COLSPAN=2>#&nbsp;Neg.&nbsp;Reply&nbsp;Sent</TH>"
 
4197
               "<TH "TH_BG">Local&nbsp;RndTrip</TH>"
 
4198
               "<TH "TH_BG">Rem&nbsp;RndTrip</TH>"
 
4199
               "</TR>\n");
 
4200
 
 
4201
    if(el->protocolInfo->dnsStats) printServiceStats("DNS", el->protocolInfo->dnsStats, 0);
 
4202
    if(el->protocolInfo->httpStats) printServiceStats("HTTP", el->protocolInfo->httpStats, 0);
 
4203
 
 
4204
    sendString("</TABLE>"TABLE_OFF"\n");
 
4205
    sendString("</CENTER>\n");
 
4206
  }
 
4207
}
 
4208
 
 
4209
/* ********************************** */
 
4210
 
 
4211
void printTableEntry(char *buf, int bufLen,
 
4212
                     char *label, char* color,
 
4213
                     float total, float percentage) {
 
4214
  int int_perc;
 
4215
  char formatBuf[32];
 
4216
 
 
4217
  if(total == 0) return;
 
4218
 
 
4219
  int_perc = (int)percentage;
 
4220
 
 
4221
  /* This shouldn't happen */
 
4222
  if(int_perc < 0) {
 
4223
    int_perc = 0;
 
4224
    percentage = 0;
 
4225
  } else if(int_perc > 100) {
 
4226
    int_perc = 100;
 
4227
    percentage = 100;
 
4228
  }
 
4229
 
 
4230
  switch(int_perc) {
 
4231
  case 0:
 
4232
    if(snprintf(buf, bufLen, "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT WIDTH=150 "DARK_BG">%s</TH>"
 
4233
                "<TD "TD_BG" ALIGN=RIGHT WIDTH=50>%s</TD><TD "TD_BG" ALIGN=RIGHT WIDTH=50>0%%</TD>"
 
4234
                "<TD "TD_BG" WIDTH=200>&nbsp;</TD></TR>\n",
 
4235
                getRowColor(), label, formatKBytes(total, formatBuf, sizeof(formatBuf))) < 0)
 
4236
      BufferTooShort();
 
4237
    break;
 
4238
  case 100:
 
4239
    if(snprintf(buf, bufLen, "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT WIDTH=150 "DARK_BG">%s</TH>"
 
4240
                "<TD "TD_BG" ALIGN=RIGHT WIDTH=50>%s</TD><TD "TD_BG" ALIGN=RIGHT WIDTH=50>100%%</TD>"
 
4241
                "<TD ALIGN=CENTER WIDTH=200><IMG ALT=\"100%%\" ALIGN=MIDDLE SRC=\"/gauge.jpg\" WIDTH=200 HEIGHT=12>"
 
4242
                "</TD></TR>\n",
 
4243
                getRowColor(), label, formatKBytes(total, formatBuf, sizeof(formatBuf))) < 0)
 
4244
      BufferTooShort();
 
4245
    break;
 
4246
  default:
 
4247
    if(snprintf(buf, bufLen, "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT WIDTH=150 "DARK_BG">%s</TH>"
 
4248
                "<TD "TD_BG" ALIGN=RIGHT WIDTH=50>%s</TD><TD "TD_BG" ALIGN=RIGHT WIDTH=50>%d%%</TD>"
 
4249
                "<TD "TD_BG" WIDTH=200><TABLE BORDER=0 "TABLE_DEFAULTS" CELLPADDING=0 CELLSPACING=0 WIDTH=200>"
 
4250
                "<TR "TR_ON"><TD><IMG ALIGN=MIDDLE ALT=\"%d%%\" SRC=\"/gauge.jpg\" WIDTH=\"%d\" HEIGHT=12>"
 
4251
                "</TD><TD "TD_BG" ALIGN=CENTER WIDTH=\"%d\" %s>"
 
4252
                "<P>&nbsp;</TD></TR></TABLE>"TABLE_OFF"</TD></TR>\n",
 
4253
                getRowColor(), label, formatKBytes(total, formatBuf, sizeof(formatBuf)), int_perc,
 
4254
                int_perc, (200*int_perc)/100,
 
4255
                (200*(100-int_perc))/100, getActualRowColor()) < 0)
 
4256
      BufferTooShort();
 
4257
  }
 
4258
 
 
4259
  sendString(buf);
 
4260
}
 
4261
 
 
4262
/* ************************ */
 
4263
 
 
4264
char* buildHTMLBrowserWindowsLabel(int i, int j, u_short forIpTraffic) {
 
4265
  static char buf[LEN_GENERAL_WORK_BUFFER];
 
4266
  int idx = i*myGlobals.device[myGlobals.actualReportDeviceId].numHosts + j;
 
4267
  char formatBuf[32], formatBuf1[32], formatBuf2[32], formatBuf3[32];
 
4268
 
 
4269
  accessAddrResMutex("buildHTMLBrowserWindowsLabel");
 
4270
 
 
4271
  if((myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx] == NULL)
 
4272
     || ((myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent.value == 0)
 
4273
         && (myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesRcvd.value == 0)))
 
4274
    buf[0]='\0';
 
4275
  else if ((myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent.value > 0)
 
4276
           && (myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesRcvd.value == 0)) {
 
4277
    if(snprintf(buf, sizeof(buf), "(%s->%s)=%s/%s Pkts",
 
4278
                myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrixHosts[i]->hostResolvedName,
 
4279
                myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrixHosts[j]->hostResolvedName,
 
4280
                formatBytes(myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent.value, 1, formatBuf, sizeof(formatBuf)),
 
4281
                formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->pktsSent.value, formatBuf1, sizeof(formatBuf1))) < 0)
 
4282
      BufferTooShort();
 
4283
  } else if ((myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent.value == 0)
 
4284
             && (myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesRcvd.value > 0)) {
 
4285
    if(snprintf(buf, sizeof(buf), "(%s->%s)=%s/%s Pkts",
 
4286
                myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrixHosts[j]->hostResolvedName,
 
4287
                myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrixHosts[i]->hostResolvedName,
 
4288
                formatBytes(myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesRcvd.value, 1, formatBuf, sizeof(formatBuf)),
 
4289
                formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->pktsRcvd.value, formatBuf1, sizeof(formatBuf1))) < 0)
 
4290
      BufferTooShort();
 
4291
  } else {
 
4292
    if(snprintf(buf, sizeof(buf), "(%s->%s)=%s/%s Pkts, (%s->%s)=%s/%s Pkts",
 
4293
                myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrixHosts[i]->hostResolvedName,
 
4294
                myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrixHosts[j]->hostResolvedName,
 
4295
                formatBytes(myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent.value, 1, formatBuf, sizeof(formatBuf)),
 
4296
                formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->pktsSent.value, formatBuf1, sizeof(formatBuf1)),
 
4297
                myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrixHosts[j]->hostResolvedName,
 
4298
                myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrixHosts[i]->hostResolvedName,
 
4299
                formatBytes(myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesRcvd.value, 1, formatBuf2, sizeof(formatBuf2)),
 
4300
                formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->pktsRcvd.value, formatBuf3, sizeof(formatBuf3))) < 0)
 
4301
      BufferTooShort();
 
4302
  }
 
4303
 
 
4304
  releaseAddrResMutex();
 
4305
  return(buf);
 
4306
}
 
4307
 
 
4308
/* *********************************** */
 
4309
 
 
4310
void printHostHourlyTrafficEntry(HostTraffic *el, int i,
 
4311
                                 Counter tcSent, Counter tcRcvd) {
 
4312
  float pctg;
 
4313
  char buf[LEN_GENERAL_WORK_BUFFER], formatBuf[32];
 
4314
 
 
4315
  if(el->trafficDistribution == NULL) return;
 
4316
 
 
4317
  if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, "<TD "TD_BG" ALIGN=RIGHT>%s</TD>",
 
4318
              formatBytes(el->trafficDistribution->last24HoursBytesSent[i].value, 0, formatBuf, sizeof(formatBuf))) < 0)
 
4319
    BufferTooShort();
 
4320
  sendString(buf);
 
4321
 
 
4322
  if(tcSent > 0)
 
4323
    pctg = (float)(el->trafficDistribution->last24HoursBytesSent[i].value*100)/(float)tcSent;
 
4324
  else
 
4325
    pctg = 0;
 
4326
 
 
4327
  if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, "<TD ALIGN=RIGHT %s>%.1f %%</TD>",
 
4328
           getBgPctgColor(pctg), pctg) < 0)
 
4329
    BufferTooShort();
 
4330
  sendString(buf);
 
4331
 
 
4332
  if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, "<TD "TD_BG" ALIGN=RIGHT>%s</TD>",
 
4333
           formatBytes(el->trafficDistribution->last24HoursBytesRcvd[i].value, 0, formatBuf, sizeof(formatBuf))) < 0)
 
4334
    BufferTooShort();
 
4335
  sendString(buf);
 
4336
 
 
4337
 if(tcRcvd > 0)
 
4338
    pctg = (float)(el->trafficDistribution->last24HoursBytesRcvd[i].value*100)/(float)tcRcvd;
 
4339
  else
 
4340
    pctg = 0;
 
4341
 
 
4342
  if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, "<TD ALIGN=RIGHT %s>%.1f %%</TD></TR>",
 
4343
              getBgPctgColor(pctg), pctg) < 0)
 
4344
    BufferTooShort();
 
4345
  sendString(buf);
 
4346
}
 
4347
 
 
4348
/* ************************************ */
 
4349
 
 
4350
char* getNbNodeType(char nodeType) {
 
4351
 
 
4352
  switch(nodeType) {
 
4353
  case 0x0:
 
4354
    return("Workstation");
 
4355
  case 0x20:
 
4356
  default:
 
4357
    return("Server");
 
4358
  }
 
4359
 
 
4360
  return(""); /* NOTREACHED */
 
4361
}
 
4362
 
 
4363
 /* ********************************** */
 
4364
 
 
4365
void printFlagedWarning(char *text) {
 
4366
  char buf[LEN_GENERAL_WORK_BUFFER];
 
4367
 
 
4368
  if(snprintf(buf, LEN_GENERAL_WORK_BUFFER,
 
4369
           "<center>\n"
 
4370
           "<p><img alt=\"Warning\" src=\"/warning.gif\"></p>\n"
 
4371
           "<p><font color=\"#FF0000\" size=\"+1\">%s</font></p>\n"
 
4372
           "</center>\n", text) < 0)
 
4373
    BufferTooShort();
 
4374
  sendString(buf);
 
4375
}
 
4376
 
 
4377
/* ********************************** */
 
4378
 
 
4379
void printPageTitle(char *text) {
 
4380
  sendString("<p>&nbsp;</p>\n");
 
4381
  switch (myGlobals.capturePackets) {
 
4382
      case FLAG_NTOPSTATE_RUN:
 
4383
          break;
 
4384
          ;;
 
4385
      case FLAG_NTOPSTATE_STOPCAP:
 
4386
          sendString("<center><font face=\"Helvetica, Arial, Sans Serif\" size=\"+1\"><b>"
 
4387
                     "Packet capture stopped"
 
4388
                     "</b></font></center>\n");
 
4389
          break;
 
4390
          ;;
 
4391
      case FLAG_NTOPSTATE_TERM:
 
4392
          sendString("<center><font face=\"Helvetica, Arial, Sans Serif\" size=\"+1\"><b>"
 
4393
                     "ntop stopped"
 
4394
                     "</b></font></center>\n");
 
4395
          break;
 
4396
          ;;
 
4397
  }
 
4398
 
 
4399
  sendString("<center>\n<H1><font face=\"Helvetica, Arial, Sans Serif\">");
 
4400
  sendString(text);
 
4401
  sendString("</font></H1>\n</center>\n");
 
4402
}
 
4403
 
 
4404
/* ******************************** */
 
4405
 
 
4406
void printSectionTitle(char *text) {
 
4407
  sendString("<p>&nbsp;</p>\n"
 
4408
             "<center>\n<H2><font face=\"Helvetica, Arial, Sans Serif\">");
 
4409
  sendString(text);
 
4410
  sendString("</font></H2>\n</center>\n");
 
4411
}
 
4412
 
 
4413
/* ******************************** */
 
4414
 
 
4415
void printHostsCharacterization(void) {
 
4416
  u_int a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0, unhealthy=0, totHosts=0;
 
4417
  HostTraffic *el;
 
4418
  char buf[LEN_GENERAL_WORK_BUFFER], hostLinkBuf[LEN_GENERAL_WORK_BUFFER], headerSent = 0;
 
4419
 
 
4420
  printHTMLheader("Local Hosts Characterization", NULL, 0);
 
4421
 
 
4422
  for(el=getFirstHost(myGlobals.actualReportDeviceId);
 
4423
      el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) {
 
4424
    if((broadcastHost(el) == 0) /* No broadcast addresses please */
 
4425
       && (multicastHost(el) == 0) /* No multicast addresses please */
 
4426
       && subnetPseudoLocalHost(el)) {
 
4427
      totHosts++;
 
4428
 
 
4429
      if(isPrinter(el)
 
4430
         || isBridgeHost(el)
 
4431
         || nameServerHost(el) || isNtpServer(el)
 
4432
         || gatewayHost(el)
 
4433
         || isSMTPhost(el) || isIMAPhost(el) || isPOPhost(el)
 
4434
         || isDirectoryHost(el)
 
4435
         || isFTPhost(el)
 
4436
         || isHTTPhost(el)
 
4437
         || isWINShost(el)
 
4438
         || isDHCPClient(el) || isDHCPServer(el)
 
4439
         || isP2P(el)
 
4440
         || (isHostHealthy(el) != 0)
 
4441
         ) {
 
4442
        if(!headerSent) {
 
4443
 
 
4444
          sendString("<center>"TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS">\n<TR "TR_ON" "DARK_BG"><TH "TH_BG">Host</TH>"
 
4445
                     "<TH>Unhealthy<br>Host</TH>"
 
4446
                     "<TH>L2 Switch<br>Bridge</TH>"
 
4447
                     "<TH>Gateway</TH>"
 
4448
                     "<TH>Printer</TH>"
 
4449
                     "<TH>NTP/DNS<br>Server</TH>"
 
4450
                     "<TH>SMTP/POP/IMAP<br>Server</TH>"
 
4451
                     "<TH>Directory/FTP/HTTP<br>Server</TH>"
 
4452
                     "<TH>DHCP/WINS<br>Server</TH>"
 
4453
                     "<TH>DHCP<br>Client</TH>"
 
4454
                     "<TH>P2P</TH>"
 
4455
                     "</TR>\n"
 
4456
                     );
 
4457
          headerSent = 1;
 
4458
        }
 
4459
 
 
4460
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH ALIGN=LEFT>%s</TH>",
 
4461
                    getRowColor(),
 
4462
                    makeHostLink(el, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0,
 
4463
                                 hostLinkBuf, sizeof(hostLinkBuf))) < 0)
 
4464
          BufferTooShort();
 
4465
        sendString(buf);
 
4466
 
 
4467
        if(isHostHealthy(el) != 0) { sendString("<TD ALIGN=CENTER>X</TD>"); unhealthy++; } else sendString("<TD>&nbsp;</TD>");
 
4468
        if(isBridgeHost(el)) { sendString("<TD ALIGN=CENTER>X</TD>"); a++; } else sendString("<TD>&nbsp;</TD>");
 
4469
        if(gatewayHost(el)) { sendString("<TD ALIGN=CENTER>X</TD>"); b++; } else sendString("<TD>&nbsp;</TD>");
 
4470
        if(isPrinter(el)) { sendString("<TD ALIGN=CENTER>X</TD>"); c++; } else sendString("<TD>&nbsp;</TD>");
 
4471
        if(nameServerHost(el) || isNtpServer(el)) { sendString("<TD ALIGN=CENTER>X</TD>"); d++; } else sendString("<TD>&nbsp;</TD>");
 
4472
        if(isSMTPhost(el) || isIMAPhost(el) || isPOPhost(el)) { sendString("<TD ALIGN=CENTER>X</TD>"); e++; } else sendString("<TD>&nbsp;</TD>");
 
4473
        if(isDirectoryHost(el) || isFTPhost(el) || isHTTPhost(el)) { sendString("<TD ALIGN=CENTER>X</TD>"); f++; } else sendString("<TD>&nbsp;</TD>");
 
4474
        if(isDHCPServer(el) || isWINShost(el)) { sendString("<TD ALIGN=CENTER>X</TD>"); g++; } else sendString("<TD>&nbsp;</TD>");
 
4475
        if(isDHCPClient(el)) { sendString("<TD ALIGN=CENTER>X</TD>"); h++; } else sendString("<TD>&nbsp;</TD>");
 
4476
        if(isP2P(el)) { sendString("<TD ALIGN=CENTER>X</TD>"); i++; } else sendString("<TD>&nbsp;</TD>");
 
4477
 
 
4478
        sendString("</TR>\n");
 
4479
      }
 
4480
    }
 
4481
  }
 
4482
 
 
4483
  if(!headerSent) {
 
4484
    printNoDataYet();
 
4485
  } else {
 
4486
    sendString("<TR><TH>Total</TH>");
 
4487
    if(unhealthy > 0) {
 
4488
      if(snprintf(buf, sizeof(buf),
 
4489
                  "<TD ALIGN=CENTER>%d [%.1f %%]</TD>",
 
4490
                  unhealthy, (float)(unhealthy*100)/(float)totHosts) < 0)
 
4491
        BufferTooShort();
 
4492
      sendString(buf);
 
4493
    } else
 
4494
      sendString("<TD>&nbsp;</TD>");
 
4495
 
 
4496
    if(a > 0) {
 
4497
      if(snprintf(buf, sizeof(buf), "<TD ALIGN=CENTER>%d</TD>", a) < 0)
 
4498
        BufferTooShort();
 
4499
      sendString(buf);
 
4500
    } else
 
4501
      sendString("<TD>&nbsp;</TD>");
 
4502
    if(b > 0) {
 
4503
      if(snprintf(buf, sizeof(buf), "<TD ALIGN=CENTER>%d</TD>", b) < 0)
 
4504
        BufferTooShort();
 
4505
      sendString(buf);
 
4506
    } else
 
4507
      sendString("<TD>&nbsp;</TD>");
 
4508
    if(c > 0) {
 
4509
      if(snprintf(buf, sizeof(buf), "<TD ALIGN=CENTER>%d</TD>", c) < 0)
 
4510
        BufferTooShort();
 
4511
      sendString(buf);
 
4512
    } else
 
4513
      sendString("<TD>&nbsp;</TD>");
 
4514
    if(d > 0) {
 
4515
      if(snprintf(buf, sizeof(buf), "<TD ALIGN=CENTER>%d</TD>", d) < 0)
 
4516
        BufferTooShort();
 
4517
      sendString(buf);
 
4518
    } else
 
4519
      sendString("<TD>&nbsp;</TD>");
 
4520
    if(e > 0) {
 
4521
      if(snprintf(buf, sizeof(buf), "<TD ALIGN=CENTER>%d</TD>", e) < 0)
 
4522
        BufferTooShort();
 
4523
      sendString(buf);
 
4524
    } else
 
4525
      sendString("<TD>&nbsp;</TD>");
 
4526
    if(f > 0) {
 
4527
      if(snprintf(buf, sizeof(buf), "<TD ALIGN=CENTER>%d</TD>", f) < 0)
 
4528
        BufferTooShort();
 
4529
      sendString(buf);
 
4530
    } else
 
4531
      sendString("<TD>&nbsp;</TD>");
 
4532
    if(g > 0) {
 
4533
      if(snprintf(buf, sizeof(buf), "<TD ALIGN=CENTER>%d</TD>", g) < 0)
 
4534
        BufferTooShort();
 
4535
      sendString(buf);
 
4536
    } else
 
4537
      sendString("<TD>&nbsp;</TD>");
 
4538
    if(h > 0) {
 
4539
      if(snprintf(buf, sizeof(buf), "<TD ALIGN=CENTER>%d</TD>", h) < 0)
 
4540
        BufferTooShort();
 
4541
      sendString(buf);
 
4542
    } else
 
4543
      sendString("<TD>&nbsp;</TD>");
 
4544
    if(i > 0) {
 
4545
      if(snprintf(buf, sizeof(buf), "<TD ALIGN=CENTER>%d</TD>", i) < 0)
 
4546
        BufferTooShort();
 
4547
      sendString(buf);
 
4548
    } else
 
4549
      sendString("<TD>&nbsp;</TD>");
 
4550
    sendString("</TABLE></CENTER>\n");
 
4551
  }
 
4552
}
 
4553
 
 
4554
/* ******************************** */
 
4555
 
 
4556
static printFingerprintCounts(int countScanned, int countWithoutFP, int countBroadcast,
 
4557
                              int countMulticast, int countRemote, int countNotIP,
 
4558
                              int countUnknownFP, int unknownFPsEtc, int countCantResolve,
 
4559
                              int fingerprintRemote,
 
4560
                              char *unknownFPs) {
 
4561
 
 
4562
  char buf[LEN_GENERAL_WORK_BUFFER];
 
4563
  struct tm t;
 
4564
 
 
4565
  sendString("<p><hr><p>\n");
 
4566
 
 
4567
  printSectionTitle("Statistics");
 
4568
 
 
4569
  if(snprintf(buf, sizeof(buf), 
 
4570
              "<center>\n<table border=1 "TABLE_DEFAULTS">\n"
 
4571
              "<tr><th colspan=\"2\"><i>Scanned</i></th></tr>\n"
 
4572
              "<tr><td>Hosts</td><td align=\"right\">%d</td></tr>\n"
 
4573
              "<tr><th colspan=\"2\"><i>Less:</i></th></tr>\n"
 
4574
              "<tr><td>No fingerprint</td><td align=\"right\">%d</td></tr>\n"
 
4575
              "<tr><td>Broadcast</td><td align=\"right\">%d</td></tr>\n"
 
4576
              "<tr><td>Multicast</td><td align=\"right\">%d</td></tr>\n",
 
4577
              countScanned,
 
4578
              countWithoutFP,
 
4579
              countBroadcast,
 
4580
              countMulticast) < 0)
 
4581
    BufferTooShort();
 
4582
  sendString(buf);
 
4583
 
 
4584
  if(fingerprintRemote != TRUE) {
 
4585
    if(snprintf(buf, sizeof(buf), 
 
4586
                "<tr><td>Remote</td><td align=\"right\">%d</td></tr>\n",
 
4587
                countRemote) < 0)
 
4588
      BufferTooShort();
 
4589
    sendString(buf);
 
4590
  }
 
4591
 
 
4592
  if(snprintf(buf, sizeof(buf), 
 
4593
              "<tr><td>Non IP host</td><td align=\"right\">%d</td></tr>\n"
 
4594
              "<tr><th colspan=\"2\"><i>Gives:</i></th></tr>\n"
 
4595
              "<tr><td>Possible to report</td><td align=\"right\">%d</td></tr>\n",
 
4596
              countNotIP,
 
4597
              countScanned - countWithoutFP - countBroadcast - countMulticast
 
4598
                           - countRemote - countNotIP) < 0)
 
4599
    BufferTooShort();
 
4600
  sendString(buf);
 
4601
 
 
4602
  if(snprintf(buf, sizeof(buf), 
 
4603
              "<tr><td>Less: Can not resolve<sup>*</sup></td>"
 
4604
                  "<td align=\"right\">%d</td></tr>\n",
 
4605
              countCantResolve) < 0)
 
4606
    BufferTooShort();
 
4607
  sendString(buf);
 
4608
 
 
4609
  if(snprintf(buf, sizeof(buf), 
 
4610
              "<tr><td>Less: Unknown Fingerprint<sup>**</sup></td>"
 
4611
                  "<td align=\"right\">%d</td></tr>\n",
 
4612
              countUnknownFP) < 0)
 
4613
    BufferTooShort();
 
4614
  sendString(buf);
 
4615
 
 
4616
  sendString("</td></tr>\n</table>\n<p><table border=0 width=80%%>\n");
 
4617
 
 
4618
  sendString("<tr><td><sup>*</sup>&nbsp;<i>Can not resolve</i>&nbsp;means "
 
4619
             "either the fingerprint was incomplete, or we tried to resolve "
 
4620
             "it on a previous scan and it was not on file. "
 
4621
             "No further action will occur for these hosts.</td></tr>\n");
 
4622
 
 
4623
  sendString("<tr><td><sup>**</sup>&nbsp;<i>Unknown Fingerprints</i>&nbsp;means "
 
4624
             "we have not tried to resolve them yet.\n"
 
4625
             "<ul>");
 
4626
 
 
4627
#ifdef CFG_MULTITHREADED
 
4628
  if((myGlobals.nextFingerprintScan > 0) &&
 
4629
     (countUnknownFP > 0) &&
 
4630
     (myGlobals.debugMode != 1)) {
 
4631
        strftime(buf, sizeof(buf), 
 
4632
                 CONST_LOCALE_TIMESPEC, localtime_r(&myGlobals.nextFingerprintScan, &t));
 
4633
        sendString("<li>May be resolved during the next scan, scheduled for ");
 
4634
        sendString(buf);
 
4635
        sendString(" (approximately).</li>\n");
 
4636
      }
 
4637
#endif
 
4638
 
 
4639
  if(unknownFPs[0] != '\0') {
 
4640
    unknownFPs[0]=' ';
 
4641
    if(snprintf(buf, sizeof(buf), 
 
4642
              "<li>Are:</i>&nbsp;%s%s</li>\n",
 
4643
              unknownFPs,
 
4644
              unknownFPsEtc == 1 ? " ..." : "") < 0)
 
4645
      BufferTooShort();
 
4646
    sendString(buf);
 
4647
  }
 
4648
 
 
4649
  sendString("<li><p>Click "
 
4650
             "<a href=\"http://ettercap.sourceforge.net/index.php?s=stuff&p=fingerprint\" "
 
4651
             "alt=\"Ettercap page at SourceForge\">here</a> to visit Ettercap's home "
 
4652
             "page at SourceForge and upload new fingerprints, or download additional, "
 
4653
             "unverified, ones.</li>\n"
 
4654
             "</ul></td></tr>\n");
 
4655
 
 
4656
  if(fingerprintRemote != TRUE)
 
4657
    sendString("<tr><td>Fingerprinting of non-local hosts may be erroneous "
 
4658
               "- routers and intermediate hosts can alter the characteristics used to "
 
4659
               "determine the operating system. Unfortunately, this can also occur because "
 
4660
               "of entries not in the signature file, " CONST_OSFINGERPRINT_FILE "(.gz) - "
 
4661
               "and there's no way to tell."
 
4662
               "\n<br>That said, if you would like to see a page with ALL host fingerprints, "
 
4663
               "local and remote, click <a href=\"" CONST_HOSTS_REMOTE_FINGERPRINT_HTML 
 
4664
               "\" title=\"All host fingerprints page\">here</a></td></tr>\n");
 
4665
 
 
4666
  sendString("</table></center>\n");
 
4667
}
 
4668
 
 
4669
/* ******************************** */
 
4670
 
 
4671
void printHostsStats(int fingerprintRemote) {
 
4672
  u_int idx, numEntries=0, maxHosts;
 
4673
  HostTraffic *el, **tmpTable;
 
4674
  OsNumInfo theOSs[MAX_NUM_OS];
 
4675
  int i, 
 
4676
      countScanned=0,
 
4677
      countWithoutFP=0,
 
4678
      countBroadcast=0,
 
4679
      countMulticast=0,
 
4680
      countRemote=0,
 
4681
      countNotIP=0,
 
4682
      countUnknownFP=0,
 
4683
      countCantResolve=0;
 
4684
  char buf[LEN_GENERAL_WORK_BUFFER], hostLinkBuf[LEN_GENERAL_WORK_BUFFER];
 
4685
  char unknownFPs[LEN_GENERAL_WORK_BUFFER];
 
4686
  int unknownFPsEtc=0;
 
4687
 
 
4688
  memset(theOSs, 0, sizeof(theOSs));
 
4689
  memset(unknownFPs, 0, sizeof(unknownFPs));
 
4690
 
 
4691
  if(fingerprintRemote == 1)
 
4692
    printHTMLheader("All Host Fingerprints (Local+Remote)", NULL, BITFLAG_HTML_NO_REFRESH);
 
4693
  else
 
4694
    printHTMLheader("Local Host Fingerprints", NULL, BITFLAG_HTML_NO_REFRESH);
 
4695
 
 
4696
  printSectionTitle("OS Summary");
 
4697
 
 
4698
  if(myGlobals.device[myGlobals.actualReportDeviceId].dummyDevice) {
 
4699
    printFlagedWarning("<I>Host statistics (OS fingerprinting) are not available for virtual interfaces</I>");
 
4700
    return;
 
4701
  }
 
4702
 
 
4703
  maxHosts = myGlobals.device[myGlobals.actualReportDeviceId].hostsno; /* save it as it can change */
 
4704
  tmpTable = (HostTraffic**)mallocAndInitWithReportWarn(maxHosts*sizeof(HostTraffic*), "printHostsStats");
 
4705
  if(tmpTable == NULL)
 
4706
    return;
 
4707
 
 
4708
  for(el=getFirstHost(myGlobals.actualReportDeviceId);
 
4709
      el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) {
 
4710
    countScanned++;
 
4711
    if(el->fingerprint == NULL) {
 
4712
      countWithoutFP++;
 
4713
      continue;
 
4714
    }
 
4715
    if(broadcastHost(el)) {
 
4716
      /* No broadcast addresses please */
 
4717
      countBroadcast++;
 
4718
      continue;
 
4719
    }
 
4720
    if(multicastHost(el)) {
 
4721
      /* No multicast addresses please */
 
4722
      countMulticast++;
 
4723
      continue;
 
4724
    }
 
4725
    if((!subnetPseudoLocalHost(el)) &&
 
4726
       (fingerprintRemote != TRUE)) {
 
4727
      /* Local only */
 
4728
      countRemote++;
 
4729
      continue;
 
4730
    }
 
4731
    if((el->fingerprint[0] != ':') /* fingerprint has not been computed */ &&
 
4732
       ((el->hostNumIpAddress[0] == '\0') ||
 
4733
        (addrnull(&el->hostIpAddress)))) {
 
4734
      countNotIP++;
 
4735
      continue;
 
4736
    }
 
4737
 
 
4738
    if(el->fingerprint[0] != ':') setHostFingerprint(el);
 
4739
    if(el->fingerprint[0] != ':') {
 
4740
      countUnknownFP++;
 
4741
      if(strstr(unknownFPs, el->fingerprint) == NULL) {
 
4742
          if(strlen(unknownFPs) + strlen(el->fingerprint) > (sizeof(unknownFPs) - 5)) {
 
4743
            unknownFPsEtc=1;
 
4744
          } else {
 
4745
            strncat(unknownFPs, ", ", (sizeof(unknownFPs) - strlen(unknownFPs) - 1));
 
4746
            strncat(unknownFPs, el->fingerprint, (sizeof(unknownFPs) - strlen(unknownFPs) - 1));
 
4747
          }
 
4748
      }
 
4749
      continue;
 
4750
    }
 
4751
 
 
4752
    if((el->fingerprint[0] == ':') && (el->fingerprint[1] == '\0')) {
 
4753
      /* Too short */
 
4754
      countCantResolve++;
 
4755
      continue;
 
4756
    }
 
4757
 
 
4758
    tmpTable[numEntries++] = el;
 
4759
 
 
4760
    for(i=0; i<MAX_NUM_OS; i++) {
 
4761
      if(theOSs[i].name == NULL) break;
 
4762
      if(strcmp(theOSs[i].name, &el->fingerprint[1]) == 0) {
 
4763
          theOSs[i].num++;
 
4764
          break;
 
4765
      }
 
4766
    }
 
4767
 
 
4768
    if(theOSs[i].name == NULL) {
 
4769
      theOSs[i].name = strdup(&el->fingerprint[1]);
 
4770
      theOSs[i].num++;
 
4771
    }
 
4772
 
 
4773
    if(numEntries >= maxHosts)
 
4774
      break;
 
4775
  }
 
4776
 
 
4777
  if(numEntries <= 0) {
 
4778
      printNoDataYet();
 
4779
 
 
4780
      free(tmpTable);
 
4781
 
 
4782
      printFingerprintCounts(countScanned, countWithoutFP, countBroadcast,
 
4783
                             countMulticast, countRemote, countNotIP,
 
4784
                             countUnknownFP, unknownFPsEtc, countCantResolve,
 
4785
                             fingerprintRemote,
 
4786
                             unknownFPs);
 
4787
 
 
4788
      return;
 
4789
  }
 
4790
 
 
4791
  myGlobals.columnSort = 0;
 
4792
  qsort(tmpTable, numEntries, sizeof(HostTraffic*), cmpFctn);
 
4793
 
 
4794
  sendString("<CENTER>\n");
 
4795
  sendString(""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS">\n<TR "TR_ON" "DARK_BG"><TH "TH_BG">Host</TH>");
 
4796
 
 
4797
  for(i=0; i<MAX_NUM_OS; i++) {
 
4798
      if(theOSs[i].name == NULL)
 
4799
        break;
 
4800
      else {
 
4801
        char *strtokState, *os, *word;
 
4802
        int sentBR=0;
 
4803
 
 
4804
        sendString("<TH>");
 
4805
        os = strdup(theOSs[i].name);
 
4806
 
 
4807
        word = strtok_r(os, " ", &strtokState);
 
4808
        while(word != NULL) {
 
4809
          if((sentBR++) > 0) sendString("<br>\n");
 
4810
          sendString(word);
 
4811
          word = strtok_r(NULL, " ", &strtokState);
 
4812
        }
 
4813
 
 
4814
        free(os);
 
4815
        sendString("</TH>");
 
4816
      }
 
4817
  }
 
4818
 
 
4819
  sendString("</TR>\n");
 
4820
 
 
4821
  for(idx=0; idx<numEntries; idx++) {
 
4822
      el = tmpTable[idx];
 
4823
 
 
4824
      if(el != NULL) {
 
4825
        char *tmpName1;
 
4826
        tmpName1 = el->hostNumIpAddress;
 
4827
        if((tmpName1[0] == '\0') || (strcmp(tmpName1, "0.0.0.0") == 0))
 
4828
          tmpName1 = myGlobals.separator;
 
4829
 
 
4830
        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH ALIGN=LEFT>%s</TH>",
 
4831
                    getRowColor(),
 
4832
                    makeHostLink(el, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf))) < 0)
 
4833
          BufferTooShort();
 
4834
        sendString(buf);
 
4835
 
 
4836
        for(i=0; i<MAX_NUM_OS; i++) {
 
4837
          if(theOSs[i].name == NULL)
 
4838
            break;
 
4839
          else {
 
4840
            if(strcmp(theOSs[i].name, &el->fingerprint[1]) == 0) {
 
4841
              if((el->protocolInfo != NULL) && (el->protocolInfo->userList != NULL)) {
 
4842
                sendString("<TD ALIGN=LEFT>");
 
4843
                printUserList(el);
 
4844
                sendString("<br>\n</TD>");
 
4845
              } else {
 
4846
                if((el->nonIPTraffic != NULL) && (el->nonIPTraffic->nbDomainName != NULL)) {
 
4847
                  if(snprintf(buf, sizeof(buf),
 
4848
                              "<TD ALIGN=CENTER>[ %s ]</TD>",
 
4849
                              el->nonIPTraffic->nbDomainName) < 0)
 
4850
                    BufferTooShort();
 
4851
                  sendString(buf);
 
4852
                } else
 
4853
                  sendString("<TD ALIGN=CENTER>X</TD>");
 
4854
              }
 
4855
            } else
 
4856
              sendString("<TD>&nbsp;</TD>");
 
4857
          }
 
4858
        } /* for */
 
4859
 
 
4860
        sendString("</TR>\n");
 
4861
      }
 
4862
  }
 
4863
 
 
4864
  sendString("</TABLE></center>\n<p>&nbsp;</p>");
 
4865
 
 
4866
  /* ********************************** */
 
4867
 
 
4868
  qsort(theOSs, MAX_NUM_OS, sizeof(OsNumInfo), cmpOSFctn);
 
4869
 
 
4870
  sendString("<center>" TABLE_ON "<table border=\"1\" " TABLE_DEFAULTS ">\n"
 
4871
             "<tr "TR_ON" "DARK_BG"><th "TH_BG">OS</th>\n<th "TH_BG">Total</th></tr>\n");
 
4872
 
 
4873
  for(i=0; i<MAX_NUM_OS; i++) {
 
4874
     if(theOSs[i].name != NULL) {
 
4875
        if(snprintf(buf, sizeof(buf),
 
4876
                    "<tr><th align=\"left\">%s</th>\n"
 
4877
                    "<td align=\"right\">%d</td></tr>\n", 
 
4878
                    theOSs[i].name, theOSs[i].num) < 0)
 
4879
          BufferTooShort();
 
4880
        sendString(buf);
 
4881
        free(theOSs[i].name);
 
4882
      }
 
4883
  }
 
4884
 
 
4885
  sendString("</table>\n</center>\n");
 
4886
 
 
4887
  free(tmpTable);
 
4888
 
 
4889
  printFingerprintCounts(countScanned, countWithoutFP, countBroadcast,
 
4890
                         countMulticast, countRemote, countNotIP,
 
4891
                         countUnknownFP, unknownFPsEtc, countCantResolve,
 
4892
                         fingerprintRemote,
 
4893
                         unknownFPs);
 
4894
}
 
4895
 
 
4896
/* ******************************************************** */
 
4897
 
 
4898
#ifdef CFG_MULTITHREADED
 
4899
void printMutexStatus(int textPrintFlag, PthreadMutex *mutexId, char *mutexName) {
 
4900
  char buf[LEN_GENERAL_WORK_BUFFER], buf2[64];
 
4901
  struct tm t;
 
4902
 
 
4903
  if(mutexId->numLocks == 0) /* Mutex never used */
 
4904
    return;
 
4905
  memset(buf2, 0, sizeof(buf2));
 
4906
  strftime(buf2, sizeof(buf2), CONST_LOCALE_TIMESPEC, localtime_r(&mutexId->lockTime, &t));
 
4907
  if(textPrintFlag == TRUE) {
 
4908
    if(myGlobals.disableMutexExtraInfo) {
 
4909
        if(snprintf(buf, sizeof(buf),
 
4910
                    "Mutex %s is %s, locked: %u times.\n",
 
4911
                    mutexName, mutexId->isLocked ? "locked" : "unlocked",
 
4912
                    mutexId->numLocks) < 0)
 
4913
          BufferTooShort();
 
4914
        sendString(buf);
 
4915
    } else if(mutexId->lockAttemptLine > 0) {
 
4916
        if(snprintf(buf, sizeof(buf),
 
4917
                    "Mutex %s is %s.\n"
 
4918
                    "     locked: %u times, last was at %s %s:%d(%d)\n"
 
4919
                    "     blocked: at %s:%d%(%d)\n",
 
4920
                    mutexName, mutexId->isLocked ? "locked" : "unlocked",
 
4921
                    mutexId->numLocks,
 
4922
                    buf2,
 
4923
                    mutexId->lockFile, mutexId->lockLine, mutexId->lockPid,
 
4924
                    mutexId->lockAttemptFile, mutexId->lockAttemptLine, mutexId->lockAttemptPid) < 0)
 
4925
          BufferTooShort();
 
4926
                    sendString(buf);
 
4927
 
 
4928
        if(snprintf(buf, sizeof(buf),
 
4929
                    "     unlocked: %u times, last was %s:%d(%d)\n"
 
4930
                    "     longest: %d sec from %s:%d\n",
 
4931
                    mutexId->numReleases, mutexId->unlockFile, mutexId->unlockLine, mutexId->unlockPid,
 
4932
                    mutexId->maxLockedDuration, mutexId->maxLockedDurationUnlockFile,
 
4933
                    mutexId->maxLockedDurationUnlockLine) < 0)
 
4934
          BufferTooShort();
 
4935
    } else {
 
4936
        if(snprintf(buf, sizeof(buf),
 
4937
                    "Mutex %s, is %s.\n"
 
4938
                    "     locked: %u times, last was at %s %s:%d(%d)\n"
 
4939
                    "     unlocked: %u times, last was %s:%d(%d)\n"
 
4940
                    "     longest: %d sec from %s:%d\n",
 
4941
                    mutexName,
 
4942
                    mutexId->isLocked ? "locked" : "unlocked",
 
4943
                    mutexId->numLocks,
 
4944
                    buf2,
 
4945
                    mutexId->lockFile, mutexId->lockLine, mutexId->lockPid,
 
4946
                    mutexId->numReleases,
 
4947
                    mutexId->unlockFile, mutexId->unlockLine, mutexId->unlockPid,
 
4948
                    mutexId->maxLockedDuration,
 
4949
                    mutexId->maxLockedDurationUnlockFile,
 
4950
                    mutexId->maxLockedDurationUnlockLine) < 0)
 
4951
          BufferTooShort();
 
4952
    }
 
4953
  } else {
 
4954
    if(myGlobals.disableMutexExtraInfo) {
 
4955
        if(snprintf(buf, sizeof(buf),
 
4956
                    "<TR><TH ALIGN=LEFT>%s</TH><TD ALIGN=CENTER>%s</TD>"
 
4957
                    "<TD ALIGN=RIGHT>%u</TD><TD ALIGN=RIGHT>%u</TD></TR>\n",
 
4958
                    mutexName,
 
4959
                    mutexId->isLocked ? "<FONT COLOR=\"RED\">locked</FONT>" : "unlocked",
 
4960
                    mutexId->numLocks, mutexId->numReleases) < 0)
 
4961
          BufferTooShort();
 
4962
    } else if (mutexId->lockAttemptLine > 0) {
 
4963
        if(snprintf(buf, sizeof(buf),
 
4964
                    "<TR><TH ALIGN=LEFT>%s</TH><TD ALIGN=CENTER>%s</TD>"
 
4965
                    "<TD ALIGN=RIGHT>at %s %s:%d(%d)</TD>"
 
4966
                    "<TD ALIGN=RIGHT>%s:%d(%d)</TD>"
 
4967
                    "<TD ALIGN=RIGHT>%s:%d(%d)</TD>"
 
4968
                    "<TD ALIGN=RIGHT>%u</TD><TD ALIGN=RIGHT>%u</TD>"
 
4969
                    "<TD ALIGN=RIGHT>%d sec [%s:%d]</TD></TR>\n",
 
4970
                    mutexName,
 
4971
                    mutexId->isLocked ? "<FONT COLOR=\"RED\">locked</FONT>" : "unlocked",
 
4972
                    buf2,
 
4973
                    mutexId->lockFile, mutexId->lockLine, mutexId->lockPid,
 
4974
                    mutexId->lockAttemptFile, mutexId->lockAttemptLine, mutexId->lockAttemptPid,
 
4975
                    mutexId->unlockFile, mutexId->unlockLine, mutexId->unlockPid,
 
4976
                    mutexId->numLocks, mutexId->numReleases,
 
4977
                    mutexId->maxLockedDuration,
 
4978
                    mutexId->maxLockedDurationUnlockFile,
 
4979
                    mutexId->maxLockedDurationUnlockLine) < 0)
 
4980
          BufferTooShort();
 
4981
    } else {
 
4982
        if(snprintf(buf, sizeof(buf),
 
4983
                    "<TR><TH ALIGN=LEFT>%s</TH><TD ALIGN=CENTER>%s</TD>"
 
4984
                    "<TD ALIGN=RIGHT>at %s %s:%d(%d)</TD>"
 
4985
                    "<TD ALIGN=RIGHT>&nbsp;</TD>"
 
4986
                    "<TD ALIGN=RIGHT>%s:%d(%d)</TD>"
 
4987
                    "<TD ALIGN=RIGHT>%u</TD><TD ALIGN=RIGHT>%u</TD>"
 
4988
                    "<TD ALIGN=RIGHT>%d sec [%s:%d]</TD></TR>\n",
 
4989
                    mutexName,
 
4990
                    mutexId->isLocked ? "<FONT COLOR=\"RED\">locked</FONT>" : "unlocked",
 
4991
                    buf2,
 
4992
                    mutexId->lockFile, mutexId->lockLine, mutexId->lockPid,
 
4993
                    mutexId->unlockFile, mutexId->unlockLine, mutexId->unlockPid,
 
4994
                    mutexId->numLocks, mutexId->numReleases,
 
4995
                    mutexId->maxLockedDuration,
 
4996
                    mutexId->maxLockedDurationUnlockFile,
 
4997
                    mutexId->maxLockedDurationUnlockLine) < 0)
 
4998
          BufferTooShort();
 
4999
    }
 
5000
  }
 
5001
 
 
5002
  sendString(buf);
 
5003
}
 
5004
#endif
 
5005
 
 
5006
void printFcHeader(int reportType, int revertOrder, u_int column, u_int hourId, char *url)
 
5007
{
 
5008
  char buf[LEN_GENERAL_WORK_BUFFER];
 
5009
  char *sign, *arrowGif, *arrow[48], *theAnchor[48];
 
5010
  int soFar=2;
 
5011
  char htmlAnchor[64], htmlAnchor1[64];
 
5012
  char hours[][24] = {"12<BR>AM", "1<BR>AM", "2<BR>AM", "3<BR>AM", "4<BR>AM", "5<BR>AM", "6<BR>AM",
 
5013
                       "7<BR>AM", "8<BR>AM", "9<BR>AM", "10<BR>AM", "11<BR>AM", "12<BR>PM", "1<BR>PM",
 
5014
                       "2<BR>PM", "3<BR>PM", "4<BR>PM", "5<BR>PM", "6<BR>PM", "7<BR>PM", "8<BR>PM",
 
5015
                       "9<BR>PM", "10<BR>PM", "11<BR>PM"};
 
5016
  int i, j;
 
5017
 
 
5018
  /* printf("->%d<-\n",screenNumber); */
 
5019
 
 
5020
  if(revertOrder) {
 
5021
    sign = "";
 
5022
    arrowGif = "&nbsp;" CONST_IMG_ARROW_UP;
 
5023
  } else {
 
5024
    sign = "-";
 
5025
    arrowGif = "&nbsp;" CONST_IMG_ARROW_DOWN;
 
5026
  }
 
5027
 
 
5028
  memset(buf, 0, sizeof(buf));
 
5029
 
 
5030
  if(snprintf(htmlAnchor, sizeof(htmlAnchor), "<A HREF=\"%s?col=%s", url, sign) < 0)
 
5031
    BufferTooShort();
 
5032
  if(snprintf(htmlAnchor1, sizeof(htmlAnchor1), "<A HREF=\"%s?col=",  url) < 0)
 
5033
    BufferTooShort();
 
5034
 
 
5035
  if(abs(column) == FLAG_HOST_DUMMY_IDX) {
 
5036
    arrow[0] = arrowGif; theAnchor[0] = htmlAnchor;
 
5037
  } else {
 
5038
    arrow[0] = ""; theAnchor[0] = htmlAnchor1;
 
5039
  }
 
5040
 
 
5041
  if(abs(column) == FLAG_DOMAIN_DUMMY_IDX) {
 
5042
    arrow[1] = arrowGif; theAnchor[1] = htmlAnchor;
 
5043
  } else {
 
5044
    arrow[1] = "";  theAnchor[1] = htmlAnchor1;
 
5045
  }
 
5046
 
 
5047
  if(abs(column) == 0) {
 
5048
    arrow[2] = arrowGif; theAnchor[2] = htmlAnchor;
 
5049
  } else {
 
5050
    arrow[2] = ""; theAnchor[2] = htmlAnchor1;
 
5051
  }
 
5052
 
 
5053
  switch(reportType) {
 
5054
  case SORT_FC_DATA:
 
5055
    sendString("<CENTER>\n");
 
5056
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS"><TR "TR_ON">"
 
5057
                "<TH "TH_BG" "DARK_BG">%s" FLAG_DOMAIN_DUMMY_IDX_STR "\">VSAN%s</A></TH>\n"
 
5058
                "<TH "TH_BG" "DARK_BG">%s" FLAG_HOST_DUMMY_IDX_STR "\">FC_Port%s</A></TH>\n"
 
5059
                "<TH "TH_BG" COLSPAN=2 "DARK_BG">%s0\">Total Bytes%s</A></TH>\n",
 
5060
                theAnchor[1], arrow[1], theAnchor[0], arrow[0],
 
5061
                theAnchor[2], arrow[2]) < 0)
 
5062
      BufferTooShort();
 
5063
    sendString(buf);
 
5064
 
 
5065
    if(abs(column) == 1)
 
5066
      { arrow[0] = arrowGif; theAnchor[0] = htmlAnchor; }
 
5067
    else { arrow[0] = ""; theAnchor[0] = htmlAnchor1;  }
 
5068
    if(abs(column) == 2)
 
5069
      { arrow[1] = arrowGif; theAnchor[1] = htmlAnchor;  }
 
5070
    else { arrow[1] = "";  theAnchor[1] = htmlAnchor1;}
 
5071
    if(abs(column) == 3)
 
5072
      { arrow[2] = arrowGif; theAnchor[2] = htmlAnchor;  }
 
5073
    else { arrow[2] = ""; theAnchor[2] = htmlAnchor1; }
 
5074
    if(abs(column) == 4)
 
5075
      { arrow[3] = arrowGif; theAnchor[3] = htmlAnchor;  }
 
5076
    else { arrow[3] = ""; theAnchor[3] = htmlAnchor1; }
 
5077
    if(abs(column) == 5)
 
5078
      { arrow[4] = arrowGif; theAnchor[4] = htmlAnchor;  }
 
5079
    else { arrow[4] = ""; theAnchor[4] = htmlAnchor1;  }
 
5080
    if(abs(column) == 6)
 
5081
      { arrow[5] = arrowGif; theAnchor[5] = htmlAnchor;  }
 
5082
    else { arrow[5] = ""; theAnchor[5] = htmlAnchor1;  }
 
5083
    if(abs(column) == 7)
 
5084
      { arrow[6] = arrowGif; theAnchor[6] = htmlAnchor1;  }
 
5085
 
 
5086
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, "<TH "TH_BG" "DARK_BG">%s1\">SCSI%s</A></TH>"
 
5087
                "<TH "TH_BG" "DARK_BG">%s2\">ELS%s</A></TH><TH "TH_BG" "DARK_BG">%s3\">NS%s</A></TH>"
 
5088
                "<TH "TH_BG" "DARK_BG">%s4\">IP/FC%s</A><TH "TH_BG" "DARK_BG">%s5\">SWILS%s</A></TH>"
 
5089
                "<TH "TH_BG" "DARK_BG">%s6\">Other%s</A></TH>",
 
5090
                theAnchor[0], arrow[0], theAnchor[1], arrow[1],
 
5091
                theAnchor[2], arrow[2], theAnchor[3], arrow[3],
 
5092
                theAnchor[4], arrow[4], theAnchor[5], arrow[5]) < 0)
 
5093
      BufferTooShort();
 
5094
    sendString(buf);
 
5095
    break;
 
5096
 
 
5097
  case SORT_FC_ACTIVITY:
 
5098
    sendString("<CENTER>\n");
 
5099
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS"><TR >"
 
5100
                "<TH "TH_BG" "DARK_BG">%s" FLAG_DOMAIN_DUMMY_IDX_STR "\">VSAN%s</A></TH>"
 
5101
                "<TH "TH_BG" "DARK_BG">%s" FLAG_HOST_DUMMY_IDX_STR "\">FC_Port%s</A></TH>\n",
 
5102
                theAnchor[1], arrow[1], theAnchor[0], arrow[0]) < 0)
 
5103
      BufferTooShort();
 
5104
    sendString(buf);
 
5105
    j = hourId;
 
5106
    for (i = 0; i < 24; i++) {
 
5107
        j = j % 24;
 
5108
        if (snprintf (buf, sizeof(buf), "<TH "TH_BG" "DARK_BG">%s</TH>\n", hours[j]) < 0)
 
5109
            BufferTooShort();
 
5110
        sendString (buf);
 
5111
        if (!j) {
 
5112
            j = 23;
 
5113
        }
 
5114
        else {
 
5115
            j--;
 
5116
        }
 
5117
    }
 
5118
    break;
 
5119
  case SORT_FC_THPT:
 
5120
    sendString("<CENTER>\n");
 
5121
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS"><TR "TR_ON">"
 
5122
                "<TH "TH_BG" ROWSPAN=\"2\" "DARK_BG">%s" FLAG_DOMAIN_DUMMY_IDX_STR "\">VSAN%s</A></TH>"
 
5123
                "<TH "TH_BG" ROWSPAN=\"2\" "DARK_BG">%s" FLAG_HOST_DUMMY_IDX_STR "\">FC_Port%s</A></TH>",
 
5124
                theAnchor[1], arrow[1], theAnchor[0], arrow[0], theAnchor[2], arrow[2]) < 0)
 
5125
      BufferTooShort();
 
5126
    sendString(buf);
 
5127
    updateThpt(1);
 
5128
    if(abs(column) == 1) { arrow[0] = arrowGif; theAnchor[0] = htmlAnchor; }
 
5129
    else { arrow[0] = ""; theAnchor[0] = htmlAnchor1;  }
 
5130
    if(abs(column) == 2) { arrow[1] = arrowGif; theAnchor[1] = htmlAnchor; }
 
5131
    else { arrow[1] = ""; theAnchor[1] = htmlAnchor1; }
 
5132
    if(abs(column) == 3) { arrow[2] = arrowGif; theAnchor[2] = htmlAnchor; }
 
5133
    else { arrow[2] = "";  theAnchor[2] = htmlAnchor1;}
 
5134
    if(abs(column) == 4) { arrow[3] = arrowGif; theAnchor[3] = htmlAnchor; }
 
5135
    else { arrow[3] = "";  theAnchor[3] = htmlAnchor1;}
 
5136
    if(abs(column) == 5) { arrow[4] = arrowGif; theAnchor[4] = htmlAnchor; }
 
5137
    else { arrow[4] = "";  theAnchor[4] = htmlAnchor1;}
 
5138
    if(abs(column) == 6) { arrow[5] = arrowGif; theAnchor[5] = htmlAnchor; }
 
5139
    else { arrow[5] = "";  theAnchor[5] = htmlAnchor1;}
 
5140
 
 
5141
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, "<TH "TH_BG" COLSPAN=\"3\" ALIGN=\"CENTER\" "DARK_BG">Bytes</TH>"
 
5142
            "<TH "TH_BG" COLSPAN=\"3\" ALIGN=\"CENTER\" "DARK_BG">Packets</TH>"
 
5143
            "</TR><TR "TR_ON">") < 0)
 
5144
      BufferTooShort();
 
5145
    sendString(buf);
 
5146
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, "<TH "TH_BG" "DARK_BG">%s1\">Current%s</A></TH>"
 
5147
             "<TH "TH_BG" "DARK_BG">%s2\">Avg%s</A></TH>"
 
5148
             "<TH "TH_BG" "DARK_BG">%s3\">Peak%s</A></TH>"
 
5149
            "<TH "TH_BG" "DARK_BG">%s4\">Current%s</A></TH><TH "TH_BG" "DARK_BG">%s5\">Avg%s</A></TH>"
 
5150
             "<TH "TH_BG" "DARK_BG">%s6\">Peak%s</A></TH>",
 
5151
            theAnchor[0], arrow[0], theAnchor[1], arrow[1], theAnchor[2], arrow[2],
 
5152
            theAnchor[3], arrow[3], theAnchor[4], arrow[4], theAnchor[5], arrow[5]) < 0)
 
5153
      BufferTooShort();
 
5154
    sendString(buf);
 
5155
    break;
 
5156
  default:
 
5157
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, 
 
5158
                "<CENTER><p>ERROR: reportType=%d</p>\n",
 
5159
                reportType) < 0)
 
5160
      BufferTooShort();
 
5161
    sendString(buf);
 
5162
    if(snprintf(buf, LEN_GENERAL_WORK_BUFFER, ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS"><TR "TR_ON">"
 
5163
                "<TH "TH_BG" "DARK_BG">%s" FLAG_DOMAIN_DUMMY_IDX_STR "\">VSAN%s</A></TH>"
 
5164
                "<TH "TH_BG" "DARK_BG">%s" FLAG_HOST_DUMMY_IDX_STR "\">FC_Port%s</A></TH>",
 
5165
                theAnchor[1], arrow[1], theAnchor[0], arrow[0],
 
5166
                theAnchor[2], arrow[2]) < 0)
 
5167
      BufferTooShort();
 
5168
    sendString(buf);
 
5169
    break;
 
5170
  }
 
5171
 
 
5172
  sendString("</TR>\n");
 
5173
}
 
5174
 
 
5175
/* ******************************* */
 
5176
 
 
5177
void printFcHostHeader (HostTraffic *el, char *url, int revertOrder,
 
5178
                        int column, int hostInfoPage)
 
5179
{
 
5180
  char buf[LEN_GENERAL_WORK_BUFFER];
 
5181
  int soFar=2;
 
5182
  char theLink[256];
 
5183
 
 
5184
  if(snprintf(theLink, sizeof(theLink),
 
5185
              "/%s.html?col=%s%d&showF=",
 
5186
              url, 
 
5187
              revertOrder ? "-" : "",
 
5188
              column) < 0)
 
5189
    BufferTooShort();
 
5190
 
 
5191
  switch(hostInfoPage) {
 
5192
  case showHostLunStats:
 
5193
      if ((el->devType != SCSI_DEV_INITIATOR) &&
 
5194
          (el->devType != SCSI_DEV_UNINIT)) {
 
5195
          if(snprintf(buf, sizeof(buf), "<P ALIGN=LEFT>"
 
5196
                   "[ <A HREF=%s0>Main Page</A> ]&nbsp;"
 
5197
                   "[<B>LUN Statistics</B> ]&nbsp;"
 
5198
                   "[ <A HREF=%s2>LUN Graphs</A> ]&nbsp;"
 
5199
                   "[ <A HREF=%s3>SCSI Session(Bytes)</A> ]&nbsp;"
 
5200
                   "[ <A HREF=%s4>SCSI Session(Times)</A> ]&nbsp;"
 
5201
                   "[ <A HREF=%s5>SCSI Session(Status)</A> ]&nbsp;"
 
5202
                   "[ <A HREF=%s6>SCSI Session(Task Mgmt)</A> ]&nbsp;"
 
5203
                   "[ <A HREF=%s7>FC Sessions</A> ]&nbsp;</p>",
 
5204
                   theLink, theLink, theLink, theLink, theLink, theLink, theLink) < 0)
 
5205
            BufferTooShort();
 
5206
      }
 
5207
      break;
 
5208
  case showHostLunGraphs:
 
5209
      if ((el->devType != SCSI_DEV_INITIATOR) &&
 
5210
          (el->devType != SCSI_DEV_UNINIT)) {
 
5211
          if(snprintf(buf, sizeof(buf), "<P ALIGN=LEFT>"
 
5212
                   "[ <A HREF=%s0>Main Page</A> ]&nbsp;"
 
5213
                   "[ <A HREF=%s1>LUN Statistics</A> ]&nbsp;"
 
5214
                   "[ <B>LUN Graphs</B> ]&nbsp;"
 
5215
                   "[ <A HREF=%s3>SCSI Session(Bytes)</A> ]&nbsp;"
 
5216
                   "[ <A HREF=%s4>SCSI Session(Times)</A> ]&nbsp;"
 
5217
                   "[ <A HREF=%s5>SCSI Session(Status)</A> ]&nbsp;"
 
5218
                   "[ <A HREF=%s6>SCSI Session(Task Mgmt)</A> ]&nbsp;"
 
5219
                   "[ <A HREF=%s7>FC Sessions</A> ]&nbsp;</p>",
 
5220
                   theLink, theLink, theLink, theLink, theLink, theLink, theLink) < 0)
 
5221
            BufferTooShort();
 
5222
      }
 
5223
      break;
 
5224
  case showHostScsiSessionBytes:
 
5225
      if ((el->devType != SCSI_DEV_INITIATOR) &&
 
5226
          (el->devType != SCSI_DEV_UNINIT)) {
 
5227
          if(snprintf(buf, sizeof(buf), "<P ALIGN=LEFT>"
 
5228
                   "[ <A HREF=%s0>Main Page</A> ]&nbsp;"
 
5229
                   "[ <A HREF=%s1>LUN Statistics</A> ]&nbsp;"
 
5230
                   "[ <A HREF=%s2>LUN Graphs</A> ]&nbsp;"
 
5231
                   "[ <B>SCSI Session(Bytes)</B> ]&nbsp;"
 
5232
                   "[ <A HREF=%s4>SCSI Session(Times)</A> ]&nbsp;"
 
5233
                   "[ <A HREF=%s5>SCSI Session(Status)</A> ]&nbsp;"
 
5234
                   "[ <A HREF=%s6>SCSI Session(Task Mgmt)</A> ]&nbsp;"
 
5235
                   "[ <A HREF=%s7>FC Sessions</A> ]&nbsp;</p>",
 
5236
                   theLink, theLink, theLink, theLink, theLink, theLink, theLink) < 0)
 
5237
            BufferTooShort();
 
5238
      }
 
5239
      else {
 
5240
          if(snprintf(buf, sizeof(buf), "<P ALIGN=LEFT>"
 
5241
                   "[ <A HREF=%s0>Main Page</A> ]&nbsp;"
 
5242
                   "[ <B>SCSI Session(Bytes)</B> ]&nbsp;"
 
5243
                   "[ <A HREF=%s4>SCSI Session(Times)</A> ]&nbsp;"
 
5244
                   "[ <A HREF=%s5>SCSI Session(Status)</A> ]&nbsp;"
 
5245
                   "[ <A HREF=%s6>SCSI Session(Task Mgmt)</A> ]&nbsp;"
 
5246
                   "[ <A HREF=%s7>FC Sessions</A> ]&nbsp;</p>",
 
5247
                   theLink, theLink, theLink, theLink, theLink) < 0)
 
5248
            BufferTooShort();
 
5249
      }
 
5250
      break;
 
5251
  case showHostScsiSessionTimes:
 
5252
      if ((el->devType != SCSI_DEV_INITIATOR) &&
 
5253
          (el->devType != SCSI_DEV_UNINIT)) {
 
5254
          if(snprintf(buf, sizeof(buf), "<P ALIGN=LEFT>"
 
5255
                   "[ <A HREF=%s0>Main Page</A>]&nbsp;"
 
5256
                   "[ <A HREF=%s1>LUN Statistics</A> ]&nbsp;"
 
5257
                   "[ <A HREF=%s2>LUN Graphs</A> ]&nbsp;"
 
5258
                   "[ <A HREF=%s3>SCSI Session(Bytes)</A> ]&nbsp;"
 
5259
                   "[ <B>SCSI Session(Times)</B> ]&nbsp;"
 
5260
                   "[ <A HREF=%s5>SCSI Session(Status)</A> ]&nbsp;"
 
5261
                   "[ <A HREF=%s6>SCSI Session(Task Mgmt)</A> ]&nbsp;"
 
5262
                   "[ <A HREF=%s7>FC Sessions</A> ]&nbsp;</p>",
 
5263
                   theLink, theLink, theLink, theLink, theLink, theLink, theLink) < 0)
 
5264
            BufferTooShort();
 
5265
      }
 
5266
      else {
 
5267
          if(snprintf(buf, sizeof(buf), "<P ALIGN=LEFT>"
 
5268
                   "[ <A HREF=%s0>Main Page</A>]&nbsp;"
 
5269
                   "[ <A HREF=%s3>SCSI Session(Bytes)</A> ]&nbsp;"
 
5270
                   "[ <B>SCSI Session(Times)</B> ]&nbsp;"
 
5271
                   "[ <A HREF=%s5>SCSI Session(Status)</A> ]&nbsp;"
 
5272
                   "[ <A HREF=%s6>SCSI Session(Task Mgmt)</A> ]&nbsp;"
 
5273
                   "[ <A HREF=%s7>FC Sessions</A> ]&nbsp;</p>",
 
5274
                   theLink, theLink, theLink, theLink, theLink) < 0)
 
5275
            BufferTooShort();
 
5276
      }
 
5277
      break;
 
5278
  case showHostScsiSessionStatus:
 
5279
      if ((el->devType != SCSI_DEV_INITIATOR) &&
 
5280
          (el->devType != SCSI_DEV_UNINIT)) {
 
5281
          if(snprintf(buf, sizeof(buf), "<P ALIGN=LEFT>"
 
5282
                   "[ <A HREF=%s0>Main Page</A> ]&nbsp;"
 
5283
                   "[ <A HREF=%s1>LUN Statistics</A> ]&nbsp;"
 
5284
                   "[ <A HREF=%s2>LUN Graphs</A> ]&nbsp;"
 
5285
                   "[ <A HREF=%s3>SCSI Session(Bytes)</A> ]&nbsp;"
 
5286
                   "[ <A HREF=%s4>SCSI Session(Times)</A> ]&nbsp;"
 
5287
                   "[ <B>SCSI Session(Status)</B> ]&nbsp;"
 
5288
                   "[ <A HREF=%s6>SCSI Session(Task Mgmt)</A> ]&nbsp;"
 
5289
                   "[ <A HREF=%s7>FC Sessions</A> ]&nbsp;</p>",
 
5290
                   theLink, theLink, theLink, theLink, theLink, theLink, theLink) < 0)
 
5291
            BufferTooShort();
 
5292
      }
 
5293
      else {
 
5294
          if(snprintf(buf, sizeof(buf), "<P ALIGN=LEFT>"
 
5295
                   "[ <A HREF=%s0>Main Page</A> ]&nbsp;"
 
5296
                   "[ <A HREF=%s3>SCSI Session(Bytes)</A> ]&nbsp;"
 
5297
                   "[ <A HREF=%s4>SCSI Session(Times)</A> ]&nbsp;"
 
5298
                   "[ <B>SCSI Session(Status)</B> ]&nbsp;"
 
5299
                   "[ <A HREF=%s6>SCSI Session(Task Mgmt)</A> ]&nbsp;"
 
5300
                   "[ <A HREF=%s7>FC Sessions</A> ]&nbsp;</p>",
 
5301
                   theLink, theLink, theLink, theLink, theLink) < 0)
 
5302
            BufferTooShort();
 
5303
      }
 
5304
      break;
 
5305
  case showHostScsiSessionTMInfo:
 
5306
      if ((el->devType != SCSI_DEV_INITIATOR) &&
 
5307
          (el->devType != SCSI_DEV_UNINIT)) {
 
5308
          if(snprintf(buf, sizeof(buf), "<P ALIGN=LEFT>"
 
5309
                   "[ <A HREF=%s0>Main Page</A> ]&nbsp;"
 
5310
                   "[ <A HREF=%s1>LUN Statistics</A> ]&nbsp;"
 
5311
                   "[ <A HREF=%s2>LUN Graphs</A> ]&nbsp;"
 
5312
                   "[ <A HREF=%s3>SCSI Session(Bytes)</A> ]&nbsp;"
 
5313
                   "[ <A HREF=%s4>SCSI Session(Times)</A> ]&nbsp;"
 
5314
                   "[ <A HREF=%s5>SCSI Session(Status)</A> ]&nbsp;"
 
5315
                   "[ <B>SCSI Session(Task Mgmt)</B> ]&nbsp;"
 
5316
                   "[ <A HREF=%s7>FC Sessions</A> ]&nbsp;</p>",
 
5317
                   theLink, theLink, theLink, theLink, theLink, theLink, theLink) < 0)
 
5318
            BufferTooShort();
 
5319
      }
 
5320
      else {
 
5321
          if(snprintf(buf, sizeof(buf), "<P ALIGN=LEFT>"
 
5322
                   "[ <A HREF=%s0>Main Page</A> ]&nbsp;"
 
5323
                   "[ <A HREF=%s3>SCSI Session(Bytes)</A> ]&nbsp;"
 
5324
                   "[ <A HREF=%s4>SCSI Session(Times)</A> ]&nbsp;"
 
5325
                   "[ <A HREF=%s5>SCSI Session(Status)</A> ]&nbsp;"
 
5326
                   "[ <B>SCSI Session(Task Mgmt)</B> ]&nbsp;"
 
5327
                   "[ <A HREF=%s7>FC Sessions</A> ]&nbsp;</p>",
 
5328
                   theLink, theLink, theLink, theLink, theLink) < 0)
 
5329
            BufferTooShort();
 
5330
      }
 
5331
      break;
 
5332
  case showHostFcSessions:
 
5333
      if ((el->devType != SCSI_DEV_INITIATOR) &&
 
5334
          (el->devType != SCSI_DEV_UNINIT)) {
 
5335
          if(snprintf(buf, sizeof(buf), "<P ALIGN=LEFT>"
 
5336
                   "[ <A HREF=%s0>Main Page</A> ]&nbsp;"
 
5337
                   "[ <A HREF=%s1>LUN Statistics</A> ]&nbsp;"
 
5338
                   "[ <A HREF=%s2>LUN Graphs</A> ]&nbsp;"
 
5339
                   "[ <A HREF=%s3>SCSI Session(Bytes)</A> ]&nbsp;"
 
5340
                   "[ <A HREF=%s4>SCSI Session(Times)</A> ]&nbsp;"
 
5341
                   "[ <A HREF=%s5>SCSI Session(Status)</A> ]&nbsp;"
 
5342
                   "[ <A HREF=%s6>SCSI Session(Task Mgmt)</A> ]&nbsp;"
 
5343
                   "[ <B>FC Sessions</B> ]&nbsp;</p>",
 
5344
                   theLink, theLink, theLink, theLink, theLink, theLink, theLink) < 0)
 
5345
            BufferTooShort();
 
5346
      }
 
5347
      else {
 
5348
          if(snprintf(buf, sizeof(buf), "<P ALIGN=LEFT>"
 
5349
                   "[ <A HREF=%s0>Main Page</A> ]&nbsp;"
 
5350
                   "[ <A HREF=%s3>SCSI Session(Bytes)</A> ]&nbsp;"
 
5351
                   "[ <A HREF=%s4>SCSI Session(Times)</A> ]&nbsp;"
 
5352
                   "[ <A HREF=%s5>SCSI Session(Status)</A> ]&nbsp;"
 
5353
                   "[ <A HREF=%s6>SCSI Session(Task Mgmt)</A> ]&nbsp;"
 
5354
                   "[ <B>FC Sessions</B> ]&nbsp;</p>",
 
5355
                   theLink, theLink, theLink, theLink, theLink, theLink, theLink) < 0)
 
5356
            BufferTooShort();
 
5357
      }
 
5358
      break;
 
5359
  case showHostMainPage:
 
5360
  default:
 
5361
      if ((el->devType != SCSI_DEV_INITIATOR) &&
 
5362
          (el->devType != SCSI_DEV_UNINIT)) {
 
5363
          if(snprintf(buf, sizeof(buf), "<P ALIGN=RIGHT>"
 
5364
                   "[<B>Main&nbsp;Page</B> ]&nbsp;"
 
5365
                   "[ <A HREF=%s1>LUN Statistics</A> ]&nbsp;"
 
5366
                   "[ <A HREF=%s2>LUN Graphs</A> ]&nbsp;"
 
5367
                   "[ <A HREF=%s3>SCSI Session(Bytes)</A> ]&nbsp;"
 
5368
                   "[ <A HREF=%s4>SCSI Session(Times)</A> ]&nbsp;"
 
5369
                   "[ <A HREF=%s5>SCSI Session(Status)</A> ]&nbsp;"
 
5370
                   "[ <A HREF=%s6>SCSI Session(Task Mgmt)</A> ]&nbsp;"
 
5371
                   "[ <A HREF=%s7>FC Sessions</A> ]&nbsp;</p>",
 
5372
                   theLink, theLink, theLink, theLink, theLink, theLink, theLink) < 0)
 
5373
            BufferTooShort();
 
5374
      }
 
5375
      else {
 
5376
          if(snprintf(buf, sizeof(buf), "<P ALIGN=RIGHT>"
 
5377
                   "[<B>Main&nbsp;Page</B> ]&nbsp;"
 
5378
                   "[ <A HREF=%s3>SCSI Session(Bytes)</A> ]&nbsp;"
 
5379
                   "[ <A HREF=%s4>SCSI Session(Times)</A> ]&nbsp;"
 
5380
                   "[ <A HREF=%s5>SCSI Session(Status)</A> ]&nbsp;"
 
5381
                   "[ <A HREF=%s6>SCSI Session(Task Mgmt)</A> ]&nbsp;"
 
5382
                   "[ <A HREF=%s7>FC Sessions</A> ]&nbsp;</p>",
 
5383
                   theLink, theLink, theLink, theLink, theLink) < 0)
 
5384
            BufferTooShort();
 
5385
      }
 
5386
      break;
 
5387
  }
 
5388
  sendString(buf);
 
5389
 
 
5390
    
 
5391
}
 
5392
 
 
5393
/* ******************************* */
 
5394
 
 
5395
int cmpFcFctn(const void *_a, const void *_b)
 
5396
{
 
5397
  HostTraffic **a = (HostTraffic **)_a;
 
5398
  HostTraffic **b = (HostTraffic **)_b;
 
5399
  Counter a_=0, b_=0, a_val, b_val;
 
5400
  float fa_=0, fb_=0;
 
5401
  short floatCompare=0, columnProtoId;
 
5402
 
 
5403
  if((a == NULL) && (b != NULL)) {
 
5404
    traceEvent(CONST_TRACE_WARNING, "cmpFcFctn() error (1)");
 
5405
    return(1);
 
5406
  } else if((a != NULL) && (b == NULL)) {
 
5407
    traceEvent(CONST_TRACE_WARNING, "cmpFcFctn() error (2)");
 
5408
    return(-1);
 
5409
  } else if((a == NULL) && (b == NULL)) {
 
5410
    traceEvent(CONST_TRACE_WARNING, "cmpFcFctn() error (3)");
 
5411
    return(0);
 
5412
  }
 
5413
 
 
5414
  if(myGlobals.columnSort == FLAG_HOST_DUMMY_IDX) {
 
5415
    int rc;
 
5416
 
 
5417
    /* Host name */
 
5418
    accessAddrResMutex("cmpFctn");
 
5419
 
 
5420
    CMP_FC_PORT ((*a), (*b))
 
5421
    releaseAddrResMutex();
 
5422
    return(rc);
 
5423
  } else if(myGlobals.columnSort == FLAG_DOMAIN_DUMMY_IDX) {
 
5424
    int rc;
 
5425
 
 
5426
    accessAddrResMutex("cmpFctn");
 
5427
 
 
5428
    a_ = (*a)->vsanId, b_ = (*b)->vsanId;
 
5429
 
 
5430
    rc = (a_ < b_) ? -1 : (a_ > b_) ? 1 : 0;
 
5431
 
 
5432
    releaseAddrResMutex();
 
5433
    return(rc);
 
5434
  }
 
5435
 
 
5436
#ifdef DEBUG
 
5437
  traceEvent(CONST_TRACE_INFO,
 
5438
             "reportKind=%d/columnSort=%d/sortSendMode=%d/numIpProtosToMonitor=%d\n",
 
5439
             myGlobals.reportKind, myGlobals.columnSort, myGlobals.sortSendMode, myGlobals.numIpProtosToMonitor);
 
5440
#endif
 
5441
 
 
5442
 
 
5443
  switch(myGlobals.reportKind) {
 
5444
  case SORT_DATA_RECEIVED_PROTOS:
 
5445
    switch(myGlobals.columnSort) {
 
5446
    case 0:
 
5447
      a_ = (*a)->fcBytesRcvd.value, b_ = (*b)->fcBytesRcvd.value;
 
5448
      break;
 
5449
    case 1:
 
5450
        a_ = (*a)->fcFcpBytesRcvd.value;
 
5451
        b_ = (*b)->fcFcpBytesRcvd.value;
 
5452
      break;
 
5453
    case 2:
 
5454
        a_ = (*a)->fcElsBytesRcvd.value;
 
5455
        b_ = (*b)->fcElsBytesRcvd.value;
 
5456
      break;
 
5457
    case 3:
 
5458
        a_ = (*a)->fcDnsBytesRcvd.value;
 
5459
        b_ = (*b)->fcDnsBytesRcvd.value;
 
5460
      break;
 
5461
    case 4:
 
5462
        a_ = (*a)->fcIpfcBytesRcvd.value;
 
5463
        b_ = (*b)->fcIpfcBytesRcvd.value;
 
5464
        break;
 
5465
    case 5:
 
5466
        a_ = (*a)->fcSwilsBytesRcvd.value;
 
5467
        b_ = (*b)->fcSwilsBytesRcvd.value;
 
5468
        break;
 
5469
    case 6:
 
5470
        a_ = (*a)->otherFcBytesRcvd.value;
 
5471
        b_ = (*b)->otherFcBytesRcvd.value;
 
5472
        break;
 
5473
    }
 
5474
    break;
 
5475
  case SORT_DATA_RECEIVED_IP:
 
5476
    columnProtoId = myGlobals.columnSort - 1;
 
5477
    if((columnProtoId != -1) && (columnProtoId <= myGlobals.numIpProtosToMonitor)) {
 
5478
      if(columnProtoId <= 0) {
 
5479
        a_ = b_ = 0;
 
5480
      } else {
 
5481
        a_ = (*a)->protoIPTrafficInfos[columnProtoId-1].rcvdLoc.value+
 
5482
          (*a)->protoIPTrafficInfos[columnProtoId-1].rcvdFromRem.value;
 
5483
        b_ = (*b)->protoIPTrafficInfos[columnProtoId-1].rcvdLoc.value+
 
5484
          (*b)->protoIPTrafficInfos[columnProtoId-1].rcvdFromRem.value;
 
5485
      }
 
5486
    } else {
 
5487
      a_ = (*a)->ipBytesRcvd.value, b_ = (*b)->ipBytesRcvd.value;
 
5488
 
 
5489
      if(myGlobals.numIpProtosToMonitor == (columnProtoId-1)) {
 
5490
        /* other IP */
 
5491
        int i;
 
5492
 
 
5493
        for(i=0; i<myGlobals.numIpProtosToMonitor; i++) {
 
5494
          a_val = ((*a)->protoIPTrafficInfos[i].rcvdLoc.value
 
5495
                   +(*a)->protoIPTrafficInfos[i].rcvdFromRem.value);
 
5496
          b_val = ((*b)->protoIPTrafficInfos[i].rcvdLoc.value
 
5497
                   +(*b)->protoIPTrafficInfos[i].rcvdFromRem.value);
 
5498
 
 
5499
          /* Better be safe... */
 
5500
          if(a_ > a_val) a_ -= a_val; else a_ = 0;
 
5501
          if(b_ > b_val) b_ -= b_val; else b_ = 0;
 
5502
        }
 
5503
      }
 
5504
    }
 
5505
    break;
 
5506
  case SORT_DATA_RECEIVED_THPT:
 
5507
    switch(myGlobals.columnSort) {
 
5508
    case 1:
 
5509
      fa_ = (*a)->actualRcvdThpt, fb_ = (*b)->actualRcvdThpt, floatCompare = 1;
 
5510
      break;
 
5511
    case 2:
 
5512
      fa_ = (*a)->averageRcvdThpt, fb_ = (*b)->averageRcvdThpt, floatCompare = 1;
 
5513
      break;
 
5514
    case 3:
 
5515
      fa_ = (*a)->peakRcvdThpt, fb_ = (*b)->peakRcvdThpt, floatCompare = 1;
 
5516
      break;
 
5517
    case 4:
 
5518
      fa_ = (*a)->actualRcvdPktThpt, fb_ = (*b)->actualRcvdPktThpt, floatCompare = 1;
 
5519
      break;
 
5520
    case 5:
 
5521
      fa_ = (*a)->averageRcvdPktThpt, fb_ = (*b)->averageRcvdPktThpt, floatCompare = 1;
 
5522
      break;
 
5523
    case 6:
 
5524
      fa_ = (*a)->peakRcvdPktThpt, fb_ = (*b)->peakRcvdPktThpt, floatCompare = 1;
 
5525
      break;
 
5526
    }
 
5527
    break;
 
5528
  case SORT_DATA_RCVD_HOST_TRAFFIC:
 
5529
  case SORT_DATA_SENT_HOST_TRAFFIC:
 
5530
  case SORT_DATA_HOST_TRAFFIC:
 
5531
    /* Nothing */
 
5532
    break;
 
5533
  case SORT_DATA_SENT_PROTOS:
 
5534
    switch(myGlobals.columnSort) {
 
5535
    case 0:
 
5536
      a_ = (*a)->fcBytesSent.value, b_ = (*b)->fcBytesSent.value;
 
5537
      break;
 
5538
    case 1:
 
5539
        a_ = (*a)->fcFcpBytesSent.value;
 
5540
        b_ = (*b)->fcFcpBytesSent.value;
 
5541
      break;
 
5542
    case 2:
 
5543
        a_ = (*a)->fcElsBytesSent.value;
 
5544
        b_ = (*b)->fcElsBytesSent.value;
 
5545
      break;
 
5546
    case 3:
 
5547
        a_ = (*a)->fcDnsBytesSent.value;
 
5548
        b_ = (*b)->fcDnsBytesSent.value;
 
5549
      break;
 
5550
    case 4:
 
5551
        a_ = (*a)->fcIpfcBytesSent.value;
 
5552
        b_ = (*b)->fcIpfcBytesSent.value;
 
5553
        break;
 
5554
    case 5:
 
5555
        a_ = (*a)->fcSwilsBytesSent.value;
 
5556
        b_ = (*b)->fcSwilsBytesSent.value;
 
5557
        break;
 
5558
    case 6:
 
5559
        a_ = (*a)->otherFcBytesSent.value;
 
5560
        b_ = (*b)->otherFcBytesSent.value;
 
5561
        break;
 
5562
    }
 
5563
    break;
 
5564
  case SORT_DATA_SENT_IP:
 
5565
    columnProtoId = myGlobals.columnSort - 1;
 
5566
    if((columnProtoId != -1) && (columnProtoId <= myGlobals.numIpProtosToMonitor)) {
 
5567
      if(columnProtoId <= 0) {
 
5568
        a_ = b_ = 0;
 
5569
      } else {
 
5570
        a_ = (*a)->protoIPTrafficInfos[columnProtoId-1].sentLoc.value
 
5571
          +(*a)->protoIPTrafficInfos[columnProtoId-1].sentRem.value;
 
5572
        b_ = (*b)->protoIPTrafficInfos[columnProtoId-1].sentLoc.value
 
5573
          +(*b)->protoIPTrafficInfos[columnProtoId-1].sentRem.value;
 
5574
      }
 
5575
    } else {
 
5576
      a_ = (*a)->ipBytesSent.value, b_ = (*b)->ipBytesSent.value;
 
5577
 
 
5578
      if(myGlobals.numIpProtosToMonitor == (columnProtoId-1)) {
 
5579
        /* other IP */
 
5580
        int i;
 
5581
 
 
5582
        for(i=0; i<myGlobals.numIpProtosToMonitor; i++) {
 
5583
          a_val = ((*a)->protoIPTrafficInfos[i].sentLoc.value
 
5584
                   +(*a)->protoIPTrafficInfos[i].sentRem.value);
 
5585
          b_val = ((*b)->protoIPTrafficInfos[i].sentLoc.value
 
5586
                   +(*b)->protoIPTrafficInfos[i].sentRem.value);
 
5587
 
 
5588
          /* Better be safe... */
 
5589
          if(a_ > a_val) a_ -= a_val; else a_ = 0;
 
5590
          if(b_ > b_val) b_ -= b_val; else b_ = 0;
 
5591
        }
 
5592
      }
 
5593
    }
 
5594
    break;
 
5595
  case SORT_DATA_SENT_THPT:
 
5596
    switch(myGlobals.columnSort) {
 
5597
    case 1:
 
5598
      fa_ = (*a)->actualSentThpt, fb_ = (*b)->actualSentThpt, floatCompare = 1;
 
5599
      break;
 
5600
    case 2:
 
5601
      fa_ = (*a)->averageSentThpt, fb_ = (*b)->averageSentThpt, floatCompare = 1;
 
5602
      break;
 
5603
    case 3:
 
5604
      fa_ = (*a)->peakSentThpt, fb_ = (*b)->peakSentThpt, floatCompare = 1;
 
5605
      break;
 
5606
    case 4:
 
5607
      fa_ = (*a)->actualSentPktThpt, fb_ = (*b)->actualSentPktThpt, floatCompare = 1;
 
5608
      break;
 
5609
    case 5:
 
5610
      fa_ = (*a)->averageSentPktThpt, fb_ = (*b)->averageSentPktThpt, floatCompare = 1;
 
5611
      break;
 
5612
    case 6:
 
5613
      fa_ = (*a)->peakSentPktThpt, fb_ = (*b)->peakSentPktThpt, floatCompare = 1;
 
5614
      break;
 
5615
    }
 
5616
    break;
 
5617
  case TRAFFIC_STATS:
 
5618
    /* Nothing */
 
5619
    break;
 
5620
  case SORT_DATA_PROTOS:
 
5621
    switch(myGlobals.columnSort) {
 
5622
    case 0:
 
5623
        a_ = (*a)->fcBytesSent.value + (*a)->fcBytesRcvd.value;
 
5624
        b_ = (*b)->fcBytesSent.value + (*b)->fcBytesRcvd.value;
 
5625
        break;
 
5626
    case 1:
 
5627
        a_ = (*a)->fcFcpBytesSent.value + (*a)->fcFcpBytesRcvd.value;
 
5628
        b_ = (*b)->fcFcpBytesSent.value + (*b)->fcFcpBytesRcvd.value;
 
5629
        break;
 
5630
    case 2:
 
5631
        a_ = (*a)->fcElsBytesSent.value + (*a)->fcElsBytesRcvd.value;
 
5632
        b_ = (*b)->fcElsBytesSent.value + (*b)->fcElsBytesRcvd.value;
 
5633
        break;
 
5634
    case 3:
 
5635
        a_ = (*a)->fcDnsBytesSent.value + (*a)->fcDnsBytesRcvd.value;
 
5636
        b_ = (*b)->fcDnsBytesSent.value + (*b)->fcDnsBytesRcvd.value;
 
5637
        break;
 
5638
    case 4:
 
5639
        a_ = (*a)->fcIpfcBytesSent.value + (*a)->fcIpfcBytesRcvd.value;
 
5640
        b_ = (*b)->fcIpfcBytesSent.value + (*b)->fcIpfcBytesRcvd.value;
 
5641
        break;
 
5642
    case 5:
 
5643
        a_ = (*a)->fcSwilsBytesSent.value + (*a)->fcSwilsBytesRcvd.value;
 
5644
        b_ = (*b)->fcSwilsBytesSent.value + (*b)->fcSwilsBytesRcvd.value;
 
5645
        break;
 
5646
    case 6:
 
5647
        a_ = (*a)->otherFcBytesSent.value + (*a)->otherFcBytesRcvd.value;
 
5648
        b_ = (*b)->otherFcBytesSent.value + (*b)->otherFcBytesRcvd.value;
 
5649
        break;
 
5650
    }
 
5651
    break;
 
5652
  case SORT_DATA_IP:
 
5653
    columnProtoId = myGlobals.columnSort - 1;
 
5654
    if((columnProtoId != -1) && (columnProtoId <= myGlobals.numIpProtosToMonitor)) {
 
5655
      if(columnProtoId <= 0) {
 
5656
        a_ = b_ = 0;
 
5657
      } else {
 
5658
        a_ = (*a)->protoIPTrafficInfos[columnProtoId-1].rcvdLoc.value+
 
5659
          (*a)->protoIPTrafficInfos[columnProtoId-1].rcvdFromRem.value+
 
5660
          (*a)->protoIPTrafficInfos[columnProtoId-1].sentLoc.value+
 
5661
          (*a)->protoIPTrafficInfos[columnProtoId-1].sentRem.value;
 
5662
        b_ = (*b)->protoIPTrafficInfos[columnProtoId-1].rcvdLoc.value+
 
5663
          (*b)->protoIPTrafficInfos[columnProtoId-1].rcvdFromRem.value+
 
5664
          (*b)->protoIPTrafficInfos[columnProtoId-1].sentLoc.value+
 
5665
          (*b)->protoIPTrafficInfos[columnProtoId-1].sentRem.value;
 
5666
      }
 
5667
    } else {
 
5668
      a_ = (*a)->ipBytesRcvd.value+(*a)->ipBytesSent.value;
 
5669
      b_ = (*b)->ipBytesRcvd.value+(*b)->ipBytesSent.value;
 
5670
 
 
5671
      if(myGlobals.numIpProtosToMonitor == (columnProtoId-1)) {
 
5672
        /* other IP */
 
5673
        int i;
 
5674
 
 
5675
        for(i=0; i<myGlobals.numIpProtosToMonitor; i++) {
 
5676
          a_val = ((*a)->protoIPTrafficInfos[i].rcvdLoc.value
 
5677
                   +(*a)->protoIPTrafficInfos[i].rcvdFromRem.value
 
5678
                   +(*a)->protoIPTrafficInfos[i].sentLoc.value
 
5679
                   +(*a)->protoIPTrafficInfos[i].sentRem.value);
 
5680
          b_val = ((*b)->protoIPTrafficInfos[i].rcvdLoc.value
 
5681
                   +(*b)->protoIPTrafficInfos[i].rcvdFromRem.value
 
5682
                   +(*b)->protoIPTrafficInfos[i].sentLoc.value
 
5683
                   +(*b)->protoIPTrafficInfos[i].sentRem.value);
 
5684
 
 
5685
          /* Better be safe... */
 
5686
          if(a_ > a_val) a_ -= a_val; else a_ = 0;
 
5687
          if(b_ > b_val) b_ -= b_val; else b_ = 0;
 
5688
        }
 
5689
      }
 
5690
    }
 
5691
    break;
 
5692
  case SORT_DATA_THPT:
 
5693
    switch(myGlobals.columnSort) {
 
5694
    case 1:
 
5695
      fa_ = (*a)->actualTThpt;
 
5696
      fb_ = (*b)->actualTThpt;
 
5697
      floatCompare = 1;
 
5698
      break;
 
5699
    case 2:
 
5700
      fa_ = (*a)->averageTThpt;
 
5701
      fb_ = (*b)->averageTThpt;
 
5702
      floatCompare = 1;
 
5703
      break;
 
5704
    case 3:
 
5705
      fa_ = (*a)->peakTThpt;
 
5706
      fb_ = (*b)->peakTThpt;
 
5707
      floatCompare = 1;
 
5708
      break;
 
5709
    case 4:
 
5710
      fa_ = (*a)->actualTPktThpt;
 
5711
      fb_ = (*b)->actualTPktThpt;
 
5712
      floatCompare = 1;
 
5713
      break;
 
5714
    case 5:
 
5715
      fa_ = (*a)->averageTPktThpt;
 
5716
      fb_ = (*b)->averageTPktThpt;
 
5717
      floatCompare = 1;
 
5718
      break;
 
5719
    case 6:
 
5720
      fa_ = (*a)->peakTPktThpt;
 
5721
      fb_ = (*b)->peakTPktThpt;
 
5722
      floatCompare = 1;
 
5723
      break;
 
5724
    }
 
5725
    break;
 
5726
  }
 
5727
 
 
5728
  /*
 
5729
    traceEvent(CONST_TRACE_INFO, "%s=%u - %s=%u",
 
5730
    (*a)->hostResolvedName, (unsigned long)a_,
 
5731
    (*b)->hostResolvedName, (unsigned long)b_);
 
5732
  */
 
5733
 
 
5734
  if(floatCompare == 0) {
 
5735
    if(a_ < b_) {
 
5736
      return(1);
 
5737
    } else if (a_ > b_) {
 
5738
      return(-1);
 
5739
    } else {
 
5740
      return(0);
 
5741
    }
 
5742
  } else {
 
5743
    if(fa_ < fb_) {
 
5744
      return(1);
 
5745
    } else if (fa_ > fb_) {
 
5746
      return(-1);
 
5747
    } else {
 
5748
      return(0);
 
5749
    }
 
5750
  }
 
5751
}
 
5752
 
 
5753
/* ******************************* */
 
5754
 
 
5755
int cmpFcSessionsFctn (const void *_a, const void *_b)
 
5756
{
 
5757
    FCSession **a = (FCSession **)_a;
 
5758
    FCSession **b = (FCSession **)_b;
 
5759
    int a_, b_;
 
5760
    int actualDeviceId, rc;
 
5761
 
 
5762
    switch (myGlobals.columnSort) {
 
5763
    case 1: /* VSAN */
 
5764
        actualDeviceId = (*a)->deviceId; /* for macro checkSession */
 
5765
        a_ = (*a)->initiator->vsanId;
 
5766
        actualDeviceId = (*b)->deviceId;
 
5767
        b_ = (*b)->initiator->vsanId;
 
5768
        return ( (a_ > b_) ? 1 : (a_ < b_) ? -1 : 0 );
 
5769
        break;
 
5770
    case 2: /* Initiator Alias, pWWN or FC Addr */
 
5771
        CMP_FC_PORT (((*a)->initiator), ((*b)->initiator))
 
5772
        return (rc);
 
5773
        break;
 
5774
    case 3: /* Target Alias, pWWN or FC Addr */
 
5775
        CMP_FC_PORT (((*a)->remotePeer), ((*b)->remotePeer))
 
5776
        return (rc);
 
5777
        break;
 
5778
    case 4: /* Data Sent */
 
5779
        return ( ((*a)->bytesSent.value > (*b)->bytesSent.value) ? 1 :
 
5780
                 ((*a)->bytesSent.value < (*b)->bytesSent.value) ? -1 : 0);
 
5781
        break;
 
5782
    case 5: /* Data Rcvd */
 
5783
        return ( ((*a)->bytesRcvd.value > (*b)->bytesRcvd.value) ? 1 :
 
5784
                 ((*a)->bytesRcvd.value < (*b)->bytesRcvd.value) ? -1 : 0);
 
5785
        break;
 
5786
    case 6:
 
5787
        return (((*a)->fcpBytesSent.value > (*b)->fcpBytesSent.value) ? 1 :
 
5788
                ((*a)->fcpBytesSent.value < (*b)->fcpBytesSent.value) ? -1 : 0);
 
5789
        break;
 
5790
    case 7:
 
5791
        return (((*a)->fcpBytesRcvd.value > (*b)->fcpBytesRcvd.value) ? 1 :
 
5792
                ((*a)->fcpBytesRcvd.value < (*b)->fcpBytesRcvd.value) ? -1 : 0);
 
5793
        break;
 
5794
    case 8:
 
5795
        return (((*a)->fcElsBytesSent.value > (*b)->fcElsBytesSent.value) ? 1 :
 
5796
                ((*a)->fcElsBytesSent.value < (*b)->fcElsBytesSent.value) ? -1 : 0);
 
5797
        break;
 
5798
    case 9:
 
5799
        return (((*a)->fcElsBytesRcvd.value > (*b)->fcElsBytesRcvd.value) ? 1 :
 
5800
                ((*a)->fcElsBytesRcvd.value < (*b)->fcElsBytesRcvd.value) ? -1 : 0);
 
5801
        break;
 
5802
    case 10:
 
5803
        return (((*a)->fcDnsBytesSent.value > (*b)->fcDnsBytesSent.value) ? 1 :
 
5804
                ((*a)->fcDnsBytesSent.value < (*b)->fcDnsBytesSent.value) ? -1 : 0);
 
5805
        break;
 
5806
    case 11:
 
5807
        return (((*a)->fcDnsBytesRcvd.value > (*b)->fcDnsBytesRcvd.value) ? 1 :
 
5808
                ((*a)->fcDnsBytesRcvd.value < (*b)->fcDnsBytesRcvd.value) ? -1 : 0);
 
5809
        break;
 
5810
    case 12:
 
5811
        return (((*a)->ipfcBytesSent.value > (*b)->ipfcBytesSent.value) ? 1 :
 
5812
                ((*a)->ipfcBytesSent.value < (*b)->ipfcBytesSent.value) ? -1 : 0);
 
5813
        break;
 
5814
    case 13:
 
5815
        return (((*a)->ipfcBytesRcvd.value > (*b)->ipfcBytesRcvd.value) ? 1 :
 
5816
                ((*a)->ipfcBytesRcvd.value < (*b)->ipfcBytesRcvd.value) ? -1 : 0);
 
5817
        break;
 
5818
    case 14:
 
5819
        return (((*a)->fcSwilsBytesSent.value > (*b)->fcSwilsBytesSent.value) ? 1 :
 
5820
                ((*a)->fcSwilsBytesSent.value < (*b)->fcSwilsBytesSent.value) ? -1 : 0);
 
5821
        break;
 
5822
    case 15:
 
5823
        return (((*a)->fcSwilsBytesRcvd.value > (*b)->fcSwilsBytesRcvd.value) ? 1 :
 
5824
                ((*a)->fcSwilsBytesRcvd.value < (*b)->fcSwilsBytesRcvd.value) ? -1 : 0);
 
5825
        break;
 
5826
    case 16:
 
5827
        return (((*a)->otherBytesSent.value > (*b)->otherBytesSent.value) ? 1 :
 
5828
                ((*a)->otherBytesSent.value < (*b)->otherBytesSent.value) ? -1 : 0);
 
5829
        break;
 
5830
    case 17:
 
5831
        return (((*a)->otherBytesRcvd.value > (*b)->otherBytesRcvd.value) ? 1 :
 
5832
                ((*a)->otherBytesRcvd.value < (*b)->otherBytesRcvd.value) ? -1 : 0);
 
5833
        break;
 
5834
    case 18:
 
5835
        return (CMPTV ((*a)->firstSeen, (*b)->firstSeen));
 
5836
        break;
 
5837
        
 
5838
    case 19:
 
5839
        return (CMPTV ((*a)->lastSeen, (*b)->lastSeen));
 
5840
        break;
 
5841
        
 
5842
    default:
 
5843
        break;
 
5844
    }
 
5845
}
 
5846
 
 
5847
int cmpScsiSessionsFctn (const void *_a, const void *_b)
 
5848
{
 
5849
    ScsiSessionSortEntry *a = (ScsiSessionSortEntry *)_a;
 
5850
    ScsiSessionSortEntry *b = (ScsiSessionSortEntry *)_b;
 
5851
    int a_, b_, rc;
 
5852
 
 
5853
    switch (myGlobals.columnSort) {
 
5854
    case 1: /* VSAN */
 
5855
        a_ = a->initiator->vsanId;
 
5856
        b_ = b->initiator->vsanId;
 
5857
        return ( (a_ > b_) ? 1 : (a_ < b_) ? -1 : 0 );
 
5858
        break;
 
5859
    case 2: /* Initiator FC Address */
 
5860
        CMP_FC_PORT ((a->initiator), (b->initiator))
 
5861
        return (rc);
 
5862
        break;
 
5863
    case 3: /* Target FC Address */
 
5864
        CMP_FC_PORT ((a->target), (b->target))
 
5865
        return (rc);
 
5866
        break;
 
5867
    case 4: /* Data Sent */
 
5868
        /* The first three entries account for the unknown LUN entry */ 
 
5869
        if ((a->lun == 0xFFFF) && (b->lun != 0xFFFF)) {
 
5870
            return ( (((FCSession *)a->stats)->unknownLunBytesSent.value > b->stats->bytesSent.value) ? 1 :
 
5871
                     (((FCSession *)a->stats)->unknownLunBytesSent.value < b->stats->bytesSent.value) ? -1 : 0);
 
5872
        }
 
5873
        else if ((a->lun != 0xFFFF) && (b->lun == 0xFFFF)) {
 
5874
             return ( (a->stats->bytesSent.value > ((FCSession *)b->stats)->unknownLunBytesSent.value) ? 1 :
 
5875
                      (a->stats->bytesSent.value < ((FCSession *)b->stats)->unknownLunBytesSent.value) ? -1 : 0);
 
5876
        }
 
5877
        else if ((a->lun == 0xFFFF) && (b->lun == 0xFFFF)) {
 
5878
            return ( (((FCSession *)a->stats)->unknownLunBytesSent.value
 
5879
                      > ((FCSession *)b->stats)->unknownLunBytesSent.value) ? 1 :
 
5880
                     (((FCSession *)a->stats)->unknownLunBytesSent.value <
 
5881
                      ((FCSession *)b->stats)->unknownLunBytesSent.value) ? -1 : 0);
 
5882
        }
 
5883
        return ( (a->stats->bytesSent.value > b->stats->bytesSent.value) ? 1 :
 
5884
                 (a->stats->bytesSent.value < b->stats->bytesSent.value) ? -1 : 0);
 
5885
        break;
 
5886
    case 5: /* Data Rcvd */
 
5887
        /* The first three entries account for the unknown LUN entry */ 
 
5888
        if ((a->lun == 0xFFFF) && (b->lun != 0xFFFF)) {
 
5889
            return ( (((FCSession *)a->stats)->unknownLunBytesRcvd.value > b->stats->bytesRcvd.value) ? 1 :
 
5890
                     (((FCSession *)a->stats)->unknownLunBytesRcvd.value < b->stats->bytesRcvd.value) ? -1 : 0);
 
5891
        }
 
5892
        else if ((a->lun != 0xFFFF) && (b->lun == 0xFFFF)) {
 
5893
            return ( (a->stats->bytesRcvd.value > ((FCSession *)b->stats)->unknownLunBytesRcvd.value) ? 1 :
 
5894
                     (a->stats->bytesRcvd.value < ((FCSession *)b->stats)->unknownLunBytesRcvd.value) ? -1 : 0);
 
5895
        }
 
5896
        else if ((a->lun == 0xFFFF) && (b->lun == 0xFFFF)) {
 
5897
            return ( (((FCSession *)a->stats)->unknownLunBytesRcvd.value >
 
5898
                      ((FCSession *)b->stats)->unknownLunBytesRcvd.value) ? 1 :
 
5899
                     (((FCSession *)a->stats)->unknownLunBytesRcvd.value <
 
5900
                      ((FCSession *)b->stats)->unknownLunBytesRcvd.value) ? -1 : 0);
 
5901
        }
 
5902
        return ( (a->stats->bytesRcvd.value > b->stats->bytesRcvd.value) ? 1 :
 
5903
                 (a->stats->bytesRcvd.value < b->stats->bytesRcvd.value) ? -1 : 0);
 
5904
        break;
 
5905
 
 
5906
    case 6:
 
5907
        /* Unknown LUNs don't have any valid info to compare for this field. So
 
5908
         * we dump them at the end of the list
 
5909
         */
 
5910
        if ((a->lun == 0xFFFF) && (b->lun != 0xFFFF)) {
 
5911
            return (1);
 
5912
        }
 
5913
        else if ((a->lun != 0xFFFF) && (b->lun == 0xFFFF)) {
 
5914
            return (-1);
 
5915
        }
 
5916
        else if ((a->lun == 0xFFFF) && (b->lun == 0xFFFF)) {
 
5917
            return (0);
 
5918
        }
 
5919
        return ( (a->stats->scsiRdBytes.value > b->stats->scsiRdBytes.value) ? 1 :
 
5920
                 (a->stats->scsiRdBytes.value < b->stats->scsiRdBytes.value) ? -1 : 0);
 
5921
        break;
 
5922
 
 
5923
    case 7:
 
5924
        /* Unknown LUNs don't have any valid info to compare for this field. So
 
5925
         * we dump them at the end of the list
 
5926
         */
 
5927
        if ((a->lun == 0xFFFF) && (b->lun != 0xFFFF)) {
 
5928
            return (1);
 
5929
        }
 
5930
        else if ((a->lun != 0xFFFF) && (b->lun == 0xFFFF)) {
 
5931
            return (-1);
 
5932
        }
 
5933
        else if ((a->lun == 0xFFFF) && (b->lun == 0xFFFF)) {
 
5934
            return (0);
 
5935
        }
 
5936
        return ( (a->stats->scsiWrBytes.value > b->stats->scsiWrBytes.value) ? 1 :
 
5937
                 (a->stats->scsiWrBytes.value < b->stats->scsiWrBytes.value) ? -1 : 0);
 
5938
        break;
 
5939
 
 
5940
    case 8:
 
5941
        /* Unknown LUNs don't have any valid info to compare for this field. So
 
5942
         * we dump them at the end of the list
 
5943
         */
 
5944
        if ((a->lun == 0xFFFF) && (b->lun != 0xFFFF)) {
 
5945
            return (1);
 
5946
        }
 
5947
        else if ((a->lun != 0xFFFF) && (b->lun == 0xFFFF)) {
 
5948
            return (-1);
 
5949
        }
 
5950
        else if ((a->lun == 0xFFFF) && (b->lun == 0xFFFF)) {
 
5951
            return (0);
 
5952
        }
 
5953
        return ( (a->stats->scsiOtBytes.value > b->stats->scsiOtBytes.value) ? 1 :
 
5954
                 (a->stats->scsiOtBytes.value < b->stats->scsiOtBytes.value) ? -1 : 0);
 
5955
        break;
 
5956
 
 
5957
    case 9:
 
5958
        /* Unknown LUNs don't have any valid info to compare for this field. So
 
5959
         * we dump them at the end of the list
 
5960
         */
 
5961
        if ((a->lun == 0xFFFF) && (b->lun != 0xFFFF)) {
 
5962
            return (1);
 
5963
        }
 
5964
        else if ((a->lun != 0xFFFF) && (b->lun == 0xFFFF)) {
 
5965
            return (-1);
 
5966
        }
 
5967
        else if ((a->lun == 0xFFFF) && (b->lun == 0xFFFF)) {
 
5968
            return (0);
 
5969
        }
 
5970
        return ( (a->stats->minRdSize > b->stats->minRdSize) ? 1:
 
5971
                 (a->stats->minRdSize < b->stats->minRdSize) ? -1 : 0);
 
5972
        break;
 
5973
 
 
5974
    case 10:
 
5975
        /* Unknown LUNs don't have any valid info to compare for this field. So
 
5976
         * we dump them at the end of the list
 
5977
         */
 
5978
        if ((a->lun == 0xFFFF) && (b->lun != 0xFFFF)) {
 
5979
            return (1);
 
5980
        }
 
5981
        else if ((a->lun != 0xFFFF) && (b->lun == 0xFFFF)) {
 
5982
            return (-1);
 
5983
        }
 
5984
        else if ((a->lun == 0xFFFF) && (b->lun == 0xFFFF)) {
 
5985
            return (0);
 
5986
        }
 
5987
        return ( (a->stats->maxRdSize > b->stats->maxRdSize) ? 1:
 
5988
                 (a->stats->maxRdSize < b->stats->maxRdSize) ? -1 : 0);
 
5989
        break;
 
5990
 
 
5991
    case 11:
 
5992
        /* Unknown LUNs don't have any valid info to compare for this field. So
 
5993
         * we dump them at the end of the list
 
5994
         */
 
5995
        if ((a->lun == 0xFFFF) && (b->lun != 0xFFFF)) {
 
5996
            return (1);
 
5997
        }
 
5998
        else if ((a->lun != 0xFFFF) && (b->lun == 0xFFFF)) {
 
5999
            return (-1);
 
6000
        }
 
6001
        else if ((a->lun == 0xFFFF) && (b->lun == 0xFFFF)) {
 
6002
            return (0);
 
6003
        }
 
6004
        return ( (a->stats->minWrSize > b->stats->minWrSize) ? 1:
 
6005
                 (a->stats->minWrSize < b->stats->minWrSize) ? -1 : 0);
 
6006
        break;
 
6007
 
 
6008
    case 12:
 
6009
        /* Unknown LUNs don't have any valid info to compare for this field. So
 
6010
         * we dump them at the end of the list
 
6011
         */
 
6012
        if ((a->lun == 0xFFFF) && (b->lun != 0xFFFF)) {
 
6013
            return (1);
 
6014
        }
 
6015
        else if ((a->lun != 0xFFFF) && (b->lun == 0xFFFF)) {
 
6016
            return (-1);
 
6017
        }
 
6018
        else if ((a->lun == 0xFFFF) && (b->lun == 0xFFFF)) {
 
6019
            return (0);
 
6020
        }
 
6021
        return ( (a->stats->maxWrSize > b->stats->maxWrSize) ? 1:
 
6022
                 (a->stats->maxWrSize < b->stats->maxWrSize) ? -1 : 0);
 
6023
        break;
 
6024
 
 
6025
    case 13:
 
6026
        /* Unknown LUNs don't have any valid info to compare for this field. So
 
6027
         * we dump them at the end of the list
 
6028
         */
 
6029
        if ((a->lun == 0xFFFF) && (b->lun != 0xFFFF)) {
 
6030
            return (1);
 
6031
        }
 
6032
        else if ((a->lun != 0xFFFF) && (b->lun == 0xFFFF)) {
 
6033
            return (-1);
 
6034
        }
 
6035
        else if ((a->lun == 0xFFFF) && (b->lun == 0xFFFF)) {
 
6036
            return (0);
 
6037
        }
 
6038
        return ( (a->stats->minXferRdySize > b->stats->minXferRdySize) ? 1:
 
6039
                 (a->stats->minXferRdySize < b->stats->minXferRdySize) ? -1 : 0);
 
6040
        break;
 
6041
 
 
6042
    case 14:
 
6043
        /* Unknown LUNs don't have any valid info to compare for this field. So
 
6044
         * we dump them at the end of the list
 
6045
         */
 
6046
        if ((a->lun == 0xFFFF) && (b->lun != 0xFFFF)) {
 
6047
            return (1);
 
6048
        }
 
6049
        else if ((a->lun != 0xFFFF) && (b->lun == 0xFFFF)) {
 
6050
            return (-1);
 
6051
        }
 
6052
        else if ((a->lun == 0xFFFF) && (b->lun == 0xFFFF)) {
 
6053
            return (0);
 
6054
        }
 
6055
        return ( (a->stats->maxXferRdySize > b->stats->maxXferRdySize) ? 1:
 
6056
                 (a->stats->maxXferRdySize < b->stats->maxXferRdySize) ? -1 : 0);
 
6057
        break;
 
6058
 
 
6059
    case 15:
 
6060
        /* Unknown LUNs don't have any valid info to compare for this field. So
 
6061
         * we dump them at the end of the list
 
6062
         */
 
6063
        if ((a->lun == 0xFFFF) && (b->lun != 0xFFFF)) {
 
6064
            return (1);
 
6065
        }
 
6066
        else if ((a->lun != 0xFFFF) && (b->lun == 0xFFFF)) {
 
6067
            return (-1);
 
6068
        }
 
6069
        else if ((a->lun == 0xFFFF) && (b->lun == 0xFFFF)) {
 
6070
            return (0);
 
6071
        }
 
6072
        return ( (a->stats->minIops > b->stats->minIops) ? 1:
 
6073
                 (a->stats->minIops < b->stats->minIops) ? -1 : 0);
 
6074
        break;
 
6075
 
 
6076
    case 16:
 
6077
        /* Unknown LUNs don't have any valid info to compare for this field. So
 
6078
         * we dump them at the end of the list
 
6079
         */
 
6080
        if ((a->lun == 0xFFFF) && (b->lun != 0xFFFF)) {
 
6081
            return (1);
 
6082
        }
 
6083
        else if ((a->lun != 0xFFFF) && (b->lun == 0xFFFF)) {
 
6084
            return (-1);
 
6085
        }
 
6086
        else if ((a->lun == 0xFFFF) && (b->lun == 0xFFFF)) {
 
6087
            return (0);
 
6088
        }
 
6089
        return ( (a->stats->maxIops > b->stats->maxIops) ? 1:
 
6090
                 (a->stats->maxIops < b->stats->maxIops) ? -1 : 0);
 
6091
        break;
 
6092
        
 
6093
    case 17: /* # Failed Commands */
 
6094
        /* The first three entries account for the unknown LUN entry */ 
 
6095
        if ((a->lun == 0xFFFF) && (b->lun != 0xFFFF)) {
 
6096
            return (1);
 
6097
        }
 
6098
        else if ((a->lun != 0xFFFF) && (b->lun == 0xFFFF)) {
 
6099
            return (-1);
 
6100
        }
 
6101
        else if ((a->lun == 0xFFFF) && (b->lun == 0xFFFF)) {
 
6102
            return (0);
 
6103
        }
 
6104
        return ( (a->stats->numFailedCmds > b->stats->numFailedCmds) ? 1 :
 
6105
                 (a->stats->numFailedCmds < b->stats->numFailedCmds) ? -1 : 0);
 
6106
        break;
 
6107
    case 18:
 
6108
        return (CMPTV (a->stats->minRTT, b->stats->minRTT));
 
6109
        break;
 
6110
        
 
6111
    case 19:
 
6112
        return (CMPTV (a->stats->maxRTT, b->stats->maxRTT));
 
6113
        break;
 
6114
 
 
6115
    case 20:
 
6116
        return (CMPTV (a->stats->minXfrRdyRTT, b->stats->minXfrRdyRTT));
 
6117
        break;
 
6118
 
 
6119
    case 21:
 
6120
        return (CMPTV (a->stats->maxXfrRdyRTT, b->stats->maxXfrRdyRTT));
 
6121
        break;
 
6122
 
 
6123
    case 22:
 
6124
        return (CMPTV (a->stats->minRdFrstDataRTT, b->stats->minRdFrstDataRTT));
 
6125
        break;
 
6126
 
 
6127
    case 23:
 
6128
        return (CMPTV (a->stats->maxRdFrstDataRTT, b->stats->maxRdFrstDataRTT));
 
6129
        break;
 
6130
 
 
6131
    case 24:
 
6132
        return (CMPTV (a->stats->minWrFrstDataRTT, b->stats->minWrFrstDataRTT));
 
6133
        break;
 
6134
 
 
6135
    case 25:
 
6136
        return (CMPTV (a->stats->maxWrFrstDataRTT, b->stats->maxWrFrstDataRTT));
 
6137
        break;
 
6138
 
 
6139
    case 26:
 
6140
        return (CMPTV (a->stats->firstSeen, b->stats->firstSeen));
 
6141
        break;
 
6142
 
 
6143
    case 27:
 
6144
        return (CMPTV (a->stats->lastSeen, b->stats->lastSeen));
 
6145
        break;
 
6146
 
 
6147
    case 28:
 
6148
        return ( (a->stats->chkCondCnt > b->stats->chkCondCnt) ? 1 :
 
6149
                 (a->stats->chkCondCnt < b->stats->chkCondCnt) ? -1 : 0);
 
6150
        break;
 
6151
 
 
6152
    case 29:
 
6153
        return ( (a->stats->busyCnt > b->stats->busyCnt) ? 1 :
 
6154
                 (a->stats->busyCnt < b->stats->busyCnt) ? -1 : 0);
 
6155
        break;
 
6156
 
 
6157
    case 30:
 
6158
        return ( (a->stats->resvConflictCnt > b->stats->resvConflictCnt) ? 1 :
 
6159
                 (a->stats->resvConflictCnt < b->stats->resvConflictCnt) ? -1
 
6160
                 : 0);
 
6161
        break;
 
6162
 
 
6163
    case 31:
 
6164
        return ( (a->stats->taskSetFullCnt > b->stats->taskSetFullCnt) ? 1 :
 
6165
                 (a->stats->taskSetFullCnt < b->stats->taskSetFullCnt) ? -1
 
6166
                 : 0);
 
6167
        break;
 
6168
 
 
6169
    case 32:
 
6170
        return ( (a->stats->taskAbrtCnt > b->stats->taskAbrtCnt) ? 1 :
 
6171
                 (a->stats->taskAbrtCnt < b->stats->taskAbrtCnt) ? -1 : 0);
 
6172
        break;
 
6173
 
 
6174
    case 33:
 
6175
        return ( (a->stats->abrtTaskSetCnt > b->stats->abrtTaskSetCnt) ? 1 :
 
6176
                 (a->stats->abrtTaskSetCnt < b->stats->abrtTaskSetCnt) ? -1 : 0);
 
6177
        break;
 
6178
 
 
6179
    case 34:
 
6180
        return ( (a->stats->clearTaskSetCnt > b->stats->clearTaskSetCnt) ? 1 :
 
6181
                 (a->stats->clearTaskSetCnt < b->stats->clearTaskSetCnt) ? -1 : 0);
 
6182
        break;
 
6183
 
 
6184
    case 35:
 
6185
        return ( (a->stats->tgtRstCnt > b->stats->tgtRstCnt) ? 1 :
 
6186
                 (a->stats->tgtRstCnt < b->stats->tgtRstCnt) ? -1 : 0);
 
6187
        break;
 
6188
 
 
6189
    case 36:
 
6190
        return ( (a->stats->lunRstCnt > b->stats->lunRstCnt) ? 1 :
 
6191
                 (a->stats->lunRstCnt < b->stats->lunRstCnt) ? -1 : 0);
 
6192
        break;
 
6193
 
 
6194
    case 37:
 
6195
        return ( (a->stats->lastTgtRstTime > b->stats->lastTgtRstTime) ? 1 :
 
6196
                 (a->stats->lastTgtRstTime < b->stats->lastTgtRstTime) ? -1 : 0);
 
6197
        break;
 
6198
 
 
6199
    case 38:
 
6200
        return ( (a->stats->lastLunRstTime > b->stats->lastLunRstTime) ? 1 :
 
6201
                 (a->stats->lastLunRstTime < b->stats->lastLunRstTime) ? -1 : 0);
 
6202
        break;
 
6203
 
 
6204
    default:
 
6205
        break;
 
6206
    }
 
6207
}
 
6208
 
 
6209
int cmpLunFctn (const void *_a, const void *_b)
 
6210
{
 
6211
    LunStatsSortedEntry *a = (LunStatsSortedEntry *)_a;
 
6212
    LunStatsSortedEntry *b = (LunStatsSortedEntry *)_b;
 
6213
    Counter a_=0, b_=0;
 
6214
 
 
6215
    switch(myGlobals.columnSort) {
 
6216
    case 1: /* LU number i.e. LUN */
 
6217
        return (a->lun > b->lun ? 1 : a->lun < b->lun ? -1 : 0);
 
6218
        break;
 
6219
 
 
6220
    case 2: /* Data Sent.value */
 
6221
        a_ = a->stats->bytesSent.value;
 
6222
        b_ = b->stats->bytesSent.value;
 
6223
        if(a_ < b_) return(-1); else if (a_ > b_) return(1); else return(0);
 
6224
        break;
 
6225
 
 
6226
    case 3: /* Data Rcvd.value */
 
6227
        a_ = a->stats->bytesRcvd.value;
 
6228
        b_ = b->stats->bytesRcvd.value;
 
6229
 
 
6230
        if(a_ < b_) return(-1); else if (a_ > b_) return(1); else return(0);
 
6231
        break;
 
6232
 
 
6233
    case 4:
 
6234
        a_ = a->stats->bytesSent.value + a->stats->bytesRcvd.value;
 
6235
        b_ = b->stats->bytesSent.value + b->stats->bytesRcvd.value;
 
6236
 
 
6237
        if(a_ < b_) return(-1); else if (a_ > b_) return(1); else return(0);
 
6238
        break;
 
6239
 
 
6240
    case 5:
 
6241
        a_ = a->stats->pktSent + a->stats->pktRcvd;
 
6242
        b_ = b->stats->pktSent + b->stats->pktRcvd;
 
6243
 
 
6244
        if(a_ < b_) return(-1); else if (a_ > b_) return(1); else return(0);
 
6245
        break;
 
6246
 
 
6247
        
 
6248
    default: /* LU number i.e. LUN */
 
6249
        return (a->lun > b->lun ? 1 : a->lun < b->lun ? -1 : 0);
 
6250
        break;
 
6251
    }
 
6252
}
 
6253
 
 
6254
int cmpVsanFctn (const void *_a, const void *_b)
 
6255
{
 
6256
    FcFabricElementHash **a = (FcFabricElementHash **)_a;
 
6257
    FcFabricElementHash **b = (FcFabricElementHash **)_b;
 
6258
    Counter a_=0, b_=0;
 
6259
 
 
6260
    switch(myGlobals.columnSort) {
 
6261
    case 1: /* VSAN */
 
6262
        return ((*a)->vsanId > (*b)->vsanId ? 1 : (*a)->vsanId < (*b)->vsanId ? -1 : 0);
 
6263
        break;
 
6264
 
 
6265
    case 2: /* Principal Switch */
 
6266
        return (memcmp ((void *)&(*a)->principalSwitch.str,
 
6267
                        (void *)&(*b)->principalSwitch.str, 8));
 
6268
        break;
 
6269
 
 
6270
    case 3: /* Total bytes */
 
6271
        a_ = (*a)->totBytes.value;
 
6272
        b_ = (*b)->totBytes.value;
 
6273
 
 
6274
        if(a_ < b_) return(-1); else if (a_ > b_) return(1); else return(0);
 
6275
        break;
 
6276
        
 
6277
    case 4: /* Total Frames */
 
6278
        a_ = (*a)->totPkts.value;
 
6279
        b_ = (*b)->totPkts.value;
 
6280
 
 
6281
        if(a_ < b_) return(-1); else if (a_ > b_) return(1); else return(0);
 
6282
        break;
 
6283
    }
 
6284
}
 
6285
 
 
6286
/* ************************************ */
 
6287
 
 
6288
int cmpFcDomainFctn (const void *_a, const void *_b)
 
6289
{
 
6290
    SortedFcDomainStatsEntry *a = (SortedFcDomainStatsEntry *)_a;
 
6291
    SortedFcDomainStatsEntry *b = (SortedFcDomainStatsEntry *)_b;
 
6292
    Counter a_=0, b_=0;
 
6293
 
 
6294
    switch(myGlobals.columnSort) {
 
6295
    case 0: /* Rcvd */
 
6296
        return (a->stats->rcvdBytes.value > b->stats->rcvdBytes.value ? 1 :
 
6297
                a->stats->rcvdBytes.value < b->stats->rcvdBytes.value ? -1 : 0);
 
6298
        break;
 
6299
 
 
6300
    case 2: /* Sent */
 
6301
    default:
 
6302
        return (a->stats->sentBytes.value > b->stats->sentBytes.value ? 1 :
 
6303
                a->stats->sentBytes.value < b->stats->sentBytes.value ? -1 : 0);
 
6304
        break;
 
6305
    }
 
6306
}
 
6307
 
 
6308
/* ************************************ */
 
6309
 
 
6310
void printFcHostTrafficStats(HostTraffic *el, int actualDeviceId) {
 
6311
  Counter totalSent, totalRcvd;
 
6312
  Counter actTotalSent, actTotalRcvd;
 
6313
  char buf[LEN_GENERAL_WORK_BUFFER];
 
6314
  char linkName[LEN_GENERAL_WORK_BUFFER/2];
 
6315
 
 
6316
  totalSent = el->fcBytesSent.value;
 
6317
  totalRcvd = el->fcBytesRcvd.value;
 
6318
  
 
6319
  printHostHourlyTraffic(el);
 
6320
  
 
6321
/*   printPacketStats(el, actualDeviceId); */
 
6322
 
 
6323
 
 
6324
  if((totalSent == 0) && (totalRcvd == 0))
 
6325
    return;
 
6326
 
 
6327
  printSectionTitle("Protocol Distribution");
 
6328
 
 
6329
  sendString("<CENTER>\n"
 
6330
             ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS"><TR><TH "TH_BG" WIDTH=100 "DARK_BG">Protocol</TH>"
 
6331
             "<TH "TH_BG" WIDTH=200 COLSPAN=2 "DARK_BG">Total&nbsp;Bytes&nbsp;Sent</TH>"
 
6332
             "<TH "TH_BG" WIDTH=200 COLSPAN=2 "DARK_BG">Total&nbsp;Bytes&nbsp;Rcvd</TH></TR>\n");
 
6333
 
 
6334
  actTotalSent = el->fcFcpBytesSent.value;
 
6335
  actTotalRcvd = el->fcFcpBytesRcvd.value;
 
6336
 
 
6337
  printTableDoubleEntry(buf, sizeof(buf), "SCSI", CONST_COLOR_1, (float)actTotalSent/1024,
 
6338
                        100*((float)SD(actTotalSent, totalSent)),
 
6339
                        (float)actTotalRcvd/1024,
 
6340
                        100*((float)SD(actTotalRcvd, totalRcvd)));
 
6341
 
 
6342
  actTotalSent = el->fcElsBytesSent.value;
 
6343
  actTotalRcvd = el->fcElsBytesRcvd.value;
 
6344
 
 
6345
  printTableDoubleEntry(buf, sizeof(buf), "ELS", CONST_COLOR_1, (float)actTotalSent/1024,
 
6346
                        100*((float)SD(actTotalSent, totalSent)),
 
6347
                        (float)actTotalRcvd/1024,
 
6348
                        100*((float)SD(actTotalRcvd, totalRcvd)));
 
6349
 
 
6350
  actTotalSent = el->fcDnsBytesSent.value;
 
6351
  actTotalRcvd = el->fcDnsBytesRcvd.value;
 
6352
  
 
6353
  printTableDoubleEntry(buf, sizeof(buf), "NS", CONST_COLOR_1, (float)actTotalSent/1024,
 
6354
                        100*((float)SD(actTotalSent, totalSent)),
 
6355
                        (float)actTotalRcvd/1024,
 
6356
                        100*((float)SD(actTotalRcvd, totalRcvd)));
 
6357
 
 
6358
  actTotalSent = el->fcSwilsBytesSent.value;
 
6359
  actTotalRcvd = el->fcSwilsBytesRcvd.value;
 
6360
  
 
6361
  printTableDoubleEntry(buf, sizeof(buf), "SWILS", CONST_COLOR_1, (float)actTotalSent/1024,
 
6362
                        100*((float)SD(actTotalSent, totalSent)),
 
6363
                        (float)actTotalRcvd/1024,
 
6364
                        100*((float)SD(actTotalRcvd, totalRcvd)));
 
6365
 
 
6366
  actTotalSent = el->fcIpfcBytesSent.value;
 
6367
  actTotalRcvd = el->fcIpfcBytesRcvd.value;
 
6368
  
 
6369
  printTableDoubleEntry(buf, sizeof(buf), "IP/FC", CONST_COLOR_1, (float)actTotalSent/1024,
 
6370
                        100*((float)SD(actTotalSent, totalSent)),
 
6371
                        (float)actTotalRcvd/1024,
 
6372
                        100*((float)SD(actTotalRcvd, totalRcvd)));
 
6373
 
 
6374
  actTotalSent = el->otherFcBytesSent.value;
 
6375
  actTotalRcvd = el->otherFcBytesRcvd.value;
 
6376
  
 
6377
  printTableDoubleEntry(buf, sizeof(buf), "Others", CONST_COLOR_1, (float)actTotalSent/1024,
 
6378
                        100*((float)SD(actTotalSent, totalSent)),
 
6379
                        (float)actTotalRcvd/1024,
 
6380
                        100*((float)SD(actTotalRcvd, totalRcvd)));
 
6381
 
 
6382
  {
 
6383
      totalSent = el->fcBytesSent.value;
 
6384
      totalRcvd = el->fcBytesRcvd.value;
 
6385
 
 
6386
    if((totalSent > 0) || (totalRcvd > 0)) {
 
6387
      if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT>Protocol Distribution</TH>",
 
6388
                  getRowColor()) < 0)
 
6389
        BufferTooShort();
 
6390
      sendString(buf);
 
6391
 
 
6392
      if(el->hostNumFcAddress[0] != '\0') {
 
6393
          strncpy (linkName, fc_to_str ((u_int8_t *)&el->hostFcAddress), sizeof (linkName));
 
6394
      } 
 
6395
 
 
6396
      if(totalSent > 0) {
 
6397
        if(snprintf(buf, sizeof(buf),
 
6398
                    "<TD WIDTH=250 "TD_BG" ALIGN=RIGHT COLSPAN=2 BGCOLOR=white>"
 
6399
                    "<IMG SRC=hostFcTrafficDistrib-%s"CHART_FORMAT"?1 ALT=\"Sent Traffic Distribution for %s\"></TD>",
 
6400
                    linkName,
 
6401
                    fc_to_str ((u_int8_t *)&el->hostFcAddress)) < 0)
 
6402
          BufferTooShort();
 
6403
        sendString(buf);
 
6404
      } else {
 
6405
        sendString("<TD width=250 "TD_BG" ALIGN=RIGHT COLSPAN=2 WIDTH=250>&nbsp;</TD>");
 
6406
      }
 
6407
 
 
6408
      if(totalRcvd > 0) {
 
6409
        if(snprintf(buf, sizeof(buf),
 
6410
                    "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2 BGCOLOR=white><IMG SRC=hostFcTrafficDistrib-"
 
6411
                    "%s"CHART_FORMAT" ALT=\"Received Traffic Distribution for %s\"></TD>",
 
6412
                    linkName,
 
6413
                    fc_to_str ((u_int8_t *)&el->hostFcAddress)) < 0)
 
6414
          BufferTooShort();
 
6415
        sendString(buf);
 
6416
      } else {
 
6417
        sendString("<TD "TD_BG" ALIGN=RIGHT COLSPAN=2 WIDTH=250>&nbsp;</TD>");
 
6418
      }
 
6419
 
 
6420
      sendString("</TD></TR>");
 
6421
 
 
6422
#ifdef NOT_YET
 
6423
      if((el->fcFcpBytesSent.value + el->fcElsBytesSent.value + el->fcDnsBytesSent.value + el->otherFcBytesSent.value)
 
6424
         > 0) {
 
6425
          if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT>Traffic Distribution</TH>",
 
6426
                      getRowColor()) < 0)
 
6427
              BufferTooShort();
 
6428
          sendString(buf);
 
6429
 
 
6430
          if((el->fcFcpBytesSent.value + el->fcElsBytesSent.value + el->fcDnsBytesSent.value + el->otherFcBytesSent.value) > 0) { 
 
6431
              if(snprintf(buf, sizeof(buf),
 
6432
                          "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2 BGCOLOR=white>"
 
6433
                          "<IMG SRC=hostIPTrafficDistrib-%s"CHART_FORMAT"?1 ALT=\"Sent Traffic Distribution for %s\"></TD>",
 
6434
                          fc_to_str(&el->hostFcAddress), fc_to_str (&el->hostFcAddress)) < 0)
 
6435
                  BufferTooShort();
 
6436
              sendString(buf);
 
6437
          } else
 
6438
              sendString("<TD "TD_BG" COLSPAN=2 WIDTH=250>&nbsp;</TD>");
 
6439
 
 
6440
          if((el->fcFcpBytesRcvd.value + el->fcElsBytesRcvd.value + el->fcDnsBytesRcvd.value + el->otherFcBytesRcvd.value) > 0) { 
 
6441
              if(snprintf(buf, sizeof(buf),
 
6442
                          "<TD "TD_BG" ALIGN=RIGHT COLSPAN=2 BGCOLOR=white><IMG SRC=hostIPTrafficDistrib-"
 
6443
                          "%s"CHART_FORMAT" ALT=\"Received Traffic Distribution for %s\"></TD></TR>",
 
6444
                          fc_to_str(&el->hostFcAddress), fc_to_str (&el->hostFcAddress)) < 0)
 
6445
                  BufferTooShort();
 
6446
              sendString(buf);
 
6447
          } else
 
6448
              sendString("<TD "TD_BG" COLSPAN=2 WIDTH=250>&nbsp;</TD>");
 
6449
 
 
6450
          sendString("</TR>");
 
6451
      }
 
6452
#endif /* NOT_YET */  
 
6453
    }
 
6454
  }
 
6455
 
 
6456
  sendString("</TABLE>"TABLE_OFF"<P>\n");
 
6457
  sendString("</CENTER>\n");
 
6458
}
 
6459
 
 
6460
/* ************************************ */
 
6461
 
 
6462
void printFcHostContactedPeers(HostTraffic *el, int actualDeviceId)
 
6463
{
 
6464
    u_int i, titleSent = 0;
 
6465
    char buf[LEN_GENERAL_WORK_BUFFER], hostLinkBuf[LEN_GENERAL_WORK_BUFFER];
 
6466
    HostTraffic tmpEl;
 
6467
 
 
6468
    if((el->pktSent.value != 0) || (el->pktRcvd.value != 0)) {
 
6469
        int ok =0;
 
6470
 
 
6471
        for(i=0; i<MAX_NUM_CONTACTED_PEERS; i++)
 
6472
            if((!emptySerial(&el->contactedSentPeers.peersSerials[i])
 
6473
                && (!cmpSerial(&el->contactedSentPeers.peersSerials[i], &myGlobals.otherHostEntry->hostSerial))
 
6474
                || (!emptySerial(&el->contactedRcvdPeers.peersSerials[i])
 
6475
                    && (!cmpSerial(&el->contactedRcvdPeers.peersSerials[i], &myGlobals.otherHostEntry->hostSerial))))) {
 
6476
                ok = 1;
 
6477
                break;
 
6478
            }
 
6479
 
 
6480
        if(ok) {
 
6481
            HostTraffic *el2;
 
6482
            int numEntries;
 
6483
 
 
6484
            for(numEntries = 0, i=0; i<MAX_NUM_CONTACTED_PEERS; i++)
 
6485
                if(!emptySerial(&el->contactedSentPeers.peersSerials[i])
 
6486
             && (!cmpSerial(&el->contactedSentPeers.peersSerials[i], &myGlobals.otherHostEntry->hostSerial))) {
 
6487
                    if((el2 = quickHostLink(el->contactedSentPeers.peersSerials[i],
 
6488
                                            myGlobals.actualReportDeviceId, &tmpEl)) != NULL) {
 
6489
                        if(numEntries == 0) {
 
6490
                            printSectionTitle("Last Contacted Peers");
 
6491
 
 
6492
                            titleSent = 1;
 
6493
                            sendString("<CENTER>\n"
 
6494
                                       "<TABLE BORDER=0 "TABLE_DEFAULTS"><TR><TD "TD_BG" VALIGN=TOP>\n");
 
6495
 
 
6496
                            sendString(""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\">"
 
6497
                                       "<TR "TR_ON"><TH "TH_BG" "DARK_BG">Sent To</TH>"
 
6498
                                       "<TH "TH_BG" "DARK_BG">Address</TH></TR>\n");
 
6499
                        }
 
6500
            
 
6501
                        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
 
6502
                                    "<TD "TD_BG" ALIGN=RIGHT>%s&nbsp;</TD></TR>\n",
 
6503
                                    getRowColor(),
 
6504
                                    makeFcHostLink(el2,
 
6505
                                                   FLAG_HOSTLINK_TEXT_FORMAT,
 
6506
                                                   0, 0, hostLinkBuf,
 
6507
                                                   sizeof (hostLinkBuf)),
 
6508
                                    el2->hostNumFcAddress) < 0)
 
6509
                            BufferTooShort();
 
6510
 
 
6511
                        sendString(buf);
 
6512
                        numEntries++;
 
6513
                    }
 
6514
                }
 
6515
 
 
6516
            if(numEntries > 0) {
 
6517
                sendString("</TABLE>"TABLE_OFF"</TD><TD "TD_BG" VALIGN=TOP>\n");
 
6518
            } else {
 
6519
                sendString("&nbsp;</TD><TD "TD_BG">\n");
 
6520
            }
 
6521
 
 
6522
            /* ***************************************************** */
 
6523
 
 
6524
            for(numEntries = 0, i=0; i<MAX_NUM_CONTACTED_PEERS; i++)
 
6525
                if((!emptySerial(&el->contactedRcvdPeers.peersSerials[i]))
 
6526
                   && (!cmpSerial(&el->contactedRcvdPeers.peersSerials[i], &myGlobals.otherHostEntry->hostSerial))) {
 
6527
                    if((el2 = quickHostLink(el->contactedRcvdPeers.peersSerials[i],
 
6528
                                            myGlobals.actualReportDeviceId, &tmpEl)) != NULL) {
 
6529
                        if(numEntries == 0) {
 
6530
                            if(!titleSent) printSectionTitle("Last Contacted Peers");
 
6531
                            sendString("<CENTER>"TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS">"
 
6532
                                       "<TR "TR_ON"><TH "TH_BG" "DARK_BG">Received From</TH>"
 
6533
                                       "<TH "TH_BG" "DARK_BG">Address</TH></TR>\n");
 
6534
                        }
 
6535
 
 
6536
                        if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
 
6537
                                    "<TD "TD_BG" ALIGN=RIGHT>%s</TD></TR>\n",
 
6538
                                    getRowColor(),
 
6539
                                    makeFcHostLink(el2,
 
6540
                                                   FLAG_HOSTLINK_TEXT_FORMAT,
 
6541
                                                   0, 0, hostLinkBuf,
 
6542
                                                   sizeof (hostLinkBuf)),
 
6543
                                    el2->hostNumFcAddress) < 0)
 
6544
                            BufferTooShort();
 
6545
 
 
6546
                        sendString(buf);
 
6547
                        numEntries++;
 
6548
                    }
 
6549
                }
 
6550
            
 
6551
            if(numEntries > 0) {
 
6552
                sendString("</TABLE>"TABLE_OFF"\n");
 
6553
            }
 
6554
 
 
6555
            sendString("</TD></TR></TABLE>"TABLE_OFF"<P>\n");
 
6556
            sendString("</CENTER>\n");
 
6557
        } /* ok */
 
6558
    }
 
6559
    else {
 
6560
        traceEvent (CONST_TRACE_ALWAYSDISPLAY, "printFcHostContactedPeers: else part\n");
 
6561
    }
 
6562
}
 
6563
 
 
6564
/* ************************************ */
 
6565
 
 
6566
void printFcHostDetailedInfo(HostTraffic *el, int actualDeviceId)
 
6567
{
 
6568
    char buf[LEN_GENERAL_WORK_BUFFER], buf1[64],
 
6569
         hostLinkBuf[LEN_GENERAL_WORK_BUFFER];
 
6570
    float percentage;
 
6571
    Counter total, tot1;
 
6572
    char *vendorName;
 
6573
    char formatBuf[32], formatBuf1[32], formatBuf2[32];
 
6574
    
 
6575
    accessAddrResMutex("printAllSessionsHTML");
 
6576
 
 
6577
    buf1[0]=0;
 
6578
 
 
6579
    if (snprintf (buf, sizeof(buf), "Info about %s\n",
 
6580
                  makeFcHostLink (el, FLAG_HOSTLINK_TEXT_NO_LINK_FORMAT, 1,
 
6581
                                  0, hostLinkBuf, sizeof (hostLinkBuf))) < 0)
 
6582
        BufferTooShort();
 
6583
 
 
6584
    releaseAddrResMutex();
 
6585
    printHTMLheader(buf, 0, 0);
 
6586
    sendString("<CENTER>\n");
 
6587
    sendString("<P>"TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\">\n");
 
6588
 
 
6589
    accessAddrResMutex("printAllSessions-2");
 
6590
 
 
6591
    if (el->vsanId) {
 
6592
        if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6593
                    "%d%s</TD></TR>\n",
 
6594
                    getRowColor(), "VSAN",
 
6595
                    el->vsanId,
 
6596
                    myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
6597
            BufferTooShort();
 
6598
    }
 
6599
    else {
 
6600
        if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6601
                    "N/A%s</TD></TR>\n",
 
6602
                    getRowColor(), "VSAN",
 
6603
                    myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
6604
            BufferTooShort();
 
6605
    }
 
6606
    sendString(buf);
 
6607
  
 
6608
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6609
                "%s%s</TD></TR>\n",
 
6610
                getRowColor(), "FC_ID",
 
6611
                el->hostNumFcAddress,
 
6612
                myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
6613
        BufferTooShort();
 
6614
    sendString(buf);
 
6615
 
 
6616
    if (el->pWWN.str[0] != '\0') {
 
6617
        if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6618
                    "%s%s</TD></TR>\n",
 
6619
                    getRowColor(), "Port&nbsp;WWN",
 
6620
                    fcwwn_to_str ((u_int8_t *)&el->pWWN), 
 
6621
                    myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
6622
            BufferTooShort();
 
6623
        sendString(buf);
 
6624
    }
 
6625
    
 
6626
    if (el->nWWN.str[0] != '\0') {
 
6627
        if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6628
                    "%s%s</TD></TR>\n",
 
6629
                    getRowColor(), "Node&nbsp;WWN",
 
6630
                    fcwwn_to_str ((u_int8_t *)&el->nWWN), 
 
6631
                    myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
6632
            BufferTooShort();
 
6633
        sendString(buf);
 
6634
    }
 
6635
    
 
6636
    vendorName = getVendorInfo(&el->pWWN.str[2], 1);
 
6637
    if(vendorName[0] != '\0') {
 
6638
        if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6639
                    "%s%s</TD></TR>\n",
 
6640
                    getRowColor(), "Nw&nbsp;Board&nbsp;Vendor",
 
6641
                    vendorName,
 
6642
                    myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
6643
            BufferTooShort();
 
6644
        sendString(buf);
 
6645
    }
 
6646
 
 
6647
    sendString("</TABLE>"TABLE_OFF"<P>\n");
 
6648
    sendString("</CENTER>\n");
 
6649
 
 
6650
    sendString("<CENTER>\n");
 
6651
    sendString("<P>"TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\">\n");
 
6652
 
 
6653
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
6654
                "<TD "TD_BG" ALIGN=RIGHT>"
 
6655
                "%s&nbsp;&nbsp;-&nbsp;&nbsp;%s&nbsp;[%s]</TD></TR>\n",
 
6656
                getRowColor(),
 
6657
                "First/Last&nbsp;Seen",
 
6658
                formatTime(&(el->firstSeen), formatBuf, sizeof (formatBuf)),
 
6659
                formatTime(&(el->lastSeen), formatBuf1, sizeof (formatBuf1)),
 
6660
                formatSeconds(el->lastSeen - el->firstSeen, formatBuf2,
 
6661
                              sizeof (formatBuf2))) < 0)
 
6662
        BufferTooShort();
 
6663
    sendString(buf);
 
6664
 
 
6665
    if (el->numOffline.value) {
 
6666
        if (snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6667
                     "%s%s</TD></TR>\n",
 
6668
                     getRowColor(), "Number&nbsp;Of&nbsp;Times&nbsp;Offline",
 
6669
                     formatPkts(el->numOffline.value, formatBuf, sizeof (formatBuf)),
 
6670
                     myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
6671
            BufferTooShort();
 
6672
        sendString (buf);
 
6673
        
 
6674
        if (snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6675
                     "%s%s</TD></TR>\n",
 
6676
                     getRowColor(), "Last&nbsp;Offline&nbsp;Time",
 
6677
                     formatTime(&el->lastOfflineTime, formatBuf, sizeof (formatBuf)),
 
6678
                     myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
6679
            BufferTooShort();
 
6680
        sendString (buf);
 
6681
 
 
6682
        if (el->lastOnlineTime) {
 
6683
            if (snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6684
                         "%s%s</TD></TR>\n",
 
6685
                         getRowColor(), "Last&nbsp;Online&nbsp;Time",
 
6686
                         formatTime(&el->lastOnlineTime, formatBuf, sizeof (formatBuf)),
 
6687
                         myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
6688
                BufferTooShort();
 
6689
            sendString (buf);
 
6690
        }
 
6691
    }
 
6692
 
 
6693
    sendString("</TABLE>"TABLE_OFF"<P>\n");
 
6694
    sendString("</CENTER>\n");
 
6695
 
 
6696
    sendString("<CENTER>\n");
 
6697
    sendString("<P>"TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\">\n");
 
6698
 
 
6699
    if (snprintf (buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH>"
 
6700
                  "<TD "TD_BG" ALIGN=RIGHT>%d&nbsp;</TD></TR>\n",
 
6701
                  getRowColor(), "MTU", el->fcRecvSize) < 0)
 
6702
        BufferTooShort();
 
6703
    sendString(buf);
 
6704
                
 
6705
    if (el->devType != SCSI_DEV_UNINIT) {
 
6706
        if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6707
                    "%s%s</TD></TR>\n",
 
6708
                    getRowColor(), "SCSI&nbsp;Device&nbsp;Type",
 
6709
                    el->devType == SCSI_DEV_BLOCK ? "Target, Block" :
 
6710
                    el->devType == SCSI_DEV_SSC  ? "Target, Tape" :
 
6711
                    el->devType == SCSI_DEV_UNKNOWN ? "Target, Unknown" :
 
6712
                    el->devType == SCSI_DEV_INITIATOR ? "Initiator" : "Other",
 
6713
                    myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
6714
            BufferTooShort();
 
6715
        sendString(buf);
 
6716
    }
 
6717
 
 
6718
    if ((el->devType != SCSI_DEV_UNINIT) &&
 
6719
        (el->devType != SCSI_DEV_INITIATOR)) {
 
6720
 
 
6721
        if (el->vendorId[0] != '\0') {
 
6722
            if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6723
                        "%s%s</TD></TR>\n",
 
6724
                        getRowColor(), "Device&nbsp;Vendor",
 
6725
                        el->vendorId,
 
6726
                        myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
6727
                BufferTooShort();
 
6728
            sendString(buf);
 
6729
        }
 
6730
 
 
6731
        if (el->productId[0] != '\0') {
 
6732
            if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6733
                        "%s%s</TD></TR>\n",
 
6734
                        getRowColor(), "Product&nbsp;Name",
 
6735
                        el->productId,
 
6736
                        myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
6737
                BufferTooShort();
 
6738
            sendString(buf);
 
6739
        }
 
6740
 
 
6741
        if (el->productRev[0] != '\0') {
 
6742
            if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6743
                        "%s%s</TD></TR>\n",
 
6744
                        getRowColor(), "Product&nbsp;Revision",
 
6745
                        el->productRev,
 
6746
                        myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
6747
                BufferTooShort();
 
6748
            sendString(buf);
 
6749
        }
 
6750
    }
 
6751
 
 
6752
    sendString("</TABLE>"TABLE_OFF"<P>\n");
 
6753
    sendString("</CENTER>\n");
 
6754
 
 
6755
    sendString("<CENTER>\n");
 
6756
    sendString("<P>"TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\">\n");
 
6757
 
 
6758
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s"
 
6759
                "</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6760
                "%s/%s Pkts</TD></TR>\n",
 
6761
                getRowColor(), "Total&nbsp;Data&nbsp;Rcvd",
 
6762
                formatBytes(el->fcBytesRcvd.value, 1,
 
6763
                            formatBuf, sizeof (formatBuf)),
 
6764
                formatPkts(el->pktRcvd.value, formatBuf1,
 
6765
                           sizeof (formatBuf1))) < 0)
 
6766
        BufferTooShort();
 
6767
    sendString(buf);
 
6768
 
 
6769
    if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s"
 
6770
                "</TH><TD "TD_BG" ALIGN=RIGHT>"
 
6771
                "%s/%s Pkts</TD></TR>\n",
 
6772
                getRowColor(), "Total&nbsp;Data&nbsp;Sent",
 
6773
                formatBytes(el->fcBytesSent.value, 1, formatBuf,
 
6774
                            sizeof (formatBuf)),
 
6775
                formatPkts(el->pktSent.value, formatBuf1,
 
6776
                           sizeof (formatBuf1))) < 0)
 
6777
        BufferTooShort();
 
6778
    sendString(buf);
 
6779
 
 
6780
    total = el->pktSent.value+el->pktRcvd.value;
 
6781
    if(total > 0) {
 
6782
        percentage = ((float)el->pktSent.value*100)/((float)total);
 
6783
        printTableEntryPercentage(buf, sizeof(buf), "Sent&nbsp;vs.&nbsp;Rcvd&nbsp;Pkts",
 
6784
                                  "Sent", "Rcvd", -1, percentage);
 
6785
    }
 
6786
 
 
6787
    total = el->fcBytesSent.value+el->fcBytesRcvd.value;
 
6788
    if(total > 0) {
 
6789
        percentage = ((float)el->fcBytesSent.value*100)/((float)total);
 
6790
        printTableEntryPercentage(buf, sizeof(buf), "Sent&nbsp;vs.&nbsp;Rcvd&nbsp;Data",
 
6791
                                  "Sent", "Rcvd", -1, percentage);
 
6792
    }
 
6793
 
 
6794
    tot1 = el->class3Sent.value + el->class3Rcvd.value;
 
6795
    if ((total > 0) && (tot1 > 0)) {
 
6796
        percentage = (((float)tot1*100)/total);
 
6797
        printTableEntryPercentage(buf, sizeof(buf), "Class&nbsp;3&nbsp;vs.&nbsp;Other&nbsp;Traffic",
 
6798
                                  "Class 3", "Other Classes", -1, percentage);
 
6799
    }
 
6800
 
 
6801
    tot1 = el->fcFcpBytesRcvd.value + el->fcFcpBytesSent.value;
 
6802
    if ((total > 0) && (tot1 > 0)) {
 
6803
        percentage = (((float)tot1*100)/total);
 
6804
        printTableEntryPercentage(buf, sizeof(buf), "SCSI&nbsp;vs.&nbsp;Others&nbsp;Traffic",
 
6805
                                  "SCSI", "Others", -1, percentage);
 
6806
    }
 
6807
 
 
6808
    tot1 = el->scsiReadBytes.value + el->scsiWriteBytes.value;
 
6809
    if (tot1 > 0) {
 
6810
        percentage = (((float)el->scsiReadBytes.value*100)/tot1);
 
6811
        printTableEntryPercentage(buf, sizeof(buf), "SCSI&nbsp;Read&nbsp;vs.&nbsp;Write&nbsp;Bytes",
 
6812
                                  "SCSI Read", "SCSI Write", -1, percentage);
 
6813
    }
 
6814
  
 
6815
    /* **************************** */
 
6816
 
 
6817
    sendString("</TABLE>"TABLE_OFF"<P>\n");
 
6818
    sendString("</CENTER>\n");
 
6819
}
 
6820
 
 
6821
void printScsiLunStats (HostTraffic *el, int actualDeviceId, int sortedColumn,
 
6822
                        int revertOrder, int pageNum, char *url)
 
6823
{
 
6824
 
 
6825
    u_int idx, numEntries, skipEntries = 0;
 
6826
    int printedEntries=0;
 
6827
    int duration;
 
6828
    LunStatsSortedEntry sortedLunTbl[MAX_LUNS_SUPPORTED];
 
6829
    LunStatsSortedEntry *entry;
 
6830
    char buf[LEN_GENERAL_WORK_BUFFER], *sign, *title=NULL;
 
6831
    char formatBuf[32], formatBuf1[32], formatBuf2[32], formatBuf3[32],
 
6832
         formatBuf4[32], formatBuf5[32];
 
6833
    char *arrowGif, *arrow[48], *theAnchor[48];
 
6834
    char htmlAnchor[64], htmlAnchor1[64], pageUrl[64];
 
6835
    char pcapFilename[128];
 
6836
    Counter dataSent, dataRcvd;
 
6837
  
 
6838
    if ((el->devType == SCSI_DEV_UNINIT) ||
 
6839
        (el->devType == SCSI_DEV_INITIATOR)) {
 
6840
        printNoDataYet();
 
6841
        return;
 
6842
    }
 
6843
    
 
6844
    printHTMLheader("LUN Statistics", 0, 0);
 
6845
    
 
6846
    memset(buf, 0, sizeof(buf));
 
6847
    memset(sortedLunTbl, 0, sizeof (sortedLunTbl));
 
6848
 
 
6849
    myGlobals.columnSort = sortedColumn;
 
6850
 
 
6851
    for (idx=0, numEntries=0; idx < MAX_LUNS_SUPPORTED; idx++) {
 
6852
        if(el->activeLuns[idx] != NULL) {
 
6853
            sortedLunTbl[numEntries].lun = idx;
 
6854
            sortedLunTbl[numEntries++].stats = el->activeLuns[idx];
 
6855
        }
 
6856
    }
 
6857
 
 
6858
    if(revertOrder) {
 
6859
        sign = "";
 
6860
        arrowGif = "&nbsp;" CONST_IMG_ARROW_UP;
 
6861
    } else {
 
6862
        sign = "-";
 
6863
        arrowGif = "&nbsp;" CONST_IMG_ARROW_DOWN;
 
6864
    }
 
6865
 
 
6866
    if(numEntries > 0) {
 
6867
 
 
6868
        myGlobals.columnSort = sortedColumn;
 
6869
        qsort(sortedLunTbl, numEntries, sizeof(LunStatsSortedEntry), cmpLunFctn);
 
6870
 
 
6871
        /* Need to add info about page in Hosts Info mode */
 
6872
        if(snprintf(htmlAnchor, sizeof(htmlAnchor),
 
6873
                    "<A HREF=/%s.html?showF=%d&page=%d&col=%s", url,
 
6874
                    showHostLunStats, pageNum, sign) < 0)
 
6875
            BufferTooShort();
 
6876
        if(snprintf(htmlAnchor1, sizeof(htmlAnchor1),
 
6877
                    "<A HREF=/%s.html?showF=%d&page=%d&col=", url,
 
6878
                    showHostLunStats, pageNum) < 0)
 
6879
            BufferTooShort();
 
6880
        if (snprintf (pageUrl, sizeof (pageUrl), "%s.html?showF=%d",
 
6881
                      url, showHostLunStats) < 0)
 
6882
            BufferTooShort();
 
6883
 
 
6884
        if(abs(myGlobals.columnSort) == 1) {
 
6885
            arrow[1] = arrowGif;
 
6886
            theAnchor[1] = htmlAnchor;
 
6887
        } else {
 
6888
            arrow[1] = "";
 
6889
            theAnchor[1] = htmlAnchor1;
 
6890
        }
 
6891
 
 
6892
        if(abs(myGlobals.columnSort) == 2)  {
 
6893
            arrow[2] = arrowGif;
 
6894
            theAnchor[2] = htmlAnchor;
 
6895
        } else {
 
6896
            arrow[2] = "";
 
6897
            theAnchor[2] = htmlAnchor1;
 
6898
        }
 
6899
 
 
6900
        if(abs(myGlobals.columnSort) == 3) {
 
6901
            arrow[3] = arrowGif;
 
6902
            theAnchor[3] = htmlAnchor;
 
6903
        } else {
 
6904
            arrow[3] = "";
 
6905
            theAnchor[3] = htmlAnchor1;
 
6906
        }
 
6907
 
 
6908
        if(abs(myGlobals.columnSort) == 4) {
 
6909
            arrow[4] = arrowGif;
 
6910
            theAnchor[4] = htmlAnchor;
 
6911
        } else {
 
6912
            arrow[4] = "";
 
6913
            theAnchor[4] = htmlAnchor1;
 
6914
        }
 
6915
 
 
6916
#ifdef WIN32        
 
6917
        sprintf(pcapFilename, "file:%s/ntop-suspicious-pkts.none.pcap",
 
6918
                myGlobals.pcapLogBasePath); /* Added by Ola Lundqvist <opal@debian.org> */
 
6919
#else
 
6920
        sprintf(pcapFilename, "file://%s/ntop-suspicious-pkts.none.pcap",
 
6921
                myGlobals.pcapLogBasePath); /* Added by Ola Lundqvist <opal@debian.org> */
 
6922
#endif        
 
6923
        
 
6924
        sendString("<CENTER>\n");
 
6925
        if (snprintf(buf, sizeof (buf),
 
6926
                     ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\"><TR "TR_ON">"
 
6927
                     "<TH "TH_BG" >%s1>LUN%s</A></TH>"
 
6928
                     "<TH "TH_BG" COLSPAN=2>Total&nbsp;Bytes</TH>"
 
6929
                     "<TH "TH_BG" COLSPAN=3>Data&nbsp;Bytes</TH>"
 
6930
                     "<TH "TH_BG" COLSPAN=2>Read&nbsp;Size</TH>"
 
6931
                     "<TH "TH_BG" COLSPAN=2>Write&nbsp;Size</TH>"
 
6932
                     "<TH "TH_BG" COLSPAN=2>Xfer&nbsp;Rdy&nbsp;Size</TH>"
 
6933
                     "<TH "TH_BG">#&nbsp;Failed&nbsp;Cmds</TH>"
 
6934
                     "<TH "TH_BG" >Duration(secs)</TH>"
 
6935
                     "<TH "TH_BG" >Last&nbsp;Seen</TH>"
 
6936
                     "</TR>\n",
 
6937
                     theAnchor[1], arrow[1]
 
6938
                     ) < 0)                 
 
6939
            BufferTooShort();
 
6940
 
 
6941
        sendString(buf);
 
6942
 
 
6943
        if (snprintf(buf, sizeof (buf),
 
6944
                     "<TR "TR_ON" %s>"
 
6945
                     "<TH "TH_BG"><br></TH>"
 
6946
                     "<TH "TH_BG">%s2>Sent%s</A></TH>"
 
6947
                     "<TH "TH_BG">%s3>Rcvd%s</A></TH>"
 
6948
                     "<TH "TH_BG">Read</TH>"
 
6949
                     "<TH "TH_BG">Write</TH>"
 
6950
                     "<TH "TH_BG">Other</TH>"
 
6951
                     "<TH "TH_BG">Min</TH>"
 
6952
                     "<TH "TH_BG">Max</TH>"
 
6953
                     "<TH "TH_BG">Min</TH>"
 
6954
                     "<TH "TH_BG">Max</TH>"
 
6955
                     "<TH "TH_BG">Min</TH>"
 
6956
                     "<TH "TH_BG">Max</TH>"
 
6957
                     "<TH "TH_BG"><br></TH>"
 
6958
                     "<TH "TH_BG"><br></TH>"
 
6959
                     "<TH "TH_BG"><br></TH>"
 
6960
                     "</TR>\n",
 
6961
                     getRowColor(), theAnchor[2], arrow[2], theAnchor[3],
 
6962
                     arrow[3]) < 0)
 
6963
            BufferTooShort();
 
6964
 
 
6965
        sendString(buf);
 
6966
 
 
6967
        for(idx=0; idx<numEntries; idx++) {
 
6968
 
 
6969
            if(revertOrder)
 
6970
                entry = &sortedLunTbl[numEntries-idx-1];
 
6971
            else
 
6972
                entry = &sortedLunTbl[idx];
 
6973
 
 
6974
            if((skipEntries++) < pageNum*myGlobals.maxNumLines) {
 
6975
                continue;
 
6976
            }
 
6977
            
 
6978
            dataSent = entry->stats->bytesSent.value;
 
6979
            dataRcvd = entry->stats->bytesRcvd.value;
 
6980
            duration = entry->stats->lastSeen.tv_sec-entry->stats->firstSeen.tv_sec;
 
6981
            
 
6982
            if(entry != NULL) {
 
6983
                if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s>"
 
6984
                            "<TD "TD_BG" ALIGN=RIGHT>%d</TD>"
 
6985
                            "<TD "TD_BG" ALIGN=RIGHT>%s</TD>"
 
6986
                            "<TD "TD_BG" ALIGN=RIGHT>%s</TD>"
 
6987
                            "<TD "TD_BG" ALIGN=RIGHT>%s</TD>"
 
6988
                            "<TD "TD_BG" ALIGN=RIGHT>%s</TD>"
 
6989
                            "<TD "TD_BG" ALIGN=RIGHT>%s</TD>"
 
6990
                            "<TD "TD_BG" ALIGN=RIGHT>%d</TD>"
 
6991
                            "<TD "TD_BG" ALIGN=RIGHT>%d</TD>"
 
6992
                            "<TD "TD_BG" ALIGN=RIGHT>%d</TD>"
 
6993
                            "<TD "TD_BG" ALIGN=RIGHT>%d</TD>"
 
6994
                            "<TD "TD_BG" ALIGN=RIGHT>%d</TD>"
 
6995
                            "<TD "TD_BG" ALIGN=RIGHT>%d</TD>"
 
6996
                            "<TD "TD_BG" ALIGN=RIGHT>%d</TD>"
 
6997
                            "<TD "TD_BG" ALIGN=RIGHT>%d</TD>"
 
6998
                            "<TD "TD_BG" ALIGN=RIGHT>%s</TD>"
 
6999
                            "</TR>\n",
 
7000
                            getRowColor(),
 
7001
                            entry->lun,
 
7002
                            formatBytes (dataSent, 1, formatBuf, sizeof (formatBuf)),
 
7003
                            formatBytes (dataRcvd, 1, formatBuf1, sizeof (formatBuf1)),
 
7004
                            formatBytes (entry->stats->scsiRdBytes.value, 1,
 
7005
                                         formatBuf2, sizeof (formatBuf2)),
 
7006
                            formatBytes (entry->stats->scsiWrBytes.value, 1,
 
7007
                                         formatBuf3, sizeof (formatBuf3)),
 
7008
                            formatBytes (entry->stats->scsiOtBytes.value, 1,
 
7009
                                         formatBuf4, sizeof (formatBuf4)),
 
7010
                            entry->stats->minRdSize,
 
7011
                            entry->stats->maxRdSize,
 
7012
                            entry->stats->minWrSize,
 
7013
                            entry->stats->maxWrSize,
 
7014
                            entry->stats->minXferRdySize,
 
7015
                            entry->stats->maxXferRdySize,
 
7016
                            entry->stats->numFailedCmds,
 
7017
                            duration,
 
7018
                            formatTime((time_t *)&(entry->stats->lastSeen),
 
7019
                                       formatBuf5, sizeof (formatBuf5))
 
7020
                       ) < 0)
 
7021
                    BufferTooShort();
 
7022
                
 
7023
                sendString(buf);
 
7024
 
 
7025
                /* Avoid huge tables */
 
7026
                if(printedEntries++ > myGlobals.maxNumLines)
 
7027
                    break;
 
7028
            }
 
7029
        }
 
7030
 
 
7031
        sendString("</TABLE>"TABLE_OFF"\n");
 
7032
        sendString("</CENTER>\n");
 
7033
 
 
7034
        addPageIndicator(pageUrl, pageNum, numEntries, myGlobals.maxNumLines,
 
7035
                         revertOrder, sortedColumn);
 
7036
 
 
7037
        printFooterHostLink();
 
7038
    } else
 
7039
        printNoDataYet();
 
7040
}
 
7041
 
 
7042
void printScsiLunGraphs (HostTraffic *el, int actualDeviceId)
 
7043
{
 
7044
    char buf[LEN_GENERAL_WORK_BUFFER], buf1[64];
 
7045
 
 
7046
    buf[0] = buf1[0] = '\0';
 
7047
 
 
7048
    if ((el->devType == SCSI_DEV_UNINIT) ||
 
7049
        (el->devType == SCSI_DEV_INITIATOR)) {
 
7050
        printNoDataYet();
 
7051
        return;
 
7052
    }
 
7053
 
 
7054
    printHTMLheader ("LUN Traffic Graphs (Top 25)", 0, 0);
 
7055
    
 
7056
    printSectionTitle("LUN Traffic (Total Bytes)");
 
7057
    
 
7058
    if(snprintf(buf, sizeof(buf),
 
7059
                "<TR "TR_ON" BGCOLOR=white><TH BGCOLOR=white ALIGN=CENTER COLSPAN=3>"
 
7060
                "<IMG SRC=\"" CONST_BAR_LUNSTATS_DIST "-%s" CHART_FORMAT "?1 "
 
7061
                "ALT=\"LUN Traffic (Total Bytes) %s\"></TH></TR>",
 
7062
                el->hostNumFcAddress, el->hostNumFcAddress) < 0)
 
7063
        BufferTooShort();
 
7064
    sendString(buf);
 
7065
    
 
7066
    printSectionTitle("LUN Traffic (Total Frames)");
 
7067
    
 
7068
    if(snprintf(buf, sizeof(buf),
 
7069
                "<TR "TR_ON" BGCOLOR=white><TH BGCOLOR=white ALIGN=CENTER COLSPAN=3>"
 
7070
                "<IMG SRC=drawLunStatsPktsDistribution-%s"CHART_FORMAT"?1 ALT=\"LUN Frames Statistics "
 
7071
                "LUN Traffic (Total Frames) %s\"></TH></TR>",
 
7072
                el->hostNumFcAddress, el->hostNumFcAddress) < 0)
 
7073
        BufferTooShort();
 
7074
    sendString(buf);
 
7075
}
 
7076
 
 
7077
void printVsanDetailedInfo (u_int vsanId, int actualDeviceId)
 
7078
{
 
7079
    char buf[LEN_GENERAL_WORK_BUFFER], buf1[64];
 
7080
    char formatBuf[32], formatBuf1[32];
 
7081
    int i;
 
7082
    char *vendorName;
 
7083
    u_int idx;
 
7084
    FcFabricElementHash *hash, **theHash;
 
7085
    FcDomainList *domListEntry;
 
7086
 
 
7087
    accessAddrResMutex("printAllSessionsHTML");
 
7088
 
 
7089
    buf1[0]=0;
 
7090
 
 
7091
    if (vsanId) {
 
7092
        if(snprintf (buf, sizeof(buf), "Info about VSAN %d\n", vsanId) < 0)
 
7093
            BufferTooShort();
 
7094
    }
 
7095
    else {
 
7096
        if(snprintf (buf, sizeof(buf), "Info about VSAN\n") < 0)
 
7097
            BufferTooShort();
 
7098
    }
 
7099
 
 
7100
    releaseAddrResMutex();
 
7101
 
 
7102
    printHTMLheader(buf, 0, 0);
 
7103
 
 
7104
    if ((theHash = myGlobals.device[actualDeviceId].vsanHash) == NULL) {
 
7105
        printNoDataYet ();
 
7106
        return;
 
7107
    }
 
7108
  
 
7109
    /* Locate the entry belonging to the VSAN */
 
7110
    idx = vsanId % MAX_ELEMENT_HASH;
 
7111
 
 
7112
    if (theHash[idx] == NULL) {
 
7113
        printNoDataYet ();
 
7114
        return;
 
7115
    }
 
7116
 
 
7117
    while (1) {
 
7118
        if (theHash[idx]->vsanId == vsanId)
 
7119
            break;
 
7120
 
 
7121
        idx = (idx+1) % MAX_ELEMENT_HASH;
 
7122
        if(++idx == MAX_ELEMENT_HASH) {
 
7123
            printNoDataYet ();
 
7124
            return;
 
7125
        }
 
7126
    }
 
7127
 
 
7128
    hash = theHash[idx];
 
7129
  
 
7130
    sendString("<CENTER>\n");
 
7131
    sendString("<P>"TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=\"100%\">\n");
 
7132
 
 
7133
    accessAddrResMutex("printAllSessions-2");
 
7134
 
 
7135
    if (hash->principalSwitch.str[0] != '\0') {
 
7136
        if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
7137
                    "%s%s</TD></TR>\n",
 
7138
                    getRowColor(), "Principal&nbsp;Switch",
 
7139
                    fcwwn_to_str (&hash->principalSwitch.str[0]), 
 
7140
                    myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
7141
            BufferTooShort();
 
7142
        sendString(buf);
 
7143
 
 
7144
        vendorName = getVendorInfo(&hash->principalSwitch.str[2], 1);
 
7145
        if(vendorName[0] != '\0') {
 
7146
            if(snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
7147
                        "%s%s</TD></TR>\n",
 
7148
                        getRowColor(), "Principal&nbsp;Switch&nbsp;Vendor",
 
7149
                        vendorName,
 
7150
                        myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
7151
                BufferTooShort();
 
7152
            sendString(buf);
 
7153
        }
 
7154
    }
 
7155
 
 
7156
    if (hash->fabricConfStartTime) {
 
7157
        if (snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
7158
                     "%s%s</TD></TR>\n",
 
7159
                     getRowColor(), "Last&nbsp;Fabric&nbsp;Configuration&nbsp;Started&nbsp;At",
 
7160
                     formatTime(&hash->fabricConfStartTime, formatBuf,
 
7161
                                 sizeof (formatBuf)),
 
7162
                     myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
7163
            BufferTooShort();
 
7164
        sendString(buf);
 
7165
    }
 
7166
 
 
7167
    if (hash->zoneConfStartTime) {
 
7168
        if (snprintf(buf, sizeof(buf), "<TR %s><TH "TH_BG" ALIGN=LEFT "DARK_BG">%s</TH><TD "TD_BG" ALIGN=RIGHT>"
 
7169
                     "%s%s</TD></TR>\n",
 
7170
                     getRowColor(), "Last&nbsp;Zone&nbsp;Configuration&nbsp;Started&nbsp;At",
 
7171
                     formatTime(&hash->zoneConfStartTime, formatBuf,
 
7172
                                 sizeof (formatBuf)),
 
7173
                     myGlobals.separator /* it avoids empty cells not to be rendered */) < 0)
 
7174
            BufferTooShort();
 
7175
        sendString(buf);
 
7176
    }
 
7177
  
 
7178
    sendString("<TR><TH "TH_BG" align=left "DARK_BG">Switches In Fabric</TH>"
 
7179
               "<TD "TD_BG" ALIGN=RIGHT>");
 
7180
    
 
7181
    sendString(""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS" WIDTH=100%%>\n<TR "TR_ON"><TH "TH_BG" "DARK_BG">Domain</TH>"
 
7182
               "<TH "TH_BG" "DARK_BG">WWN</TH><TH "TH_BG" "DARK_BG">Switch Vendor</TH>"
 
7183
               "<TH "TH_BG" "DARK_BG">Bytes Sent</TH><TH "TH_BG" "DARK_BG">Bytes Rcvd</TH></TR>\n");
 
7184
    
 
7185
    i = hash->domainListLen;
 
7186
    domListEntry = hash->domainList;
 
7187
 
 
7188
    if (domListEntry != NULL) {
 
7189
        while ((i > 0) && (domListEntry != NULL)) {
 
7190
            if (domListEntry->recordType == 1 /* TBD: Change 01 to meaningful
 
7191
                                               * define */) {
 
7192
                if (snprintf (buf, sizeof (buf), "<TR "TR_ON" %s><TD "TD_BG" align=right>%x</TD>"
 
7193
                              "<TD "TD_BG" align=right>%s</TD><TD "TD_BG" align=right>%s</TD>"
 
7194
                              "<TD "TD_BG" align=right>%s</TD><TD "TD_BG" align=right>%s</TD>",
 
7195
                              getRowColor(), domListEntry->domainId,
 
7196
                              fcwwn_to_str ((u_int8_t *)&domListEntry->switchWWN.str),
 
7197
                              getVendorInfo (&domListEntry->switchWWN.str[2], 1),
 
7198
                              formatBytes (hash->domainStats[domListEntry->domainId].sentBytes.value, 1,
 
7199
                                           formatBuf, sizeof (formatBuf)),
 
7200
                              formatBytes (hash->domainStats[domListEntry->domainId].rcvdBytes.value, 1,
 
7201
                                           formatBuf1, sizeof (formatBuf1))
 
7202
                        ) < 0)
 
7203
                    BufferTooShort();
 
7204
                sendString (buf);
 
7205
            }
 
7206
            
 
7207
            i -= 16;
 
7208
            domListEntry = (FcDomainList *)((char *)domListEntry + 16);
 
7209
        }
 
7210
    }
 
7211
    else {
 
7212
        /* Print just the stats, without more switch information */
 
7213
        for (i = 1; i < MAX_FC_DOMAINS; i++) {
 
7214
            if ((hash->domainStats[i].sentBytes.value != 0) ||
 
7215
                (hash->domainStats[i].rcvdBytes.value != 0)) {
 
7216
                if (snprintf (buf, sizeof (buf), "<TR "TR_ON" %s><TD "TD_BG" align=right>%x</td>"
 
7217
                              "<TD "TD_BG" align=right>%s</TD><TD "TD_BG" align=right>%s</TD>"
 
7218
                              "<TD "TD_BG" align=right>%s</TD><TD "TD_BG" align=right>%s</TD>",
 
7219
                              getRowColor(), i, "N/A", "N/A",
 
7220
                              formatBytes (hash->domainStats[i].sentBytes.value, 1,
 
7221
                                           formatBuf, sizeof (formatBuf)),
 
7222
                              formatBytes (hash->domainStats[i].rcvdBytes.value, 1,
 
7223
                                           formatBuf1, sizeof (formatBuf1))
 
7224
                        ) < 0)
 
7225
                    BufferTooShort();
 
7226
                sendString (buf);
 
7227
                
 
7228
            }
 
7229
        }
 
7230
    }
 
7231
    
 
7232
    sendString("</TD></TR>\n");
 
7233
    sendString("</TABLE>"TABLE_OFF"<P>\n");
 
7234
    sendString("</TABLE>"TABLE_OFF"<P>\n");
 
7235
 
 
7236
                
 
7237
    /* **************************** */
 
7238
    printSectionTitle("Top Domain Traffic Distribution (Sent)");
 
7239
    if(snprintf(buf, sizeof(buf),
 
7240
                "<TR "TR_ON" BGCOLOR=white><TH BGCOLOR=white ALIGN=CENTER COLSPAN=3>"
 
7241
                "<IMG SRC=" CONST_BAR_VSAN_TRAF_DIST_SENT "-%d"CHART_FORMAT"?1 "
 
7242
                "ALT=\"VSAN Domain Traffic Distribution for VSAN %d\"></TH></TR>",
 
7243
                vsanId, vsanId) < 0)
 
7244
        BufferTooShort();
 
7245
    sendString(buf);
 
7246
 
 
7247
    printSectionTitle("Top Domain Traffic Distribution (Received)");
 
7248
    if(snprintf(buf, sizeof(buf),
 
7249
                "<TR "TR_ON" BGCOLOR=white><TH BGCOLOR=white ALIGN=CENTER COLSPAN=3>"
 
7250
                "<IMG SRC=" CONST_BAR_VSAN_TRAF_DIST_RCVD "-%d"CHART_FORMAT"?1 "
 
7251
                "ALT=\"VSAN Domain Traffic Distribution for VSAN %d\"></TH></TR>",
 
7252
                vsanId, vsanId) < 0)
 
7253
        BufferTooShort();
 
7254
    sendString(buf);
 
7255
 
 
7256
    printVsanProtocolStats (hash, actualDeviceId);
 
7257
 
 
7258
#ifdef NOT_YET
 
7259
    printFcTrafficMatrix (vsanId, TRUE);
 
7260
 
 
7261
    printSectionTitle("Control Traffic Distribution");
 
7262
    if(snprintf(buf, sizeof(buf),
 
7263
                "<TR "TR_ON" BGCOLOR=white><TH BGCOLOR=white ALIGN=CENTER COLSPAN=3>"
 
7264
                "<IMG SRC=" CONST_PIE_VSAN_CNTL_TRAF_DIST "-%d"CHART_FORMAT"?1 ALT=\"VSAN Control "
 
7265
                "Traffic Protocol Distribution for VSAN %d\"></TH></TR>",
 
7266
                vsanId, vsanId) < 0)
 
7267
        BufferTooShort();
 
7268
    sendString(buf);
 
7269
#endif
 
7270
  
 
7271
    sendString("</CENTER>\n");
 
7272
}
 
7273
 
 
7274
/* ************************************ */
 
7275
 
 
7276
static char* formatFcElementData (FcFabricElementHash *hash, u_char printBytes, char *buf, int bufLen)
 
7277
{
 
7278
    char formatBuf[32];
 
7279
    
 
7280
    if ((printBytes && (hash->totBytes.value == 0)) ||
 
7281
        (!printBytes && (hash->totPkts.value == 0)))
 
7282
        return("&nbsp;");
 
7283
 
 
7284
    if (printBytes) {
 
7285
        if(snprintf(buf, bufLen, "%s",
 
7286
                    formatBytes(hash->totBytes.value, 1, formatBuf,
 
7287
                                sizeof (formatBuf))) < 0)
 
7288
            BufferTooShort();
 
7289
    }
 
7290
    else {
 
7291
        if(snprintf(buf, bufLen, "%s",
 
7292
                    formatPkts(hash->totPkts.value, formatBuf,
 
7293
                               sizeof (formatBuf))) < 0)
 
7294
            BufferTooShort();
 
7295
    }
 
7296
 
 
7297
    return(buf);
 
7298
}
 
7299
 
 
7300
/* ******************************** */
 
7301
 
 
7302
void dumpFcFabricElementHash (FcFabricElementHash **theHash, char* label,
 
7303
                              u_char dumpLoopbackTraffic, u_char vsanHash) {
 
7304
    u_char entries[MAX_HASHDUMP_ENTRY];
 
7305
    char buf[LEN_GENERAL_WORK_BUFFER], buf1[96], buf3[96],
 
7306
         hostLinkBuf[LEN_GENERAL_WORK_BUFFER], formatBuf[32], vsanBuf[32];
 
7307
    int i;
 
7308
    HostTraffic *el;
 
7309
 
 
7310
    if(theHash == NULL) return;
 
7311
 
 
7312
    /* *********** */
 
7313
 
 
7314
#ifdef FC_DEBUG
 
7315
    for(i=0; i<MAX_ELEMENT_HASH; i++)
 
7316
        if(theHash[i] != NULL) {
 
7317
            printf("[%d] ", theHash[i]->vsanId);
 
7318
            hash = theHash[i]->next;
 
7319
 
 
7320
            while(hash != NULL) {
 
7321
                printf("%d ", hash->vsanId);
 
7322
                hash = hash->next;
 
7323
            }
 
7324
 
 
7325
            printf("\n");
 
7326
        }
 
7327
#endif
 
7328
 
 
7329
    /* *********** */
 
7330
 
 
7331
    memset(entries, 0, sizeof(entries));
 
7332
 
 
7333
    for (i=0; i<MAX_ELEMENT_HASH; i++) {
 
7334
        if((theHash[i] != NULL) && (theHash[i]->vsanId < MAX_HASHDUMP_ENTRY) &&
 
7335
           (theHash[i]->vsanId < MAX_USER_VSAN)) {
 
7336
            if (theHash[i]->totPkts.value)
 
7337
                entries[theHash[i]->vsanId] = 1;
 
7338
        }
 
7339
    }
 
7340
 
 
7341
    sendString("<CENTER><TABLE BORDER=1 "TABLE_DEFAULTS">\n<TR><TH "DARK_BG">");
 
7342
    sendString(label);
 
7343
 
 
7344
    sendString("</TH>\n<TH "DARK_BG">Principal Switch");
 
7345
    sendString("</TH>\n<TH "DARK_BG">Total Traffic (Bytes)</TH>\n"
 
7346
               "<TH "DARK_BG">Total Traffic (Frames)</TH>\n");
 
7347
    sendString("<TH "DARK_BG">Last Fabric Conf Time</TH>\n");
 
7348
    if(vsanHash) sendString("<TH "DARK_BG">Nx_Ports</TH>\n");
 
7349
    sendString("</TR>\n");
 
7350
 
 
7351
    /* ****************** */
 
7352
 
 
7353
    for(i=0; i<MAX_HASHDUMP_ENTRY; i++) {
 
7354
        if(entries[i] == 1) {
 
7355
            if(snprintf(buf, sizeof(buf), "<TR><TH "TH_BG" ALIGN=LEFT NOWRAP>%s\">%d</a></TH>\n"
 
7356
                        "<TD>%s</TD>\n<TD>%s</TD>\n<TD>%s</TD>\n<TD>%s</TD>\n",
 
7357
                        makeVsanLink (i, FLAG_HOSTLINK_TEXT_FORMAT, vsanBuf, sizeof (vsanBuf)), i,
 
7358
                        fcwwn_to_str ((u_int8_t *)&theHash[i]->principalSwitch.str),
 
7359
                        formatFcElementData(theHash[i], 1, buf1, sizeof(buf1)),
 
7360
                        formatFcElementData(theHash[i], 0, buf3, sizeof(buf3)),
 
7361
                        formatTime(&theHash[i]->fabricConfStartTime,
 
7362
                                    formatBuf, sizeof (formatBuf))) < 0)
 
7363
                BufferTooShort();
 
7364
            sendString(buf);
 
7365
 
 
7366
 
 
7367
            sendString("<TD>&nbsp;");
 
7368
            if(vsanHash) {
 
7369
                int iEntryCount=0;
 
7370
        
 
7371
                for(el = getFirstHost(myGlobals.actualReportDeviceId);
 
7372
                    el != NULL; el = getNextHost (myGlobals.actualReportDeviceId, el)) {
 
7373
                    if ((el->vsanId == i) && isValidFcNxPort (&el->hostFcAddress) &&
 
7374
                        (el->fcBytesSent.value || el->fcBytesRcvd.value)) {
 
7375
                        if(++iEntryCount == 1) sendString("<ul>");
 
7376
                        sendString("<li>");
 
7377
                        sendString (makeFcHostLink (el,
 
7378
                                                    FLAG_HOSTLINK_TEXT_FORMAT,
 
7379
                                                    0, 0, hostLinkBuf,
 
7380
                                                    sizeof(hostLinkBuf)));
 
7381
                        sendString("</li>\n");
 
7382
                    }
 
7383
                }
 
7384
                if(iEntryCount > 0) sendString("</ul>\n");
 
7385
            }
 
7386
 
 
7387
            sendString("</TD>\n</TR>\n");
 
7388
        }
 
7389
    }
 
7390
 
 
7391
    sendString("</TR>\n</TABLE>\n</CENTER>\n");
 
7392
}
 
7393
 
 
7394
/* ************************************ */
 
7395
 
 
7396
void printFcDisplayOptions (void)
 
7397
{
 
7398
  sendHTTPHeader(FLAG_HTTP_TYPE_HTML, 0, 1);
 
7399
  printHTMLheader("FC Host Display Options ", 0, 0);
 
7400
}
 
7401
 
 
7402
/* ******************************************************** */
 
7403
 
 
7404
void printVsanProtocolStats (FcFabricElementHash *hash, int actualDeviceId)
 
7405
{
 
7406
    Counter total;
 
7407
    char buf[LEN_GENERAL_WORK_BUFFER];
 
7408
 
 
7409
    if (hash == NULL) {
 
7410
        return;
 
7411
    }
 
7412
    
 
7413
    if ((total = hash->totBytes.value) == 0) {
 
7414
        return;
 
7415
    }
 
7416
  
 
7417
    printSectionTitle("VSAN Protocol Distribution");
 
7418
 
 
7419
    sendString("<CENTER>\n"
 
7420
               ""TABLE_ON"<TABLE BORDER=1 "TABLE_DEFAULTS"><TR><TH "TH_BG" WIDTH=100 "DARK_BG">Protocol</TH>"
 
7421
               "<TH "TH_BG" WIDTH=200 COLSPAN=3 "DARK_BG">Total&nbsp;Bytes</TH></TR>\n");
 
7422
 
 
7423
    if (hash->fcFcpBytes.value) {
 
7424
        printTableEntry (buf, sizeof(buf), "SCSI", CONST_COLOR_1,
 
7425
                         (float)hash->fcFcpBytes.value/1024,
 
7426
                         100*((float)SD(hash->fcFcpBytes.value, total)));
 
7427
    }
 
7428
 
 
7429
    if (hash->fcElsBytes.value) {
 
7430
        printTableEntry (buf, sizeof(buf), "ELS", CONST_COLOR_1,
 
7431
                         (float)hash->fcElsBytes.value/1024,
 
7432
                         100*((float)SD(hash->fcElsBytes.value, total)));
 
7433
    }
 
7434
 
 
7435
    if (hash->fcDnsBytes.value) {
 
7436
        printTableEntry (buf, sizeof (buf), "NS", CONST_COLOR_1,
 
7437
                         (float)hash->fcDnsBytes.value/1024,
 
7438
                         100*((float)SD(hash->fcDnsBytes.value, total)));
 
7439
    }
 
7440
 
 
7441
    if (hash->fcIpfcBytes.value) {
 
7442
        printTableEntry (buf, sizeof (buf), "IP/FC", CONST_COLOR_1,
 
7443
                         (float)hash->fcIpfcBytes.value/1024,
 
7444
                         100*((float)SD(hash->fcIpfcBytes.value, total)));
 
7445
    }
 
7446
 
 
7447
    if (hash->fcSwilsBytes.value) {
 
7448
        printTableEntry (buf, sizeof (buf), "SWILS", CONST_COLOR_1,
 
7449
                         (float)hash->fcSwilsBytes.value/1024,
 
7450
                         100*((float)SD(hash->fcSwilsBytes.value, total)));
 
7451
    }
 
7452
 
 
7453
    if (hash->otherFcBytes.value) {
 
7454
        printTableEntry (buf, sizeof (buf), "Others", CONST_COLOR_1,
 
7455
                         (float)hash->otherFcBytes.value/1024,
 
7456
                         100*((float)SD(hash->otherFcBytes.value, total)));
 
7457
    }
 
7458
 
 
7459
    sendString("</TABLE>"TABLE_OFF"<P>\n");
 
7460
    sendString("</CENTER>\n");
 
7461
}
 
7462
 
 
7463
/* ************************************ */
 
7464
 
 
7465
void printPluginTrailer(char *left, char *middle) {
 
7466
  sendString("<br>\n<hr>\n<br>\n<table border=\"0\" width=\"100%\"><tr>");
 
7467
 
 
7468
  if(left != NULL) {
 
7469
    sendString("<td width=\"20%\">[ <a href=\"../" CONST_PLUGINS_HEADER);
 
7470
    sendString(left);
 
7471
    sendString("\">Refresh this data</a> ]");
 
7472
    sendString("&nbsp;</td>\n");  /* So there's at least something in to cell */
 
7473
  }
 
7474
 
 
7475
  sendString("<td align=\"left\">");
 
7476
 
 
7477
  sendString("&nbsp;");
 
7478
  if(middle != NULL) 
 
7479
    sendString(middle);
 
7480
  sendString("&nbsp;");
 
7481
 
 
7482
  sendString("</td>\n<td align=\"right\">"
 
7483
             "&nbsp;[ Back to <a href=\"../" CONST_SHOW_PLUGINS_HTML "\">plugins</a> ]"
 
7484
             "</td></tr></table>\n<br>\n");
 
7485
}
 
7486
 
 
7487
/* ************************************ */