Module jcifs

Class NameServiceClientImpl

java.lang.Object
org.codelibs.jcifs.smb.netbios.NameServiceClientImpl
All Implemented Interfaces:
Runnable, NameServiceClient

public class NameServiceClientImpl extends Object implements Runnable, NameServiceClient
Implementation of NetBIOS name service client for resolving NetBIOS names to IP addresses. Provides functionality for NetBIOS name resolution and network discovery operations.
Author:
mbechler
  • Constructor Details

    • NameServiceClientImpl

      public NameServiceClientImpl(CIFSContext tc)
      Constructs a name service client with the given context.
      Parameters:
      tc - the CIFS context containing configuration
  • Method Details

    • run

      public void run()
      Specified by:
      run in interface Runnable
    • getNodeStatus

      public NbtAddress[] getNodeStatus(NetbiosAddress addr) throws UnknownHostException
      Description copied from interface: NameServiceClient
      Retrieves the node status information for the specified NetBIOS address.
      Specified by:
      getNodeStatus in interface NameServiceClient
      Parameters:
      addr - the NetBIOS address to query
      Returns:
      the node status responses
      Throws:
      UnknownHostException - if the node status cannot be retrieved
    • getNbtByName

      public NbtAddress getNbtByName(String host) throws UnknownHostException
      Description copied from interface: NameServiceClient
      Determines the address of a host given it's host name. The name can be a NetBIOS name like "freto" or an IP address like "192.168.1.15". It cannot be a DNS name; the analygous UniAddress or InetAddress getByName methods can be used for that.
      Specified by:
      getNbtByName in interface NameServiceClient
      Parameters:
      host - hostname to resolve
      Returns:
      the resolved address
      Throws:
      UnknownHostException - if there is an error resolving the name
    • getNbtByName

      public NbtAddress getNbtByName(String host, int type, String scope) throws UnknownHostException
      Description copied from interface: NameServiceClient
      Determines the address of a host given it's host name. NetBIOS names also have a type. Types(aka Hex Codes) are used to distinguish the various services on a host. Here is a fairly complete list of NetBIOS hex codes. Scope is not used but is still functional in other NetBIOS products and so for completeness it has been implemented. A scope of null or "" signifies no scope.
      Specified by:
      getNbtByName in interface NameServiceClient
      Parameters:
      host - the name to resolve
      type - the hex code of the name
      scope - the scope of the name
      Returns:
      the resolved address
      Throws:
      UnknownHostException - if there is an error resolving the name
    • getNbtByName

      public NbtAddress getNbtByName(String host, int type, String scope, InetAddress svr) throws UnknownHostException
      Description copied from interface: NameServiceClient
      Determines the address of a host given it's host name. NetBIOS names also have a type. Types(aka Hex Codes) are used to distinguish the various services on a host. Here is a fairly complete list of NetBIOS hex codes. Scope is not used but is still functional in other NetBIOS products and so for completeness it has been implemented. A scope of null or "" signifies no scope. The additional svr parameter specifies the address to query. This might be the address of a specific host, a name server, or a broadcast address.
      Specified by:
      getNbtByName in interface NameServiceClient
      Parameters:
      host - the name to resolve
      type - the hex code of the name
      scope - the scope of the name
      svr - server to query
      Returns:
      the resolved address
      Throws:
      UnknownHostException - if there is an error resolving the name
    • getNbtAllByName

      public NbtAddress[] getNbtAllByName(String host, int type, String scope, InetAddress svr) throws UnknownHostException
      Description copied from interface: NameServiceClient
      Retrieve all addresses of a host by it's name.
      Specified by:
      getNbtAllByName in interface NameServiceClient
      Parameters:
      host - hostname to lookup all addresses for
      type - the hexcode of the name
      scope - the scope of the name
      svr - server to query
      Returns:
      the resolved addresses
      Throws:
      UnknownHostException - if the host cannot be resolved
    • getNbtAllByAddress

      public NbtAddress[] getNbtAllByAddress(String host) throws UnknownHostException
      Description copied from interface: NameServiceClient
      Retrieve all addresses of a host by it's address. NetBIOS hosts can have many names for a given IP address. The name and IP address make the NetBIOS address. This provides a way to retrieve the other names for a host with the same IP address.
      Specified by:
      getNbtAllByAddress in interface NameServiceClient
      Parameters:
      host - hostname to lookup all addresses for
      Returns:
      resolved addresses
      Throws:
      UnknownHostException - if there is an error resolving the name
    • getNbtAllByAddress

      public NbtAddress[] getNbtAllByAddress(String host, int type, String scope) throws UnknownHostException
      Description copied from interface: NameServiceClient
      Retrieve all addresses of a host by it's address. NetBIOS hosts can have many names for a given IP address. The name and IP address make the NetBIOS address. This provides a way to retrieve the other names for a host with the same IP address. See NameServiceClient.getByName(java.lang.String, boolean) for a description of type and scope.
      Specified by:
      getNbtAllByAddress in interface NameServiceClient
      Parameters:
      host - hostname to lookup all addresses for
      type - the hexcode of the name
      scope - the scope of the name
      Returns:
      resolved addresses
      Throws:
      UnknownHostException - if there is an error resolving the name
    • getNbtAllByAddress

      public NbtAddress[] getNbtAllByAddress(NetbiosAddress addr) throws UnknownHostException
      Description copied from interface: NameServiceClient
      Retrieve all addresses of a host by it's address. NetBIOS hosts can have many names for a given IP address. The name and IP address make the NetBIOS address. This provides a way to retrieve the other names for a host with the same IP address.
      Specified by:
      getNbtAllByAddress in interface NameServiceClient
      Parameters:
      addr - the address to query
      Returns:
      resolved addresses
      Throws:
      UnknownHostException - if address cannot be resolved
    • getWINSAddress

      protected InetAddress getWINSAddress()
      Get the address of the active WINS server
      Returns:
      address of active WINS server
    • isWINS

      protected boolean isWINS(InetAddress svr)
      Checks if the given address is one of the configured WINS servers.
      Parameters:
      svr - the server address to check
      Returns:
      whether the given address is a WINS server
    • switchWINS

      protected InetAddress switchWINS()
      Switches to the next available WINS server in round-robin fashion.
      Returns:
      the next WINS server address, or null if no WINS servers are configured
    • getByName

      public UniAddress getByName(String hostname) throws UnknownHostException
      Description copied from interface: NameServiceClient
      Determines the address of a host given it's host name. The name can be a machine name like "jcifs.samba.org", or an IP address like "192.168.1.15".
      Specified by:
      getByName in interface NameServiceClient
      Parameters:
      hostname - NetBIOS or DNS hostname to resolve
      Returns:
      the found address
      Throws:
      UnknownHostException - if there is an error resolving the name
    • getByName

      public UniAddress getByName(String hostname, boolean possibleNTDomainOrWorkgroup) throws UnknownHostException
      Description copied from interface: NameServiceClient
      Lookup hostname and return it's UniAddress. If the possibleNTDomainOrWorkgroup parameter is true an additional name query will be performed to locate a master browser.
      Specified by:
      getByName in interface NameServiceClient
      Parameters:
      hostname - the hostname to resolve
      possibleNTDomainOrWorkgroup - if true, perform additional master browser lookup
      Returns:
      the first resolved address
      Throws:
      UnknownHostException - if the hostname cannot be resolved
    • getAllByName

      public UniAddress[] getAllByName(String hostname, boolean possibleNTDomainOrWorkgroup) throws UnknownHostException
      Description copied from interface: NameServiceClient
      Lookup addresses for the given hostname.
      Specified by:
      getAllByName in interface NameServiceClient
      Parameters:
      hostname - the hostname to resolve
      possibleNTDomainOrWorkgroup - if true, perform additional master browser lookup
      Returns:
      found addresses
      Throws:
      UnknownHostException - if the hostname cannot be resolved
    • getLocalHost

      public NbtAddress getLocalHost()
      Gets the local host NetBIOS address.
      Specified by:
      getLocalHost in interface NameServiceClient
      Returns:
      local host address
      See Also:
    • getLocalName

      public Name getLocalName()
      Gets the local host NetBIOS name.
      Specified by:
      getLocalName in interface NameServiceClient
      Returns:
      the local host name
      See Also:
    • getLmhosts

      public Lmhosts getLmhosts()
      Gets the lmhosts resolver instance used by this client.
      Returns:
      lmhosts file used
    • getUnknownName

      public Name getUnknownName()
      Gets the unknown NetBIOS name instance.
      Specified by:
      getUnknownName in interface NameServiceClient
      Returns:
      the unknown name
      See Also: