Port scan issue

Discussion to talk about software related topics only.
Post Reply
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Port scan issue

Post by SeeCwriter »

I have a NANO project built with v3.3.6. I ran into a problem when I ran a port scan on the module where I can no longer make a TCP connection after the port scanner scans the TCP port I'm using.
The port scanner is a free app I found named "Angry IP Scanner". What it does is, first, it sends several pings to module's IP address and the module replies normally. Second, it sends several "NBNS" packets (whatever that is), the module replies with "Destination unreachable (Port unreachable)". Then it attempts a TCP connection, and the module replies with an accept and ACK. The scanner then immediately closes the connection, and is done.
At this point the module is locked up. I verified that the app never returns from accept. I my guess is that, the scanner closed the connection before the call to accept has completed and that accepts blocks forever because the timeout value was set to zero.
Original call:

Code: Select all

int fd =  accept( listener, &addr, NULL, 0 );
New call:

Code: Select all

int fd =  accept( listener, &addr, NULL, TICKS_PER_SECOND / 2);
if ( fd <=0 ) return;
With this change, the program no longer blocks. But I also can't make a TCP connection.
To determine whether to call accept, I check to see if a connection request is pending. This is the way I've handled TCP connections for years.

Code: Select all

if ( !IsSocketReadable( listener ) ) return;
int fd =  accept( listener, &addr, NULL, TICKS_PER_SECOND / 2);
if ( fd <=0 ) return;
I use the following to check for a pending connection. And after the scan, it always returns true, even if no connection attempts are being made.

Code: Select all

bool IsSocketReadable( int fd )
  {
  static fd_set fds_list;
  FD_ZERO( &fds_list );                 // reset file descriptor list.
  FD_SET( fd, &fds_list );              // add us to list, to be checked for readability.
  return ZeroWaitSelect( FD_SETSIZE, &fds_list, NULL, NULL ) != 0;   // check for readability and return immediately.
  }
What can I do to clear this condition?
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: Port scan issue

Post by pbreed »

What your doing looks basically correct..

You don't need to write your own function ...
#include <iosys.h> //Likely already included in your chain...
if(dataavail(listener))

Given that I'm not sure why its messed up...
You are describing a bug we had a long time ago that I was 99% sure was fixed.
But it fits your description EXACTLY.....humm need to look at this more..

Can you try this:
#include <diagnostics.h>

In your user main add:
EnableSystemDiagnostics();

Then when it hangs up go to the config page with a web browser:

youip:20034
Then select the Diagnostics button...

Or
go to
http://xx.xx.xx.xx:20034/DIAG

This will generate a big JSON blob...
Some of the info is on the state of TCP sockets..
Other is the state of all your tasks...

Include the ELF file and this JSON blob with a support request and I'll see what I can figure out.
(You probably don't want to post those to a public forum)
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Re: Port scan issue

Post by SeeCwriter »

Does v3.3.7 correct this issue? It wasn't clear from the releases notes if that was the case.

Also, projects built with v2.9.5 exhibit the same behavior.
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Re: Port scan issue

Post by SeeCwriter »

v3.3.7 definitely improves the issue. The module no longer locks up, and I can continue to make tcp connections, and not lose a tcp connection if a port scan comes along. A minor issue still present is that once a port scan occurs, the function IsSocketReadable always returns true even when no connection is pending, until a real tcp connection request is attempted.
zealott
Posts: 40
Joined: Thu Oct 30, 2008 1:15 am

Re: Port scan issue

Post by zealott »

Has this been fixed in 3.3.7? I don't see anything in the release notes about this issue being fixed, it's similar to something I have experienced a few times but not been able to figure out.
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Re: Port scan issue

Post by SeeCwriter »

According to my testing, it has been fixed in v3.3.7. Still looking for the the fix to be added to the v2.x tools.
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Re: Port scan issue

Post by SeeCwriter »

Do you think this issue will be fixed in the v2.x tools?
Post Reply