1830899 Members
1990 Online
110017 Solutions
New Discussion

Re: RPC Question

 
David N
New Member

RPC Question

Bear with me as I explain the problem ... many thanks in advance to anyone that can help ...

We are re-implementing a legacy application that uses RPC over TCP to communicate requests to the app from clients on other boxes. The legacy app was on SunOS - we are on HPUX. The legacy app, for some reason that I don't know, hardwired their RPC server to a specific port (which the customer could configure). They did, however, register the server with rpcbind.

I have successfully implemented (C++) the app using rpcbind with dynamic port assignment (used the svc_tp_create() API). The problem is that I cannot get it to work on a hard-wired port (as the legacy app does, and as the customer insists it must forever be done). I have tried several methods:

(1) The original code in the legacy app called svctcp_create() followed by svc_register(). The file descriptor bound to the fixed port was passed to svctcp_create(). Ignoring the man page warning about these APIs being obsolete, this compiles and initializes fine. rpcinfo reports the registered entry on the fixed port. But pinging the server with rpcinfo causes the error "RPC: Miscellaneous tli error - bad flags".

(2) Looking for alternate APIs that are not obsolete, I see svc_tli_create(). The man page warns that the HP implementation of RPC only supports XTI and TLI apps must be re-written. So that one won't work (I tried anyway).

(3) svc_fd_create() looks like it might also be an alternative, but the call fails.

So can anyone help me get this to work?
1 REPLY 1
Laurent Menase
Honored Contributor

Re: RPC Question

You can use svc_tli_create()

1) create a tbind structure
inSockTcp = t_open( "/dev/tcp", O_RDWR, &tinfo );
tbind = (struct t_bind *) t_alloc(inSockTcp, T_BIND, T_ADDR);
taddr = (short *) tbind->addr.buf;
taddr[0] = AF_INET;
taddr[1] = htons( (unsigned long) 9999);
taddr[2] = 0;
taddr[3] = 0;
tbind->qlen = 1;
tbind->addr.len=8;
Then use svc_tli_create() :
lcl_netcfg = getnetconfigent("tcp");
if ( lcl_netcfg == NULL ) {
fprintf( stderr, "Can not read netconfig database for udp.\n");
exit( 1 );
}
transp = svc_tli_create( inSockTcp, NULL, tbind, 0, 0 );
if ( transp == NULL ) {
fprintf( stderr, "Can not create TLI entry.\n");
exit(1);
}
Then register the service with svc_reg() :
if ( !svc_reg( (SVCXPRT *) transp, (unsigned long) 222222, (unsigned long) 22, dispatch, lcl_netcfg
) ) { fprintf( stderr, "Can not register service.\n" ); exit( 1 ); }