org.acplt.oncrpc.apps.jportmap
Class jportmap

java.lang.Object
  extended by org.acplt.oncrpc.server.OncRpcServerStub
      extended by org.acplt.oncrpc.apps.jportmap.jportmap
All Implemented Interfaces:
OncRpcDispatchable
Direct Known Subclasses:
OncRpcEmbeddedPortmap.embeddedjportmap

public class jportmap
extends OncRpcServerStub
implements OncRpcDispatchable

The class jportmap implements a Java-based ONC/RPC port mapper, speaking the widely deployed protocol version 2.

This class can be either used stand-alone (a static main is provided for this purpose) or as part of an application. In this case you should check first for another portmap already running before starting your own one.


Field Summary
 java.net.InetAddress[] locals
          List of IP addresses assigned to this host.
static int PMAP_PORT
          Well-known port where the portmap process can be found on Internet hosts.
static int PMAP_PROGRAM
          Program number of the portmapper as defined in RFC 1832.
static int PMAP_VERSION
          Program version number of the portmapper as defined in RFC 1832.
 java.util.Vector servers
          The list of registrated servers.
 
Fields inherited from class org.acplt.oncrpc.server.OncRpcServerStub
info, shutdownSignal, transports
 
Constructor Summary
jportmap()
          Create a new portmap instance, create the transport registration information and UDP and TCP-based transports, which will be bound later to port 111.
 
Method Summary
 void dispatchOncRpcCall(OncRpcCallInformation call, int program, int version, int procedure)
          Dispatch incomming ONC/RPC calls to the individual handler functions.
(package private)  OncRpcGetPortResult getPort(OncRpcServerIdent params)
          Lookup port for (program, version, protocol).
(package private)  boolean isLocalAddress(java.net.InetAddress addr)
          Checks whether the address given belongs to one of the local addresses of this host.
(package private)  OncRpcDumpResult listServers()
          Return list of registered ONC/RPC servers.
static void main(java.lang.String[] args)
          Create an instance of an ONC/RPC portmapper and run it.
(package private)  XdrBoolean setPort(OncRpcServerIdent params)
          Register a port number for a particular (program, version, protocol).
(package private)  XdrBoolean unsetPort(OncRpcServerIdent params)
          Deregister all port settings for a particular (program, version) for all transports (TCP, UDP, ...).
 
Methods inherited from class org.acplt.oncrpc.server.OncRpcServerStub
close, getCharacterEncoding, register, run, run, setCharacterEncoding, stopRpcProcessing, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

locals

public java.net.InetAddress[] locals
List of IP addresses assigned to this host. Will be filled later by constructor.


servers

public java.util.Vector servers
The list of registrated servers.


PMAP_PORT

public static final int PMAP_PORT
Well-known port where the portmap process can be found on Internet hosts.

See Also:
Constant Field Values

PMAP_PROGRAM

public static final int PMAP_PROGRAM
Program number of the portmapper as defined in RFC 1832.

See Also:
Constant Field Values

PMAP_VERSION

public static final int PMAP_VERSION
Program version number of the portmapper as defined in RFC 1832.

See Also:
Constant Field Values
Constructor Detail

jportmap

public jportmap()
         throws OncRpcException,
                java.io.IOException
Create a new portmap instance, create the transport registration information and UDP and TCP-based transports, which will be bound later to port 111. The constructor does not start the dispatcher loop.

Throws:
OncRpcException
java.io.IOException
Method Detail

getPort

OncRpcGetPortResult getPort(OncRpcServerIdent params)
Lookup port for (program, version, protocol). If no suitable registration entry if found and an entry with another version, but the same program and version number is found, this is returned instead. This is compatible with the way Sun's portmap implementation works.

Parameters:
params - server identification (program, version, protocol) to look up. The port field is not used.
Returns:
port number where server listens for incomming ONC/RPC calls, or 0, if no server is registered for (program, protocol).

setPort

XdrBoolean setPort(OncRpcServerIdent params)
Register a port number for a particular (program, version, protocol). Note that a caller can not register the same (program, version, protocol) for another port. In this case we return false. Thus, a caller first needs to deregister any old entries which it whishes to update. Always add new registration entries to the end of the list (vector).

Parameters:
params - (program, version, protocol, port) to register.
Returns:
true if registration succeeded.

unsetPort

XdrBoolean unsetPort(OncRpcServerIdent params)
Deregister all port settings for a particular (program, version) for all transports (TCP, UDP, ...). While these are strange semantics, they are compatible with Sun's portmap implementation.

Parameters:
params - (program, version) to deregister. The protocol and port fields are not used.
Returns:
true if deregistration succeeded.

listServers

OncRpcDumpResult listServers()
Return list of registered ONC/RPC servers.

Returns:
list of ONC/RPC server descriptions (program, version, protocol, port).

isLocalAddress

boolean isLocalAddress(java.net.InetAddress addr)
Checks whether the address given belongs to one of the local addresses of this host.

Parameters:
addr - IP address to check.
Returns:
true if address specified belongs to one of the local addresses of this host.

dispatchOncRpcCall

public void dispatchOncRpcCall(OncRpcCallInformation call,
                               int program,
                               int version,
                               int procedure)
                        throws OncRpcException,
                               java.io.IOException
Dispatch incomming ONC/RPC calls to the individual handler functions. The CALLIT method is currently unimplemented.

Specified by:
dispatchOncRpcCall in interface OncRpcDispatchable
Parameters:
call - The ONC/RPC call, with references to the transport and XDR streams to use for retrieving parameters and sending replies.
program - the portmap's program number, 100000
version - the portmap's protocol version, 2
procedure - the procedure to call.
Throws:
OncRpcException - if an ONC/RPC error occurs.
java.io.IOException - if an I/O error occurs.
See Also:
OncRpcCallInformation

main

public static void main(java.lang.String[] args)
Create an instance of an ONC/RPC portmapper and run it. As we have to bootstrap the ONC/RPC port information chain, we do not use the usual overloaded run() method without any parameters, but instead supply it the transports to handle. Registration and deregistration is not necessary and not possible.