FileDocCategorySizeDatePackage
Lmhosts.javaAPI DocJCIFS 1.3.17 API6065Tue Oct 18 15:26:24 BST 2011jcifs.netbios

Lmhosts

public class Lmhosts extends Object

Fields Summary
private static final String
FILENAME
private static final Hashtable
TAB
private static long
lastModified
private static int
alt
private static jcifs.util.LogStream
log
Constructors Summary
Methods Summary
public static synchronized NbtAddressgetByName(java.lang.String host)
This is really just for {@link jcifs.UniAddress}. It does not throw an {@link java.net.UnknownHostException} because this is queried frequently and exceptions would be rather costly to throw on a regular basis here.


                                         

            
        return getByName( new Name( host, 0x20, null ));
    
static synchronized NbtAddressgetByName(Name name)

        NbtAddress result = null;

        try {
            if( FILENAME != null ) {
                File f = new File( FILENAME );
                long lm;

                if(( lm = f.lastModified() ) > lastModified ) {
                    lastModified = lm;
                    TAB.clear();
                    alt = 0;
                    populate( new FileReader( f ));
                }
                result = (NbtAddress)TAB.get( name );
            }
        } catch( FileNotFoundException fnfe ) {
            if( log.level > 1 ) {
                log.println( "lmhosts file: " + FILENAME );
                fnfe.printStackTrace( log );
            }
        } catch( IOException ioe ) {
            if( log.level > 0 )
                ioe.printStackTrace( log );
        }
        return result;
    
static voidpopulate(java.io.Reader r)

        String line;
        BufferedReader br = new BufferedReader( r );

        while(( line = br.readLine() ) != null ) {
            line = line.toUpperCase().trim();
            if( line.length() == 0 ) {
                continue;
            } else if( line.charAt( 0 ) == '#" ) {
                if( line.startsWith( "#INCLUDE " )) {
                    line = line.substring( line.indexOf( '\\" ));
                    String url = "smb:" + line.replace( '\\", '/" );

                    if( alt > 0 ) {
                        try {
                            populate( new InputStreamReader( new SmbFileInputStream( url )));
                        } catch( IOException ioe ) {
                            log.println( "lmhosts URL: " + url );
                            ioe.printStackTrace( log );
                            continue;
                        }

                        /* An include was loaded successfully. We can skip
                         * all other includes up to the #END_ALTERNATE tag.
                         */

                        alt--;
                        while(( line = br.readLine() ) != null ) {
                            line = line.toUpperCase().trim();
                            if( line.startsWith( "#END_ALTERNATE" )) {
                                break;
                            }
                        }
                    } else {
                        populate( new InputStreamReader( new SmbFileInputStream( url )));
                    }
                } else if( line.startsWith( "#BEGIN_ALTERNATE" )) {
                    alt++;
                } else if( line.startsWith( "#END_ALTERNATE" ) && alt > 0 ) {
                    alt--;
                    throw new IOException( "no lmhosts alternate includes loaded" );
                }
            } else if( Character.isDigit( line.charAt( 0 ))) {
                char[] data = line.toCharArray();
                int ip, i, j;
                Name name;
                NbtAddress addr;
                char c;

                c = '.";
                ip = i = 0;
                for( ; i < data.length && c == '."; i++ ) {
                    int b = 0x00;

                    for( ; i < data.length && ( c = data[i] ) >= 48 && c <= 57; i++ ) {
                        b = b * 10 + c - '0";
                    }
                    ip = ( ip << 8 ) + b;
                }
                while( i < data.length && Character.isWhitespace( data[i] )) {
                    i++;
                }
                j = i;
                while( j < data.length && Character.isWhitespace( data[j] ) == false ) {
                    j++;
                }

                name = new Name( line.substring( i, j ), 0x20, null );
                addr = new NbtAddress( name, ip, false, NbtAddress.B_NODE,
                                    false, false, true, true,
                                    NbtAddress.UNKNOWN_MAC_ADDRESS );
                TAB.put( name, addr );
            }
        }