Finds the address of a remote service.
Network Services Library (libnsl.a)
#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;
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. |
Item | Description |
---|---|
TRUE | successful |
FALSE | unsuccessful |
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. |
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;
}