/* * Copyright (C) 1998-2007 Luca Deri * * http://www.ntop.org/ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "ntop.h" #include "globals-report.h" #define NETWORK_VIEW 1 #define AS_VIEW 2 #define AS_GRAPH_VIEW 3 static int network_mode_sort; /* *************************** */ #ifndef WIN32 static void ignoreSignal(int signalId) { closeNwSocket(&myGlobals.newSock); (void)signal(signalId, ignoreSignal); } #endif /* ******************************* */ void printBandwidthFooter(void) { sendString("

NOTE:

\n

"); } /* ******************************* */ void checkReportDevice(void) { int i; char value[LEN_SMALL_WORK_BUFFER]; /* Show device table */ for(i=0; i= myGlobals.numDevices) { traceEvent(CONST_TRACE_WARNING, "INITWEB: Reporting device (%d) invalid (> max, %d), defaulting to 0", atoi(value), myGlobals.numDevices); storePrefsValue("actualReportDeviceId", "0"); } /* Retrieve it */ if(fetchPrefsValue("actualReportDeviceId", value, sizeof(value)) == -1) { myGlobals.actualReportDeviceId = 0; } else { myGlobals.actualReportDeviceId = atoi(value); } if(myGlobals.device[myGlobals.actualReportDeviceId].virtualDevice) { /* Bad idea, set to 1st non-virtual device */ traceEvent(CONST_TRACE_WARNING, "INITWEB: Reporting device (%d) invalid (virtual), using 1st non-virtual device", i); for(i=0; i= 1) { safe_snprintf(__FILE__, __LINE__, prevBuf, sizeof(prevBuf), "\"Back " "\"Prior", url, separator, netmode, shortBuf, url, separator, pageNum-1, netmode, shortBuf); } else prevBuf[0] = '\0'; if(actPage < numPages) { safe_snprintf(__FILE__, __LINE__, nextBuf, sizeof(nextBuf), "\"Next " "\"Forward", url, separator, pageNum+1, netmode, shortBuf, url, separator, numPages-1, netmode, shortBuf); } else nextBuf[0] = '\0'; sendString("

"); sendString(prevBuf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), " [ %d / %d ] ", actPage, numPages); sendString(buf); sendString(nextBuf); sendString("\n"); } /* ******************************* */ void printTrafficSummary (int revertOrder) { Counter unicastPkts; int i; char buf[LEN_GENERAL_WORK_BUFFER], formatBuf[32], formatBuf1[32]; struct pcap_stat pcapStat; unicastPkts = 0; printHTMLheader("Global Traffic Summary", NULL, 0); sendString("

"TABLE_ON"\n"); sendString("" "\n"); if(myGlobals.runningPref.domainName[0] != '\0') { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", myGlobals.runningPref.domainName); sendString(buf); } if(myGlobals.runningPref.rFileName == NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", ctime(&myGlobals.initialSniffTime), formatSeconds(time(NULL)-myGlobals.initialSniffTime, formatBuf, sizeof(formatBuf))); sendString(buf); } else { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", ctime(&myGlobals.initialSniffTime)); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", ctime((time_t *)&myGlobals.lastPktTime), formatSeconds(myGlobals.lastPktTime.tv_sec-myGlobals.initialSniffTime, formatBuf, sizeof(formatBuf))); sendString(buf); } if((i = numActiveSenders(myGlobals.actualReportDeviceId)) > 0) { /* Do NOT add a '/' at the end of the path because Win32 will complain about it */ struct stat statbuf; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s/interfaces/%s", myGlobals.rrdPath != NULL ? myGlobals.rrdPath : ".", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName); revertSlashIfWIN32(buf, 0); if(stat(buf, &statbuf) != 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", i); } else safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", i, myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, (unsigned int)(myGlobals.actTime-3600), (unsigned int)myGlobals.actTime, "Active+End+Nodes"); sendString(buf); } if((myGlobals.runningPref.currentFilterExpression != NULL) && (myGlobals.runningPref.currentFilterExpression[0] != '\0')) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", myGlobals.runningPref.currentFilterExpression); sendString(buf); } #ifndef EMBEDDED if(myGlobals.numDevices > 1) { int found = 0; for(i=0; i 0) { found = 1; break; } if(found) { sendString("\n"); } } #endif if(myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value > 0) { unicastPkts = myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value - myGlobals.device[myGlobals.actualReportDeviceId].broadcastPkts.value - myGlobals.device[myGlobals.actualReportDeviceId].multicastPkts.value; if(myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value <= 0) myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value = 1; if(myGlobals.device[myGlobals.actualReportDeviceId].pcapPtr != NULL) { if(pcap_stats(myGlobals.device[myGlobals.actualReportDeviceId].pcapPtr, &pcapStat) >= 0) { Counter realDropped; /* Recent libpcap versions do not report total/cumulative values but their value is reset everytime is read */ if(myGlobals.device[myGlobals.actualReportDeviceId].receivedPkts.value > pcapStat.ps_recv) { /* The counter is reset at each run */ realDropped = (myGlobals.device[myGlobals.actualReportDeviceId].pcapDroppedPkts.value += pcapStat.ps_drop); } else { /* The counter is NOT reset at each run */ myGlobals.device[myGlobals.actualReportDeviceId].pcapDroppedPkts.value = pcapStat.ps_drop; realDropped = myGlobals.device[myGlobals.actualReportDeviceId].pcapDroppedPkts.value - myGlobals.device[myGlobals.actualReportDeviceId].initialPcapDroppedPkts.value; } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(realDropped, formatBuf, sizeof(formatBuf)), (float)(realDropped*100) /(float)myGlobals.device[myGlobals.actualReportDeviceId].receivedPkts.value); sendString(buf); } } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].droppedPkts.value, formatBuf, sizeof(formatBuf)), (float)(myGlobals.device[myGlobals.actualReportDeviceId].droppedPkts.value*100) /(float)myGlobals.device[myGlobals.actualReportDeviceId].receivedPkts.value); sendString(buf); if(!myGlobals.runningPref.printFcOnly) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(unicastPkts, formatBuf, sizeof(formatBuf)), (float)(100*unicastPkts)/(float)myGlobals.device[myGlobals.actualReportDeviceId]. ethernetPkts.value); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].broadcastPkts.value, formatBuf, sizeof(formatBuf)), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId].broadcastPkts.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].multicastPkts.value, formatBuf, sizeof(formatBuf)), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId].multicastPkts.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), myGlobals.mtuSize[myGlobals.device[myGlobals.actualReportDeviceId].datalink], formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.tooLong.value, formatBuf, sizeof(formatBuf)), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.tooLong.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.badChecksum.value, formatBuf, sizeof(formatBuf)), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktStats.badChecksum.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value); sendString(buf); } /* ****************** */ if(!myGlobals.runningPref.printIpOnly && myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value > 0) { if(myGlobals.device[myGlobals.actualReportDeviceId].pcapPtr != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatBytes(myGlobals.device[myGlobals.actualReportDeviceId].fcBytes.value, 1, formatBuf, sizeof(formatBuf)), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value, formatBuf1, sizeof(formatBuf1))); sendString(buf); #ifdef NOT_YET if(myGlobals.device[myGlobals.actualReportDeviceId].droppedPkts.value > 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].droppedPkts.value, formatBuf, sizeof(formatBuf)), (float)(myGlobals.device[myGlobals.actualReportDeviceId].droppedPkts.value*100) /(float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value); sendString(buf); } #endif } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(unicastPkts, formatBuf, sizeof(formatBuf)), (float)(100*unicastPkts)/(float)myGlobals.device[myGlobals.actualReportDeviceId]. fcPkts.value); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].fcBroadcastPkts.value, formatBuf, sizeof(formatBuf)), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId].fcBroadcastPkts.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value); sendString(buf); } /* ****************** */ if(!myGlobals.device[myGlobals.actualReportDeviceId].dummyDevice) { updateThpt(0); sendString("\n"); } } /* ********************* */ sendString("
Network Interface(s)"); sendString(""TABLE_ON"\n" "" "" ""); #ifdef INET6 sendString("\n"); #endif for(i=0; i", myGlobals.device[i].humanFriendlyName[0] != '\0' ? myGlobals.device[i].humanFriendlyName : " "); else safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", myGlobals.device[i].uniqueIfName[0] != '\0' ? myGlobals.device[i].uniqueIfName : " ", myGlobals.device[i].name); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", myGlobals.device[i].name); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", getNwInterfaceType(i), myGlobals.device[i].virtualDevice ? " virtual" : ""); sendString(buf); sendString(""); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", myGlobals.device[i].samplingRate); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", myGlobals.mtuSize[myGlobals.device[i].datalink]); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", myGlobals.headerSize[myGlobals.device[i].datalink]); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", _intoa(myGlobals.device[i].ifAddr, buf1, sizeof(buf1))); sendString(buf); #ifdef INET6 sendString(""); #endif sendString("\n"); } } sendString("
NameDeviceTypeSpeedSampling RateMTUHeaderAddressIPv6 Addresses
" "%s
" "%s " "\"Change%s%s%s "); if(myGlobals.device[i].deviceSpeed > 0) { /* The speed is known */ sendString(formatAdapterSpeed(myGlobals.device[i].deviceSpeed, formatBuf, sizeof(formatBuf))); } else sendString(" "); sendString("%d%d%d%s"); if(myGlobals.device[i].v6Addrs > 0) { for(ifaddr = myGlobals.device[i].v6Addrs; ifaddr != NULL; ifaddr = ifaddr->next) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s/%d
", _intop(&ifaddr->af.inet6.ifAddr, buf1, sizeof(buf1)), ifaddr->af.inet6.prefixlen); sendString(buf); } } else sendString(" "); sendString("
"TABLE_OFF); sendString("
Local Domain Name%s 
Sampling Since%s [%s]
Sampling Since%s
Last Packet Seen%s [%s]
Active End Nodes%u
Active End Nodes" "%u " "" "
Traffic Filter%s
" "
Dropped (libpcap)%s(%.1f%%)
Dropped (ntop)%s(%.1f%%)
Unicast%s(%.1f%%)
Broadcast%s(%.1f%%)
Multicast%s(%.1f%%)
Packets too long [> %d]%s(%.1f%%)
Bad Packets (Checksum)%s(%.1f%%)
Total%s [%s Pkts]
Dropped by the kernel%s [%.2f %%]
Unicast%s(%.1f%%)
Broadcast%s(%.1f%%)
Network Load\n"); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId].actualThpt, 1, formatBuf, sizeof(formatBuf)), myGlobals.device[myGlobals.actualReportDeviceId].actualPktsThpt); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "\n", getRowColor(), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId].lastMinThpt, 1, formatBuf, sizeof(formatBuf)), myGlobals.device[myGlobals.actualReportDeviceId].lastMinPktsThpt); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "\n", getRowColor(), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId].lastFiveMinsThpt, 1, formatBuf, sizeof(formatBuf)), myGlobals.device[myGlobals.actualReportDeviceId].lastFiveMinsPktsThpt); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "\n", getRowColor(), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId].peakThroughput, 1, formatBuf, sizeof(formatBuf)), myGlobals.device[myGlobals.actualReportDeviceId].peakPacketThroughput); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "\n", getRowColor(), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value/ (myGlobals.actTime-myGlobals.initialSniffTime+1), 1, formatBuf, sizeof(formatBuf)), /* Bug below fixed courtesy of Eddy Lai */ ((float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value/ (float)(myGlobals.actTime-myGlobals.initialSniffTime+1))); sendString(buf); sendString("
Actual%s%.1f Pkt/s
Last Minute%s%.1f Pkt/s
Last 5 Minutes%s%.1f Pkt/s
Peak%s%.1f Pkt/s
Average%s%.1f Pkt/s
"TABLE_OFF"
\n"); if(!myGlobals.runningPref.printFcOnly) { printProtoTraffic(FALSE); sendString("

\n"); printIpProtocolDistribution(FLAG_HOSTLINK_HTML_FORMAT, revertOrder, FALSE); } if(!myGlobals.runningPref.printIpOnly) { sendString("

\n"); printFcTrafficSummary(0); } } /* ******************************* */ void printTrafficStatistics(int revertOrder) { Counter unicastPkts, avgPktLen; int i; char buf[LEN_GENERAL_WORK_BUFFER], formatBuf[32], formatBuf1[32]; struct stat statbuf; struct pcap_stat pcapStat; unicastPkts = 0; printHTMLheader("Global Traffic Statistics", NULL, 0); sendString("

"TABLE_ON"\n"); sendString("" "\n"); if(myGlobals.runningPref.domainName[0] != '\0') { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", myGlobals.runningPref.domainName); sendString(buf); } if(myGlobals.runningPref.rFileName == NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", ctime(&myGlobals.initialSniffTime), formatSeconds(time(NULL)-myGlobals.initialSniffTime, formatBuf, sizeof(formatBuf))); sendString(buf); } else { time_t t = myGlobals.lastPktTime.tv_sec; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", ctime(&myGlobals.initialSniffTime)); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", ctime(&t), formatSeconds(myGlobals.lastPktTime.tv_sec-myGlobals.initialSniffTime, formatBuf, sizeof(formatBuf))); sendString(buf); } if((i = numActiveSenders(myGlobals.actualReportDeviceId)) > 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s/interfaces/%s", myGlobals.rrdPath != NULL ? myGlobals.rrdPath : ".", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName); revertSlashIfWIN32(buf, 0); if(stat(buf, &statbuf) != 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", i); } else safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", i, myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, (unsigned int)(myGlobals.actTime-3600), (unsigned int)myGlobals.actTime, "Active+End+Nodes"); sendString(buf); } if((myGlobals.runningPref.currentFilterExpression != NULL) && (myGlobals.runningPref.currentFilterExpression[0] != '\0')) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", myGlobals.runningPref.currentFilterExpression); sendString(buf); } #ifndef EMBEDDED if(myGlobals.numDevices > 1) { int found = 0; for(i=0; i 0) { found = 1; break; } if(found) { sendString("\n"); } } #endif if(myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value > 0) { Counter dummyCounter; sendString("
Network Interface(s)"); sendString(""TABLE_ON"\n" "" "" ""); #ifdef INET6 sendString("\n"); #endif for(i=0; i", myGlobals.device[i].humanFriendlyName[0] != '\0' ? myGlobals.device[i].humanFriendlyName : " "); else safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", myGlobals.device[i].uniqueIfName[0] != '\0' ? myGlobals.device[i].uniqueIfName : " ", myGlobals.device[i].name); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", myGlobals.device[i].name); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", getNwInterfaceType(i), myGlobals.device[i].virtualDevice ? " virtual" : ""); sendString(buf); sendString(""); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", myGlobals.device[i].samplingRate); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", myGlobals.mtuSize[myGlobals.device[i].datalink]); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", myGlobals.headerSize[myGlobals.device[i].datalink]); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", _intoa(myGlobals.device[i].ifAddr, buf1, sizeof(buf1))); sendString(buf); #ifdef INET6 sendString(""); #endif sendString("\n"); } } sendString("
NameDeviceTypeSpeedSampling RateMTUHeaderAddressIPv6 Addresses
" "%s
" "%s " "\"Change%s%s%s "); if(myGlobals.device[i].deviceSpeed > 0) { /* The speed is known */ sendString(formatAdapterSpeed(myGlobals.device[i].deviceSpeed, formatBuf, sizeof(formatBuf))); } else sendString(" "); sendString("%d%d%d%s"); if(myGlobals.device[i].v6Addrs > 0) { for(ifaddr = myGlobals.device[i].v6Addrs; ifaddr != NULL; ifaddr = ifaddr->next) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s/%d
", _intop(&ifaddr->af.inet6.ifAddr, buf1, sizeof(buf1)), ifaddr->af.inet6.prefixlen); sendString(buf); } } else sendString(" "); sendString("
"TABLE_OFF); sendString("
Local Domain Name%s 
Sampling Since%s [%s]
Sampling Since%s
Last Packet Seen%s [%s]
Active End Nodes%u
Active End Nodes" "%u " "" "
Traffic Filter%s
" "
"TABLE_OFF"
\n"); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Traffic Report for '%s' [switch]", myGlobals.device[myGlobals.actualReportDeviceId].humanFriendlyName); printSectionTitle(buf); sendString("
"TABLE_ON"\n"); sendString(""); /* ************************ */ #ifndef EMBEDDED if(myGlobals.runningPref.enableSessionHandling && drawHostsDistanceGraph(1)) sendString("" "\n"); #endif if(!myGlobals.device[myGlobals.actualReportDeviceId].dummyDevice) { updateThpt(0); sendString("\n"); } } /* ********************* */ #ifndef EMBEDDED if(strcmp(myGlobals.device[0].name, "pcap-file")) { /* RRD */ /* Do NOT add a '/' at the end of the path because Win32 will complain about it */ safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s/interfaces/%s", myGlobals.rrdPath != NULL ? myGlobals.rrdPath : ".", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName); revertSlashIfWIN32(buf, 0); if((i = stat(buf, &statbuf)) == 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n" "\n", getRowColor(), myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName); sendString(buf); } } #endif /* ********************* */ sendString("
Packets\n" "\n"); unicastPkts = myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value - myGlobals.device[myGlobals.actualReportDeviceId].broadcastPkts.value - myGlobals.device[myGlobals.actualReportDeviceId].multicastPkts.value; if(myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value <= 0) myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value = 1; if(myGlobals.device[myGlobals.actualReportDeviceId].pcapPtr != NULL) { if(pcap_stats(myGlobals.device[myGlobals.actualReportDeviceId].pcapPtr, &pcapStat) >= 0) { /* Recent libpcap versions do not report total/cumulative values but their value is reset everytime is read */ if(myGlobals.device[myGlobals.actualReportDeviceId].receivedPkts.value > pcapStat.ps_recv) { /* The counter is reset at each run */ myGlobals.device[myGlobals.actualReportDeviceId].pcapDroppedPkts.value += pcapStat.ps_drop; } else { /* The counter is NOT reset at each run */ myGlobals.device[myGlobals.actualReportDeviceId].pcapDroppedPkts.value = pcapStat.ps_drop; } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(myGlobals.device[myGlobals.actualReportDeviceId].pcapDroppedPkts.value*100) /(float)myGlobals.device[myGlobals.actualReportDeviceId].receivedPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].pcapDroppedPkts.value, formatBuf, sizeof(formatBuf))); sendString(buf); } } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(myGlobals.device[myGlobals.actualReportDeviceId].droppedPkts.value*100) /(float)myGlobals.device[myGlobals.actualReportDeviceId].receivedPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].droppedPkts.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].receivedPkts.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*unicastPkts)/(float)myGlobals.device[myGlobals.actualReportDeviceId]. ethernetPkts.value, formatPkts(unicastPkts, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId].broadcastPkts.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].broadcastPkts.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId].multicastPkts.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].multicastPkts.value, formatBuf, sizeof(formatBuf))); sendString(buf); #ifndef EMBEDDED if(myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value > 0) sendString("\n"); #endif if(!myGlobals.device[myGlobals.actualReportDeviceId].dummyDevice) { /* Very rudimental formula. Note that as specified in RMON, packets smaller than 64 or larger than 1518 octets are not counted. */ safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.shortest.value, formatBuf, sizeof(formatBuf))); sendString(buf); avgPktLen = (96*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.upTo128.value +192*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.upTo256.value +384*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.upTo512.value +768*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.upTo1024.value +1271*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.upTo1518.value)/ (myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value+1); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(avgPktLen, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktStats.longest.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktStats.upTo64.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.upTo64.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktStats.upTo128.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.upTo128.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktStats.upTo256.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.upTo256.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktStats.upTo512.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.upTo512.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktStats.upTo1024.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.upTo1024.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktStats.upTo1518.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.upTo1518.value, formatBuf, sizeof(formatBuf))); sendString(buf); #ifdef MAKE_WITH_JUMBO_FRAMES safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktStats.upTo2500.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.upTo2500.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktStats.upTo6500.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.upTo6500.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktStats.upTo9000.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.upTo9000.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktStats.above9000.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.above9000.value, formatBuf, sizeof(formatBuf))); sendString(buf); #else safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktStats.above1518.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.above1518.value, formatBuf, sizeof(formatBuf))); sendString(buf); #endif /* MAKE_WITH_JUMBO_FRAMES */ #ifndef EMBEDDED if(myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value > 0) sendString("\n"); #endif safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), myGlobals.mtuSize[myGlobals.device[myGlobals.actualReportDeviceId].datalink], (float)(100*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.tooLong.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.tooLong.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktStats.badChecksum.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktStats.badChecksum.value, formatBuf, sizeof(formatBuf))); sendString(buf); } /* ****************** */ if(!myGlobals.runningPref.printIpOnly && myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value > 0) { sendString("
Dropped (libpcap)%.1f%%%s
Dropped (ntop)%.1f%%%s
Total Received (ntop)%s
Total Packets Processed%s
Unicast%.1f%%%s
Broadcast%.1f%%%s
Multicast%.1f%%%s
" "
Shortest%s bytes
Average Size%s bytes
Longest%s bytes
Size <= 64 bytes%.1f%%%s
64 < Size <= 128 bytes%.1f%%%s
128 < Size <= 256 bytes%.1f%%%s
256 < Size <= 512 bytes%.1f%%%s
512 < Size <= 1024 bytes%.1f%%%s
1024 < Size <= 1518 bytes%.1f%%%s
1518 < Size <= 2500 bytes%.1f%%%s
2500 < Size <= 6500 bytes%.1f%%%s
6500 < Size <= 9000 bytes%.1f%%%s
> 9000 bytes%.1f%%%s
Size > 1518 bytes%.1f%%%s
" "
Packets too long [> %d]%.1f%%%s
Bad Packets (Checksum)%.1f%%%s
"TABLE_OFF"
FC Packets\n"); if(myGlobals.device[myGlobals.actualReportDeviceId].pcapPtr != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatBytes(myGlobals.device[myGlobals.actualReportDeviceId].fcBytes.value, 1, formatBuf, sizeof(formatBuf)), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value, formatBuf1, sizeof(formatBuf1))); sendString(buf); #ifdef NOT_YET if(myGlobals.device[myGlobals.actualReportDeviceId].droppedPkts.value > 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].droppedPkts.value, formatBuf, sizeof(formatBuf)), (float)(myGlobals.device[myGlobals.actualReportDeviceId].droppedPkts.value*100) /(float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value); sendString(buf); } #endif } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*unicastPkts)/(float)myGlobals.device[myGlobals.actualReportDeviceId]. fcPkts.value, formatPkts(unicastPkts, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId].fcBroadcastPkts.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].fcBroadcastPkts.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdFcPktStats.shortest.value, formatBuf, sizeof(formatBuf))); sendString(buf); avgPktLen = myGlobals.device[myGlobals.actualReportDeviceId].fcBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(avgPktLen, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId]. rcvdFcPktStats.longest.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdFcPktStats.upTo36.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdFcPktStats.upTo36.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdFcPktStats.upTo48.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdFcPktStats.upTo48.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdFcPktStats.upTo52.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdFcPktStats.upTo52.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdFcPktStats.upTo68.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdFcPktStats.upTo68.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdFcPktStats.upTo104.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdFcPktStats.upTo104.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdFcPktStats.upTo548.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdFcPktStats.upTo548.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdFcPktStats.upTo1060.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdFcPktStats.upTo1060.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdFcPktStats.upTo2136.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdFcPktStats.upTo2136.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdFcPktStats.above2136.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdFcPktStats.above2136.value, formatBuf, sizeof(formatBuf))); sendString(buf); sendString("\n"); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), 2136, (float)(100*myGlobals.device[myGlobals.actualReportDeviceId].rcvdFcPktStats.above2136.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdFcPktStats.above2136.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdFcPktStats.badCRC.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].fcPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdFcPktStats.badCRC.value, formatBuf, sizeof(formatBuf))); sendString(buf); } /* ****************** */ sendString("
Total%s [%s Pkts]
Dropped by the kernel%s [%.2f %%]
Unicast%.1f%%%s
Broadcast%.1f%%%s
Shortest%s bytes
Average Size%s bytes
Longest%s bytes
&le 36 bytes%.1f%%%s
≤ 48 bytes%.1f%%%s
≤ 52 bytes%.1f%%%s
≤ 68 bytes%.1f%%%s
≤ 104 bytes%.1f%%%s
≤ 548 bytes%.1f%%%s
≤ 1060 bytes%.1f%%%s
≤ 2136 bytes%.1f%%%s
> 2136 bytes%.1f%%%s
" "
Packets too long [> %d]%.1f%%%s
Bad EOF Frames%.1f%%%s
"TABLE_OFF"
Traffic\n"); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatBytes(myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value, 1, formatBuf, sizeof(formatBuf)), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatBuf1, sizeof(formatBuf1))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatBytes(myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value, 1, formatBuf, sizeof(formatBuf)), formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].ipPkts.value, formatBuf1, sizeof(formatBuf1))); sendString(buf); if(myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value > 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatBytes(myGlobals.device[myGlobals.actualReportDeviceId].fragmentedIpBytes.value, 1, formatBuf, sizeof(formatBuf)), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId].fragmentedIpBytes.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value); sendString(buf); } /* Just in case... */ if(myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value > myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value) dummyCounter = myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value- myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value; else dummyCounter = 0; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatBytes(dummyCounter, 1, formatBuf, sizeof(formatBuf))); sendString(buf); #ifndef EMBEDDED if(myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value > 0) sendString("\n"); #endif /* ********************* */ if(myGlobals.device[myGlobals.actualReportDeviceId].ipPkts.value > 0) { int avgPktTTL; avgPktTTL = (int)((16*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo32.value +48*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo64.value +80*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo96.value +112*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo128.value +144*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo160.value +176*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo192.value +208*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo224.value +240*myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo255.value)/ myGlobals.device[myGlobals.actualReportDeviceId].ipPkts.value); if(avgPktTTL > 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), avgPktTTL); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktTTLStats.upTo32.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo32.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktTTLStats.upTo64.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo64.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktTTLStats.upTo96.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo96.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktTTLStats.upTo128.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo128.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktTTLStats.upTo160.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo160.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktTTLStats.upTo192.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo192.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktTTLStats.upTo224.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo224.value, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), (float)(100*myGlobals.device[myGlobals.actualReportDeviceId]. rcvdPktTTLStats.upTo255.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value, formatPkts(myGlobals.device[myGlobals.actualReportDeviceId].rcvdPktTTLStats.upTo255.value, formatBuf, sizeof(formatBuf))); sendString(buf); #ifndef EMBEDDED sendString("\n"); #endif } } sendString("
Total%s [%s Pkts]
IP Traffic%s [%s Pkts]
Fragmented IP Traffic%s [%.1f%%]
Non IP Traffic%s
" "
Average TTL%d
TTL <= 32%.1f%%%s
32 < TTL <= 64%.1f%%%s
64 < TTL <= 96%.1f%%%s
96 < TTL <= 128%.1f%%%s
128 < TTL <= 160%.1f%%%s
160 < TTL <= 192%.1f%%%s
192 < TTL <= 224%.1f%%%s
224 < TTL <= 256%.1f%%%s
" "
"TABLE_OFF"
Remote Hosts Distance" "" "
Network Load\n"); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", getRowColor(), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId].actualThpt, 1, formatBuf, sizeof(formatBuf)), myGlobals.device[myGlobals.actualReportDeviceId].actualPktsThpt); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "\n", getRowColor(), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId].lastMinThpt, 1, formatBuf, sizeof(formatBuf)), myGlobals.device[myGlobals.actualReportDeviceId].lastMinPktsThpt); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "\n", getRowColor(), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId].lastFiveMinsThpt, 1, formatBuf, sizeof(formatBuf)), myGlobals.device[myGlobals.actualReportDeviceId].lastFiveMinsPktsThpt); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "\n", getRowColor(), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId].peakThroughput, 1, formatBuf, sizeof(formatBuf)), myGlobals.device[myGlobals.actualReportDeviceId].peakPacketThroughput); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "\n", getRowColor(), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value/ (myGlobals.actTime-myGlobals.initialSniffTime+1), 1, formatBuf, sizeof(formatBuf)), /* Bug below fixed courtesy of Eddy Lai */ ((float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value/ (float)(myGlobals.actTime-myGlobals.initialSniffTime+1))); sendString(buf); #if 0 sendString("\n"); #endif #if 0 sendString("\n"); #endif sendString("
Actual%s%.1f Pkt/s
Last Minute%s%.1f Pkt/s
Last 5 Minutes%s%.1f Pkt/s
Peak%s%.1f Pkt/s
Average%s%.1f Pkt/s
" "" "
"TABLE_OFF"
Historical Data" "[ " "\"View ]" "
\n"); if(!myGlobals.runningPref.printFcOnly) { printProtoTraffic(TRUE); sendString("

\n"); printIpProtocolDistribution(FLAG_HOSTLINK_HTML_FORMAT, revertOrder, TRUE); } if(!myGlobals.runningPref.printIpOnly) { sendString("

\n"); printFcProtocolDistribution(FLAG_HOSTLINK_HTML_FORMAT, revertOrder, TRUE); } } /* ******************************* */ int combineReportTypeLocality(int reportTypeReq, LocalityDisplayPolicy showLocalityMode) { int rc = reportTypeReq; switch(reportTypeReq) { case SORT_DATA_HOST_TRAFFIC: switch(showLocalityMode) { case showOnlySent: rc = SORT_DATA_SENT_HOST_TRAFFIC; break; case showOnlyReceived: rc = SORT_DATA_RCVD_HOST_TRAFFIC; default: /* Nothign to do */ break; } break; case SORT_DATA_PROTOS: switch(showLocalityMode) { case showOnlySent: rc = SORT_DATA_SENT_PROTOS; break; case showOnlyReceived: rc = SORT_DATA_RECEIVED_PROTOS; default: /* Nothign to do */ break; } break; case SORT_DATA_IP: switch(showLocalityMode) { case showOnlySent: rc = SORT_DATA_SENT_IP; break; case showOnlyReceived: rc = SORT_DATA_RECEIVED_IP; default: /* Nothign to do */ break; } break; case SORT_DATA_THPT: switch(showLocalityMode) { case showOnlySent: rc = SORT_DATA_SENT_THPT; break; case showOnlyReceived: rc = SORT_DATA_RECEIVED_THPT; default: /* Nothign to do */ break; } break; default: /* Nothing to do */ break; } return(rc); } /* ******************************* */ void printHostsTraffic(int reportTypeReq, int sortedColumn, int revertOrder, int pageNum, char* url, HostsDisplayPolicy showHostsMode, LocalityDisplayPolicy showLocalityMode, int vlanId) { u_int idx, idx1, numEntries=0; int printedEntries=0, hourId, maxHosts; char theDate[8]; struct tm t; HostTraffic *el; HostTraffic** tmpTable; char buf[LEN_GENERAL_WORK_BUFFER*2], hostLinkBuf[LEN_GENERAL_WORK_BUFFER]; float sentPercent=0, rcvdPercent=0, totPercent=0; Counter totIpBytesSent=0, totIpBytesRcvd=0, totIpBytes=0; Counter totEthBytesSent=0, totEthBytesRcvd=0, totEthBytes=0; ProtocolsList *protoList; char formatBuf[32], formatBuf1[32], formatBuf2[32], formatBuf3[32], formatBuf4[32], formatBuf5[32], formatBuf6[32], formatBuf7[32], formatBuf8[32], formatBuf9[32]; int reportType; u_char *vlanList; vlanList = calloc(1, MAX_VLAN); if(vlanList == NULL) return; vlanId = abs(vlanId); /* traceEvent(CONST_TRACE_INFO, "VLAN: %d", vlanId); */ reportType = combineReportTypeLocality(reportTypeReq, showLocalityMode); memset(buf, 0, sizeof(buf)); switch(reportType) { case SORT_DATA_RCVD_HOST_TRAFFIC: case SORT_DATA_SENT_HOST_TRAFFIC: case SORT_DATA_HOST_TRAFFIC: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Network Activity: "); break; case SORT_DATA_RECEIVED_PROTOS: case SORT_DATA_SENT_PROTOS: case SORT_DATA_PROTOS: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Network Traffic [All Protocols]: "); break; case SORT_DATA_RECEIVED_IP: case SORT_DATA_SENT_IP: case SORT_DATA_IP: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Network Traffic [TCP/IP]: "); break; case SORT_DATA_RECEIVED_THPT: case SORT_DATA_SENT_THPT: case SORT_DATA_THPT: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Network Throughput: "); break; default: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "?: "); break; } switch(showHostsMode) { case showAllHosts: strncat(buf, "All Hosts", (sizeof(buf) - strlen(buf) - 1)); break; case showOnlyLocalHosts: strncat(buf, "Local Hosts", (sizeof(buf) - strlen(buf) - 1)); break; case showOnlyRemoteHosts: strncat(buf, "Remote Hosts", (sizeof(buf) - strlen(buf) - 1)); break; } switch(showLocalityMode) { case showSentReceived: strncat(buf, " - Data Sent+Received", (sizeof(buf) - strlen(buf) - 1)); break; case showOnlySent: strncat(buf, " - Data Sent", (sizeof(buf) - strlen(buf) - 1)); break; case showOnlyReceived: strncat(buf, " - Data Received", (sizeof(buf) - strlen(buf) - 1)); break; } for(el=getFirstHost(myGlobals.actualReportDeviceId); el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) if((el->vlanId > 0) && (el->vlanId < MAX_VLAN)) vlanList[el->vlanId] = 1; printHTMLheader(buf, NULL, 0); printHeader(reportTypeReq, revertOrder, abs(sortedColumn), showHostsMode, showLocalityMode, (char*)vlanList, vlanId); strftime(theDate, 8, CONST_TOD_HOUR_TIMESPEC, localtime_r(&myGlobals.actTime, &t)); hourId = atoi(theDate); maxHosts = myGlobals.device[myGlobals.actualReportDeviceId].hostsno; /* save ths as it can change */ tmpTable = (HostTraffic**)mallocAndInitWithReportWarn(maxHosts*sizeof(HostTraffic*), "printHostsTraffic"); if(tmpTable == NULL) { free(vlanList); return; } for(el=getFirstHost(myGlobals.actualReportDeviceId); el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) { if(!isFcHost (el) && (broadcastHost(el) == 0)) { u_char addHost; if((vlanId > 0) && (el->vlanId != vlanId)) continue; if(el->community && (!isAllowedCommunity(el->community))) continue; if(((showLocalityMode == showOnlySent) && (el->bytesSent.value > 0)) || ((showLocalityMode == showOnlyReceived) && (el->bytesRcvd.value > 0)) || ((showLocalityMode == showSentReceived) && (el->bytesSent.value + el->bytesRcvd.value > 0))) { if(((reportType == SORT_DATA_RECEIVED_IP) || (reportType == SORT_DATA_SENT_IP) || (reportType == SORT_DATA_IP)) && (el->hostNumIpAddress[0] == '\0')) { continue; } addHost = 1; switch(myGlobals.hostsDisplayPolicy) { case showOnlyLocalHosts: if(!subnetPseudoLocalHost(el)) addHost = 0; break; case showOnlyRemoteHosts: if(subnetPseudoLocalHost(el)) addHost = 0; break; default: /* Nothign to do */ break; } if(addHost) { tmpTable[numEntries++] = el; if(numEntries >= maxHosts) break; } } } } /* for */ if(numEntries > 0) { /* The switch below is needed to: - sort data according to the selected column - 'recycle' (somebody would call this "code reuse") the cmpFctn function */ if(sortedColumn == FLAG_HOST_DUMMY_IDX) myGlobals.columnSort = FLAG_HOST_DUMMY_IDX; /* Host name */ else if(sortedColumn == FLAG_DOMAIN_DUMMY_IDX) myGlobals.columnSort = FLAG_DOMAIN_DUMMY_IDX; /* domain name */ else myGlobals.columnSort = sortedColumn; #ifdef DEBUG traceEvent(CONST_TRACE_INFO, ">reportType=%d/sortedColumn=%d/myGlobals.columnSort=%d<", reportType, sortedColumn, myGlobals.columnSort); #endif myGlobals.reportKind = reportType; /* if(myGlobals.columnSort == 0) myGlobals.reportKind = 0;*/ qsort(tmpTable, numEntries, sizeof(HostTraffic*), cmpFctn); switch(reportType) { case SORT_DATA_RECEIVED_PROTOS: case SORT_DATA_SENT_PROTOS: totEthBytesSent = totEthBytesRcvd = 0; for(idx=0; idxbytesSent.value; totEthBytesRcvd += tmpTable[idx]->bytesRcvd.value; } } /* Avoid core dumps */ if(totEthBytesSent == 0) totEthBytesSent = 1; if(totEthBytesRcvd == 0) totEthBytesRcvd = 1; break; case SORT_DATA_PROTOS: totEthBytes = 0; for(idx=0; idxbytesSent.value + tmpTable[idx]->bytesRcvd.value; } } /* Avoid core dumps */ if(totEthBytes == 0) totEthBytes = 1; break; case SORT_DATA_RECEIVED_IP: case SORT_DATA_SENT_IP: totIpBytesSent = totIpBytesRcvd = 0; for(idx=0; idxipBytesSent.value; totIpBytesRcvd += tmpTable[idx]->ipBytesRcvd.value; } } /* Avoid core dumps */ if(totIpBytesSent == 0) totIpBytesSent = 1; if(totIpBytesRcvd == 0) totIpBytesRcvd = 1; break; case SORT_DATA_IP: totIpBytes = 0; for(idx=0; idxipBytesSent.value + tmpTable[idx]->ipBytesRcvd.value; } } /* Avoid core dumps */ if(totIpBytes == 0) totIpBytes = 1; break; } #ifdef DEBUG traceEvent(CONST_TRACE_INFO, "totIpBytesSent=%u, totIpBytesRcvd=%u totIpBytes=%u", totIpBytesSent, totIpBytesRcvd, totIpBytes); #endif for(idx=pageNum*myGlobals.runningPref.maxNumLines; idxbytesSent.value)/totEthBytesSent; rcvdPercent = (100*(float)el->bytesRcvd.value)/totEthBytesRcvd; break; case SORT_DATA_PROTOS: totPercent = (100*(float) (el->bytesSent.value + el->bytesRcvd.value) )/totEthBytes; break; case SORT_DATA_RECEIVED_IP: case SORT_DATA_SENT_IP: sentPercent = (100*(float)el->ipBytesSent.value)/totIpBytesSent; rcvdPercent = (100*(float)el->ipBytesRcvd.value)/totIpBytesRcvd; break; case SORT_DATA_IP: totPercent = (100*(float) (el->ipBytesSent.value + el->ipBytesRcvd.value) )/totIpBytes; break; case SORT_DATA_RECEIVED_THPT: case SORT_DATA_RCVD_HOST_TRAFFIC: case SORT_DATA_SENT_HOST_TRAFFIC: case SORT_DATA_SENT_THPT: case TRAFFIC_STATS: case SORT_DATA_HOST_TRAFFIC: case SORT_DATA_THPT: sentPercent = rcvdPercent = 0; break; } /* Fixed buffer overflow. Courtesy of Rainer Tammer */ strncpy(webHostName, makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 1, hostLinkBuf, sizeof(hostLinkBuf)), sizeof(webHostName)); switch(reportType) { case SORT_DATA_RECEIVED_PROTOS: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s" "%s%.1f%s%%" "%s%s" "%s""%s" "%s%s" "%s" "%s%s", getRowColor(), webHostName, formatBytes(el->bytesRcvd.value, 1, formatBuf, sizeof(formatBuf)), rcvdPercent, myGlobals.separator, formatBytes(el->tcpRcvdLoc.value+el->tcpRcvdFromRem.value, 1, formatBuf1, sizeof(formatBuf1)), formatBytes(el->udpRcvdLoc.value+el->udpRcvdFromRem.value, 1, formatBuf2, sizeof(formatBuf2)), formatBytes(el->icmpRcvd.value, 1, formatBuf3, sizeof(formatBuf3)), formatBytes(el->icmp6Rcvd.value, 1, formatBuf4, sizeof(formatBuf4)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->dlcRcvd.value, 1, formatBuf5, sizeof(formatBuf5)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->ipxRcvd.value, 1, formatBuf6, sizeof(formatBuf6)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->decnetRcvd.value, 1, formatBuf7, sizeof(formatBuf7)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->arp_rarpRcvd.value, 1, formatBuf8, sizeof(formatBuf8)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->appletalkRcvd.value, 1, formatBuf9, sizeof(formatBuf9)) ); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s" "%s" "%s" "%s", formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->netbiosRcvd.value, 1, formatBuf1, sizeof(formatBuf1)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->osiRcvd.value, 1, formatBuf2, sizeof(formatBuf2)), formatBytes(el->ipv6Rcvd.value, 1, formatBuf3, sizeof(formatBuf3)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->stpRcvd.value, 1, formatBuf4, sizeof(formatBuf4))); sendString(buf); protoList = myGlobals.ipProtosList, idx1=0; while(protoList != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", el->ipProtosList[idx1] != NULL ? formatBytes(el->ipProtosList[idx1]->rcvd.value, 1, formatBuf, sizeof(formatBuf)) : "0"); sendString(buf); idx1++, protoList = protoList->next; } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->otherRcvd.value, 1, formatBuf, sizeof(formatBuf))); sendString(buf); break; case SORT_DATA_SENT_PROTOS: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s" "%s%.1f%s%%" "%s%s" "%s" "%s%s" "%s""%s" "%s%s", getRowColor(), webHostName, formatBytes(el->bytesSent.value, 1, formatBuf, sizeof(formatBuf)), sentPercent, myGlobals.separator, formatBytes(el->tcpSentLoc.value+el->tcpSentRem.value, 1, formatBuf1, sizeof(formatBuf1)), formatBytes(el->udpSentLoc.value+el->udpSentRem.value, 1, formatBuf2, sizeof(formatBuf2)), formatBytes(el->icmpSent.value, 1, formatBuf3, sizeof(formatBuf3)), formatBytes(el->icmp6Sent.value, 1, formatBuf4, sizeof(formatBuf4)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->dlcSent.value, 1, formatBuf5, sizeof(formatBuf5)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->ipxSent.value, 1, formatBuf6, sizeof(formatBuf6)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->decnetSent.value, 1, formatBuf7, sizeof(formatBuf7)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->arp_rarpSent.value, 1, formatBuf8, sizeof(formatBuf8)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->appletalkSent.value, 1, formatBuf9, sizeof(formatBuf9)) ); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s" "%s" "%s" "%s", formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->netbiosSent.value, 1, formatBuf, sizeof(formatBuf)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->osiSent.value, 1, formatBuf1, sizeof(formatBuf1)), formatBytes(el->ipv6Sent.value, 1, formatBuf2, sizeof(formatBuf2)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->stpSent.value, 1, formatBuf3, sizeof(formatBuf3))); sendString(buf); protoList = myGlobals.ipProtosList, idx1=0; while(protoList != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", el->ipProtosList[idx1] != NULL ? formatBytes(el->ipProtosList[idx1]->sent.value, 1, formatBuf, sizeof(formatBuf)) : "0"); sendString(buf); idx1++, protoList = protoList->next; } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->otherSent.value, 1, formatBuf, sizeof(formatBuf)) ); sendString(buf); break; case SORT_DATA_PROTOS: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s" "%s%.1f%s%%" "%s%s" "%s" "%s%s" "%s""%s" "%s%s", getRowColor(), webHostName, formatBytes(el->bytesSent.value+el->bytesRcvd.value, 1, formatBuf, sizeof(formatBuf)), totPercent, myGlobals.separator, formatBytes(el->tcpSentLoc.value+el->tcpSentRem.value+ el->tcpRcvdLoc.value+el->tcpRcvdFromRem.value, 1, formatBuf1, sizeof(formatBuf1)), formatBytes(el->udpSentLoc.value+el->udpSentRem.value+ el->udpRcvdLoc.value+el->udpRcvdFromRem.value, 1, formatBuf2, sizeof(formatBuf2)), formatBytes(el->icmpSent.value+el->icmpRcvd.value, 1, formatBuf3, sizeof(formatBuf3)), formatBytes(el->icmp6Sent.value+el->icmp6Rcvd.value, 1, formatBuf4, sizeof(formatBuf4)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->dlcSent.value+el->nonIPTraffic->dlcRcvd.value, 1, formatBuf5, sizeof(formatBuf5)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->ipxSent.value+el->nonIPTraffic->ipxRcvd.value, 1, formatBuf6, sizeof(formatBuf6)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->decnetSent.value+el->nonIPTraffic->decnetRcvd.value, 1, formatBuf7, sizeof(formatBuf7)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->arp_rarpSent.value+el->nonIPTraffic->arp_rarpRcvd.value, 1, formatBuf8, sizeof(formatBuf8)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->appletalkSent.value+el->nonIPTraffic->appletalkRcvd.value, 1, formatBuf9, sizeof(formatBuf9)) ); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s" "%s" "%s" "%s", formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->netbiosSent.value+el->nonIPTraffic->netbiosRcvd.value, 1, formatBuf, sizeof(formatBuf)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->osiSent.value+el->nonIPTraffic->osiRcvd.value, 1, formatBuf1, sizeof(formatBuf1)), formatBytes(el->ipv6Sent.value+el->ipv6Rcvd.value, 1, formatBuf2, sizeof(formatBuf2)), formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->stpSent.value+el->nonIPTraffic->stpRcvd.value, 1, formatBuf3, sizeof(formatBuf3))); sendString(buf); protoList = myGlobals.ipProtosList, idx1=0; while(protoList != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", el->ipProtosList[idx1] != NULL ? formatBytes(el->ipProtosList[idx1]->sent.value +el->ipProtosList[idx1]->rcvd.value, 1, formatBuf, sizeof(formatBuf)) : "0"); sendString(buf); idx1++, protoList = protoList->next; } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", formatBytes(el->nonIPTraffic == NULL ? 0 : el->nonIPTraffic->otherSent.value+el->nonIPTraffic->otherRcvd.value, 1, formatBuf, sizeof(formatBuf)) ); sendString(buf); break; case SORT_DATA_RECEIVED_IP: { Counter totalIPTraffic=0; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s" "%s%.1f%s%%", getRowColor(), webHostName, formatBytes(el->ipBytesRcvd.value, 1, formatBuf, sizeof(formatBuf)), rcvdPercent, myGlobals.separator); sendString(buf); for(i=0; iprotoIPTrafficInfos[i]) totalIPTraffic += el->protoIPTrafficInfos[i]->rcvdLoc.value+ el->protoIPTrafficInfos[i]->rcvdFromRem.value; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", el->protoIPTrafficInfos[i] ? formatBytes(el->protoIPTrafficInfos[i]->rcvdLoc.value+ el->protoIPTrafficInfos[i]->rcvdFromRem.value, 1, formatBuf, sizeof(formatBuf)) : "0"); sendString(buf); } /* Rounding may cause troubles */ if(el->ipBytesRcvd.value > totalIPTraffic) totalIPTraffic = el->ipBytesRcvd.value - totalIPTraffic; else totalIPTraffic = 0; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", formatBytes(totalIPTraffic, 1, formatBuf, sizeof(formatBuf))); sendString(buf); } break; case SORT_DATA_SENT_IP: { Counter totalIPTraffic=0; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s" "%s%.1f%s%%", getRowColor(), webHostName, formatBytes(el->ipBytesSent.value, 1, formatBuf, sizeof(formatBuf)), sentPercent, myGlobals.separator); sendString(buf); for(i=0; iprotoIPTrafficInfos[i]) totalIPTraffic += el->protoIPTrafficInfos[i]->sentLoc.value+ el->protoIPTrafficInfos[i]->sentRem.value; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", el->protoIPTrafficInfos[i] ? formatBytes(el->protoIPTrafficInfos[i]->sentLoc.value+ el->protoIPTrafficInfos[i]->sentRem.value, 1, formatBuf, sizeof(formatBuf)) : "0"); sendString(buf); } /* Rounding may cause troubles */ if(el->ipBytesSent.value > totalIPTraffic) totalIPTraffic = el->ipBytesSent.value - totalIPTraffic; else totalIPTraffic = 0; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", formatBytes(totalIPTraffic, 1, formatBuf, sizeof(formatBuf))); sendString(buf); } break; case SORT_DATA_IP: { Counter totalIPTraffic=0; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s" "%s%.1f%s%%", getRowColor(), webHostName, formatBytes(el->ipBytesSent.value+el->ipBytesRcvd.value, 1, formatBuf, sizeof(formatBuf)), totPercent, myGlobals.separator); sendString(buf); for(i=0; iprotoIPTrafficInfos[i]) totalIPTraffic += el->protoIPTrafficInfos[i]->sentLoc.value+ el->protoIPTrafficInfos[i]->rcvdLoc.value+ el->protoIPTrafficInfos[i]->sentRem.value+ el->protoIPTrafficInfos[i]->rcvdFromRem.value; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", el->protoIPTrafficInfos[i] ? formatBytes(el->protoIPTrafficInfos[i]->sentLoc.value+ el->protoIPTrafficInfos[i]->rcvdLoc.value+ el->protoIPTrafficInfos[i]->sentRem.value+ el->protoIPTrafficInfos[i]->rcvdFromRem.value, 1, formatBuf, sizeof(formatBuf)) : "0"); sendString(buf); } /* Rounding may cause troubles */ if(el->ipBytesSent.value+el->ipBytesRcvd.value > totalIPTraffic) totalIPTraffic = el->ipBytesSent.value + el->ipBytesRcvd.value - totalIPTraffic; else totalIPTraffic = 0; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", formatBytes(totalIPTraffic, 1, formatBuf, sizeof(formatBuf))); sendString(buf); } break; case SORT_DATA_RECEIVED_THPT: { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s" "%s" "%s" "%s" "%.1f Pkt/s" "%.1f Pkt/s" "%.1f Pkt/s", getRowColor(), webHostName, formatThroughput(el->actualRcvdThpt, 1, formatBuf, sizeof(formatBuf)), formatThroughput(el->averageRcvdThpt, 1, formatBuf1, sizeof(formatBuf1)), formatThroughput(el->peakRcvdThpt, 1, formatBuf2, sizeof(formatBuf2)), el->actualRcvdPktThpt, el->averageRcvdPktThpt, el->peakRcvdPktThpt); sendString(buf); } break; case SORT_DATA_SENT_THPT: { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s" "%s" "%s" "%s" "%.1f Pkt/s" "%.1f Pkt/s" "%.1f Pkt/s", getRowColor(), webHostName, formatThroughput(el->actualSentThpt, 1, formatBuf, sizeof(formatBuf)), formatThroughput(el->averageSentThpt, 1, formatBuf1, sizeof(formatBuf1)), formatThroughput(el->peakSentThpt, 1, formatBuf2, sizeof(formatBuf2)), el->actualSentPktThpt, el->averageSentPktThpt, el->peakSentPktThpt); sendString(buf); } break; case SORT_DATA_THPT: { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s" "%s" "%s" "%s" "%.1f Pkt/s" "%.1f Pkt/s" "%.1f Pkt/s", getRowColor(), webHostName, formatThroughput(el->actualTThpt, 1, formatBuf, sizeof(formatBuf)), formatThroughput(el->averageTThpt, 1, formatBuf1, sizeof(formatBuf1)), formatThroughput(el->peakTThpt, 1, formatBuf2, sizeof(formatBuf2)), el->actualTPktThpt, el->averageTPktThpt, el->peakTPktThpt); sendString(buf); } break; case SORT_DATA_RCVD_HOST_TRAFFIC: case SORT_DATA_SENT_HOST_TRAFFIC: case SORT_DATA_HOST_TRAFFIC: case TRAFFIC_STATS: { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", getRowColor(), webHostName); sendString(buf); printHostThtpShort(el, reportType, hourId); } break; } sendString("\n"); /* Avoid huge tables */ if(printedEntries++ > myGlobals.runningPref.maxNumLines) break; } } } else idx = 0; sendString("\n"TABLE_OFF"\n"); switch(reportType) { case SORT_DATA_RCVD_HOST_TRAFFIC: case SORT_DATA_SENT_HOST_TRAFFIC: case SORT_DATA_HOST_TRAFFIC: case SORT_DATA_RECEIVED_THPT: case SORT_DATA_SENT_THPT: case SORT_DATA_THPT: break; case SORT_DATA_RECEIVED_PROTOS: case SORT_DATA_RECEIVED_IP: case SORT_DATA_SENT_PROTOS: case SORT_DATA_SENT_IP: case SORT_DATA_PROTOS: case SORT_DATA_IP: sendString("

Note: These counters do not include broadcasts and will not equal the 'Global Protocol Distribution'

\n"); break; } sendString("\n"); printFooter(reportType); addPageIndicator(url, pageNum, numEntries, myGlobals.runningPref.maxNumLines, revertOrder, abs(sortedColumn), -1); sendString("

NOTE:

\n
    " "
  • Click here " "for more information about host and domain sorting.
  • \n" "

\n"); myGlobals.lastRefreshTime = myGlobals.actTime; free(vlanList); free(tmpTable); } /* ******************************* */ void printMulticastStats(int sortedColumn /* ignored so far */, int revertOrder, int pageNum) { u_int idx, numEntries=0, maxHosts; int printedEntries=0, i; HostTraffic *el; HostTraffic** tmpTable; char buf[LEN_GENERAL_WORK_BUFFER], *sign, *theAnchor[6], *arrow[6], *arrowGif; char formatBuf[32], formatBuf1[32], formatBuf2[32], formatBuf3[32]; char htmlAnchor[64], htmlAnchor1[64], hostLinkBuf[LEN_GENERAL_WORK_BUFFER]; printHTMLheader("Multicast Statistics", NULL, 0); memset(buf, 0, sizeof(buf)); maxHosts = myGlobals.device[myGlobals.actualReportDeviceId].hostsno; /* save it as it can change */ tmpTable = (HostTraffic**)mallocAndInitWithReportWarn(maxHosts*sizeof(HostTraffic*), "printMulticastStats"); if(tmpTable == NULL) return; /* All the ALT tags courtesy of "Burton M. Strauss III" */ if(revertOrder) { sign = ""; arrowGif = " " CONST_IMG_ARROW_UP; } else { sign = "-"; arrowGif = " " CONST_IMG_ARROW_DOWN; } for(el=getFirstHost(myGlobals.actualReportDeviceId); el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) { if(((el->pktMulticastSent.value > 0) || (el->pktMulticastRcvd.value > 0)) && (!broadcastHost(el))) { if(el->community && (!isAllowedCommunity(el->community))) continue; tmpTable[numEntries++] = el; } if(numEntries >= maxHosts) break; } if(numEntries > 0) { myGlobals.columnSort = sortedColumn; /* Host name */ safe_snprintf(__FILE__, __LINE__, htmlAnchor, sizeof(htmlAnchor), "\n"); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), ""TABLE_ON"\n" "" "" "" "" "" "\n", theAnchor[0], arrow[0], theAnchor[1], arrow[1], theAnchor[2], arrow[2], theAnchor[3], arrow[3], theAnchor[4], arrow[4], theAnchor[5], arrow[5] ); sendString(buf); qsort(tmpTable, numEntries, sizeof(HostTraffic*), cmpMulticastFctn); for(idx=pageNum*myGlobals.runningPref.maxNumLines; idx%s" "" "" "\n", getRowColor(), makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 1, hostLinkBuf, sizeof(hostLinkBuf)), formatPkts(el->pktMulticastSent.value, formatBuf, sizeof(formatBuf)), formatBytes(el->bytesMulticastSent.value, 1, formatBuf1, sizeof(formatBuf1)), formatPkts(el->pktMulticastRcvd.value, formatBuf2, sizeof(formatBuf2)), formatBytes(el->bytesMulticastRcvd.value, 1, formatBuf3, sizeof(formatBuf3))); sendString(buf); /* Avoid huge tables */ if(printedEntries++ > myGlobals.runningPref.maxNumLines) break; } } sendString("
%s0>Host%s%s1>Domain%s%s2>Pkts Sent%s%s3>Data Sent%s%s4>Pkts Rcvd%s%s5>Data Rcvd%s
%s%s%s%s
"TABLE_OFF"\n"); sendString("\n"); addPageIndicator(CONST_MULTICAST_STATS_HTML, pageNum, numEntries, myGlobals.runningPref.maxNumLines, revertOrder, abs(sortedColumn), -1); printFooterHostLink(); } else printNoDataYet(); free(tmpTable); sendString("

List of multicast addresses

\n"); } /* ****************************************************************** */ static void makeHostName(HostTraffic *el, char *buf, int len) { if(el->hostResolvedName[0] != '\0') strcpy(buf, el->hostResolvedName); else if(el->hostNumIpAddress[0] != '\0') strcpy(buf, el->hostNumIpAddress); else if(el->ethAddressString[0] != '\0') strcpy(buf, el->ethAddressString); } /* ****************************************************************** */ #define LOCAL_COLOR "mistyrose2" #define REMOTE_COLOR "lightsteelblue1" static int addNodeInfo(FILE *fd, HostTraffic *el) { char buf0[128], buf1[128]; makeHostName(el, buf0, sizeof(buf0)); makeHostLink(el, FLAG_HOSTLINK_TEXT_LITE_FORMAT, 0, 0, buf1, sizeof(buf1)); if(buf1[0] != '\0') { fprintf(fd, "\"%s\" [URL=\"%s\", color=%s];\n", buf0, buf1, subnetLocalHost(el) ? LOCAL_COLOR : REMOTE_COLOR); return(1); } return(0); } /* ****************************************************************** */ void makeDot() { #ifdef WIN32 returnHTTPpageNotFound("This feature is not available on your platform"); return; #else HostTraffic *el, *el2, tmpEl; char buf[LEN_GENERAL_WORK_BUFFER], buf1[LEN_GENERAL_WORK_BUFFER], path[384], dotPath[256]; FILE *fd, *cmap, *in, *out, *make; struct stat statbuf; int rc; printHTMLheader("Local Network Traffic Map", NULL, 0); /* First of all let's see if the path of dot is inside the preferences */ if(fetchPrefsValue("dot.path", buf, sizeof(buf)) != -1) { snprintf(dotPath, sizeof(dotPath), "%s", buf); } else { snprintf(dotPath, sizeof(dotPath), "/usr/bin/dot"); storePrefsValue("dot.path", dotPath); /* Set the default */ } revertSlashIfWIN32(dotPath, 0); if(stat(dotPath, &statbuf) != 0) { snprintf(buf, sizeof(buf), "

ERROR

\n
Missing dot tool (expected %s). Please set its path (key dot.path) " "here.
", dotPath); sendString(buf); return; } snprintf(path, sizeof(path), "%s/ntop-all.dot", myGlobals.spoolPath); fd = fopen(path, "w"); if(fd != NULL) { for(el=getFirstHost(myGlobals.actualReportDeviceId); el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) { int numEntries, i, urlSent = 0; if(el->community && (!isAllowedCommunity(el->community))) continue; if(subnetLocalHost(el)) { makeHostName(el, buf, sizeof(buf)); for(numEntries = 0, i=0; icontactedSentPeers.peersSerials[i]) && (!cmpSerial(&el->contactedSentPeers.peersSerials[i], &myGlobals.otherHostEntry->hostSerial))) { if((el2 = quickHostLink(el->contactedSentPeers.peersSerials[i], myGlobals.actualReportDeviceId, &tmpEl)) != NULL) { makeHostName(el2, buf1, sizeof(buf1)); if(addNodeInfo(fd, el2)) { fprintf(fd, "\"%s\" -> \"%s\";\n", buf, buf1); if(!urlSent) urlSent = addNodeInfo(fd, el); } } } /* ****************************** */ for(numEntries = 0, i=0; icontactedRcvdPeers.peersSerials[i]) && (!cmpSerial(&el->contactedRcvdPeers.peersSerials[i], &myGlobals.otherHostEntry->hostSerial))) { if((el2 = quickHostLink(el->contactedRcvdPeers.peersSerials[i], myGlobals.actualReportDeviceId, &tmpEl)) != NULL) { makeHostName(el2, buf1, sizeof(buf1)); for(i=0; i \"%s\";\n", buf1, buf); if(!urlSent) urlSent = addNodeInfo(fd, el); } } } } } fclose(fd); snprintf(path, sizeof(path), "sort -u %s/ntop-all.dot > %s/ntop-sort.dot", myGlobals.spoolPath, myGlobals.spoolPath); sendString("\n"); errno = 0; rc = system(path); if((rc == -1) && (errno != ECHILD)) { snprintf(buf, sizeof(buf), "

ERROR

\n
Sorting of ntop-all.dot failed, rc %d
", errno); sendString(buf); return; } snprintf(path, sizeof(path), "%s/ntop.dot", myGlobals.spoolPath); out = fopen(path, "w"); if(out != NULL) { fprintf(out, "digraph ntop {\n"); fprintf(out, "node [shape = polygon, sides=4, fontsize=9, style=filled, fontname=\"Helvetica\"];\n"); snprintf(path, sizeof(path), "%s/ntop-sort.dot", myGlobals.spoolPath); if((in = fopen(path, "r")) != NULL) { while(!feof(in) && (fgets(buf, sizeof(buf), in) != NULL)) fprintf(out, "%s", buf); } fprintf(out, "}\n"); fclose(out); fclose(in); } /* Added -c courtesy of Max Waterman */ snprintf(path, sizeof(path), "%s -Tpng -Goverlap=false %s/ntop.dot -o %s/"CONST_NETWORK_IMAGE_MAP " 2>&1 ", dotPath, myGlobals.spoolPath, myGlobals.spoolPath); sendString("\n"); errno = 0; make = popen(path, "r"); if(make == NULL) { snprintf(buf, sizeof(buf), "

ERROR

\n

Creation of network map failed, rc %s(%d)

\n" "

Command was:

\n
%s
", strerror(errno), errno, path); sendString(buf); return; } if(!feof(make) && (fgets(buf, sizeof(buf), make) != NULL)) { sendString("

ERROR

\n

Creation of network map failed

\n" "

Command was:

\n
");
       sendString(path);
       sendString("
\n

Results were:

\n
");
       sendString(buf);
       while(!feof(make) && (fgets(buf, sizeof(buf), make) != NULL)) {
	 sendString(buf);
       }
       sendString("
\n"); return; } pclose(make); snprintf(path, sizeof(path), "%s -Tcmap -Goverlap=false %s/ntop.dot", dotPath, myGlobals.spoolPath); sendString("\n"); cmap = popen(path, "r"); if(cmap != NULL) { sendString("

"); sendString("
\n"); while(!feof(cmap) && (fgets(buf, sizeof(buf), cmap) != NULL)) sendString(buf); sendString("\n"); sendString("

Graph generated by Dot, part of Graphviz, created by " "AT&T Research.\n"); pclose(cmap); } else { returnHTTPpageNotFound("Unable to generate cmap file (Is dot installed?)"); } } else { returnHTTPpageNotFound("Unable to create temporary file"); } #endif } /* ******************************* */ void printHostsInfo(int sortedColumn, int revertOrder, int pageNum, int showBytes, int vlanId, int ifId) { u_int idx, numEntries=0, maxHosts; int printedEntries=0; unsigned short maxBandwidthUsage=1 /* avoid divisions by zero */; HostTraffic *el; HostTraffic** tmpTable; char buf[2*LEN_GENERAL_WORK_BUFFER], *arrowGif, *sign, *arrow[12], *theAnchor[12], osBuf[160]; char htmlAnchor[64], htmlAnchor1[64]; char formatBuf[32], hostLinkBuf[LEN_GENERAL_WORK_BUFFER]; u_char *vlanList, foundVlan = 0, vlanStr[16], ifStr[16], foundIf = 0, *ifList; vlanList = calloc(1, MAX_VLAN); if(vlanList == NULL) { traceEvent (CONST_TRACE_WARNING, "Unable to allocate memory for vlan list"); return; } vlanId = abs(vlanId); ifList = calloc(1, MAX_INTERFACE); if(ifList == NULL) { traceEvent (CONST_TRACE_WARNING, "Unable to allocate memory for if list"); return; } ifId = abs(ifId); printHTMLheader("Host Information", NULL, 0); memset(buf, 0, sizeof(buf)); maxHosts = myGlobals.device[myGlobals.actualReportDeviceId].hostsno; /* save it as it can change */ tmpTable = (HostTraffic**)mallocAndInitWithReportWarn(maxHosts*sizeof(HostTraffic*), "printHostsInfo"); if(tmpTable == NULL) { free(vlanList); free(ifList); return; } if(revertOrder) sign = "", arrowGif = " " CONST_IMG_ARROW_UP; else sign = "-", arrowGif = " " CONST_IMG_ARROW_DOWN; myGlobals.columnSort = sortedColumn; for(el=getFirstHost(myGlobals.actualReportDeviceId); el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) { unsigned short actUsage, actUsageS, actUsageR; if(isFcHost (el) || broadcastHost(el)) continue; if(el->community && (!isAllowedCommunity(el->community))) continue; if((el->vlanId != NO_VLAN) && (el->vlanId < MAX_VLAN)) { vlanList[el->vlanId] = 1, foundVlan = 1; } if((vlanId != NO_VLAN) && (el->vlanId != vlanId)) continue; if((el->ifId != NO_INTERFACE) && (el->ifId < MAX_INTERFACE)) { ifList[el->ifId] = 1, foundIf = 1; } if((ifId != NO_INTERFACE) && (el->ifId != ifId)) continue; if(showBytes) { actUsage = (unsigned short)(0.5+100.0*(((float)el->bytesSent.value+(float)el->bytesRcvd.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value)); actUsageS = (unsigned short)(0.5+100.0*((float)el->bytesSent.value/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value)); actUsageR = (unsigned short)(0.5+100.0*((float)el->bytesRcvd.value/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value)); } else { actUsage = (unsigned short)(0.5+100.0*(((float)el->pktSent.value+(float)el->pktRcvd.value)/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value)); actUsageS = (unsigned short)(0.5+100.0*((float)el->pktSent.value/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value)); actUsageR = (unsigned short)(0.5+100.0*((float)el->pktRcvd.value/ (float)myGlobals.device[myGlobals.actualReportDeviceId].ethernetPkts.value)); } el->actBandwidthUsage = actUsage; if(el->actBandwidthUsage > maxBandwidthUsage) maxBandwidthUsage = actUsage; el->actBandwidthUsageS = actUsageS; el->actBandwidthUsageR = actUsageR; tmpTable[numEntries++] = el; getHostAS(el); if(numEntries >= maxHosts) break; } if(numEntries > 0) { int i; qsort(tmpTable, numEntries, sizeof(HostTraffic*), sortHostFctn); safe_snprintf(__FILE__, __LINE__, htmlAnchor, sizeof(htmlAnchor), ""); if(vlanId > 0) safe_snprintf(__FILE__, __LINE__, (char*)vlanStr, sizeof(vlanStr), "&vlan=%d", vlanId); else vlanStr[0] = '\0'; if(ifId > 0) safe_snprintf(__FILE__, __LINE__, (char*)ifStr, sizeof(ifStr), "&if=%d", ifId); else ifStr[0] = '\0'; if(showBytes) safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Traffic Unit: [ Bytes ] " "[ Packets ] ", CONST_HOSTS_INFO_HTML, myGlobals.columnSort, vlanStr, ifStr); else safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Traffic Unit: [ Bytes ] " "[ Packets ] ", CONST_HOSTS_INFO_HTML, myGlobals.columnSort, vlanStr, ifStr); sendString(buf); sendString("

\n"); if(foundVlan) { u_char found = 0, tmpBuf[64]; sendString("

VLAN: "); for(i=0; i%s ] ", vlan2name(i, (char*)tmpBuf, sizeof(tmpBuf))), found = 1; else safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "[ %s ] ", CONST_HOSTS_INFO_HTML, showBytes, i, vlan2name(i, (char*)tmpBuf, sizeof(tmpBuf))); sendString(buf); } } if(foundIf) { u_char found = 0; sendString("

Interface Id: "); for(i=0; i%d ] ", i), found = 1; else safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "[ %d ] ", CONST_HOSTS_INFO_HTML, showBytes, i, i); sendString(buf); } if(!found) safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "[ All ] "); else safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "[ All ] ", CONST_HOSTS_INFO_HTML, showBytes); sendString(buf); } if(!myGlobals.device[myGlobals.actualReportDeviceId].dummyDevice) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "

"TABLE_ON"\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n", theAnchor[1], arrow[1], theAnchor[0], arrow[0], theAnchor[2], arrow[2], theAnchor[3], arrow[3], theAnchor[11], arrow[11], theAnchor[6], arrow[6], theAnchor[4], arrow[4], theAnchor[5], arrow[5], theAnchor[7], arrow[7], theAnchor[8], arrow[8], theAnchor[9], arrow[9], theAnchor[10], arrow[10] ); } else { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "
"TABLE_ON"
%s1\">Host%s%s"FLAG_DOMAIN_DUMMY_IDX_STR"\">Domain%s%s2\">IP Address%s%s3\">MAC Address%s%s11\">Community%s%s6\">Other Name(s)%s%s4\">Bandwidth%s%s5\">Nw Board Vendor%s%s7\">Hops Distance%s%s8\">Host Contacts%s%s9\">Age/Inactivity%s%s10\">AS%s
\n" "\n" "\n" "\n" "" "\n" "\n" "\n" "\n" "\n" "\n" "\n", theAnchor[1], arrow[1], theAnchor[0], arrow[0], theAnchor[2], arrow[2], theAnchor[6], arrow[6], theAnchor[11], arrow[11], theAnchor[4], arrow[4], theAnchor[7], arrow[7], theAnchor[8], arrow[8], theAnchor[9], arrow[9], theAnchor[10], arrow[10] ); } sendString(buf); for(idx=pageNum*myGlobals.runningPref.maxNumLines; idxhostNumIpAddress; if((tmpName1[0] == '\0') || (strcmp(tmpName1, "0.0.0.0") == 0)) tmpName1 = myGlobals.separator; if(!myGlobals.device[myGlobals.actualReportDeviceId].dummyDevice) { tmpName2 = getVendorInfo(el->ethAddress, 1); if(tmpName2[0] == '\0') tmpName2 = myGlobals.separator; tmpName3 = el->ethAddressString; if((tmpName3[0] == '\0') || (strcmp(tmpName3, "00:00:00:00:00:00") == 0)) tmpName3 = myGlobals.separator; } else { tmpName2 = myGlobals.separator; tmpName3 = myGlobals.separator; } if(!addrnull(&el->hostIpAddress) && (getSniffedDNSName(el->hostNumIpAddress, sniffedName, sizeof(sniffedName)))) { #ifdef DEBUG traceEvent(CONST_TRACE_INFO, "%s <=> %s [%s/%s]", el->hostNumIpAddress, sniffedName, el->hostResolvedName, el->hostNumIpAddress); #endif if((el->hostResolvedName[0] == '\0') || strcmp(sniffedName, el->hostResolvedName)) { if((el->hostResolvedName[0] == '\0') || (strcmp(el->hostResolvedName, el->hostNumIpAddress) == 0)) { if(strlen(sniffedName) >= (MAX_LEN_SYM_HOST_NAME-1)) sniffedName[MAX_LEN_SYM_HOST_NAME-2] = '\0'; for(i=0; i", getRowColor()); sendString(buf); sendString(makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 1, hostLinkBuf, sizeof(hostLinkBuf))); if(!myGlobals.device[myGlobals.actualReportDeviceId].dummyDevice) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n", tmpName1, tmpName3); } else { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n", tmpName1); } sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", (el->community == NULL) ? " " : el->community); sendString(buf); sendString(""); printBar(buf, sizeof(buf), el->actBandwidthUsageS, el->actBandwidthUsageR, maxBandwidthUsage, 3); if(!myGlobals.device[myGlobals.actualReportDeviceId].dummyDevice) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", tmpName2); sendString(buf); } { char shortBuf[8]; if(!subnetPseudoLocalHost(el)) { i = guessHops(el); } else i = 0; safe_snprintf(__FILE__, __LINE__, shortBuf, sizeof(shortBuf), "%d", i % 256); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", (i == 0) ? "" : shortBuf); sendString(buf); } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", (unsigned long)(el->totContactedSentPeers+el->totContactedRcvdPeers)); sendString(buf); #if 0 /* Time distance */ safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", formatLatency(el->maxLatency, FLAG_STATE_ACTIVE)); sendString(buf); #endif safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", formatSeconds(el->lastSeen - el->firstSeen, formatBuf, sizeof(formatBuf))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", formatSeconds(myGlobals.actTime-el->lastSeen, formatBuf, sizeof(formatBuf))); sendString(buf); if(el->hostAS == 0) { sendString(""); } else { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", el->hostAS, el->hostAS); sendString(buf); } sendString("\n"); printedEntries++; /* Avoid huge tables */ if(printedEntries > myGlobals.runningPref.maxNumLines) break; } else { traceEvent(CONST_TRACE_WARNING, "qsort() problem!"); } } sendString("
%s1\">Host%s%s"FLAG_DOMAIN_DUMMY_IDX_STR"\">Domain%s%s2\">IP Address%s%s11\">Community%s%s6\">Other Name(s)%s%s4\">Bandwidth%s%s7\">Hops Distance%s%s8\">Host Contacts%s%s9\">Age/Inactivity%s%s10\">AS%s
%s%s%s%s"); if(el->nonIPTraffic && displaySniffedName) { short numAddresses = 0; if(el->nonIPTraffic->nbHostName && el->nonIPTraffic->nbDomainName) { if((el->nonIPTraffic->nbAccountName != NULL) && ((el->nonIPTraffic->nbAccountName[0] != '0'))) { if((el->nonIPTraffic->nbDomainName != NULL) && (el->nonIPTraffic->nbDomainName[0] != '0')) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s %s@%s [%s]", getOSFlag(el, "Windows", 0, osBuf, sizeof(osBuf)), el->nonIPTraffic->nbAccountName, el->nonIPTraffic->nbHostName, el->nonIPTraffic->nbDomainName); } else { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s %s@%s", getOSFlag(el, "Windows", 0, osBuf, sizeof(osBuf)), el->nonIPTraffic->nbAccountName, el->nonIPTraffic->nbHostName); } } else { if((el->nonIPTraffic->nbDomainName != NULL) && (el->nonIPTraffic->nbDomainName[0] != '0')) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s %s [%s]", getOSFlag(el, "Windows", 0, osBuf, sizeof(osBuf)), el->nonIPTraffic->nbHostName, el->nonIPTraffic->nbDomainName); } else { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s %s", getOSFlag(el, "Windows", 0, osBuf, sizeof(osBuf)), el->nonIPTraffic->nbHostName); } } sendString(buf); numAddresses++; } else if(el->nonIPTraffic->nbHostName) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s %s", getOSFlag(el, "Windows", 0, osBuf, sizeof(osBuf)), el->nonIPTraffic->nbHostName); sendString(buf); numAddresses++; } if(el->nonIPTraffic->nbDescr) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), ": %s", el->nonIPTraffic->nbDescr); sendString(buf); } if(displaySniffedName) { if(numAddresses > 0) sendString("/"); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", sniffedName); sendString(buf); numAddresses++; } if(el->nonIPTraffic->atNetwork) { char *nodeName = el->nonIPTraffic->atNodeName; if(numAddresses > 0) sendString("/"); if(nodeName == NULL) nodeName = ""; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s %s ", getOSFlag(el, "Mac", 0, osBuf, sizeof(osBuf)), nodeName); sendString(buf); if(el->nonIPTraffic->atNodeType[0] != NULL) { sendString("("); for(i=0; inonIPTraffic->atNodeType[i] == NULL) break; else { if(i > 0) sendString("/"); sendString(el->nonIPTraffic->atNodeType[i]); } sendString(") "); } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "[%d.%d]", el->nonIPTraffic->atNetwork, el->nonIPTraffic->atNode); sendString(buf); numAddresses++; } if(el->nonIPTraffic->ipxHostName) { int numSap=0; if(numAddresses > 0) sendString("/"); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s %s ", getOSFlag(el, "Novell", 0, osBuf, sizeof(osBuf)), el->nonIPTraffic->ipxHostName); sendString(buf); for(i=0; inonIPTraffic->numIpxNodeTypes; i++) { char *str = getSAPInfo(el->nonIPTraffic->ipxNodeType[i], 1); if(str[0] != '\0') { if(numSap == 0) sendString("["); else sendString("/"); sendString(str); numSap++; } } if(numSap > 0) sendString("]"); numAddresses++; } } sendString(" %s %s%lu%s-", formatLatency(el->minLatency, FLAG_STATE_ACTIVE)); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s%s%s " "%d" "
"TABLE_OFF"

\n"); sendString("

\n"); printFooterHostLink(); printBandwidthFooter(); addPageIndicator(CONST_HOSTS_INFO_HTML, pageNum, numEntries, myGlobals.runningPref.maxNumLines, revertOrder, abs(sortedColumn), -1); } free(tmpTable); free(vlanList); free(ifList); } /* ************************************ */ void printAllSessionsHTML(char* host, int actualDeviceId, int sortedColumn, int revertOrder, int pageNum, char *url, int hostInfoPage) { u_int idx, i; u_int16_t vlanId = NO_VLAN; HostTraffic *el=NULL; char buf[LEN_GENERAL_WORK_BUFFER]; char formatBuf[32], portBuf[32], hostLinkBuf[LEN_GENERAL_WORK_BUFFER]; u_short found = 0, foundFcHost = 0, vsanId = 0; char *tok; if((tok = strchr(host, '-')) != NULL) { vlanId = vsanId = atoi(&tok[1]); *tok = '\0'; } for(el=getFirstHost(actualDeviceId); el != NULL; el = getNextHost(actualDeviceId, el)) { if(el->community && (!isAllowedCommunity(el->community))) continue; if(((strcmp(el->hostNumIpAddress, host) == 0) || (strcmp(el->ethAddressString, host) == 0)) && ((vlanId == NO_VLAN) || ((el->vlanId <= 0) || (el->vlanId == vlanId)))) { found = 1; break; } else if((el->fcCounters != NULL) && ((strncmp(fc_to_str ((u_int8_t *)&el->fcCounters->hostFcAddress), host, LEN_FC_ADDRESS_DISPLAY) == 0) && ((el->fcCounters->vsanId == vsanId) || (vsanId == 0)))) { found = 1; foundFcHost = 1; break; } } /* Dennis Schoen (dennis@cns.dnsalias.org) * * send 404 if we cannot generate the requested page */ if((el == NULL) || (!found)) { char errorAdditionalText[1024], whois[256]; safe_snprintf(__FILE__, __LINE__, whois, sizeof(whois), "[ Whois ]\n", host); safe_snprintf(__FILE__, __LINE__, errorAdditionalText, sizeof(errorAdditionalText), "

\"Warning\"

\n" "

" "ntop does not currently have any information about host %s %s.

" "

 

" "

This is most likely because the host information has been " "purged as inactive. You may wish to consider the -c | --sticky-hosts " "option, although that option may substantially increase memory " "requirements.

\n", host, whois); returnHTTPpageNotFound(errorAdditionalText); return; } if(el->community && (!isAllowedCommunity(el->community))) { returnHTTPpageBadCommunity(); return; } sendHTTPHeader(FLAG_HTTP_TYPE_HTML, 0, 1); /* ************************************ */ if(found && !foundFcHost) { printHostDetailedInfo(el, actualDeviceId); printHostTrafficStats(el, actualDeviceId); printHostIcmpStats(el); printHostFragmentStats(el, actualDeviceId); printHostContactedPeers(el, actualDeviceId); printHostHTTPVirtualHosts(el, actualDeviceId); printHostUsedServices(el, actualDeviceId); } else if(foundFcHost) { printHTMLheader("", NULL, 0); printFcHostHeader(el, url, revertOrder, sortedColumn, hostInfoPage); switch (hostInfoPage) { case showHostMainPage: printFcHostDetailedInfo (el, actualDeviceId); printFcHostTrafficStats (el, actualDeviceId); printFcHostContactedPeers(el, actualDeviceId); break; case showHostLunStats: if(el->fcCounters->devType != SCSI_DEV_INITIATOR) { printScsiLunStats (el, actualDeviceId, sortedColumn, revertOrder, pageNum, url); } break; case showHostLunGraphs: if(el->fcCounters->devType != SCSI_DEV_INITIATOR) { printScsiLunGraphs (el, actualDeviceId); } break; case showHostScsiSessionBytes: printScsiSessionBytes (actualDeviceId, sortedColumn, revertOrder, pageNum, url, el); break; case showHostScsiSessionTimes: printScsiSessionTimes (actualDeviceId, sortedColumn, revertOrder, pageNum, url, el); break; case showHostScsiSessionStatus: printScsiSessionStatusInfo (actualDeviceId, sortedColumn, revertOrder, pageNum, url, el); break; case showHostScsiSessionTMInfo: printScsiSessionTmInfo (actualDeviceId, sortedColumn, revertOrder, pageNum, url, el); break; case showHostFcSessions: printFCSessions (actualDeviceId, sortedColumn, revertOrder, pageNum, url, el); break; } return; } /* ***************************************************** */ i = 0; if(el->portsUsage != NULL) { for(idx=1; idx\n"); sendString(""TABLE_ON"\n" "" "" "" "" "" "" "\n"); i++; } if(svc != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "", getRowColor(), svc, idx); } else { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "", getRowColor(), idx, idx); } sendString(buf); if(ports->clientUses > 0) { /* Fix below courtesy of Andreas Pfaller */ HostTraffic tmpEl; if(emptySerial(&ports->clientUsesLastPeer)) peerHost = NULL; else peerHost = quickHostLink(ports->clientUsesLastPeer, actualDeviceId, &tmpEl); if(peerHost == NULL) { /* Courtesy of Roberto De Luca */ strncpy(webHostName, " ", sizeof(webHostName)); } else strncpy(webHostName, makeHostLink(peerHost, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), sizeof(webHostName)); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "", ports->clientUses, formatBytes(ports->clientTraffic.value, 1, formatBuf, sizeof(formatBuf)), webHostName); sendString(buf); } else sendString(""); if(ports->serverUses > 0) { HostTraffic tmpEl; if(emptySerial(&ports->serverUsesLastPeer)) peerHost = NULL; else peerHost = quickHostLink(ports->serverUsesLastPeer, actualDeviceId, &tmpEl); if(peerHost == NULL) { /* Courtesy of Roberto De Luca */ strncpy(webHostName, " ", sizeof(webHostName)); } else strncpy(webHostName, makeHostLink(peerHost, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), sizeof(webHostName)); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "", ports->serverUses, formatBytes(ports->serverTraffic.value, 1, formatBuf, sizeof(formatBuf)), webHostName); sendString(buf); } else sendString(""); } } } if(i > 0){ sendString("
IP ServicePort# Client Sess.Last Client Peer# Server Sess.Last Server Peer
%s%d
%d%d%d/%s%s  %d/%s%s
  
"TABLE_OFF"

\n"); sendString("\n"); } /* ********************************* ********************************* */ if((el->otherIpPortsRcvd[MAX_NUM_RECENT_PORTS-1] >= 0) || (el->otherIpPortsSent[MAX_NUM_RECENT_PORTS-1] >= 0)) { /* We have something to show */ int numPrinted; printSectionTitle("TCP/UDP - Traffic on Other Ports\n"); sendString("

\n"); sendString(""TABLE_ON"\n" "" "\n"); sendString("
Client PortServer Port
    "); for(idx=0, numPrinted=0; idxotherIpPortsSent[idx] >= 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "
  • %s\n", el->otherIpPortsSent[idx], getAllPortByNum(el->otherIpPortsSent[idx], portBuf, sizeof(portBuf))); sendString(buf); numPrinted++; } } if(numPrinted == 0) sendString(" "); sendString("
    "); for(idx=0, numPrinted=0; idxotherIpPortsRcvd[idx] >= 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "
  • %s\n", el->otherIpPortsRcvd[idx], getAllPortByNum(el->otherIpPortsRcvd[idx], portBuf, sizeof(portBuf))); sendString(buf); numPrinted++; } } if(numPrinted == 0) sendString(" "); sendString("
"TABLE_OFF"
"); } /* ****************************************************************** */ if((el->recentlyUsedClientPorts[MAX_NUM_RECENT_PORTS-1] >= 0) || (el->recentlyUsedServerPorts[MAX_NUM_RECENT_PORTS-1] >= 0)) { /* We have something to show */ int numPrinted; printSectionTitle("TCP/UDP Recently Used Ports\n"); sendString("
\n"); sendString(""TABLE_ON"\n" "" "\n"); sendString("
Client PortServer Port
    "); for(idx=0, numPrinted=0; idxrecentlyUsedClientPorts[idx] >= 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "
  • %s\n", el->recentlyUsedClientPorts[idx], getAllPortByNum(el->recentlyUsedClientPorts[idx], portBuf, sizeof(portBuf))); sendString(buf); numPrinted++; } } if(numPrinted == 0) sendString(" "); sendString("
    "); for(idx=0, numPrinted=0; idxrecentlyUsedServerPorts[idx] >= 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "
  • %s\n", el->recentlyUsedServerPorts[idx], getAllPortByNum(el->recentlyUsedServerPorts[idx], portBuf, sizeof(portBuf))); sendString(buf); numPrinted++; } } if(numPrinted == 0) sendString(" "); sendString("
"TABLE_OFF"
"); } /* *************************************************** */ if((el->protocolInfo != NULL) && (el->protocolInfo->fileList != NULL)) { FileList *list = el->protocolInfo->fileList; printSectionTitle("P2P Recently Exchanged Files\n"); sendString("
\n"); sendString(""TABLE_ON"\n" "\n"); sendString("
File Name
    \n"); while(list != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "
  1. %s ", list->fileName); sendString(buf); if(FD_ISSET(BITFLAG_P2P_UPLOAD_MODE, &list->fileFlags)) sendString("Upload "); if(FD_ISSET(BITFLAG_P2P_DOWNLOAD_MODE, &list->fileFlags)) sendString("Download "); list = list->next; } sendString("\n
\n"); } /* *************************************************** */ printHostSessions(el, actualDeviceId); } /* ************************************ */ void printLocalRoutersList(int actualDeviceId) { char buf[LEN_GENERAL_WORK_BUFFER], hostLinkBuf[LEN_GENERAL_WORK_BUFFER]; HostTraffic *el, *router; u_int i, j, numEntries=0; HostSerial routerList[MAX_NUM_ROUTERS]; printHTMLheader("Local Subnet Routers", NULL, 0); if(myGlobals.runningPref.dontTrustMACaddr) { printNotAvailable("-o or --no-mac"); return; } for(el=getFirstHost(actualDeviceId); el != NULL; el = getNextHost(actualDeviceId, el)) { if(el->community && (!isAllowedCommunity(el->community))) continue; if(subnetLocalHost(el)) { for(j=0; jcontactedRouters.peersSerials[j])) { short found = 0; for(i=0; icontactedRouters.peersSerials[j], &routerList[i])) { found = 1; break; } } if((found == 0) && (numEntries < MAX_NUM_ROUTERS)) { routerList[numEntries++] = el->contactedRouters.peersSerials[j]; } } } } /* for */ if(numEntries == 0) { printNoDataYet(); return; } else { sendString("
\n"); sendString(""TABLE_ON"" "\n"); for(i=0; i\n"); } } sendString("
Router NameUsed by
%s
    \n", getRowColor(), makeHostLink(router, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf))); sendString(buf); for(el=getFirstHost(actualDeviceId); el != NULL; el = getNextHost(actualDeviceId, el)) { if(el->community && (!isAllowedCommunity(el->community))) continue; if(subnetLocalHost(el)) { for(j=0; jcontactedRouters.peersSerials[j], &routerList[i])) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "
  • %s
  • \n", makeHostLink(el, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf))); sendString(buf); break; } } } sendString("
"TABLE_OFF"\n"); sendString("
\n"); printHostColorCode(FALSE, 0); printFooterHostLink(); } } /* ************************************ */ void printIpAccounting(int remoteToLocal, int sortedColumn, int revertOrder, int pageNum) { u_int idx, numEntries=0, maxHosts; int printedEntries=0; HostTraffic *el, **tmpTable; char buf[LEN_GENERAL_WORK_BUFFER], *str=NULL, *sign, *title=NULL; Counter totalBytesSent, totalBytesRcvd, totalBytes, a=0, b=0; float sentpct, rcvdpct; time_t timeDiff = time(NULL)-myGlobals.initialSniffTime; char *arrowGif, *arrow[48], *theAnchor[48], hostLinkBuf[LEN_GENERAL_WORK_BUFFER]; char htmlAnchor[64], htmlAnchor1[64]; char formatBuf[32], formatBuf1[32], formatBuf2[32], formatBuf3[32]; switch(remoteToLocal) { case FLAG_REMOTE_TO_LOCAL_ACCOUNTING: str = CONST_IP_R_2_L_HTML; title = "Remote to Local IP Traffic"; break; case FLAG_REMOTE_TO_REMOTE_ACCOUNTING: str = CONST_IP_R_2_R_HTML; title = "Remote to Remote IP Traffic"; break; case FLAG_LOCAL_TO_REMOTE_ACCOUNTING: str = CONST_IP_L_2_R_HTML; title = "Local to Remote IP Traffic"; break; case FLAG_LOCAL_TO_LOCAL_ACCOUNTING: str = CONST_IP_L_2_L_HTML; title = "Local IP Traffic"; break; } printHTMLheader(title, NULL, 0); if(revertOrder) { sign = ""; arrowGif = " " CONST_IMG_ARROW_UP; } else { sign = "-"; arrowGif = " " CONST_IMG_ARROW_DOWN; } totalBytesSent=0, totalBytesRcvd=0; maxHosts = myGlobals.device[myGlobals.actualReportDeviceId].hostsno; /* save it as it can change */ tmpTable = (HostTraffic**)mallocAndInitWithReportWarn(maxHosts*sizeof(HostTraffic*), "printIpAccounting"); if(tmpTable == NULL) return; for(el=getFirstHost(myGlobals.actualReportDeviceId); el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) { if((broadcastHost(el) == 0) /* No broadcast addresses please */ && (multicastHost(el) == 0) /* No multicast addresses please */ && ((el->hostNumIpAddress[0] != '\0') && (!addrnull(&el->hostIpAddress)) /* This host speaks IP */)) { if(el->community && (!isAllowedCommunity(el->community))) continue; switch(remoteToLocal) { case FLAG_REMOTE_TO_LOCAL_ACCOUNTING: if(!subnetPseudoLocalHost(el)) { if((el->bytesSentLoc.value > 0) || (el->bytesRcvdLoc.value > 0)) { tmpTable[numEntries++]=el; totalBytesSent += el->bytesSentLoc.value; totalBytesRcvd += el->bytesRcvdLoc.value; } } break; case FLAG_REMOTE_TO_REMOTE_ACCOUNTING: if(!subnetPseudoLocalHost(el)) { if((el->bytesSentRem.value > 0) || (el->bytesRcvdFromRem.value > 0)) { tmpTable[numEntries++]=el; totalBytesSent += el->bytesSentRem.value; totalBytesRcvd += el->bytesRcvdFromRem.value; } } break; case FLAG_LOCAL_TO_REMOTE_ACCOUNTING: if(subnetPseudoLocalHost(el)) { if((el->bytesSentRem.value > 0) || (el->bytesRcvdFromRem.value > 0)) { tmpTable[numEntries++]=el; totalBytesSent += el->bytesSentRem.value; totalBytesRcvd += el->bytesRcvdFromRem.value; } } break; case FLAG_LOCAL_TO_LOCAL_ACCOUNTING: if(subnetPseudoLocalHost(el)) { if((el->bytesSentLoc.value > 0) || (el->bytesRcvdLoc.value > 0)) { tmpTable[numEntries++]=el; totalBytesSent += el->bytesSentLoc.value; totalBytesRcvd += el->bytesRcvdLoc.value; } } break; } if(numEntries >= maxHosts) break; } } if(numEntries > 0) { int i; myGlobals.columnSort = sortedColumn; myGlobals.sortFilter = remoteToLocal; qsort(tmpTable, numEntries, sizeof(HostTraffic*), cmpHostsFctn); safe_snprintf(__FILE__, __LINE__, htmlAnchor, sizeof(htmlAnchor), "\n"); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), ""TABLE_ON"\n" "" "\n" "" "\n", theAnchor[1], arrow[1], theAnchor[2], arrow[2], theAnchor[3], arrow[3], theAnchor[4], arrow[4]); sendString(buf); for(idx=pageNum*myGlobals.runningPref.maxNumLines; idxhostNumIpAddress; if((tmpName1[0] == '\0') || (strcmp(tmpName1, "0.0.0.0") == 0)) tmpName1 = myGlobals.separator; switch(remoteToLocal) { case FLAG_REMOTE_TO_LOCAL_ACCOUNTING: a = el->bytesSentLoc.value; b = el->bytesRcvdLoc.value; break; case FLAG_REMOTE_TO_REMOTE_ACCOUNTING: a = el->bytesSentRem.value; b = el->bytesRcvdFromRem.value; break; case FLAG_LOCAL_TO_REMOTE_ACCOUNTING: a = el->bytesSentRem.value; b = el->bytesRcvdFromRem.value; break; case FLAG_LOCAL_TO_LOCAL_ACCOUNTING: a = el->bytesSentLoc.value; b = el->bytesRcvdLoc.value; break; } if(a < 100) /* Avoid very small decimal values */ sentpct = 0; else sentpct = (100*(float)a)/totalBytesSent; if(b < 100) /* Avoid very small decimal values */ rcvdpct = 0; else rcvdpct = (100*(float)b)/totalBytesRcvd; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "%s" "" "\n", getRowColor(), makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), tmpName1, formatBytes(a, 1, formatBuf, sizeof(formatBuf)), sentpct, myGlobals.separator, formatBytes(b, 1, formatBuf1, sizeof(formatBuf1)), rcvdpct, myGlobals.separator); sendString(buf); /* Avoid huge tables */ if(printedEntries++ > myGlobals.runningPref.maxNumLines) break; } } sendString("
" "%s1>Host%s%s2>IP Address%s%s3>Data Sent%s%s4>Data Rcvd%s
%s%s%.1f%s%%%s%.1f%s%%
"TABLE_OFF"\n"); addPageIndicator(str, pageNum, numEntries, myGlobals.runningPref.maxNumLines, revertOrder, abs(sortedColumn), -1); sendString("

"TABLE_ON"\n" "\n" "\n"); totalBytes = totalBytesSent+totalBytesRcvd; /* In this case the total traffic is just half and the following statement holds: totalBytesSent == totalBytesRcvd Courtesy of Jac Engel */ if(remoteToLocal == FLAG_LOCAL_TO_LOCAL_ACCOUNTING) totalBytes /= 2; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "" "" "\n", formatBytes(totalBytes, 1, formatBuf, sizeof(formatBuf)), formatBytes(totalBytesSent, 1, formatBuf1, sizeof(formatBuf1)), formatBytes(totalBytesRcvd, 1, formatBuf2, sizeof(formatBuf2)), formatThroughput((float)(totalBytes/timeDiff), 1, formatBuf3, sizeof(formatBuf3))); sendString(buf); sendString("
Total TrafficData SentData RcvdUsed Bandwidth
%s%s%s%s
"TABLE_OFF"\n"); sendString("\n"); printFooterHostLink(); } else printNoDataYet(); free(tmpTable); } /* ********************************** */ static char* print_flags(IPSession *session, char *buf, int buf_len) { snprintf(buf, buf_len,"%s%s%s%s%s ", (session->lastFlags & TH_SYN) ? " SYN" : "", (session->lastFlags & TH_ACK) ? " ACK" : "", (session->lastFlags & TH_FIN) ? " FIN" : "", (session->lastFlags & TH_RST) ? " RST" : "", (session->lastFlags & TH_PUSH) ? " PUSH" : ""); return(buf); } /* ********************************** */ void printActiveTCPSessions(int actualDeviceId, int pageNum, HostTraffic *el) { int idx; char buf[1500], hostLinkBuf[LEN_GENERAL_WORK_BUFFER], flags_buf[64], hostLinkBuf1[LEN_GENERAL_WORK_BUFFER], *voipStr; int numSessions, printedSessions; char formatBuf[64], formatBuf1[64], formatBuf2[64], formatBuf3[64], formatBuf4[64], formatBuf5[64], formatBuf6[64]; if(!myGlobals.runningPref.enableSessionHandling) { if(el != NULL) return; printHTMLheader("Active TCP/UDP Sessions", NULL, 0); printNotAvailable("-z or --disable-sessions"); return; } if((myGlobals.device[actualDeviceId].tcpSession == NULL) || (myGlobals.device[actualDeviceId].numTcpSessions == 0)) { if(el != NULL) return; printHTMLheader("Active TCP/UDP Sessions", NULL, 0); printNoDataYet(); return; } /* Due to the way sessions are handled, sessions before those to display need to be skipped */ for(idx=1, numSessions=0, printedSessions=0; idx= el->numHostSessions)) break; accessMutex(&myGlobals.tcpSessionsMutex, "printActiveTCPSessions"); if(myGlobals.device[myGlobals.actualReportDeviceId].tcpSession[idx] != NULL) { char *sport, *dport; Counter dataSent, dataRcvd; IPSession *session = myGlobals.device[myGlobals.actualReportDeviceId].tcpSession[idx]; while((session != NULL) && (printedSessions < myGlobals.runningPref.maxNumLines)) { #ifndef PARM_PRINT_ALL_SESSIONS if(session->sessionState != FLAG_STATE_ACTIVE) { session = session->next; continue; } #endif if(el && (session->initiator != el) && (session->remotePeer != el)) { session = session->next; continue; } if((numSessions++) < pageNum*myGlobals.runningPref.maxNumLines) { session = session->next; continue; } if(printedSessions == 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%d Active TCP/UDP Sessions", myGlobals.device[actualDeviceId].numTcpSessions); if(el == NULL) printHTMLheader(buf, NULL, 0); else printSectionTitle(buf); sendString("

\n" ""TABLE_ON"" "" "" "" "" "" "" "" "" "" "" ""); #ifdef PARM_PRINT_ALL_SESSIONS sendString(""); #endif sendString("\n"); } sport = getPortByNum(session->sport, IPPROTO_TCP); dport = getPortByNum(session->dport, IPPROTO_TCP); dataSent = session->bytesSent.value; dataRcvd = session->bytesRcvd.value; if(sport == NULL) { static char _sport[8]; safe_snprintf(__FILE__, __LINE__, _sport, 8, "%d", session->sport); sport = _sport; } if(dport == NULL) { static char _dport[8]; safe_snprintf(__FILE__, __LINE__, _dport, 8, "%d", session->dport); dport = _dport; } /* Sanity check */ if((myGlobals.actTime < session->firstSeen) || (session->firstSeen == 0)) session->firstSeen = myGlobals.actTime; if((myGlobals.actTime < session->lastSeen) || (session->lastSeen == 0)) session->lastSeen = myGlobals.actTime; if((session->guessed_protocol != NULL) && session->voipSession && strstr(session->guessed_protocol, "skype")) voipStr = "/skype.gif"; else if(session->voipSession) voipStr = " <VoIP>"; else voipStr = ""; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "", getRowColor(), makeHostLink(session->initiator, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), sport, session->isP2P == 1 ? " <P2P>" : "", voipStr, makeHostLink(session->remotePeer, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0, hostLinkBuf1, sizeof(hostLinkBuf1)), dport); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "" "" "" "" "" "" "", formatBytes(dataSent, 1, formatBuf, sizeof(formatBuf)), formatBytes(dataRcvd, 1, formatBuf1, sizeof(formatBuf1)), formatTime(&(session->firstSeen), formatBuf2, sizeof(formatBuf2)), formatTime(&(session->lastSeen), formatBuf3, sizeof(formatBuf3)), formatSeconds(session->lastSeen-session->firstSeen, formatBuf4, sizeof(formatBuf4)), formatSeconds(myGlobals.actTime-session->lastSeen, formatBuf5, sizeof(formatBuf5)), formatLatency(session->nwLatency, session->sessionState, formatBuf6, sizeof(formatBuf6)), (session->guessed_protocol == NULL) ? " " : session->guessed_protocol, session->session_info ? session->session_info : print_flags(session, flags_buf, sizeof(flags_buf)) /* " " */); sendString(buf); #ifdef PARM_PRINT_ALL_SESSIONS safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "", getSessionState(session)); sendString(buf); #endif sendString("\n"); session = session->next; printedSessions++; } } releaseMutex(&myGlobals.tcpSessionsMutex); } if(printedSessions > 0) { sendString("
ClientServerData SentData RcvdActive SinceLast SeenDurationInactiveLatencyL7 ProtoNoteState
%s:%s%s%s%s:%s%s%s%s%s%s%s%s%s%s
%s
"TABLE_OFF"

\n"); sendString("

\n"); if(el == NULL) addPageIndicator(CONST_ACTIVE_TCP_SESSIONS_HTML, pageNum, myGlobals.device[actualDeviceId].numTcpSessions, myGlobals.runningPref.maxNumLines, -1, 0, -1); printHostColorCode(FALSE, 0); printFooterHostLink(); } else { if(el == NULL) { printHTMLheader("Active TCP/UDP Sessions", NULL, 0); printNoDataYet(); } } } /* ********************************** */ void printIpProtocolUsage(void) { HostTraffic **hosts, *el; u_short clientPorts[MAX_ASSIGNED_IP_PORTS], serverPorts[MAX_ASSIGNED_IP_PORTS]; u_int j, idx1, hostsNum=0, numPorts=0, maxHosts; char buf[LEN_GENERAL_WORK_BUFFER], portBuf[32], hostLinkBuf[LEN_GENERAL_WORK_BUFFER]; PortUsage *ports; printHTMLheader("TCP/UDP: Local Protocol Usage", NULL, 0); memset(clientPorts, 0, sizeof(clientPorts)); memset(serverPorts, 0, sizeof(serverPorts)); hosts = (HostTraffic**)mallocAndInitWithReportWarn(myGlobals.device[myGlobals.actualReportDeviceId]. hostsno*sizeof(HostTraffic*), "printIpProtocolUsage"); if(hosts == NULL) return; maxHosts = myGlobals.device[myGlobals.actualReportDeviceId].hostsno; for(el=getFirstHost(myGlobals.actualReportDeviceId); el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) { if(el->community && (!isAllowedCommunity(el->community))) continue; if(subnetPseudoLocalHost(el) && (el->hostNumIpAddress[0] != '\0')) { hosts[hostsNum++] = el; if(el->portsUsage != NULL) { ports = el->portsUsage; while(ports) { j = ports->port; if((clientPorts[j] == 0) && (serverPorts[j] == 0)) numPorts++; clientPorts[j] += ports->clientUses; serverPorts[j] += ports->serverUses; ports = ports->next; } } } if(hostsNum >= maxHosts) break; } /* for */ if(numPorts == 0) { printNoDataYet(); free(hosts); return; } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "

Reporting on actual traffic for %d host(s) on %d service port(s)

\n", hostsNum, numPorts); sendString(buf); /* Hosts are now in a contiguous structure (hosts[])... */ sendString("
\n"); sendString(""TABLE_ON"" "\n"); for(j=0; j 0) || (serverPorts[j] > 0)) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" ""); } /* for */ sendString("
ServiceClientsServers
%s%d\n", getRowColor(), getAllPortByNum(j, portBuf, sizeof(portBuf)), j); sendString(buf); if(clientPorts[j] > 0) { sendString("
    "); for(idx1=0; idx1portsUsage != NULL) && ports && (ports->clientUses > 0)) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "
  • %s\n", makeHostLink(hosts[idx1], FLAG_HOSTLINK_TEXT_FORMAT, 1, 0, hostLinkBuf, sizeof(hostLinkBuf))); sendString(buf); } } sendString("
"); } else sendString(" "); sendString("
"); if(serverPorts[j] > 0) { sendString("
    "); for(idx1=0; idx1portsUsage != NULL) && ports && (ports->serverUses > 0)) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "
  • %s\n", makeHostLink(hosts[idx1], FLAG_HOSTLINK_TEXT_FORMAT, 1, 0, hostLinkBuf, sizeof(hostLinkBuf))); sendString(buf); } } sendString("
"); } else sendString(" "); sendString("
"TABLE_OFF"

\n"); sendString("

\n"); printHostColorCode(FALSE, 0); printFooterHostLink(); free(hosts); } /* ********************************** */ void printBar(char *buf, int bufLen, unsigned short percentageS, /* or the ONLY percentage if R = FLAG_NONSPLITBAR */ unsigned short percentageR, unsigned short maxPercentage, unsigned short ratio) { /* This shouldn't happen */ if(maxPercentage > 100) { maxPercentage = 100; } if(percentageR == FLAG_NONSPLITBAR) { /* Single bar */ if(percentageS > maxPercentage) { percentageS = maxPercentage; } switch(percentageS) { case 0: safe_snprintf(__FILE__, __LINE__, buf, bufLen, " \n", getActualRowColor()); break; default: safe_snprintf(__FILE__, __LINE__, buf, bufLen, "" "\"%d%%\"" " \n", percentageS, ratio*percentageS); break; } } else { /* Could happen because of rounding */ if((percentageS+percentageR) > maxPercentage) percentageR--; if((percentageS+percentageR) > maxPercentage) percentageS--; switch(percentageS+percentageR) { case 0: safe_snprintf(__FILE__, __LINE__, buf, bufLen, " \n", getActualRowColor()); break; default: safe_snprintf(__FILE__, __LINE__, buf, bufLen, "" "\"Sent" "\"Received" " \n", percentageS, ratio*percentageS, percentageR, ratio*percentageR); break; } } sendString(buf); } /* ********************************** */ static int cmpPortsFctn(const void *_a, const void *_b) { if((_a == NULL) || (_b == NULL)) return(0); else { PortCounter *a, *b; a = *((PortCounter**)_a); b = *((PortCounter**)_b); if((a == NULL) || (b == NULL)) return(0); if((a->sent+a->rcvd) > (b->sent+b->rcvd)) return(-1); else return(1); } } /* ********************************** */ void printIpProtocolDistribution(int mode, int revertOrder, int printGraph) { int i; char buf[4*LEN_GENERAL_WORK_BUFFER], *sign; float total, partialTotal, remainingTraffic; float percentage; char formatBuf[32], formatBuf1[32], formatBuf2[32]; if(revertOrder) sign = ""; else sign = "-"; if(mode == FLAG_HOSTLINK_TEXT_FORMAT) { printSectionTitle("IP Protocol Distribution"); #ifndef EMBEDDED sendString("" "\n"); #endif printSectionTitle("Local Traffic"); total = (float)(myGlobals.device[myGlobals.actualReportDeviceId].tcpGlobalTrafficStats.local.value+ myGlobals.device[myGlobals.actualReportDeviceId].udpGlobalTrafficStats.local.value)/1024; if(total == 0) printNoDataYet(); else { sendString("
"TABLE_ON"" "" "\n"); if(total == 0) total = 1; /* Avoids divisions by zero */ remainingTraffic = 0; partialTotal = (float)myGlobals.device[myGlobals.actualReportDeviceId].tcpGlobalTrafficStats.local.value/1024; percentage = ((float)(partialTotal*100))/((float)total); printTableEntryPercentage(buf, sizeof(buf), "TCP vs. UDP", "TCP", "UDP", total, percentage, 0, 0); sendString("
IP ProtocolData" "Percentage
"TABLE_OFF"

\n"); sendString(""TABLE_ON"" "" "\n"); for(i=0; i 0) { remainingTraffic += partialTotal; percentage = ((float)(partialTotal*100))/((float)total); printTableEntry(buf, sizeof(buf), myGlobals.ipTrafficProtosNames[i], CONST_COLOR_1, partialTotal, percentage, 0, 0, 0); } } if(total > remainingTraffic) remainingTraffic = total - remainingTraffic; else remainingTraffic = 0; if(remainingTraffic > 0) { percentage = ((float)(remainingTraffic*100))/((float)total); printTableEntry(buf, sizeof(buf), "Other TCP/UDP-based Protocols", CONST_COLOR_1, remainingTraffic, percentage, 0, 0, 0); } sendString("
TCP/UDP ProtocolData" "Percentage
"TABLE_OFF"

\n"); sendString("

\n"); } /* ********************************************************** */ total = (float)(myGlobals.device[myGlobals.actualReportDeviceId].tcpGlobalTrafficStats.remote2local.value+ myGlobals.device[myGlobals.actualReportDeviceId].udpGlobalTrafficStats.remote2local.value)/1024; printSectionTitle("Remote to Local Traffic"); if(total == 0) printNoDataYet(); else { sendString("
\n"); sendString(""TABLE_ON"" "" "\n"); if(total == 0) total = 1; /* Avoids divisions by zero */ remainingTraffic = 0; partialTotal = (float)myGlobals.device[myGlobals.actualReportDeviceId].tcpGlobalTrafficStats.remote2local.value/1024; percentage = ((float)(partialTotal*100))/((float)total); printTableEntryPercentage(buf, sizeof(buf), "TCP vs. UDP", "TCP", "UDP", total, percentage, 0, 0); sendString("
IP ProtocolData" "Percentage
"TABLE_OFF); sendString("

"TABLE_ON"" "" "\n"); for(i=0; i 0) { remainingTraffic += partialTotal; percentage = ((float)(partialTotal*100))/((float)total); printTableEntry(buf, sizeof(buf), myGlobals.ipTrafficProtosNames[i], CONST_COLOR_1, partialTotal, percentage, 0, 0, 0); } } if(total > remainingTraffic) remainingTraffic = total - remainingTraffic; else remainingTraffic = 0; if(remainingTraffic > 0) { percentage = ((float)(remainingTraffic*100))/((float)total); printTableEntry(buf, sizeof(buf), "Other TCP/UDP-based Protocols", CONST_COLOR_1, remainingTraffic, percentage, 0, 0, 0); } sendString("
TCP/UDP ProtocolData" "Percentage
"TABLE_OFF"\n

\n"); sendString("

\n"); } /* ********************************************************** */ /* Courtesy of "Burton M. Strauss III" */ printSectionTitle("Remote Traffic"); total = (float)(myGlobals.device[myGlobals.actualReportDeviceId].tcpGlobalTrafficStats.remote.value+ myGlobals.device[myGlobals.actualReportDeviceId].udpGlobalTrafficStats.remote.value)/1024; if(total == 0) printNoDataYet(); else { sendString("
"TABLE_ON"" "" "\n"); if(total == 0) total = 1; /* Avoids divisions by zero */ remainingTraffic = 0; partialTotal = (float)myGlobals.device[myGlobals.actualReportDeviceId].tcpGlobalTrafficStats.remote.value/1024; percentage = ((float)(partialTotal*100))/((float)total); printTableEntryPercentage(buf, sizeof(buf), "TCP vs. UDP", "TCP", "UDP", total, percentage, 0, 0); sendString("
IP ProtocolData" "Percentage
"TABLE_OFF"\n"); sendString("

"TABLE_ON"" "" "\n"); for(i=0; i 0) { remainingTraffic += partialTotal; percentage = ((float)(partialTotal*100))/((float)total); printTableEntry(buf, sizeof(buf), myGlobals.ipTrafficProtosNames[i], CONST_COLOR_1, partialTotal, percentage, 0, 0, 0); } } if(total > remainingTraffic) remainingTraffic = total - remainingTraffic; else remainingTraffic = 0; if(remainingTraffic > 0) { percentage = ((float)(remainingTraffic*100))/((float)total); printTableEntry(buf, sizeof(buf), "Other TCP/UDP-based Protocols", CONST_COLOR_1, remainingTraffic, percentage, 0, 0, 0); } sendString("
TCP/UDP ProtocolData" "Percentage
"TABLE_OFF"

\n"); sendString("

\n"); } /* ********************************************************** */ printSectionTitle("Local to Remote Traffic"); total = (float)(myGlobals.device[myGlobals.actualReportDeviceId].tcpGlobalTrafficStats.local2remote.value+ myGlobals.device[myGlobals.actualReportDeviceId].udpGlobalTrafficStats.local2remote.value)/1024; if(total == 0) printNoDataYet(); else { sendString("
\n"); sendString(""TABLE_ON"" "" "" "\n"); if(total == 0) total = 1; /* Avoids divisions by zero */ remainingTraffic = 0; partialTotal = (float)myGlobals.device[myGlobals.actualReportDeviceId]. tcpGlobalTrafficStats.local2remote.value/1024; percentage = ((float)(partialTotal*100))/((float)total); printTableEntryPercentage(buf, sizeof(buf), "TCP vs. UDP", "TCP", "UDP", total, percentage, 0, 0); sendString("
IP ProtocolDataPercentage
"TABLE_OFF); sendString("

"TABLE_ON"" "" "" "\n"); for(i=0; i 0) { remainingTraffic += partialTotal; percentage = ((float)(partialTotal*100))/((float)total); printTableEntry(buf, sizeof(buf), myGlobals.ipTrafficProtosNames[i], CONST_COLOR_1, partialTotal, percentage, 0, 0, 0); } } if(total > remainingTraffic) remainingTraffic = total - remainingTraffic; else remainingTraffic = 0; if(remainingTraffic > 0) { percentage = ((float)(remainingTraffic*100))/((float)total); printTableEntry(buf, sizeof(buf), "Other IP-based Protocols", CONST_COLOR_1, remainingTraffic, percentage, 0, 0, 0); } sendString("
TCP/UDP ProtocolDataPercentage
"TABLE_OFF"

\n"); sendString("

\n"); } } else { total = (float)myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value; if(myGlobals.device[myGlobals.actualReportDeviceId].ipProtosList) { ProtocolsList *protoList = myGlobals.ipProtosList; int idx1 = 0; while(protoList != NULL) { if(total > (float)myGlobals.device[myGlobals.actualReportDeviceId].ipProtosList[idx1].value) total -= (float)myGlobals.device[myGlobals.actualReportDeviceId].ipProtosList[idx1].value; else total = 0; idx1++, protoList = protoList->next; } } if(total == 0) return; else { int numProtosFound = 0; float remainingFlows = 0; printSectionTitle("Global TCP/UDP Protocol Distribution"); sendString("
\n"); sendString(""TABLE_ON"" "" "\n"); remainingTraffic = 0; for(i=0; i 0) { remainingTraffic += partialTotal; percentage = ((float)(partialTotal*100))/((float)total); numProtosFound++; printTableEntry(buf, sizeof(buf), myGlobals.ipTrafficProtosNames[i], CONST_COLOR_1, partialTotal/1024, percentage, 1, myGlobals.device[myGlobals.actualReportDeviceId].ipProtoStats[i].totalFlows.value, 1); } } if(total > remainingTraffic) remainingTraffic = total - remainingTraffic; else remainingTraffic = 0; if(remainingTraffic > 0) { float totFlows = (float)myGlobals.device[myGlobals.actualReportDeviceId].udpGlobalTrafficStats.totalFlows.value + (float)myGlobals.device[myGlobals.actualReportDeviceId].tcpGlobalTrafficStats.totalFlows.value; if(remainingFlows > totFlows) remainingFlows = 0; else remainingFlows = totFlows - remainingFlows; percentage = ((float)(remainingTraffic*100))/((float)total); printTableEntry(buf, sizeof(buf), "Other TCP/UDP-based Protocols", CONST_COLOR_1, remainingTraffic/1024, percentage, 1, remainingFlows, 0); } #ifndef EMBEDDED if((numProtosFound > 0) && printGraph) { struct stat statbuf; if(strcmp(myGlobals.device[0].name, "pcap-file")) { sendString("\n"); /* RRD */ /* Do NOT add a '/' at the end of the path because Win32 will complain about it */ safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s/interfaces/%s", myGlobals.rrdPath != NULL ? myGlobals.rrdPath : ".", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName); revertSlashIfWIN32(buf, 0); if((i = stat(buf, &statbuf)) == 0) { time_t now = time(NULL); u_char found = 0; /* We need to check whether there are interesting rrd files in the directory */ DIR* directoryPointer = opendir(buf); if(directoryPointer != NULL) { struct dirent* dp; i = 0; while((dp = readdir(directoryPointer)) != NULL) { int len = strlen(dp->d_name); if(dp->d_name[0] == '.') continue; else if(len < 7 /* IP_ + .rrd */ ) continue; else if(strncmp(dp->d_name, "IP_", 3)) continue; else if(strstr(dp->d_name, "Flows")) continue; else found = 1; } } if(found) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, (u_int)(now - 12 * 3600), (u_int)now); sendString(buf); } sendString("\n"); } } } #endif sendString("\n"); sendString("
" "TCP/UDP ProtocolDataFlows" "Accumulated Percentage / Historical Protocol View
Accumulated View" "
Historical View" "
", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "
" "Note:\n" "
  • What is a flow?
    • TCP: a flows is a TCP connection." "
    • UDP: a flow is a set of packets with the same protocol/peers/port.
    " "
  • TCP flows are not accounted for fully (sender and recipient) remote peers." "
" "
"TABLE_OFF"

\n"); /* *********************** */ if((remainingTraffic > 0) && printGraph) { PortCounter **ipPorts; int idx = 0; ipPorts = (PortCounter**)calloc(MAX_IP_PORT, sizeof(PortCounter*)); for(i=0; i 0) { printSectionTitle("TCP/UDP Traffic Port Distribution:
Last Minute View"); sendString(""TABLE_ON"" "" ""); qsort(ipPorts, idx, sizeof(PortCounter**), cmpPortsFctn); if(idx > 32) idx = 32; /* Limit to 32 entries max */ for(i=0; iport, portBuf, sizeof(portBuf)); if(symPort == NULL) symPort = ""; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "" "" "" "\n", getRowColor(), ipPorts[i]->port, symPort, ipPorts[i]->port, formatBytes(ipPorts[i]->sent+ipPorts[i]->rcvd, 1, formatBuf, sizeof(formatBuf)), formatBytes(ipPorts[i]->sent, 1, formatBuf1, sizeof(formatBuf1)), formatBytes(ipPorts[i]->rcvd, 1, formatBuf2, sizeof(formatBuf2))); sendString(buf); } } /* for */ sendString("\n"); } free(ipPorts); sendString("
TCP/UDP PortTotalSentRcvd
%s" "%d%s%s%s
Notes:
    " "
  • sum(total traffic per port) = 2*(total IP traffic)" "
    because the traffic per port is counted twice (sent and received)" "
  • This report includes broadcast packets
"TABLE_OFF"

\n"); if(idx >= 32) sendString("

This extract is just a sample of the packets ntop has seen.

"); } else { sendString("

Note: This report includes broadcast packets.

\n"); sendString("\n"); } } } } /* ************************ */ void printProtoTraffic(int printGraph) { float total, perc; char buf[2*LEN_GENERAL_WORK_BUFFER], formatBuf[32]; total = myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value/1024; /* total is expressed in KBytes.value */ if(total == 0) return; sendString("
\n"); if(myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value > 0) { printSectionTitle("Global Protocol Distribution"); sendString("

"TABLE_ON"" "\n"); perc = 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value); if(perc > 100) perc = 100; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" ""); } else printGraph = 0; printTableEntry(buf, sizeof(buf), "(R)ARP", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].arpRarpBytes.value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].arpRarpBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value), 0, 0, 0); printTableEntry(buf, sizeof(buf), "DLC", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].dlcBytes.value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].dlcBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value), 0, 0, 0); printTableEntry(buf, sizeof(buf), "IPX", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].ipxBytes.value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].ipxBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value), 0, 0, 0); printTableEntry(buf, sizeof(buf), "Decnet", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].decnetBytes.value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].decnetBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value), 0, 0, 0); printTableEntry(buf, sizeof(buf), "AppleTalk", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].atalkBytes.value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].atalkBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value), 0, 0, 0); printTableEntry(buf, sizeof(buf), "NetBios", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].netbiosBytes.value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].netbiosBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value), 0, 0, 0); printTableEntry(buf, sizeof(buf), "OSI", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].osiBytes.value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].osiBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value), 0, 0, 0); printTableEntry(buf, sizeof(buf), "IPv6", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].ipv6Bytes.value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].ipv6Bytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value), 0, 0, 0); printTableEntry(buf, sizeof(buf), "STP", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].stpBytes.value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].stpBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value), 0, 0, 0); printTableEntry(buf, sizeof(buf), "Other", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].otherBytes.value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].otherBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value), 0, 0, 0); #ifndef EMBEDDED if(printGraph) { sendString("\n"); } #endif sendString("
ProtocolDataPercentage
IP%s" "%.1f%%" "", getRowColor(), formatBytes(myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value, 1, formatBuf, sizeof(formatBuf)), perc); sendString(buf); printTableEntry(buf, sizeof(buf), "TCP", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].tcpBytes.value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].tcpBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value), 0, 0, 0); printTableEntry(buf, sizeof(buf), "UDP", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].udpBytes.value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].udpBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value), 0, 0, 0); printTableEntry(buf, sizeof(buf), "ICMP", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].icmpBytes.value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].icmpBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value), 0, 0, 0); printTableEntry(buf, sizeof(buf), "ICMPv6", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].icmp6Bytes.value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].icmp6Bytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value), 0, 0, 0); if(myGlobals.device[myGlobals.actualReportDeviceId].ipProtosList) { ProtocolsList *protoList = myGlobals.ipProtosList; int idx = 0; while(protoList != NULL) { printTableEntry(buf, sizeof(buf), protoList->protocolName, CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].ipProtosList[idx].value/1024, 100*((float)myGlobals.device[myGlobals.actualReportDeviceId].ipProtosList[idx].value/ myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value), 0, 0, 0); idx++, protoList = protoList->next; } } printTableEntry(buf, sizeof(buf), "Other IP", CONST_COLOR_1, (float)myGlobals.device[myGlobals.actualReportDeviceId].otherIpBytes.value/1024, ((float)myGlobals.device[myGlobals.actualReportDeviceId].otherIpBytes.value/ myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value), 0, 0, 0); sendString("
"TABLE_OFF"
" "" "
"TABLE_OFF"

\n"); } /* ************************ */ void printIpTrafficMatrix(void) { int i, j, numEntries=0, numConsecutiveEmptyCells; char buf[LEN_GENERAL_WORK_BUFFER], formatBuf[32], hostLinkBuf[LEN_GENERAL_WORK_BUFFER]; short *activeHosts; Counter minTraffic=(Counter)LONG_MAX, maxTraffic=0, avgTraffic; Counter avgTrafficLow, avgTrafficHigh, tmpCounter; printHTMLheader("IP Subnet Traffic Matrix", NULL, 0); if(myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix == NULL) { printFlagedWarning("Traffic matrix is not available for the selected network interface"); return; } activeHosts = (short*)mallocAndInitWithReportWarn(myGlobals.device[myGlobals.actualReportDeviceId].numHosts*sizeof(short), "printIpTrafficMatrix"); if(activeHosts == NULL) return; for(i=0; ibytesSent.value != 0)) || ((myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[id] != NULL) && (myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[id]->bytesRcvd.value != 0))) { activeHosts[i] = 1; numEntries++; break; } } if(activeHosts[i] == 1) { if(numEntries == 1) { sendString("
\n"); sendString(""TABLE_ON"\n"); } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "", getHostName(myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrixHosts[i], 1, hostLinkBuf, sizeof(hostLinkBuf))); sendString(buf); } } if(numEntries == 0) { printNoDataYet(); free(activeHosts); return; } else sendString("\n"); for(i=0; ibytesSent.value != 0) || (myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesRcvd.value != 0)))) { if(minTraffic > myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent.value) minTraffic = myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent.value; if(minTraffic > myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesRcvd.value) minTraffic = myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesRcvd.value; if(maxTraffic < myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent.value) maxTraffic = myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent.value; if(maxTraffic < myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesRcvd.value) maxTraffic = myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesRcvd.value; } } avgTraffic = (Counter)(((float)minTraffic+(float)maxTraffic)/2); avgTrafficLow = (avgTraffic*15)/100; /* 15% of the average */ avgTrafficHigh = 2*(maxTraffic/3); /* 75% of max traffic */ for(i=0; i"); for(j=0; jhostNumIpAddress, "127.0.0.1")) numConsecutiveEmptyCells++; else if(activeHosts[j] == 1) { if(myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx] == NULL) numConsecutiveEmptyCells++; else { if(numConsecutiveEmptyCells > 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n", numConsecutiveEmptyCells); sendString(buf); numConsecutiveEmptyCells = 0; } tmpCounter = myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesSent.value+ myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrix[idx]->bytesRcvd.value; /* Fix below courtesy of Danijel Doriae */ safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n", numConsecutiveEmptyCells); sendString(buf); numConsecutiveEmptyCells = 0; } sendString("\n"); } sendString("
 F " "  To
 r
 o
 m
%s
", getRowColor()); sendString(buf); sendString(makeHostLink(myGlobals.device[myGlobals.actualReportDeviceId].ipTrafficMatrixHosts[i], FLAG_HOSTLINK_TEXT_FORMAT, 1, 0, hostLinkBuf, sizeof(hostLinkBuf))); sendString(" " "%s\n", calculateCellColor(tmpCounter, avgTrafficLow, avgTrafficHigh), buildHTMLBrowserWindowsLabel(i, j, TRUE), formatBytes(tmpCounter, 1, formatBuf, sizeof(formatBuf))); sendString(buf); } } } if(numConsecutiveEmptyCells > 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), " 
"TABLE_OFF"\n

\n"); sendString("

\n"); printFooterHostLink(); free(activeHosts); } /* ************************ */ void printThptStatsMatrix(int sortedColumn) { int i, dataSent; char label[32], label1[32], buf[LEN_GENERAL_WORK_BUFFER], formatBuf[32], hostLinkBuf[LEN_GENERAL_WORK_BUFFER]; time_t tmpTime; struct tm t; HostTraffic *el; HostTraffic tmpEl; printHTMLheader("Network Load Statistics Matrix", NULL, 0); memset (&tmpEl, 0, sizeof(HostTraffic)); if(allocFcScsiCounters(&tmpEl) == NULL) { traceEvent (CONST_TRACE_WARNING, "Unable to allocate memory for FC counters"); return; } switch(sortedColumn) { case 0: case 1: if(myGlobals.device[myGlobals.actualReportDeviceId].numThptSamples < 1) { printNoDataYet(); free(tmpEl.fcCounters); return; } sendString("
\n"); sendString(""TABLE_ON"\n" "" "" "" "\n"); for(i=0; i<(sortedColumn == 0 ? 10 : 60); i++) { if(myGlobals.device[myGlobals.actualReportDeviceId].last60MinutesThpt[i].trafficValue == 0) break; if(myGlobals.runningPref.rFileName != NULL) { tmpTime = myGlobals.lastPktTime.tv_sec-(i*60); } else { tmpTime = myGlobals.actTime-(i*60); } strftime(label, sizeof(label), CONST_TOD_NOSEC_TIMESPEC, localtime_r(&tmpTime, &t)); if(myGlobals.runningPref.rFileName != NULL) { tmpTime = myGlobals.lastPktTime.tv_sec -((i+1)*60); } else { tmpTime = myGlobals.actTime-((i+1)*60); } strftime(label1, sizeof(label), CONST_TOD_NOSEC_TIMESPEC, localtime_r(&tmpTime, &t)); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "\n"); } break; case 2: default: if(myGlobals.device[myGlobals.actualReportDeviceId].numThptSamples < 60) { printNoDataYet(); free (tmpEl.fcCounters); return; } else { sendString("
\n"); sendString(""TABLE_ON"
Sampling PeriodAverage ThptTop Hosts Sent ThptTop Hosts Rcvd Thpt
" "%s - %s%s" "", getRowColor(), label1, label, formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId]. last60MinutesThpt[i].trafficValue, 1, formatBuf, sizeof(formatBuf))); sendString(buf); dataSent = 0; /* ************************* */ if(!emptySerial(&myGlobals.device[myGlobals.actualReportDeviceId].last60MinutesThpt[i].topHostSentSerial)) { if((el = quickHostLink(myGlobals.device[myGlobals.actualReportDeviceId]. last60MinutesThpt[i].topHostSentSerial, myGlobals.actualReportDeviceId, &tmpEl)) != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s\n", makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId]. last60MinutesThpt[i].topSentTraffic.value, 1, formatBuf, sizeof(formatBuf))); sendString(buf); dataSent = 1; } } if(!emptySerial(&myGlobals.device[myGlobals.actualReportDeviceId].last60MinutesThpt[i].secondHostSentSerial)) { if((el = quickHostLink(myGlobals.device[myGlobals.actualReportDeviceId]. last60MinutesThpt[i].secondHostSentSerial, myGlobals.actualReportDeviceId, &tmpEl)) != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s\n", makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId]. last60MinutesThpt[i].secondSentTraffic.value, 1, formatBuf, sizeof(formatBuf))); sendString(buf); dataSent = 1; } } if(!emptySerial(&myGlobals.device[myGlobals.actualReportDeviceId].last60MinutesThpt[i].thirdHostSentSerial)) { if((el = quickHostLink(myGlobals.device[myGlobals.actualReportDeviceId]. last60MinutesThpt[i].thirdHostSentSerial, myGlobals.actualReportDeviceId, &tmpEl)) != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s\n", makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId]. last60MinutesThpt[i].thirdSentTraffic.value, 1, formatBuf, sizeof(formatBuf))); sendString(buf); dataSent = 1; } } /* ************************* */ if(!dataSent) sendString(" "); sendString("
%s
%s
%s
"TABLE_OFF"
\n"); dataSent = 0; /* ************************* */ if(!emptySerial(&myGlobals.device[myGlobals.actualReportDeviceId].last60MinutesThpt[i].topHostRcvdSerial)) { if((el = quickHostLink(myGlobals.device[myGlobals.actualReportDeviceId]. last60MinutesThpt[i].topHostRcvdSerial, myGlobals.actualReportDeviceId, &tmpEl)) != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s\n", makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId]. last60MinutesThpt[i].topRcvdTraffic.value, 1, formatBuf, sizeof(formatBuf))); sendString(buf); dataSent = 1; } } if(!emptySerial(&myGlobals.device[myGlobals.actualReportDeviceId].last60MinutesThpt[i].secondHostRcvdSerial)) { if((el = quickHostLink(myGlobals.device[myGlobals.actualReportDeviceId]. last60MinutesThpt[i].secondHostRcvdSerial, myGlobals.actualReportDeviceId, &tmpEl)) != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s\n", makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId]. last60MinutesThpt[i].secondRcvdTraffic.value, 1, formatBuf, sizeof(formatBuf))); sendString(buf); dataSent = 1; } } if(!emptySerial(&myGlobals.device[myGlobals.actualReportDeviceId].last60MinutesThpt[i].thirdHostRcvdSerial)) { if((el = quickHostLink(myGlobals.device[myGlobals.actualReportDeviceId]. last60MinutesThpt[i].thirdHostRcvdSerial, myGlobals.actualReportDeviceId, &tmpEl)) != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s\n", makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId]. last60MinutesThpt[i].thirdRcvdTraffic.value, 1, formatBuf, sizeof(formatBuf))); sendString(buf); dataSent = 1; } } /* ************************* */ if(!dataSent) sendString(" "); sendString("
%s
%s
%s
\n" "" "" "\n"); for(i=0; i<24; i++) { if(myGlobals.device[myGlobals.actualReportDeviceId].last24HoursThpt[i].trafficValue == 0) break; if(myGlobals.runningPref.rFileName != NULL) { tmpTime = myGlobals.lastPktTime.tv_sec-(i*60*60); } else { tmpTime = myGlobals.actTime-(i*60*60); } strftime(label, sizeof(label), CONST_TOD_NOSEC_TIMESPEC, localtime_r(&tmpTime, &t)); if(myGlobals.runningPref.rFileName != NULL) { tmpTime = myGlobals.lastPktTime.tv_sec-((i+1)*60*60); } else { tmpTime = myGlobals.actTime-((i+1)*60*60); } strftime(label1, sizeof(label1), CONST_TOD_NOSEC_TIMESPEC, localtime_r(&tmpTime, &t)); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n"); } } break; } sendString("
Sampling PeriodAverage ThptTop Thpt Sent HostsTop Rcvd Sent Hosts
%s - %s" "%s"TABLE_ON"", getRowColor(), label, label1, formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId]. last24HoursThpt[i].trafficValue, 1, formatBuf, sizeof(formatBuf))); sendString(buf); /* ************************* */ if(!emptySerial(&myGlobals.device[myGlobals.actualReportDeviceId].last24HoursThpt[i].topHostSentSerial)) { if((el = quickHostLink(myGlobals.device[myGlobals.actualReportDeviceId].last24HoursThpt[i].topHostSentSerial, myGlobals.actualReportDeviceId, &tmpEl)) != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s\n", makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId]. last24HoursThpt[i].topSentTraffic.value, 1, formatBuf, sizeof(formatBuf))); sendString(buf); } } if(!emptySerial(&myGlobals.device[myGlobals.actualReportDeviceId].last24HoursThpt[i].secondHostSentSerial)) { if((el = quickHostLink(myGlobals.device[myGlobals.actualReportDeviceId].last24HoursThpt[i].secondHostSentSerial, myGlobals.actualReportDeviceId, &tmpEl)) != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s\n", makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId]. last24HoursThpt[i].secondSentTraffic.value, 1, formatBuf, sizeof(formatBuf))); sendString(buf); } } if(!emptySerial(&myGlobals.device[myGlobals.actualReportDeviceId].last24HoursThpt[i].thirdHostSentSerial)) { if((el = quickHostLink(myGlobals.device[myGlobals.actualReportDeviceId].last24HoursThpt[i].thirdHostSentSerial, myGlobals.actualReportDeviceId, &tmpEl)) != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s\n", makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId]. last24HoursThpt[i].thirdSentTraffic.value, 1, formatBuf, sizeof(formatBuf))); sendString(buf); } } /* ************************* */ sendString(" "); sendString("
%s
%s
%s
"TABLE_OFF"
"TABLE_ON"\n"); /* ************************* */ if(!emptySerial(&myGlobals.device[myGlobals.actualReportDeviceId].last24HoursThpt[i].topHostRcvdSerial)) { if((el = quickHostLink(myGlobals.device[myGlobals.actualReportDeviceId].last24HoursThpt[i].topHostRcvdSerial, myGlobals.actualReportDeviceId, &tmpEl)) != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s\n", makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId]. last24HoursThpt[i].topRcvdTraffic.value, 1, formatBuf, sizeof(formatBuf))); sendString(buf); } } if(!emptySerial(&myGlobals.device[myGlobals.actualReportDeviceId].last24HoursThpt[i].secondHostRcvdSerial)) { if((el = quickHostLink(myGlobals.device[myGlobals.actualReportDeviceId].last24HoursThpt[i].secondHostRcvdSerial, myGlobals.actualReportDeviceId, &tmpEl)) != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s\n", makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId]. last24HoursThpt[i].secondRcvdTraffic.value, 1, formatBuf, sizeof(formatBuf))); sendString(buf); } } if(!emptySerial(&myGlobals.device[myGlobals.actualReportDeviceId].last24HoursThpt[i].thirdHostRcvdSerial)) { if((el = quickHostLink(myGlobals.device[myGlobals.actualReportDeviceId].last24HoursThpt[i].thirdHostRcvdSerial, myGlobals.actualReportDeviceId, &tmpEl)) != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s\n", makeHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), formatThroughput(myGlobals.device[myGlobals.actualReportDeviceId]. last24HoursThpt[i].thirdRcvdTraffic.value, 1, formatBuf, sizeof(formatBuf))); sendString(buf); } } /* ************************* */ sendString(" "); sendString("
%s
%s
%s
"TABLE_OFF"
"TABLE_OFF"
\n"); free (tmpEl.fcCounters); } /* ************************ */ #define RRD_THPT_URL "/plugins/rrdPlugin?action=arbreq&which=graph&arbfile=throughput&arbiface=%s&arbip=&start=%u&end=%u&counter=&title=%s" #define RRD_THPT_STR "
\"Domain-wide " void printThptStats(int sortedColumn _UNUSED_) { char tmpBuf[1024], formatBuf[32], formatBuf1[32]; struct stat statbuf; int i, useRRD = 1; time_t now = time(NULL); printHTMLheader("Network Load Statistics", NULL, 0); if(strcmp(myGlobals.device[0].name, "pcap-file")) { /* if(myGlobals.device[myGlobals.actualReportDeviceId].dummyDevice) { printFlagedWarning("Network load statistics are not available for virtual interfaces"); return; } */ /* Do NOT add a '/' at the end of the path because Win32 will complain about it */ #ifdef WIN32 { unsigned long driveSerial; get_serial(&driveSerial); safe_snprintf(__FILE__, __LINE__, tmpBuf, sizeof(tmpBuf), "%s/%u/interfaces/%s/throughput.rrd", myGlobals.rrdPath != NULL ? myGlobals.spoolPath : ".", driveSerial, myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName); } #else safe_snprintf(__FILE__, __LINE__, tmpBuf, sizeof(tmpBuf), "%s/interfaces/%s/throughput.rrd", myGlobals.rrdPath != NULL ? myGlobals.spoolPath : ".", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName); #endif revertSlashIfWIN32(tmpBuf, 0); if((i = stat(tmpBuf, &statbuf)) != 0) { useRRD = 0; sendString("

NOTE: this page is not operational when the RRD plugin " "is disabled, misconfigured or missing. Please check the ntop log file.

"); return; } if(useRRD) { sendString("
\n\n"); safe_snprintf(__FILE__, __LINE__, tmpBuf, sizeof(tmpBuf), RRD_THPT_STR, 0, myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, (unsigned int)(now-600), (unsigned int)now, "Last+10+Minutes+Throughput", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, (unsigned int)(now-600), (unsigned int)now, "Throughput" ); sendString(tmpBuf); safe_snprintf(__FILE__, __LINE__, tmpBuf, sizeof(tmpBuf), "", formatTimeStamp(0, 0, 10, formatBuf, sizeof(formatBuf)), formatTimeStamp(0, 0, 0, formatBuf1, sizeof(formatBuf1))); sendString(tmpBuf); safe_snprintf(__FILE__, __LINE__, tmpBuf, sizeof(tmpBuf), RRD_THPT_STR, 1, myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, (unsigned int)(now-3600), (unsigned int)now, "Last+Hour+Throughput", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, (unsigned int)(now-3600), (unsigned int)now, "Throughput"); sendString(tmpBuf); } safe_snprintf(__FILE__, __LINE__, tmpBuf, sizeof(tmpBuf), "", formatTimeStamp(0, 0, 60, formatBuf, sizeof(formatBuf)), formatTimeStamp(0, 0, 0, formatBuf1, sizeof(formatBuf1))); sendString(tmpBuf); if(useRRD) { safe_snprintf(__FILE__, __LINE__, tmpBuf, sizeof(tmpBuf), RRD_THPT_STR, 2, myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, (unsigned int)(now-86400), (unsigned int)now, "Current+Day+Throughput", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, (unsigned int)(now-86400), (unsigned int)now, "Throughput"); sendString(tmpBuf); } safe_snprintf(__FILE__, __LINE__, tmpBuf, sizeof(tmpBuf), "", formatTimeStamp(0, 24, 0, formatBuf, sizeof(formatBuf)), formatTimeStamp(0, 0, 0, formatBuf1, sizeof(formatBuf1))); sendString(tmpBuf); if(useRRD) { safe_snprintf(__FILE__, __LINE__, tmpBuf, sizeof(tmpBuf), RRD_THPT_STR, 3, myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, (unsigned int)(now-86400*30), (unsigned int)now, "Last+Month+Throughput", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, (unsigned int)(now-86400*30), (unsigned int)now, "Throughput"); sendString(tmpBuf); } safe_snprintf(__FILE__, __LINE__, tmpBuf, sizeof(tmpBuf), "", formatTimeStamp(30, 0, 0, formatBuf, sizeof(formatBuf)), formatTimeStamp( 0, 0, 0, formatBuf1, sizeof(formatBuf1))); sendString(tmpBuf); sendString("

Time [ %s through %s]

Time [ %s through %s]

Time [ %s through %s]

Time [ %s through %s]

\n"); if(useRRD) { safe_snprintf(__FILE__, __LINE__, tmpBuf, sizeof(tmpBuf), "

" "[ Change Throughput Granularity ]

", formatTimeStamp(0, 0, 10, formatBuf, sizeof(formatBuf)), formatTimeStamp(0, 0, 0, formatBuf1, sizeof(formatBuf1))); sendString(tmpBuf); } } sendString("

NOTE: this page is not operational when the RRD plugin is disabled, misconfigured or missing.

"); } /* ************************ */ static int cmpStatsFctn(const void *_a, const void *_b) { DomainStats *a = (DomainStats *)_a; DomainStats *b = (DomainStats *)_b; Counter a_, b_; int rc; if((a == NULL) && (b != NULL)) { traceEvent(CONST_TRACE_WARNING, "cmpStatsFctn() (1)"); return(1); } else if((a != NULL) && (b == NULL)) { traceEvent(CONST_TRACE_WARNING, "cmpStatsFctn() (2)"); return(-1); } else if((a == NULL) && (b == NULL)) { traceEvent(CONST_TRACE_WARNING, "cmpStatsFctn() (3)"); return(0); } /* traceEvent(CONST_TRACE_INFO, "--> [columnSort=%d][network_mode_sort=%d]", myGlobals.columnSort, network_mode_sort); */ switch(myGlobals.columnSort) { case 0: if(network_mode_sort == NETWORK_VIEW) { char buf1[64], buf2[64]; char *nw_name_a = host2networkName(a->domainHost, buf1, sizeof(buf1)); char *nw_name_b = host2networkName(b->domainHost, buf2, sizeof(buf2)); rc = strcmp(nw_name_a, nw_name_b); } else if(network_mode_sort == AS_VIEW) { a_ = a->domainHost->hostAS , b_ = b->domainHost->hostAS; } else { /* Host */ return(cmpFctnResolvedName(&(a->domainHost), &(b->domainHost))); } break; case 1: /* Domain Flag */ /* We don't worry about whether this is single or multi domain, since if it is a single domain, our fallback to hostResolvedName will rule anyway. */ if(a->clusterName && b->clusterName) rc = strcmp(a->clusterName, b->clusterName); else rc = cmpFctnLocationName(a, b); return(rc); case 2: a_ = a->bytesSent.value, b_ = b->bytesSent.value; break; case 3: a_ = a->bytesRcvd.value, b_ = b->bytesRcvd.value; break; case 4: a_ = a->tcpSent.value , b_ = b->tcpSent.value; break; case 5: a_ = a->tcpRcvd.value , b_ = b->tcpRcvd.value; break; case 6: a_ = a->udpSent.value , b_ = b->udpSent.value; break; case 7: a_ = a->udpRcvd.value , b_ = b->udpRcvd.value; break; case 8: a_ = a->icmpSent.value , b_ = b->icmpSent.value; break; case 9: a_ = a->icmpRcvd.value , b_ = b->icmpRcvd.value; break; case 10:a_ = a->icmp6Sent.value , b_ = b->icmp6Sent.value; break; case 11:a_ = a->icmp6Rcvd.value , b_ = b->icmp6Rcvd.value; break; } if(a_ < b_) return(1); else if(a_ > b_) return(-1); else return(0); } /* ****************************************** */ #define CLUSTER_HEADER "cluster." #define CLUSTER_HEADER_LEN strlen(CLUSTER_HEADER) #define MAX_NUM_CLUSTERS 16 /* if myGlobals.runningPref.domainName == NULL -> print all domains */ void printDomainStats(char* domain_network_name, int network_mode, int clusterMode, int sortedColumn, int revertOrder, int pageNum) { u_int idx, tmpIdx, numEntries=0, printedEntries=0, maxHosts; u_short keyValue=0, i; HostTraffic *el; char buf[LEN_GENERAL_WORK_BUFFER], buf1[64]; DomainStats **stats, *tmpStats = NULL, *statsEntry; char htmlAnchor[2*LEN_GENERAL_WORK_BUFFER], htmlAnchor1[2*LEN_GENERAL_WORK_BUFFER], *sign, *arrowGif, *arrow[48], *theAnchor[48]; Counter totBytesSent=0, totBytesRcvd=0; char formatBuf[32], formatBuf1[32], formatBuf2[32], formatBuf3[32], formatBuf4[32], formatBuf5[32], formatBuf6[32], formatBuf7[32], formatBuf8[32], formatBuf9[32], hostLinkBuf[LEN_GENERAL_WORK_BUFFER]; u_int32_t localNetworks[MAX_NUM_CLUSTERS][MAX_NUM_NETWORKS][4]; /* [0]=network, [1]=mask, [2]=broadcast, [3]=mask_v6 */ u_short numLocalNetworks[MAX_NUM_CLUSTERS], totNumClusters=0; u_char *clusterNames[MAX_NUM_CLUSTERS], debug = 0; network_mode_sort = network_mode; if(!clusterMode) { char sym_nw_name[256] = { 0 }; if(domain_network_name == NULL) safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Statistics for all %s", (network_mode == NETWORK_VIEW) ? "Networks" : ((network_mode == AS_VIEW) ? "ASs" : "Domains")); else { char link_name[256] = { 0 }; if(network_mode > 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s.name.%s", (network_mode == NETWORK_VIEW) ? "network" : "as", domain_network_name); if(fetchPrefsValue(buf, sym_nw_name, sizeof(sym_nw_name)) == -1) sym_nw_name[0] = '\0'; safe_snprintf(__FILE__, __LINE__, link_name, sizeof(link_name), " %s", CONST_EDIT_PREFS, (network_mode == NETWORK_VIEW) ? "network" : "as", domain_network_name, "\"Change"); } if(network_mode == AS_VIEW) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Statistics for hosts in AS %s %s", domain_network_name, (sym_nw_name[0] == '\0') ? domain_network_name : sym_nw_name, link_name); } else if(network_mode == AS_GRAPH_VIEW) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Statistics for AS %s %s", domain_network_name, (sym_nw_name[0] == '\0') ? domain_network_name : sym_nw_name, link_name); } else { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Statistics for hosts in %s %s %s", (network_mode == NETWORK_VIEW) ? "network" : ((network_mode == AS_VIEW) ? "AS" : "domain"), (sym_nw_name[0] == '\0') ? domain_network_name : sym_nw_name, link_name); } } } else { char localAddresses[1024]; datum key, nextkey; if(domain_network_name == NULL) { key = gdbm_firstkey(myGlobals.prefsFile); while (key.dptr) { char val[256]; if((fetchPrefsValue(key.dptr, val, sizeof(val)) == 0) && (!strncmp(key.dptr, CLUSTER_HEADER, CLUSTER_HEADER_LEN))) { localAddresses[0] = '\0'; numLocalNetworks[totNumClusters] = 0; handleAddressLists(val, localNetworks[totNumClusters], &numLocalNetworks[totNumClusters], localAddresses, sizeof(localAddresses), CONST_HANDLEADDRESSLISTS_CLUSTERS); clusterNames[totNumClusters] = (u_char*)strdup((char*)&key.dptr[CLUSTER_HEADER_LEN]); totNumClusters++; } nextkey = gdbm_nextkey (myGlobals.prefsFile, key); free (key.dptr); key = nextkey; } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Statistics for all clusters"); } else { char clusterAddresses[256]; snprintf(buf, sizeof(buf), CLUSTER_HEADER"%s", domain_network_name); if(fetchPrefsValue(buf, clusterAddresses, sizeof(clusterAddresses)) != -1) { localAddresses[0] = '\0'; numLocalNetworks[totNumClusters] = 0; handleAddressLists(clusterAddresses, localNetworks[totNumClusters], &numLocalNetworks[totNumClusters], localAddresses, sizeof(localAddresses), CONST_HANDLEADDRESSLISTS_CLUSTERS); /* clusterNames[totNumClusters] = (u_char*)strdup((char*)&domain_network_name[CLUSTER_HEADER_LEN]); */ clusterNames[totNumClusters] = (u_char*)strdup(domain_network_name); if(debug) traceEvent(CONST_TRACE_WARNING, "clusterNames[%d]=[%s]", totNumClusters, clusterNames[totNumClusters]); totNumClusters++; } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Statistics for hosts in cluster %s", domain_network_name); } if(totNumClusters == 0) { printHTMLheader(buf, NULL, 0); printFlagedWarning("Empty cluster list. Jump to cluster definition."); if(tmpStats != NULL) free(tmpStats); goto free_clusters; } } if(debug) traceEvent(CONST_TRACE_WARNING, "totNumClusters=%d", totNumClusters); printHTMLheader(buf, NULL, 0); maxHosts = myGlobals.device[myGlobals.actualReportDeviceId].hostsno; /* save it as it can change */ tmpStats = (DomainStats*)mallocAndInitWithReportWarn(maxHosts*sizeof(DomainStats), "printDomainStats"); if(tmpStats == NULL) return; /* Fix below courtesy of Francis Pintos */ stats = (DomainStats**)mallocAndInitWithReportWarn(maxHosts*sizeof(DomainStats*), "printDomainStats(2)"); if(stats == NULL) { /* also free the block of memory allocated a few lines up */ if(tmpStats != NULL) free(tmpStats); goto free_clusters; return; } if(network_mode == AS_GRAPH_VIEW) { sendString("
"); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, domain_network_name); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, domain_network_name); sendString(buf); sendString("
" "\n", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, domain_network_name); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "
" "\n", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, domain_network_name); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "
\n
\n"); } else { /* traceEvent(CONST_TRACE_INFO, "'%s' '%d' '%d'", domain_network_name, sortedColumn, revertOrder); */ if((network_mode == AS_VIEW) && (domain_network_name == NULL)) { struct stat statbuf; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s/interfaces/%s/AS/numAS.rrd", myGlobals.rrdPath, myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName); if((i = stat(buf, &statbuf)) == 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "
" "", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, (unsigned int)(myGlobals.actTime-3600), (unsigned int)myGlobals.actTime, "Active+ASs"); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" " ", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, (unsigned int)(myGlobals.actTime-3600), (unsigned int)myGlobals.actTime, "Active+ASs"); sendString(buf); sendString("

 

"); } } if(revertOrder) { sign = ""; arrowGif = " " CONST_IMG_ARROW_UP; } else { sign = "-"; arrowGif = " " CONST_IMG_ARROW_DOWN; } for(el=getFirstHost(myGlobals.actualReportDeviceId); el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) { fillDomainName(el); if(network_mode) { if(network_mode == NETWORK_VIEW) { if((el->network_mask == 0) || (el->network_mask == 32)) continue; else if((domain_network_name != NULL) && (domain_network_name[0] != '\0')) { char *nw_name = host2networkName(el, buf1, sizeof(buf1)); if(strcmp(nw_name, domain_network_name)) continue; } } else { getHostAS(el); if(el->hostAS == 0) continue; else if((domain_network_name != NULL) && (domain_network_name[0] != '\0')) { if(el->hostAS != atoi(domain_network_name)) continue; } } } else { /* Cluster */ if(el->community && (!isAllowedCommunity(el->community))) continue; else if(broadcastHost(el)) continue; else { /* if(domain_network_name && el->dnsDomainValue && (strcmp(el->dnsDomainValue, domain_network_name) != 0)) continue; if((el->dnsDomainValue == NULL) || (el->dnsDomainValue[0] == '\0') || (el->ip2ccValue == NULL) || (el->hostResolvedName[0] == '\0') || (el->ip2ccValue == '\0')) continue; */ } } if(domain_network_name == NULL) /* All entries */ { if(!clusterMode) { if(network_mode == NETWORK_VIEW) { /* Network */ char *nw_name = host2networkName(el, buf1, sizeof(buf1)); for(keyValue=0, tmpIdx=0; nw_name[tmpIdx] != '\0'; tmpIdx++) keyValue += (tmpIdx+1)*(u_short)nw_name[tmpIdx]; keyValue %= maxHosts; while(stats[keyValue] != NULL) { u_int32_t a, b; a = el->hostIpAddress.Ip4Address.s_addr && (0xFFFFFFFF << (32-el->network_mask)); b = stats[keyValue]->domainHost->hostIpAddress.Ip4Address.s_addr && (0xFFFFFFFF << (32-stats[keyValue]->domainHost->network_mask)); if(a == b) break; else keyValue = (keyValue+1) % maxHosts; } } else if(network_mode == AS_VIEW) { keyValue = (el->hostAS % maxHosts); while(stats[keyValue] != NULL) { if(stats[keyValue]->domainHost->hostAS == el->hostAS) break; else keyValue = (keyValue+1) % maxHosts; } /* traceEvent(CONST_TRACE_INFO, "--> [AS=%d]", el->hostAS); */ } else { if(el->dnsDomainValue == NULL) continue; /* Domain */ for(keyValue=0, tmpIdx=0; el->dnsDomainValue[tmpIdx] != '\0'; tmpIdx++) keyValue += (tmpIdx+1)*(u_short)el->dnsDomainValue[tmpIdx]; keyValue %= maxHosts; while((stats[keyValue] != NULL) && (strcasecmp(stats[keyValue]->domainHost->dnsDomainValue, el->dnsDomainValue) != 0)) keyValue = (keyValue+1) % maxHosts; } } else { /* Cluster */ u_char found = 0; if(el->hostIpAddress.hostFamily != AF_INET) continue; keyValue = 0; all_hosts_cluster: if(debug) traceEvent(CONST_TRACE_WARNING, "[keyValue=%d][totNumClusters=%d]", keyValue, totNumClusters); for(; keyValuehostIpAddress.addr._hostIp4Address, localNetworks[keyValue], numLocalNetworks[keyValue], NULL, NULL)) { found = 1; break; } } if((!found) || (keyValue >= totNumClusters /* due to the goto */)) continue; } if(stats[keyValue] != NULL) statsEntry = stats[keyValue]; else { statsEntry = &tmpStats[numEntries++]; memset(statsEntry, 0, sizeof(DomainStats)); if(clusterMode) statsEntry->clusterName = (char*)clusterNames[keyValue]; else statsEntry->domainHost = el; stats[keyValue] = statsEntry; /* traceEvent(CONST_TRACE_INFO, "[%d] %s/%s", numEntries, el->dnsDomainValue, el->ip2ccValue); */ } } else /* Only the selected items */ { if(clusterMode) { if(!__pseudoLocalAddress(&el->hostIpAddress.addr._hostIp4Address, localNetworks[0], numLocalNetworks[0], NULL, NULL)) continue; } statsEntry = &tmpStats[numEntries++]; memset(statsEntry, 0, sizeof(DomainStats)); statsEntry->domainHost = el; if(debug) traceEvent(CONST_TRACE_INFO, "--> Adding %s [ptr=%p]", el->hostNumIpAddress, el); stats[keyValue++] = statsEntry; } totBytesSent += el->bytesSent.value; statsEntry->bytesSent.value += el->bytesSent.value; statsEntry->bytesRcvd.value += el->bytesRcvd.value; totBytesRcvd += el->bytesRcvd.value; statsEntry->tcpSent.value += el->tcpSentLoc.value + el->tcpSentRem.value; statsEntry->udpSent.value += el->udpSentLoc.value + el->udpSentRem.value; statsEntry->icmpSent.value += el->icmpSent.value; statsEntry->icmp6Sent.value += el->icmp6Sent.value; statsEntry->tcpRcvd.value += el->tcpRcvdLoc.value + el->tcpRcvdFromRem.value; statsEntry->udpRcvd.value += el->udpRcvdLoc.value + el->udpRcvdFromRem.value; statsEntry->icmpRcvd.value += el->icmpRcvd.value; statsEntry->icmp6Rcvd.value += el->icmp6Rcvd.value; /* Handle overlapping clusters */ if(keyValue < (totNumClusters-1)) { keyValue++; goto all_hosts_cluster; } if(numEntries >= maxHosts) break; } /* for(;;) */ if(numEntries == 0) { printNoDataYet(); free(tmpStats); free(stats); goto free_clusters; return; } myGlobals.columnSort = sortedColumn; if(debug) traceEvent(CONST_TRACE_WARNING, "qsort(numEntries=%d)", numEntries); qsort(tmpStats, numEntries, sizeof(DomainStats), cmpStatsFctn); /* avoid division by zero */ if(totBytesSent == 0) totBytesSent = 1; if(totBytesRcvd == 0) totBytesRcvd = 1; /* NOTE: col= must be the last parameter */ if(domain_network_name == NULL) { safe_snprintf(__FILE__, __LINE__, htmlAnchor, sizeof(htmlAnchor), " */ sendString("

\n" TABLE_ON ""); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "" "" "" "\n", theAnchor[0], arrow[0], theAnchor[1], "Domains", arrow[1]); sendString(buf); sendString( "" "" "" "" "" "" "\n" "\n"); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "" "" "" "" "" "" "" "" "" "" "\n", theAnchor[2], arrow[2], theAnchor[3], arrow[3], theAnchor[4], arrow[4], theAnchor[5], arrow[5], theAnchor[6], arrow[6], theAnchor[7], arrow[7], theAnchor[8], arrow[8], theAnchor[9], arrow[9], theAnchor[10], arrow[10], theAnchor[11], arrow[11]); sendString(buf); for(idx=pageNum*myGlobals.runningPref.maxNumLines; idxdomainHost, buf1, sizeof(buf1)); char sym_nw_name[256]; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "network.name.%s", nw_name); if(fetchPrefsValue(buf, sym_nw_name, sizeof(sym_nw_name)) == -1) sym_nw_name[0] = '\0'; safe_snprintf(__FILE__, __LINE__, htmlAnchor, sizeof(htmlAnchor), "%s", CONST_DOMAIN_STATS_HTML, nw_name, network_mode, (sym_nw_name[0] == '\0') ? nw_name : sym_nw_name); } else if(network_mode == AS_VIEW) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "as.name.%d", statsEntry->domainHost->hostAS); if(fetchPrefsValue(buf, sym_as_name, sizeof(sym_as_name)) == -1) snprintf(sym_as_name, sizeof(sym_as_name), "%d", statsEntry->domainHost->hostAS); safe_snprintf(__FILE__, __LINE__, htmlAnchor, sizeof(htmlAnchor), "%s", CONST_DOMAIN_STATS_HTML, statsEntry->domainHost->hostAS, network_mode, sym_as_name); } else safe_snprintf(__FILE__, __LINE__, htmlAnchor, sizeof(htmlAnchor), "%s", clusterMode ? CONST_CLUSTER_STATS_HTML : CONST_DOMAIN_STATS_HTML, clusterMode ? statsEntry->clusterName : statsEntry->domainHost->dnsDomainValue, clusterMode ? statsEntry->clusterName : statsEntry->domainHost->dnsDomainValue); } else { char tmpBuf[64], *hostLink; int blankId; u_int len; accessAddrResMutex("getHostIcon"); blankId = strlen(statsEntry->domainHost->hostResolvedName)-1; if(statsEntry->domainHost->dnsDomainValue != NULL) blankId -= strlen(statsEntry->domainHost->dnsDomainValue); strncpy(tmpBuf, statsEntry->domainHost->hostResolvedName, sizeof(tmpBuf)); releaseAddrResMutex(); if((blankId > 0) && (strcmp(&tmpBuf[blankId+1], domain_network_name) == 0)) tmpBuf[blankId] = '\0'; if(network_mode == AS_VIEW) { makeHostLink(statsEntry->domainHost, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0, htmlAnchor, sizeof(htmlAnchor)); } else { hostLink = makeHostLink(statsEntry->domainHost, FLAG_HOSTLINK_TEXT_FORMAT, 1, 0, hostLinkBuf, sizeof(hostLinkBuf)); len = strlen(hostLink); if(len >= sizeof(htmlAnchor)) len = sizeof(htmlAnchor)-1; strncpy(htmlAnchor, hostLink, len); htmlAnchor[len] = '\0'; } } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "" "", getRowColor(), htmlAnchor, (clusterMode && (!domain_network_name)) ? " " : getHostCountryIconURL(statsEntry->domainHost), formatBytes(statsEntry->bytesSent.value, 1, formatBuf, sizeof(formatBuf)), (100*((float)statsEntry->bytesSent.value/(float)totBytesSent)), formatBytes(statsEntry->bytesRcvd.value, 1, formatBuf1, sizeof(formatBuf1)), (100*((float)statsEntry->bytesRcvd.value/(float)totBytesRcvd))); sendString(buf); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "" "\n", formatBytes(statsEntry->tcpSent.value, 1, formatBuf2, sizeof(formatBuf2)), formatBytes(statsEntry->tcpRcvd.value, 1, formatBuf3, sizeof(formatBuf3)), formatBytes(statsEntry->udpSent.value, 1, formatBuf4, sizeof(formatBuf4)), formatBytes(statsEntry->udpRcvd.value, 1, formatBuf5, sizeof(formatBuf5)), formatBytes(statsEntry->icmpSent.value, 1, formatBuf6, sizeof(formatBuf6)), formatBytes(statsEntry->icmpRcvd.value, 1, formatBuf7, sizeof(formatBuf7)), formatBytes(statsEntry->icmp6Sent.value, 1, formatBuf8, sizeof(formatBuf8)), formatBytes(statsEntry->icmp6Rcvd.value, 1, formatBuf9, sizeof(formatBuf9))); sendString(buf); if(sym_as_name[0] != '\0') safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s/interfaces/%s/AS/%s", myGlobals.rrdPath, myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, sym_as_name); if((sym_as_name[0] != '\0') && ((i = stat(buf, &statbuf)) == 0)) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n", CONST_DOMAIN_STATS_HTML, AS_GRAPH_VIEW, sym_as_name); sendString(buf); } else if(clusterMode && statsEntry && statsEntry->clusterName) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n", statsEntry->clusterName); sendString(buf); } else sendString(""); /* Avoid huge tables */ if(printedEntries++ > myGlobals.runningPref.maxNumLines) break; } sendString("
%s0>Name%s%s1>%s%sTCP/IPICMP 
TotalTCPUDPIPv4IPv6Graphs
%s2>Sent%s%s3>Rcvd%s%s4>Sent%s%s5>Rcvd%s%s6>Sent%s%s7>Rcvd%s%s8>Sent%s%s9>Rcvd%s%s10>Sent%s%s11>Rcvd%s 
%s%s%s%.1f%%%s%.1f%%%s%s%s%s%s%s%s%s" "
" "
 
"TABLE_OFF"\n"); sendString("
\n"); if(domain_network_name != NULL) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s?dom=%s", clusterMode ? CONST_CLUSTER_STATS_HTML : CONST_DOMAIN_STATS_HTML, domain_network_name); } else { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s", clusterMode ? CONST_CLUSTER_STATS_HTML : CONST_DOMAIN_STATS_HTML); } addPageIndicator(buf, pageNum, numEntries, myGlobals.runningPref.maxNumLines, revertOrder, abs(sortedColumn), network_mode); #ifndef EMBEDDED /* FIX */ /* RRDs for domains */ if(domain_network_name != NULL) { struct stat statbufDomain; /* Do NOT add a '/' at the end of the path because Win32 will complain about it */ safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s/interfaces/%s/domains/%s", myGlobals.rrdPath != NULL ? myGlobals.rrdPath : ".", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName,domain_network_name); revertSlashIfWIN32(buf, 0); if((i = stat(buf, &statbufDomain)) == 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "

 

\n" "
" "\n" "\n" "
Show domain-wide traffic charts:" "  " "[ " "\"Domain-wide ]" "  " "
\n
\n" "

 

\n", myGlobals.device[myGlobals.actualReportDeviceId].uniqueIfName, domain_network_name,domain_network_name); sendString(buf); } } #endif if(!clusterMode) { sendString("

NOTE: "); if(network_mode == NETWORK_VIEW) sendString("Hosts without a known network are not displayed in this report\n"); else if(network_mode == AS_VIEW) sendString("AS numbers are either received via monitoring protocols (e.g. NetFlow) or read from the AS-list ntop configuration file"); else sendString("The domain is determined by simply stripping off " "the first name, so for host x.yz.com, the domain is yz.com and for host " "x.y.z.com, the domain is y.z.com.

\n"); } else { sendString("

NOTE: You can define host clusters in the ntop preferences. " "Please understand that a host cluster is an aggregated view of hosts known to ntop.

\n"); } free(tmpStats); free(stats); free_clusters: for(i=0; iNo Data To Display (yet)"); } /* ************************* */ void printNotAvailable(char * flagName) { char buf[LEN_GENERAL_WORK_BUFFER]; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "The requested data is not available when ntop is" "
started with the command line flag %s
", flagName); printFlagedWarning(buf); } /* ************************* */ void listNetFlows(void) { char buf[LEN_GENERAL_WORK_BUFFER]; int numEntries=0; FlowFilterList *list = myGlobals.flowsList; char formatBuf[32], formatBuf1[32]; printHTMLheader(NULL, NULL, 0); if(list != NULL) { while(list != NULL) { if(list->pluginStatus.activePlugin) { if(numEntries == 0) { printSectionTitle("Network Flows"); sendString("
\n"); sendString(""TABLE_ON"" ""); } safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n", getRowColor(), list->flowName, formatPkts(list->packets.value, formatBuf, sizeof(formatBuf)), formatBytes(list->bytes.value, 1, formatBuf1, sizeof(formatBuf1))); sendString(buf); numEntries++; } list = list->next; } if(numEntries > 0) sendString("
Flow NamePacketsTraffic
%s%s" "%s
"TABLE_OFF"\n"); sendString("
\n"); } sendString("

NOTE: Network flows have no relation at all with NetFlow/sFlow protocols.

\n"); if(numEntries == 0) { sendString("

No Available/Active Network Flows

" " (see man page)

\n"); } } /* *********************************** */ void printHostHourlyTraffic(HostTraffic *el) { Counter tcSent, tcRcvd; int i, hourId, j; char theDate[8], macAddr[24], vlanStr[32]; struct tm t; char buf[LEN_GENERAL_WORK_BUFFER], *targetStr; char hours[][24] = {"12 AM", "1 AM", "2 AM", "3 AM", "4 AM", "5 AM", "6 AM", "7 AM", "8 AM", "9 AM", "10 AM", "11 AM", "12 PM", "1 PM", "2 PM", "3 PM", "4 PM", "5 PM", "6 PM", "7 PM", "8 PM", "9 PM", "10 PM", "11 PM"}; if(el->trafficDistribution == NULL) return; strftime(theDate, 8, CONST_TOD_HOUR_TIMESPEC, localtime_r(&myGlobals.actTime, &t)); hourId = atoi(theDate); /* In FC, where traffic is mostly storage traffic, the word "host" has a * specific meaning (SCSI Initiator) and so we distinguish the title for * FC_Ports */ if(isFcHost (el)) { printSectionTitle("FibreChannel Port Traffic Stats"); } else { printSectionTitle("Host Traffic Stats"); } sendString("
\n"); sendString(""TABLE_ON"\n"); sendString(""); sendString(""); sendString(""); sendString(""); sendString(""); for(i=0, tcSent=0, tcRcvd=0; i<24; i++) { tcSent += el->trafficDistribution->last24HoursBytesSent[i].value; tcRcvd += el->trafficDistribution->last24HoursBytesRcvd[i].value; } for (i = 0, j = hourId; i < 24; i++) { j = j%24; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n", hours[j]); sendString(buf); printHostHourlyTrafficEntry(el, j, tcSent, tcRcvd); if(!j) j = 23; else j--; } sendString("\n"); if(isFcHost (el)) { targetStr = el->fcCounters->hostNumFcAddress; } else { safe_snprintf(__FILE__, __LINE__, macAddr, sizeof(macAddr), "%s", el->ethAddressString); targetStr = el->hostNumIpAddress[0] == '\0' ? macAddr : el->hostNumIpAddress; } urlFixupToRFC1945Inplace(targetStr); if(el->vlanId > 0) { safe_snprintf(__FILE__, __LINE__, vlanStr, sizeof(vlanStr), "-%d", el->vlanId); } else vlanStr[0] = '\0'; if(tcSent > 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n", targetStr, vlanStr); sendString(buf); } else sendString("\n"); if(tcRcvd > 0) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n", targetStr, vlanStr); sendString(buf); } else sendString("\n"); sendString("\n"); sendString("
TimeTot. Traffic Sent% Traffic SentTot. Traffic Rcvd% Traffic Rcvd
%s
Total" " " "" " 
"TABLE_OFF"\n
\n"); } /* ************************** */ static void dumpHostsCriteria(NtopInterface *ifName, u_char criteria) { u_int numEntries=0, i, maxHosts; HostTraffic **tmpTable, *el; char buf[LEN_GENERAL_WORK_BUFFER]; char formatBuf[32], formatBuf1[32], hostLinkBuf[LEN_GENERAL_WORK_BUFFER]; maxHosts = ifName->hostsno; /* save it as it can change */ tmpTable = (HostTraffic**)mallocAndInitWithReportWarn(maxHosts*sizeof(HostTraffic*), "dumpHostsCriteria"); if(tmpTable == NULL) return; switch(criteria) { case 1: /* VLAN */ myGlobals.columnSort = CONST_VLAN_COLUMN_SORT; break; } for(el=getFirstHost(myGlobals.actualReportDeviceId); el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) { if(el->community && (!isAllowedCommunity(el->community))) continue; switch(criteria) { case 1: /* VLAN */ if(el->vlanId > 0) tmpTable[numEntries++] = el; break; } if(numEntries >= maxHosts) break; } if(numEntries > 0) { int lastId = 0; Counter dataSent, dataRcvd; qsort(tmpTable, numEntries, sizeof(HostTraffic*), sortHostFctn); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "
"TABLE_ON"\n" "" "\n" "\n" "\n" "\n", "VLAN"); sendString(buf); dataSent = dataRcvd = 0; for(i=0; ivlanId)) { /* Same VLAN as last entry... just continue it */ sendString("\n
"); } else { /* New VLAN */ if(i > 0) { /* Finish prior row */ safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "
\n" "\n" "\n", formatBytes(dataSent, 1, formatBuf, sizeof(formatBuf)), formatBytes(dataRcvd, 1, formatBuf1, sizeof(formatBuf1))); sendString(buf); } /* Start new row */ dataSent = dataRcvd = 0; sendString("\n"); lastId = el->vlanId; safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n", el->vlanId); sendString(buf); sendString("\n"); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "\n" "\n", formatBytes(dataSent, 1, formatBuf, sizeof(formatBuf)), formatBytes(dataRcvd, 1, formatBuf1, sizeof(formatBuf1))); sendString(buf); } sendString("\n
%sHostsData SentData Rcvd
%s%s
%d"); } sendString(makeHostLink(el, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf))); dataSent += el->bytesSent.value; dataRcvd += el->bytesRcvd.value; } if(i>0) { sendString("%s%s
\n
"); } else { printFlagedWarning("No entries to display(yet)"); } free(tmpTable); } /* ******************************* */ void printVLANList(unsigned int deviceId) { printHTMLheader("VLAN Traffic Statistics", NULL, 0); if(deviceId > myGlobals.numDevices) { printFlagedWarning("Invalid device specified"); return; } if(myGlobals.haveVLANs == FALSE) { printFlagedWarning("No VLANs found (yet)"); return; } dumpHostsCriteria(&myGlobals.device[deviceId], 1 /* VLAN */); } /* ******************************************* */ static int recentlyUsedPort(HostTraffic *el, int portNr, int serverPort) { int i; if(el == NULL) return(0); for(i=0; irecentlyUsedServerPorts[i] == portNr) return(1); } else { if(el->recentlyUsedClientPorts[i] == portNr) return(1); } } return(0); } /* ******************************************* */ void showPortTraffic(u_short portNr) { char buf[LEN_GENERAL_WORK_BUFFER], *str; int numRecords = 0, firstRun = 1; HostTraffic *el; char portBuf[32], hostLinkBuf[LEN_GENERAL_WORK_BUFFER]; str = getAllPortByNum(portNr, portBuf, sizeof(portBuf)); if((str[0] == '?') || (atoi(str) == portNr)) { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Recent Users of Port %u", portNr); } else { safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "Recent Users of Port %u (%s)", portNr, str); } printHTMLheader(buf, NULL, 0); sendString("
\n"); for(el=getFirstHost(myGlobals.actualReportDeviceId); el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) { if(el->community && (!isAllowedCommunity(el->community))) continue; recentlyUsedPortSent: if(recentlyUsedPort(el, portNr, 0)) { if(numRecords == 0) { sendString("\n\n"); sendString("\n" "%s%s" "" "" "" "", getRowColor(), makeVsanLink (el->fcCounters->vsanId, FLAG_HOSTLINK_HTML_FORMAT, vsanBuf, sizeof(vsanBuf)), webHostName, formatBytes(el->fcCounters->fcBytesSent.value +el->fcCounters->fcBytesRcvd.value, 1, formatBuf[1], 32), totPercent, myGlobals.separator, formatBytes(el->fcCounters->fcFcpBytesSent.value +el->fcCounters->fcFcpBytesRcvd.value, 1, formatBuf[2], 32), formatBytes(el->fcCounters->fcElsBytesSent.value +el->fcCounters->fcElsBytesRcvd.value, 1, formatBuf[3], 32), formatBytes(el->fcCounters->fcDnsBytesSent.value +el->fcCounters->fcDnsBytesRcvd.value, 1, formatBuf[4], 32), formatBytes(el->fcCounters->fcIpfcBytesSent.value +el->fcCounters->fcIpfcBytesRcvd.value, 1, formatBuf[5], 32), formatBytes(el->fcCounters->fcSwilsBytesSent.value+el->fcCounters->fcSwilsBytesRcvd.value, 1, formatBuf[6], 32), formatBytes(el->fcCounters->otherFcBytesSent.value+el->fcCounters->otherFcBytesRcvd.value, 1, formatBuf[7], 32)); break; case (100*showOnlySent + SORT_FC_DATA): safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "%s%s" "" "" "" "", getRowColor(), makeVsanLink (el->fcCounters->vsanId, FLAG_HOSTLINK_HTML_FORMAT, vsanBuf, sizeof(vsanBuf)), webHostName, formatBytes(el->fcCounters->fcBytesSent.value, 1, formatBuf[1], 32), sentPercent, myGlobals.separator, formatBytes(el->fcCounters->fcFcpBytesSent.value, 1, formatBuf[2], 32), formatBytes(el->fcCounters->fcElsBytesSent.value, 1, formatBuf[3], 32), formatBytes(el->fcCounters->fcDnsBytesSent.value, 1, formatBuf[4], 32), formatBytes(el->fcCounters->fcIpfcBytesSent.value, 1, formatBuf[5], 32), formatBytes(el->fcCounters->fcSwilsBytesSent.value, 1, formatBuf[6], 32), formatBytes(el->fcCounters->otherFcBytesSent.value, 1, formatBuf[7], 32)); break; case (100*showOnlyReceived + SORT_FC_DATA): safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "%s%s" "" "" "" "", getRowColor(), makeVsanLink (el->fcCounters->vsanId, FLAG_HOSTLINK_HTML_FORMAT, vsanBuf, sizeof(vsanBuf)), webHostName, formatBytes(el->fcCounters->fcBytesRcvd.value, 1, formatBuf[1], 32), rcvdPercent, myGlobals.separator, formatBytes(el->fcCounters->fcFcpBytesRcvd.value, 1, formatBuf[2], 32), formatBytes(el->fcCounters->fcElsBytesRcvd.value, 1, formatBuf[3], 32), formatBytes(el->fcCounters->fcDnsBytesRcvd.value, 1, formatBuf[4], 32), formatBytes(el->fcCounters->fcIpfcBytesRcvd.value, 1, formatBuf[5], 32), formatBytes(el->fcCounters->fcSwilsBytesRcvd.value, 1, formatBuf[6], 32), formatBytes(el->fcCounters->otherFcBytesRcvd.value, 1, formatBuf[7], 32)); break; case (100*showSentReceived + SORT_FC_THPT): safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "%s%s" "" "" "" "" "" "", getRowColor(), makeVsanLink (el->fcCounters->vsanId, FLAG_HOSTLINK_HTML_FORMAT, vsanBuf, sizeof(vsanBuf)), webHostName, formatThroughput(el->actualTThpt, 1, formatBuf[0], 32), formatThroughput(el->averageTThpt, 1, formatBuf[1], 32), formatThroughput(el->peakTThpt, 1, formatBuf[2], 32), el->actualTPktThpt, el->averageTPktThpt, el->peakTPktThpt); break; case (100*showOnlySent + SORT_FC_THPT): safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "%s%s" "" "" "" "" "" "", getRowColor(), makeVsanLink (el->fcCounters->vsanId, FLAG_HOSTLINK_HTML_FORMAT, vsanBuf, sizeof(vsanBuf)), webHostName, formatThroughput(el->actualSentThpt, 1, formatBuf[0], 32), formatThroughput(el->averageSentThpt, 1, formatBuf[1], 32), formatThroughput(el->peakSentThpt, 1, formatBuf[2], 32), el->actualSentPktThpt, el->averageSentPktThpt, el->peakSentPktThpt); break; case (100*showOnlyReceived + SORT_FC_THPT): safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "%s%s" "" "" "" "" "" "", getRowColor(), makeVsanLink (el->fcCounters->vsanId, FLAG_HOSTLINK_HTML_FORMAT, vsanBuf, sizeof(vsanBuf)), webHostName, formatThroughput(el->actualRcvdThpt, 1, formatBuf[0], 32), formatThroughput(el->averageRcvdThpt, 1, formatBuf[1], 32), formatThroughput(el->peakRcvdThpt, 1, formatBuf[2], 32), el->actualRcvdPktThpt, el->averageRcvdPktThpt, el->peakRcvdPktThpt); break; case SORT_FC_ACTIVITY: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "" "%s%s", getRowColor(), makeVsanLink (el->fcCounters->vsanId, FLAG_HOSTLINK_HTML_FORMAT, vsanBuf, sizeof(vsanBuf)), webHostName); sendString(buf); printHostThtpShort(el, myGlobals.reportKind, hourId); buf[0]='\0'; break; } sendString(buf); sendString("\n"); /* Avoid huge tables */ if(printedEntries++ > myGlobals.runningPref.maxNumLines) break; } } sendString("\n
ClientServer
    \n"); } sendString("\n
  • "); sendString(makeHostLink(el, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf))); numRecords++; } if(el == myGlobals.broadcastEntry) break; } if(firstRun) { firstRun=0; el = myGlobals.broadcastEntry; goto recentlyUsedPortSent; } firstRun = 1; if(numRecords > 0) { sendString("\n \n
    \n"); } for(el=getFirstHost(myGlobals.actualReportDeviceId); el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) { if(el->community && (!isAllowedCommunity(el->community))) continue; recentlyUsedPortRcvd: if(recentlyUsedPort(el, portNr, 1)) { if(numRecords == 0) { sendString("\n\n"); sendString("\n\n\n
    ClientServer
    \n"); sendString("\n \n
      \n"); } sendString("\n
    • "); sendString(makeHostLink(el, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf))); numRecords++; } if(el == myGlobals.broadcastEntry) break; } if(firstRun) { firstRun = 0; el = myGlobals.broadcastEntry; goto recentlyUsedPortRcvd; } if(numRecords == 0) { safe_snprintf(__FILE__, __LINE__, hostLinkBuf, sizeof(hostLinkBuf), "

      No hosts found: the information for this port " "has been purged in the meantime
      " "as each host keeps the last %d server/client ports only.

      \n", MAX_NUM_RECENT_PORTS); sendString(hostLinkBuf); } else sendString("\n \n

    \n"); } /* ******************************************* */ void printFcHostsTraffic(int reportType, int sortedColumn, int revertOrder, int pageNum, char* url, LocalityDisplayPolicy showLocalityMode) { u_int idx, numEntries=0, maxHosts, whatToDo; int printedEntries=0, hourId; char theDate[8]; struct tm t; HostTraffic *el; HostTraffic** tmpTable; char buf[LEN_GENERAL_WORK_BUFFER], formatBuf[8][32], vsanBuf[LEN_MEDIUM_WORK_BUFFER]; char hostLinkBuf[LEN_GENERAL_WORK_BUFFER]; float sentPercent=0, rcvdPercent=0, totPercent=0; Counter totFcBytesSent=0, totFcBytesRcvd=0, totFcBytes=0; memset(buf, 0, sizeof(buf)); switch(reportType) { case SORT_FC_ACTIVITY: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "FibreChannel Activity"); myGlobals.reportKind = SORT_DATA_HOST_TRAFFIC; showLocalityMode = 0; break; case SORT_FC_DATA: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "FibreChannel Traffic: "); break; case SORT_FC_THPT: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "FibreChannel Throughput: "); break; default: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "?? %d : ", reportType); break; } if(reportType != SORT_FC_ACTIVITY) { switch(showLocalityMode) { case showSentReceived: strncat(buf, "Data Sent+Received", sizeof(buf) - strlen(buf) - 1); myGlobals.reportKind = (reportType == SORT_FC_DATA) ? SORT_DATA_PROTOS : SORT_DATA_THPT; break; case showOnlySent: strncat(buf, "Data Sent", sizeof(buf) - strlen(buf) - 1); myGlobals.reportKind = (reportType == SORT_FC_DATA) ? SORT_DATA_SENT_PROTOS : SORT_DATA_SENT_THPT; break; case showOnlyReceived: strncat(buf, "Data Received", sizeof(buf) - strlen(buf) - 1); myGlobals.reportKind = (reportType == SORT_FC_DATA) ? SORT_DATA_RECEIVED_PROTOS : SORT_DATA_RECEIVED_THPT; break; } } printHTMLheader(buf, 0, 0); maxHosts = myGlobals.device[myGlobals.actualReportDeviceId].hostsno; /* save it as it can change */ tmpTable = (HostTraffic**)mallocAndInitWithReportWarn(myGlobals.device[myGlobals.actualReportDeviceId]. actualHashSize*sizeof(HostTraffic*), "printFcHostsTraffic"); if(tmpTable == NULL) return; strftime(theDate, 8, CONST_TOD_HOUR_TIMESPEC, localtime_r(&myGlobals.actTime, &t)); hourId = atoi(theDate); for (el = getFirstHost (myGlobals.actualReportDeviceId); el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) { if(el->community && (!isAllowedCommunity(el->community))) continue; if(isFcHost (el)) { /* Skip Control VSAN traffic */ if(el->fcCounters->vsanId > MAX_USER_VSAN) continue; if(((showLocalityMode == showOnlySent) && (el->fcCounters->fcBytesSent.value > 0)) || ((showLocalityMode == showOnlyReceived) && (el->fcCounters->fcBytesRcvd.value > 0)) || ((showLocalityMode == showSentReceived) && ((el->fcCounters->fcBytesSent.value > 0) || (el->fcCounters->fcBytesRcvd.value > 0)))) { tmpTable[numEntries++]=el; if(numEntries >= maxHosts) break; } } } if(numEntries <= 0) { printNoDataYet(); free(tmpTable); return; } if(reportType != SORT_FC_ACTIVITY) { switch(showLocalityMode) { case showSentReceived: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "

    " "[ All ] " "[ Sent Only ] " "[ Received Only

    ", url, revertOrder ? "-" : "", sortedColumn, url, revertOrder ? "-" : "", sortedColumn); break; case showOnlySent: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "

    " "[ All ] " "[ Sent Only ] " "[ Received Only

    ", url, revertOrder ? "-" : "", sortedColumn, showLocalityMode, url, revertOrder ? "-" : "", sortedColumn, showLocalityMode); break; default: safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "

    " "[ All ] " "[ Sent Only ] " "[ Received Only

    ", url, revertOrder ? "-" : "", sortedColumn, showLocalityMode, url, revertOrder ? "-" : "", sortedColumn, showLocalityMode); break; } sendString(buf); } printFcHeader(reportType, revertOrder, abs(sortedColumn), hourId, url); myGlobals.columnSort = sortedColumn; #ifdef FC_DEBUG traceEvent(CONST_TRACE_INFO, "FC_DEBUG: reportType=%d/sortedColumn=%d/myGlobals.columnSort=%d", reportType, sortedColumn, myGlobals.columnSort); #endif qsort(tmpTable, numEntries, sizeof(HostTraffic*), cmpFcFctn); totFcBytesSent = totFcBytesRcvd = totFcBytes = 0; for(idx=0; idxfcCounters->fcBytesSent.value; totFcBytesRcvd += tmpTable[idx]->fcCounters->fcBytesRcvd.value; switch(showLocalityMode) { case showSentReceived: totFcBytes += tmpTable[idx]->fcCounters->fcBytesSent.value + tmpTable[idx]->fcCounters->fcBytesRcvd.value; break; case showOnlySent: totFcBytes += tmpTable[idx]->fcCounters->fcBytesSent.value; break; case showOnlyReceived: totFcBytes += tmpTable[idx]->fcCounters->fcBytesRcvd.value; break; } } } /* Avoid core dumps */ if(totFcBytesSent == 0) totFcBytesSent = 1; if(totFcBytesRcvd == 0) totFcBytesRcvd = 1; if(totFcBytes == 0) totFcBytes = 1; #ifdef FC_DEBUG traceEvent(CONST_TRACE_INFO, "FC_DEBUG: totIpBytesSent=%u, totIpBytesRcvd=%u totIpBytes=%u", totFcBytesSent, totFcBytesRcvd, totFcBytes); #endif for(idx=pageNum*myGlobals.runningPref.maxNumLines; idxfcCounters->fcBytesSent.value)/totFcBytesSent; rcvdPercent = (100*(float)el->fcCounters->fcBytesRcvd.value)/totFcBytesRcvd; totPercent = (100*(float) (el->fcCounters->fcBytesSent.value + el->fcCounters->fcBytesRcvd.value) )/totFcBytes; strncpy(webHostName, makeFcHostLink(el, FLAG_HOSTLINK_HTML_FORMAT, 0, 0, hostLinkBuf, sizeof(hostLinkBuf)), sizeof(webHostName)); /* We have two reports x three data breakdowns + activity... cheat and create a number for a 1d switch() 100*Locality + SORT_FC precise formula is irrelevant, as long as it's unique... */ whatToDo = 100*showLocalityMode + reportType; switch(whatToDo) { case (100*showSentReceived + SORT_FC_DATA): safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "
%s%.1f%s%%%s%s%s%s%s%s
%s%.1f%s%%%s%s%s%s%s%s
%s%.1f%s%%%s%s%s%s%s%s
%s%s%s%.1f Pkt/s%.1f Pkt/s%.1f Pkt/s
%s%s%s%.1f Pkt/s%.1f Pkt/s%.1f Pkt/s
%s%s%s%.1f Pkt/s%.1f Pkt/s%.1f Pkt/s
"TABLE_OFF"\n"); switch(reportType) { case SORT_FC_THPT: break; case SORT_FC_ACTIVITY: break; case SORT_FC_DATA: sendString("

Note: These counters do not include broadcasts and " "will not equal the 'Global Protocol Distribution'

\n"); break; } sendString("
\n"); printFooter(reportType); addPageIndicator(url, pageNum, numEntries, myGlobals.runningPref.maxNumLines, revertOrder, abs(sortedColumn), -1); myGlobals.lastRefreshTime = myGlobals.actTime; free(tmpTable); } /* ************************************ */ void purgeHost(char *serialized_serial) { HostSerial theSerial; HostTraffic *el; printHTMLheader("Host Purge", NULL, 0); // printFlagedWarning("aaa"); return; str2serial(&theSerial, serialized_serial, strlen(serialized_serial)); #if 0 { char buf[64]; traceEvent(CONST_TRACE_INFO, "==> %s [type=%d][serial Len=%d]\n", _addrtostr(&theSerial.value.ipSerial.ipAddress, buf, sizeof(buf)), theSerial.serialType, strlen(serialized_serial)); } #endif el = findHostBySerial(theSerial, myGlobals.actualReportDeviceId); if(!el) { printFlagedWarning("Unable to purge the specified host: host not found"); } else { int j, found = 0; for(j=FIRST_HOSTS_ENTRY; (!found) && (jto_be_deleted = 1; /* Delete it at the next run */ break; } el1 = el1->next; } } /* for */ if(found) { char buf[LEN_GENERAL_WORK_BUFFER]; safe_snprintf(__FILE__, __LINE__, buf, LEN_GENERAL_WORK_BUFFER, "
\n" "

%s

\n" "
\n", "Host Purged Succesfully"); sendString(buf); } else printFlagedWarning("Unable to purge the specified host: internal error"); } } /* ************************************ */ void printInterfaceStats() { char buf[64]; time_t now = time(NULL); sendString(ctime(&now)); snprintf(buf, sizeof(buf), "%u %u\n", (unsigned int)myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value, (unsigned int)(myGlobals.device[myGlobals.actualReportDeviceId].ethernetBytes.value - myGlobals.device[myGlobals.actualReportDeviceId].ipBytes.value)); sendString(buf); /* traceEvent(CONST_TRACE_ERROR, "%s", buf); */ } /* ************************************ */ void findHost(char *key) { HostTraffic *el=NULL; int num = 0; char buf[256], buf1[256]; /* traceEvent(CONST_TRACE_INFO, "----------> findHost(%s)", key ? key : ""); */ sendString("{ results: ["); for(el=getFirstHost(myGlobals.actualReportDeviceId); el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) { u_char do_add = 0; if((el == myGlobals.broadcastEntry) || (el->hostNumIpAddress == NULL)) continue; if((key == NULL) || (key == "")) do_add = 1; else if(strstr(el->hostNumIpAddress, key)) do_add = 1; else if(strstr(el->ethAddressString, key)) do_add = 1; else if(strstr(el->hostResolvedName, key)) do_add = 1; if(do_add) { char *str; if(el->hostResolvedName) str = el->hostResolvedName; else if(el->ethAddressString[0] != '\0') str = el->ethAddressString; else str = ""; makeHostLink(el, FLAG_HOSTLINK_TEXT_LITE_FORMAT, 0, 0, buf1, sizeof(buf1)); safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf), "%s\n\t{ id: \"%d\", value: \"%s\", info: \"%s\" }", (num > 0) ? "," : "", num, str, buf1); sendString(buf); num++; if(num > 32) break; /* Do not display too many entries */ } } sendString("\n] }\n"); }