Porting Sun RPC to JRPC: Direct Translation Approach

To maintain full compatibility between Sun RPC and JRPC, we performed a direct translation of the original C code for Sun RPC to Java technology without major alterations. While Java is an object-oriented language and C uses structs and functions, Sun RPC was actually written in an object-oriented fashion using C constructs.

🔍 Object-Oriented Design in C

In C, objects with associated methods are represented using structs containing function pointers. These structs serve as abstract base classes, with concrete objects created by assigning specific function pointers to the struct fields.

🔄 Core Class Mappings

XDR Classes

Note: This portion of the original paper is available to customers who have licensed JRPC.

RPC Client Classes

C Implementation
typedef struct _onc_client_t {
    AUTH *cl_auth;  // authenticator
    struct clnt_ops {
        enum clnt_stat (*cl_call)(struct _onc_client_t*, 
                                 u_long, xdrproc_t, void*, 
                                 xdrproc_t, void*, 
                                 struct timeval);
        void (*cl_geterr)();  // get specific error code
        // ... other operations
    } *cl_ops;
} CLIENT;
Java Implementation
public abstract class RPCClient {
    protected Auth cl_auth;  // authenticator
    
    public abstract int call(long procNumber, 
                           XDRProc inXdr, Object inData,
                           XDRProc outXdr, Object outData,
                           Timeval timeout);
    
    public abstract void getErr();  // get specific error code
    // ... other abstract methods
}

🌐 Protocol-Specific Implementations

The CLIENT structure is abstract and cannot be used directly. Only non-abstract CLIENT instances created for specific protocols can be used to call RPC methods:

C to Java Mapping Table

C Implementation Java Implementation
CLIENT structure Abstract class RPCClient
Clnt_TCP.C file ClientTCP.java class extending RPCClient
clnttcp_create() function Constructor of ClientTCP class
clnttcp_call() function call() method in ClientTCP class
Clnt_UDP.C file ClientUDP.java class extending RPCClient
clntudp_create() function Constructor of ClientUDP class
clntudp_call() function call() method in ClientUDP class

🔧 Generic Client Implementation

Sun RPC includes clnt_create() as a convenience function to create either TCP or UDP clients based on the protocol string. This logic is mapped to the ClientGeneric class in JRPC:

C Implementation Java Implementation
Clnt_Generic.C file ClientGeneric.java class
clnt_create() function Constructor of ClientGeneric class
CLNT_CALL() macro call() method in ClientGeneric class

🖥️ Server-Side Mappings

The same mapping principles apply to the server-side components of Sun RPC:

C Implementation Java Implementation
struct AUTH Auth class
Authunix.c file AuthUnix class
struct rpc_err rpc_err exception class
Svc.C file Svc.java class
Svc_tcp.C file SvcTCP.java and TCPServer.java classes
svc_udp.C file SvcUDP.java and UDPServer.java classes
svc_run.c file svc_run() method in Svc class
pmap_cln.c file Pmap class
pmap_rmt.c file rmt_call() method in Pmap class

🎯 Benefits of Direct Translation

Full Compatibility

Maintains 100% compatibility with existing Sun RPC implementations

Proven Architecture

Leverages the battle-tested architecture of Sun ONC RPC

Seamless Integration

Enables Java applications to communicate with existing RPC services

Performance Optimized

Preserves the performance characteristics of the original implementation

📋 Conclusion

The direct translation approach ensures that JRPC maintains maximum compatibility with Sun RPC while leveraging Java's object-oriented capabilities. This allows Java developers to work with familiar RPC concepts while benefiting from Java's type safety, exception handling, and modern language features.

The client stub functions generated by Sun's rpcgen, with prototypes like return_type func(ARG, CLIENT), are easily identifiable as methods of classes derived from CLIENT, making the transition from C to Java natural and intuitive.