rpcb_getaddr Subroutine

Purpose

Finds the address of a remote service.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
bool_t rpcb_getaddr (prognum, progver, nconf, svcaddr, host)
const rpcprog_t prognum;
const rpcvers_t progver;
const struct netconfig *nconf;
struct netbuf *svcaddr;
const char *host;

Description

The rpcb_getaddr subroutine is used to get the address of the remote service that is located on the host. This remote service is registered on the host with the specified program and version. The service is associated with the specified transport. On successful completion, the value of the svcaddr parameter is the address of the remote service.
Note: You must preallocate the svcaddr parameter before calling the rpcb_getaddr subroutine.

Parameters

Item Description
prognum Specifies the program number of the remote program.
progver Specifies the version number of the remote program.
nconf Specifies the protocol associated with the service.
svcaddr Specifies the address of the remote service.
host Specifies the host name on which the server resides.

Return Values

Item Description
TRUE successful
FALSE unsuccessful
The subroutine returns FALSE in the following two conditions:
  • The mapping does not exist on the host.
  • The remote rpcbind service cannot be contacted.
The status of failure is set in the rpc_createerr global variable .

Error Codes

Item Description
RPC_UNKNOWNHOST The host name is not valid.
RPC_PROGNOTREGISTERED The service is not registered with the remote rpcbind service.
RPC_FAILED An unspecified error occurred.

Examples

In the following example, the rpcb_getaddr subroutine gets the address of remote service associated with the specified program, version, and udp transport.

#include <stdlib.h>
#include <rpcb_getaddrrpc/rpc.h>

#define ADDRBUFSIZE 255

int main()
{
    char hostname[255] ; /* The Remote host on which server is implemented */
    rpcprog_t program_number = 0x3fffffffL;
    rpcvers_t version_number = 0x1L;
    struct netbuf  nbuf;
    struct netconfig *nconf;
    char addrbuf[ADDRBUFSIZE];

    /* Get pointer to struct netconfig for udp transport */
    nconf = getnetconfigent("udp");
    if (nconf == (struct netconfig *) NULL) {
          fprintf(stdout, "\nerror in getnconfigent!\n");
          exit(1);
    }

    nbuf.len = 0;
    nbuf.maxlen = ADDRBUFSIZE;
    nbuf.buf = addrbuf;

    if (!rpcb_getaddr(program_number, version_number, nconf, &nbuf, hostname)) {
        fprintf(stdout, "\nerror in getnconfigent!\n");
          exit(1);
      }        
    
    return 0;
}