[Date Prev]   [Date Next] [Thread Prev]   [Thread Next] [Date Index]   [Thread Index]

 

     nocol-users Portmon patch

Hi, 

I'm new to this mailing list, so forgive me if this has already been
resolved.  I scanned through the mailing list archive and found a few
other people reporting problems with portmon so thought I'd post this
patch.

Paulg

Problem Description:
--------------------

portmon fails to check the status of a port often when there is no
response string check involved. Example:

testing 10 sites simultaneously
(debug) Connected: 'log:49'
(debug) portmon: Checking site 'log:49'
DONE 1. XXX.XXX.XXX.XXX
 calling select for connect(), timeout 100
select() on connect returned 5
(debug) Connected: 'log:49'
(debug) portmon: Checking site 'log:49'
DONE 1. YYY.YYY.YYY.YYY
connect() failed to XXX.XXX.XXX.XXX- Bad file number

While in the loop opening each socket to be tested, there is a condition
for processing non-blocked connects that return successful immediately.
If there was an immediate connection then the socket was removed from the
rset and wset and status was set to successful etc.  

However later in the processing open socket loop, the same socket (which
is now closed) is tested again and this of course fails.  The problem is
that subsequent calls to socket return the same fd descriptor because the
special case processing closed it and made it available again.

The patch below removes the special processing and puts the immediate
response socket into the rset and wset just like any other socket.  This
prevents subsequent socket calls returning the same descriptor.

Patch:
------

Index: portmon.c
===================================================================
RCS file: /usr/local/cvs/netplex/nocol/portmon/portmon.c,v
retrieving revision 1.1.1.1
diff -w -c -r1.1.1.1 portmon.c
*** portmon.c	1999/08/09 03:44:53	1.1.1.1
--- portmon.c	2000/01/06 01:51:23
***************
*** 229,241 ****
  
      if (NBconnect(sockarray[i], hv[i]->ipaddr, hv[i]->port) >= 0)
      {		/* immediate connect, perhaps to localhost */
!       FD_CLR(sockarray[i], &rset);
!       FD_CLR(sockarray[i], &wset);
!       status[i] = process_host(sockarray[i], hv[i]);
!       maxseverity[i] = maxsev;
!       close(sockarray[i]);
!       --nleft;
!       if (debug > 2) fprintf(stderr, "DONE %d. %s\n", i, hv[i]->ipaddr);
      }
      else	/* NBconnect returned error */
      {
--- 229,237 ----
  
  	  if (NBconnect(sockarray[i], hv[i]->ipaddr, hv[i]->port) >= 0)
  	  {		/* immediate connect, perhaps to localhost */
! 		  FD_SET(sockarray[i], &rset);
! 		  FD_SET(sockarray[i], &wset);
! 		  if (sockarray[i] > maxfd) maxfd = sockarray[i];
  	  }
  	  else	/* NBconnect returned error */
  	  {

______________________________________________________________________

For PGP Key ID B49E3514,                        mailto:paulg@apnic.net     
send mail with Subject: pgp-key-request        phoneto:+61-7-3367-0490     
Paul Gampe - Technical Manager - APNIC Pty Ltd   faxto:+61-7-3367-0482
______________________________________________________________________