[jcifs] enumerating domains with Wins server

Gary Rambo grambo at aventail.com
Fri Mar 19 00:59:11 GMT 2004


I've asked this question before in other forms but I haven't gotten an answer.

To browse the network neighborhood for a domain list using Jcifs, my only choice is something like 

	new SmbFile( "smb://" ).listFiles()

which broadcasts for __MSBROWSE__ and elicits responses from listening PDCs, selects the first to answer and sends it a  NetServerEnum2 request specifying SV_TYPE_DOMAIN_ENUM. The problem with this, in my view, is that the resulting picture of the network neighborhood depends on the PDC that answers first, and its list of domains may not be authoritative.

My users typically have WINS servers configured. If I send the NetServerEnum2 request for domains directly to the WINS server, odds are I'll get a better answer, and I spare the network the broadcast traffic. If I don't get a list of domains from the WINS server, I can revert to the method above.

To send a NetServerEnum2 request to the WINS server, because it is not a public class and SmbFile.sendTransaction is not a public method, I need to insert a class, such as the one attached, into src/jcifs/smb, and to invoke it with

	new WinsServer( "smb://" ).enumerateDomains()

Is there some reason this is not recommended practice, or is there a better way to accomplish what I'm after?


Gary Rambo
Aventail Corporation
Secure access for the real world.
-------------- next part --------------
package jcifs.smb;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;

public class WinsServer extends SmbFile {

    public WinsServer( String url ) throws MalformedURLException {
        super( url );

    public SmbFile[] enumerateDomains() 
        throws IOException, MalformedURLException {
        ArrayList list = new ArrayList();
        NetServerEnum2Response response = new NetServerEnum2Response();
        sendTransaction( new NetServerEnum2( tree.session.transport.server.oemDomainName,
                                             NetServerEnum2.SV_TYPE_DOMAIN_ENUM ), 
                         response );

        if( response.status != SmbException.NERR_Success &&
            response.status != SmbException.ERROR_MORE_DATA ) {
            throw new SmbException( SmbException.ERRRAP,
                                    response.toString() );

        for( int i = 0; i < response.numEntries; i++ ) {
            String name = response.results[i].getName();
            if( name.length() > 0 ) {
                list.add( new SmbFile( "smb://" + 
                                       name + "/" ) );

        return (SmbFile[])list.toArray(new SmbFile[list.size()]);



More information about the jcifs mailing list