--- ntop/globals-report.h 2003-07-14 17:38:06.000000000 -0500
+++ ntop/globals-report.h 2003-07-22 12:11:13.000000000 -0500
@@ -149,6 +149,7 @@
                                 int revertOrder, int pageNum);
 extern void printHostsInfo(int sortedColumn, int revertOrder, int pageNum);
 extern void printAllSessionsHTML(char* host, int actualDeviceId);
+extern void printBroadcastHTML(int actualDeviceId);
 extern void printLocalRoutersList(int actualDeviceId);
 extern void printIpAccounting(int remoteToLocal, int sortedColumn,
 			      int revertOrder, int pageNum);
@@ -230,6 +231,7 @@
 #define STR_THPT_STATS_MATRIX           "thptStatsMatrix.html"
 #define STR_DOMAIN_STATS                "domainTrafficStats.html"
 #define STR_MULTICAST_STATS             "multicastStats.html"
+#define STR_BROADCAST_STATS             "broadcastStats.html"
 #define HOSTS_INFO_HTML                 "hostsInfo.html"
 #define HOSTS_LOCAL_INFO_HTML           "localHostsInfo.html"
 #define STR_LSOF_DATA                   "lsofData.html"
--- ntop/report.c 2003-07-14 17:38:08.000000000 -0500
+++ ntop/report.c 2003-07-22 10:52:17.000000000 -0500
@@ -1950,6 +1950,197 @@
 
 /* ************************************ */
 
+void printBroadcastHTML(int actualDeviceId) {
+  u_int idx, i;
+  HostTraffic *el=myGlobals.broadcastEntry;
+  char buf[LEN_GENERAL_WORK_BUFFER];
+
+  if(el == NULL) {
+    returnHTTPpageNotFound();
+    return;
+  } else
+    sendHTTPHeader(FLAG_HTTP_TYPE_HTML, 0);
+
+  /* ************************************ */
+
+  printHostDetailedInfo(el, actualDeviceId);
+  printHostTrafficStats(el, actualDeviceId);
+  printHostIcmpStats(el);
+  printHostFragmentStats(el, actualDeviceId);
+  printHostContactedPeers(el, actualDeviceId);
+  printHostUsedServices(el, actualDeviceId);
+
+  /* ***************************************************** */
+
+  i = 0;
+
+  if(el->portsUsage != NULL) {
+    for(idx=1; idx<MAX_ASSIGNED_IP_PORTS /* 1024 */; idx++) {
+      if(el->portsUsage[idx] != NULL) {
+	char *svc = getAllPortByNum(idx);
+	char webHostName[LEN_GENERAL_WORK_BUFFER];
+	HostTraffic *peerHost;
+
+	if(i == 0) {
+	  printSectionTitle("TCP/UDP&nbsp;Service/Port&nbsp;Usage\n");
+	  sendString("<CENTER>\n");
+	  sendString(""TABLE_ON"<TABLE BORDER=1 WIDTH=100%>\n<TR "TR_ON">"
+		     "<TH "TH_BG">IP&nbsp;Service</TH>"
+		     "<TH "TH_BG">Port</TH>"
+		     "<TH "TH_BG">#&nbsp;Client&nbsp;Sess.</TH>"
+		     "<TH "TH_BG">Last&nbsp;Client&nbsp;Peer</TH>"
+		     "<TH "TH_BG">#&nbsp;Server&nbsp;Sess.</TH>"
+		     "<TH "TH_BG">Last&nbsp;Server&nbsp;Peer</TH>"
+		     "</TR>\n");
+	  i++;
+	}
+
+	if(svc != NULL) {
+	  if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT>%s</TH>"
+		      "<TD "TD_BG" ALIGN=CENTER>%d</TD>", getRowColor(), svc, idx) < 0)
+	    BufferTooShort();
+	} else {
+	  if(snprintf(buf, sizeof(buf), "<TR "TR_ON" %s><TH "TH_BG" ALIGN=LEFT>%d</TH>"
+		      "<TD "TD_BG" ALIGN=CENTER>%d</TD>", getRowColor(), idx, idx) < 0)
+	    BufferTooShort();
+	}
+
+	sendString(buf);
+
+	if(el->portsUsage[idx]->clientUses > 0) {
+	  /* Fix below courtesy of Andreas Pfaller <apfaller@yahoo.com.au> */
+	  HostTraffic tmpEl;
+
+	  if(emptySerial(&el->portsUsage[idx]->clientUsesLastPeer))
+	    peerHost = NULL;
+	  else
+	    peerHost = quickHostLink(el->portsUsage[idx]->clientUsesLastPeer, actualDeviceId, &tmpEl);
+
+	  if(peerHost == NULL) {
+	    /* Courtesy of Roberto De Luca <deluca@tandar.cnea.gov.ar> */
+	    strncpy(webHostName, "&nbsp;", sizeof(webHostName));
+	  } else
+	    strncpy(webHostName, makeHostLink(peerHost, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0), sizeof(webHostName));
+
+	  if(snprintf(buf, sizeof(buf), "<TD "TD_BG" ALIGN=CENTER>%d/%s</TD>"
+		      "<TD "TD_BG" ALIGN=CENTER>%s</TD>",
+		      el->portsUsage[idx]->clientUses,
+		      formatBytes(el->portsUsage[idx]->clientTraffic.value, 1),
+		      webHostName) < 0) BufferTooShort();
+	  sendString(buf);
+	} else
+	  sendString("<TD "TD_BG">&nbsp;</TD><TD "TD_BG">&nbsp;</TD>");
+
+	if(el->portsUsage[idx]->serverUses > 0) {
+	  HostTraffic tmpEl;
+
+	  if(emptySerial(&el->portsUsage[idx]->serverUsesLastPeer))
+	    peerHost = NULL;
+	  else
+	    peerHost = quickHostLink(el->portsUsage[idx]->serverUsesLastPeer, actualDeviceId, &tmpEl);
+
+	  if(peerHost == NULL) {
+	    /* Courtesy of Roberto De Luca <deluca@tandar.cnea.gov.ar> */
+	    strncpy(webHostName, "&nbsp;", sizeof(webHostName));
+	  } else
+	    strncpy(webHostName, makeHostLink(peerHost, FLAG_HOSTLINK_TEXT_FORMAT, 0, 0), sizeof(webHostName));
+
+	  if(snprintf(buf, sizeof(buf), "<TD "TD_BG" ALIGN=CENTER>%d/%s</TD>"
+		      "<TD "TD_BG" ALIGN=CENTER>%s</TD></TR>",
+		      el->portsUsage[idx]->serverUses,
+		      formatBytes(el->portsUsage[idx]->serverTraffic.value, 1),
+		      webHostName) < 0) BufferTooShort();
+	  sendString(buf);
+	} else
+	  sendString("<TD "TD_BG">&nbsp;</TD><TD "TD_BG">&nbsp;</TD></TR>");
+      }
+    }
+  }
+
+  if(i > 0){
+    sendString("</TABLE>"TABLE_OFF"<P>\n");
+    sendString("</CENTER>\n");
+  }
+
+  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("<CENTER>\n");
+    sendString(""TABLE_ON"<TABLE BORDER=1>\n<TR "TR_ON">"
+	       "<TH "TH_BG">Client Port</TH><TH "TH_BG">Server Port</TH>"
+	       "</TR>\n");
+
+    sendString("<TR "TR_ON"><TD "TD_BG" ALIGN=LEFT><UL>");
+
+    for(idx=0, numPrinted=0; idx<MAX_NUM_RECENT_PORTS; idx++) {
+      if(el->recentlyUsedClientPorts[idx] > 0) {
+	if(snprintf(buf, sizeof(buf), "<li><A HREF=\""SHOW_PORT_TRAFFIC"?port=%d\">%s</A>\n",
+		    el->recentlyUsedClientPorts[idx],
+		    getAllPortByNum(el->recentlyUsedClientPorts[idx])) < 0)
+	  BufferTooShort();
+	sendString(buf);
+	numPrinted++;
+      }
+    }
+
+    if(numPrinted == 0) sendString("&nbsp;");
+
+    sendString("</UL></TD><TD "TD_BG" ALIGN=LEFT><UL>");
+
+    for(idx=0, numPrinted=0; idx<MAX_NUM_RECENT_PORTS; idx++) {
+      if(el->recentlyUsedServerPorts[idx] > 0) {
+	if(snprintf(buf, sizeof(buf), "<LI><A HREF=\""SHOW_PORT_TRAFFIC"?port=%d\">%s</A>\n",
+		    el->recentlyUsedServerPorts[idx],
+		    getAllPortByNum(el->recentlyUsedServerPorts[idx])) < 0)
+	  BufferTooShort();
+	sendString(buf);
+	numPrinted++;
+      }
+    }
+
+    if(numPrinted == 0) sendString("&nbsp;");
+    sendString("</UL></TR></TABLE>"TABLE_OFF"</CENTER>");
+  }
+
+
+  /* *************************************************** */
+
+  if((el->protocolInfo != NULL)
+     && (el->protocolInfo->fileList != NULL)) {
+    FileList *list = el->protocolInfo->fileList;
+
+    printSectionTitle("P2P Recently Exchanged Files\n");
+
+    sendString("<CENTER>\n");
+    sendString(""TABLE_ON"<TABLE BORDER=1>\n<TR "TR_ON">"
+	       "<TH "TH_BG" NOWRAP>File Name</TH></TR>\n");
+    sendString("<TR><TD ALIGN=left><ol>\n");
+
+    while(list != NULL) {
+      if(snprintf(buf, sizeof(buf), "<li>%s&nbsp",
+		  list->fileName) < 0)
+	BufferTooShort();
+      sendString(buf);
+
+      if(FD_ISSET(BITFLAG_P2P_UPLOAD_MODE, &list->fileFlags))   sendString("<IMG SRC=/upload.gif ALT=Upload VALIGN=MIDDLE>&nbsp;");
+      if(FD_ISSET(BITFLAG_P2P_DOWNLOAD_MODE, &list->fileFlags)) sendString("<IMG SRC=/download.gif ALT=Download VALIGN=MIDDLE>&nbsp;");
+
+      list = list->next;
+    }
+
+    sendString("\n</ol></TD></TR></TABLE></CENTER>\n");
+  }
+
+  /* *************************************************** */
+
+  printHostSessions(el, actualDeviceId);
+}
+
+/* ************************************ */
+
 void printLocalRoutersList(int actualDeviceId) {
   char buf[LEN_GENERAL_WORK_BUFFER];
   HostTraffic *el, *router;
--- ntop/reportUtils.c 2003-07-14 17:38:08.000000000 -0500
+++ ntop/reportUtils.c 2003-07-22 11:10:30.000000000 -0500
@@ -2247,11 +2247,12 @@
 
   protoList = myGlobals.ipProtosList;    
   idx = 0;
-  
-  while(protoList != NULL) {
-    totalSent += el->ipProtosList[idx].sent.value;
-    totalRcvd += el->ipProtosList[idx].rcvd.value;
-    idx++, protoList = protoList->next;
+  if (el->ipProtosList != NULL) {
+    while(protoList != NULL) {
+      totalSent += el->ipProtosList[idx].sent.value;
+      totalRcvd += el->ipProtosList[idx].rcvd.value;
+      idx++, protoList = protoList->next;
+    }
   }
 
   actTotalSent = el->tcpSentLoc.value+el->tcpSentRem.value;
@@ -2333,10 +2334,10 @@
 			(float)el->stpRcvd.value/1024,
 			100*((float)SD(el->stpRcvd.value, totalRcvd)));
 
-  {
-    protoList = myGlobals.ipProtosList;    
-    idx = 0;
-    
+  idx = 0;
+  protoList = myGlobals.ipProtosList;    
+
+  if (el->ipProtosList != NULL) {
     while(protoList != NULL) {
       printTableDoubleEntry(buf, sizeof(buf), protoList->protocolName, CONST_COLOR_1, 
 			    (float)el->ipProtosList[idx].sent.value/1024,
@@ -2370,10 +2371,12 @@
     protoList = myGlobals.ipProtosList;    
     idx = 0;
     
-    while(protoList != NULL) {
-      totalSent += el->ipProtosList[idx].sent.value;
-      totalRcvd += el->ipProtosList[idx].rcvd.value;
-      idx++, protoList = protoList->next;
+    if (el->ipProtosList != NULL) {
+      while(protoList != NULL) {
+        totalSent += el->ipProtosList[idx].sent.value;
+        totalRcvd += el->ipProtosList[idx].rcvd.value;
+        idx++, protoList = protoList->next;
+      }
     }
     
     if((totalSent > 0) || (totalRcvd > 0)) {
--- ntop/graph.c 2003-07-15 05:57:28.000000000 -0500
+++ ntop/graph.c 2003-07-22 12:09:25.000000000 -0500
@@ -476,11 +476,13 @@
       +theHost->ipxSent.value+theHost->osiSent.value+theHost->dlcSent.value+
       theHost->arp_rarpSent.value+theHost->decnetSent.value+theHost->appletalkSent.value+
       theHost->netbiosSent.value+theHost->ipv6Sent.value+theHost->otherSent.value;
-
+  
     idx = 0;
-    while(protoList != NULL) {
-      totTraffic.value += theHost->ipProtosList[idx].sent.value;
-      idx++, protoList = protoList->next;
+    if (theHost->ipProtosList != NULL) {
+      while(protoList != NULL) {
+        totTraffic.value += theHost->ipProtosList[idx].sent.value;
+        idx++, protoList = protoList->next;
+      }
     }
   } else {
     totTraffic.value = theHost->tcpRcvdLoc.value+theHost->tcpRcvdFromRem.value+
@@ -491,9 +493,11 @@
       theHost->netbiosRcvd.value+theHost->ipv6Rcvd.value+theHost->otherRcvd.value;
 
     idx = 0;
-    while(protoList != NULL) {
-      totTraffic.value += theHost->ipProtosList[idx].rcvd.value;
-      idx++, protoList = protoList->next;
+    if (theHost->ipProtosList != NULL) {
+      while(protoList != NULL) {
+        totTraffic.value += theHost->ipProtosList[idx].rcvd.value;
+        idx++, protoList = protoList->next;
+      }
     }
   }
 
@@ -635,20 +639,22 @@
     }
 
     idx = 0; protoList = myGlobals.ipProtosList;  
-    while(protoList != NULL) {
-      if(dataSent) {
-	if(theHost->ipProtosList[idx].sent.value > 0) {
-	  p[num] = (float)((100*theHost->ipProtosList[idx].sent.value)/totTraffic.value);
-	  if(p[num] > MIN_SLICE_PERCENTAGE) lbl[num++] = protoList->protocolName;
-	}
-      } else {
-	if(theHost->ipProtosList[idx].rcvd.value > 0) {
-	  p[num] = (float)((100*theHost->ipProtosList[idx].rcvd.value)/totTraffic.value);
-	  if(p[num] > MIN_SLICE_PERCENTAGE) lbl[num++] = protoList->protocolName;
-	}
-      }     
-
-      idx++, protoList = protoList->next;
+    if (theHost->ipProtosList != NULL) {
+      while(protoList != NULL) {
+        if(dataSent) {
+  	  if(theHost->ipProtosList[idx].sent.value > 0) {
+  	    p[num] = (float)((100*theHost->ipProtosList[idx].sent.value)/totTraffic.value);
+  	    if(p[num] > MIN_SLICE_PERCENTAGE) lbl[num++] = protoList->protocolName;
+  	  }
+        } else {
+  	  if(theHost->ipProtosList[idx].rcvd.value > 0) {
+  	    p[num] = (float)((100*theHost->ipProtosList[idx].rcvd.value)/totTraffic.value);
+  	    if(p[num] > MIN_SLICE_PERCENTAGE) lbl[num++] = protoList->protocolName;
+     	  }
+        }     
+  
+        idx++, protoList = protoList->next;
+      }
     }
 
     if(num == 0) {
@@ -1501,7 +1507,6 @@
   if(myGlobals.device[myGlobals.actualReportDeviceId].otherBytes.value > 0) {
     p[idx] = myGlobals.device[myGlobals.actualReportDeviceId].otherBytes.value; lbl[idx] = "Other"; idx++; }
 
-
   {
     ProtocolsList *protoList = myGlobals.ipProtosList;    
     int idx1 = 0;
--- ntop/http.c 2003-07-22 09:25:21.000000000 -0500
+++ ntop/http.c 2003-07-22 12:11:30.000000000 -0500
@@ -1968,15 +1968,21 @@
 	if(hostName[i] == '_')
 	  hostName[i] = ':';
 
-      /* printf("HostName: '%s'\r\n", hostName); */
+#ifdef DEBUG
+      traceEvent(CONST_TRACE_INFO, "DEBUG: HostName: '%s'", hostName);
+#endif
 
-      for(el=getFirstHost(myGlobals.actualReportDeviceId); 
-	  el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) {
-	if((el != myGlobals.broadcastEntry)
-	   && (el->hostNumIpAddress != NULL)
-	   && ((strcmp(el->hostNumIpAddress, hostName) == 0)
-	       || (strcmp(el->ethAddressString, hostName) == 0)))
-	  break;
+      if(strcmp(hostName, "broadcast") == 0) {
+        el = myGlobals.broadcastEntry;
+      } else {
+        for(el=getFirstHost(myGlobals.actualReportDeviceId); 
+          el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) {
+        if((el != myGlobals.broadcastEntry)
+           && (el->hostNumIpAddress != NULL)
+           && ((strcmp(el->hostNumIpAddress, hostName) == 0)
+                 || (strcmp(el->ethAddressString, hostName) == 0)))
+	    break;
+        }
       }
 
       if(el == NULL) {
@@ -2082,6 +2088,8 @@
 	else
 	  dumpNtopTrafficInfo(NULL, &questionMark[1]);
 	printTrailer = 0;
+      } else if(strncmp(pageName, STR_BROADCAST_STATS, strlen(STR_BROADCAST_STATS)) == 0) {
+        printBroadcastHTML(myGlobals.actualReportDeviceId);
       } else if(strlen(pageName) > 5) {
 	int i;
 	char hostName[32];
--- ntop/html/Stats.html 2003-05-29 08:45:40.000000000 -0500
+++ ntop/html/Stats.html 2003-07-22 12:10:42.000000000 -0500
@@ -19,6 +19,7 @@
 &nbsp;&nbsp;
 <span class="leftmenuitem">&nbsp;Statistics:</span>
 <span class="leftmenuitem">&nbsp;<a href="multicastStats.html" target="area">Multicast</a></span>  <b>&nbsp;|&nbsp;</b>
+<span class="leftmenuitem">&nbsp;<a href="broadcastStats.html" target="area">Broadcast</a></span>  <b>&nbsp;|&nbsp;</b>
 <span class="leftmenuitem">&nbsp;<a href="trafficStats.html" target="area">Traffic</a></span>  <b>&nbsp;|&nbsp;</b>
 <span class="leftmenuitem">&nbsp;<a href="hostsInfo.html" target="area">Hosts</a></span>  <b>&nbsp;|&nbsp;</b>
 <span class="leftmenuitem">&nbsp;<a href="localHostsInfo.html" target="area">Local Info</a></span>  <b>&nbsp;|&nbsp;</b>
