This patch allows the protocols list file (-p option) to occupy multiple
lines. Comments (anything after a #) are ignored.
This patch also adds reporting of the # of protocols being monitored to the
configuration report.
Comments welcomed!
-----Burton
============================================================================
=====
--- 2.0-released/webInterface.c Thu Dec 27 01:54:29 2001
+++ work/webInterface.c Fri Jan 4 15:24:05 2002
@@ -799,4 +799,9 @@
#endif
+ if(snprintf(buf, sizeof(buf), "<TR><TH "TH_BG" align=left>IP Protocols
Being Monitored</TH>"
+ "<TD "TD_BG" align=right>%d</TD></TR>\n",
numIpProtosToMonitor) < 0)
+ traceEvent(TRACE_ERROR, "Buffer overflow!");
+ sendString(buf);
+
#ifdef MEMORY_DEBUG
if(snprintf(buf, sizeof(buf), "<TR><TH "TH_BG" align=left>Allocated
Memory</TH>"
--- 2.0-released/ntop.c Thu Dec 27 07:41:28 2001
+++ work/ntop.c Fri Jan 4 15:24:57 2002
@@ -422,10 +423,20 @@
void handleProtocols(char *protos) {
- char *proto, *buffer=NULL, *strtokState;
+ char *proto, *buffer=NULL, *bufferCurrent, *bufferWork, *strtokState;
+
+/* protos is either
+ 1) a list in the form proto=port[|port][,...]
+ 2) the name of a file containing a list in the same format.
+ Modification: Allow the file to have multiple lines, each in
+ the "standard" format.
+ Also, ignore standard Linux comments...
+ */
+
FILE *fd = fopen(protos, "rb");
- if(fd == NULL)
+ if(fd == NULL) {
+ traceEvent(TRACE_INFO, "Processing protocol list: '%s'", protos);
proto = strtok_r(protos, ",", &strtokState);
- else {
+ } else {
struct stat buf;
int len, i;
@@ -436,10 +447,42 @@
}
- buffer = (char*)malloc(buf.st_size+8) /* just to be safe */;
+ bufferCurrent = buffer = (char*)malloc(buf.st_size+8) /* just to be
safe */;
- for(i=0;i<buf.st_size;) {
- len = fread(&buffer[i], sizeof(char), buf.st_size-i, fd);
- if(len <= 0) break;
- i += len;
+ traceEvent(TRACE_INFO, "Processing protocol file: '%s', size: %d",
+ protos,
+ buf.st_size+8);
+
+ for (;;) {
+ bufferCurrent = fgets(bufferCurrent, buf.st_size, fd);
+/* On EOF, we're finished */
+ if (bufferCurrent == NULL) {
+ break;
+ }
+
+/* otherwise, bufferCurrent points to the just read line in the file,
+ of the form:
+ [protocol=protocol[|protocol][,]] [# comment]
+ */
+
+/* Strip out any comments
+ */
+ bufferWork = strchr(bufferCurrent, '#');
+ if (bufferWork != NULL) {
+ bufferWork[0] = '\n';
+ bufferWork[1] = '\0';
+ }
+
+/* Replace the \n by a comma, so at the end the buffer will
+ look indistinguishable from a single line file...
+ */
+ bufferWork = strchr(bufferCurrent, '\n');
+ if (bufferWork != NULL) {
+ bufferWork[0] = ',';
+ bufferWork[1] = '\0';
+ }
+
+/* Move pointer to end-of-string for read of next line,
+ */
+ bufferCurrent = strchr(bufferCurrent, '\0');
}
@@ -474,4 +517,8 @@
tmpStr[len+1] = '\0';
}
+
+#ifdef DEBUG
+ traceEvent(TRACE_INFO, " %30s %s", proto, tmpStr);
+#endif
handleProtocolList(proto, tmpStr);
============================================================================
=====
_______________________________________________
Ntop-dev mailing list
[EMAIL PROTECTED]
http://listmanager.unipi.it/mailman/listinfo/ntop-dev