[jcifs] jcifs problem and wins resolution

Michael B. Allen miallen at eskimo.com
Fri Sep 27 04:49:31 EST 2002


On Thu, 26 Sep 2002 05:23:13 -0700
Joe Bentley <jbentley at zonelabs.com> wrote:

>  
> > My servlet runs on the SRVGE03 Windows 2000 Server PDC,
> > which also happens to be the DMB; IPCONFIG on SRVGE03 states also that
> > it is an H-node, and its Wins "client" configuration points to SRVGE02,
> > another
> > Windows 2000 Server DC running the Wins server service.
> > 
> > In conclusion:
> > I have the  \01\02__MSBROWSE__\02<01>  entry in my Wins Server
> > but even if I don't query the Wins Server:
> > I have the  \01\02__MSBROWSE__\02<01> registered on my network (if I type
> > NBTSTAT -n on SRVGE03 I see the entry)
> > and I should get this name via Broadcast !
> > 
> > I specified the following properties in my servlet:
> >         jcifs.Config.setProperty("jcifs.netbios.wins", "192.168.69.6");
> >         jcifs.Config.setProperty("jcifs.netbios.baddr", "192.168.69.255");
> >         jcifs.Config.setProperty("jcifs.resolveOrder", "WINS,DNS,BCAST");
> > 
> 
> I've noticed the same problem too.  It's because you are executing your code
> on the PDC and a host cannot broadcast to it self.  
> 
> The problem can also be reproduced doing following:
>   jcifs.Config.setProperty("jcifs.netbios.baddr", "127.0.0.1");
> 
> If you move your code off the DCs, it should work, providing that the baddr
> includes at least one DC.  Yeah I know it's a lame work around.  Let me know
> if you find a better answer.

Interesting! I'm not so sure there is another workaround though because I don't
think Java can bind to multiple interfaces.

> 
> That reminds me, the global jcifs.Config.setProperty("jcifs.netbios.baddr")
> design doesn't work for me.  I need to be able to pass a broadcast address
> into the SmbFile("smb://") call to locally override the jcifs.netbios.baddr
> setting.  My jCIFS code is sitting on a gateway machine where I need to
> broadcast to separate networks that may have over-lapping domain names.

Since I'm doing the URL overhaul I'll consider making baddr a query
string parameter like:

  smb://server/share/path?BADDR=192.168.10.255

> Currently a single-threaded synchronized block is required to protect the
> global baddr value before a broadcast call.
> 
> Here's an example:
> 
> class CIFSDriver {
> 
> 	public static String getDomainController(String domain,
> 		String broadcastAddress) {
> 
> 		InetAddress	baddr;
> 
> 		try {
> 			baddr = InetAddress.getByName(broadcastAddress);
> 		}
> 		catch (UnknownHostException e)
> 		{
> 			baddr = null;
> 		}
> 
> 		try {
> 			return NbtAddress.getByName(domain, 0x1c, null,
> 				baddr).getHostAddress();
> 		}
> 		catch (UnknownHostException e)
> 		{
> 			return null;
> 		}
> 	}
> 
> 	public synchronized static void listDomains(String broadcastAddress)
> 		throws Exception {
> 
> 		String oldAddr = jcifs.Config.getProperty("baddr");
> 		jcifs.Config.setProperty("baddr", broadcastAddress);
> 
> 		SmbFile connection = new SmbFile("smb://");
> 		String[] domains = connection.list();
> 		for (int i = 0; i < domains.length; i++)
> 			System.out.println(domains[i] + ":" +
> 				getDomainController(domains[i],
> broadcastAddress));
> 
> 		if (oldAddr != null)
> 			jcifs.Config.setProperty("baddr", oldAddr);
> 	}

I'm surprised this actually works. Another thing I will have to do
eventually is make it so that all (most) parameters can be set at runtime
rather than in static initializers.

> 
> 	public static void main(String[] args) throws Exception {
> 
> 		listDomains("192.168.50.255");
> 		listDomains("115.63.255.255");
> 	}
> }
> 
> -joe


-- 
A  program should be written to model the concepts of the task it
performs rather than the physical world or a process because this
maximizes  the  potential  for it to be applied to tasks that are
conceptually  similar and more importantly to tasks that have not
yet been conceived. 



More information about the jcifs mailing list