[jcifs] threaded network crawler code examples (transport problem)

Dan Dumont Dan at canofsleep.com
Tue Jul 29 13:49:08 EST 2003

Sorry that last message was in error.  You will never have more than 10
since client.maxMpxCount is 10 at the start by default, which you can change
via the settings.  Or, if you set it to something ridiculously high, you
will never have more than the best server can support.   But you share this
with all the other threads...   So that's not a lot when you have 190+
threads going...

It still causes weird and unpleasant things to happen when you snag a bad

-----Original Message-----
From: jcifs-bounces+dan=canofsleep.com at lists.samba.org
[mailto:jcifs-bounces+dan=canofsleep.com at lists.samba.org] On Behalf Of Dan
Sent: Monday, July 28, 2003 11:32 PM
To: 'Allen, Michael B (RSCH)'
Cc: jcifs at lists.samba.org
Subject: RE: [jcifs] threaded network crawler code examples (transport

What you are saying makes sense, Mike.  I agree with you that you can't go
making all sorts of threads for non existent hosts.  That's why, in the
existing threads that do the scanning, I put a mini port scan with a 3
second timeout on the cifs port.  To filter out dead hosts, and if a host
takes > 3 seconds I don't wanna scan it.  (jdk 1.4 implemented timeouts on
socket connects)

But what you need to do is make a transport for each thread, like you said.
But not only that, you need to maintain a separate maxmpxcount for each
server you are connected to, like Chris stated and you agreed.

Having the variable static is not just a minor problem.   I looked through
the code.  You never increase maxmpxcount, the only time you ever modify it
is here

negotiatedMaxMpxCount = client.maxMpxCount < server.maxMpxCount ?
client.maxMpxCount : server.maxMpxCount;

Take the lesser of the two

mpxCtrl.maxMpxCount = negotiatedMaxMpxCount < 1 ? 1 : negotiatedMaxMpxCount;

If its less then one, set it to one, otherwise leave it alone.

And that will never result in an upping of the count. So once you've hit a
bad server, you are screwed, for the rest of the index.   Regardless of how
many dead hosts you hit. EVERY live host from then on out will be executed
one after the other.

Thank you for your time, both of you.


-----Original Message-----
From: jcifs-bounces+dan=canofsleep.com at lists.samba.org
[mailto:jcifs-bounces+dan=canofsleep.com at lists.samba.org] On Behalf Of
Allen, Michael B (RSCH)
Sent: Monday, July 28, 2003 9:45 PM
To: 'Dan Dumont'
Cc: jcifs at samba.org; Christopher R. Hertel
Subject: RE: [jcifs] threaded network crawler code examples (transportpro


You're basically trying to create sockets to many servers that do not exist
right? It takes a thread to open a socket. When the socket cannot establish
a connection because the target host does not
exist that thread hangs for 1 min 15 sec. Right? Now you've knocked out that
thread. So once you try to open a socket you're stuck. That's it. You just
have to wait 1 min 15 sec. Now if you never
negotiate with a CIFS server during this, maxMpxCount will not be increased
and will stay at 1 which will cause each thread to wait in line and proceed
syncronously resulting in scanning 1 host every
1 min 15 sec.

Note now that this problem has nothing to do with maxMpxCount. Let's say I
fixed this "problem" with maxMpxCount being static and it was allways
initialized to say 10. Now 10 threads will be permitted
to open sockets to hosts that do not exist and you're now scanning a
whopping 10 hosts every 1 min 15 sec. The net result is basically nothing
considering it would take you several years to scan a
large network at either rate.

You cannot do nmap in Java. You simply cannot do what you want with jCIFS.
You would need to write your program in C. IOW you simply cannot write a
network scanner with Java.


More information about the jcifs mailing list