clntudp_bufcreate Subroutine

Purpose

Creates a User Datagram Protocol/Internet Protocol (UDP/IP) client transport handle with specified maximum packet size for UDP-based remote procedure call (RPC) messages.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
CLIENT *clntudp_bufcreate( addr, prognum, versnum, wait, fdp, sendsz, recvsz)
struct sockaddr_in * addr;
rpcprog_t prognum;
rpcvers_t versnum;
struct timeval wait;
int * fdp;
uint_t sendsz;
uint_t recvsz;

Description

The clntudp_bufcreate subroutine creates an RPC client transport handle for a remote program. The client uses UDP as the transport to pass messages to the service. The remote program is located at the internet address specified by the addr parameter. The fdp parameter represents the open and bound file descriptor. If it is set to RPC_ANYSOCK, the subroutine opens a new file descriptor and binds it to the UDP transport. The sendsz and recvsz parameters specify the size of send and receive buffers used for sending and receiving UDP-based RPC messages.

Parameters

Item Description
addr Points to the Internet address of the remote program. If the port number for this Internet address (addr->sin_port) is 0, the value of the addr parameter is set to the port that the remote program is listening on. The clntudp_bufcreate subroutine consults the remote portmap daemon for this information.
prognum Specifies the program number of the remote program.
versnum Specifies the version number of the remote program.
wait Sets the amount of time that the UDP/IP transport waits to receive a response before the transport sends another remote procedure call or the remote procedure call times out. You can use the clnt_call macro to set the total time for the call to time out.
fdp Specifies the open and bound file descriptor. If the value of the fdp parameter is RPC_ANYSOCK, the clntudp_bufcreate subroutine opens a new file descriptor and sets the fdp pointer to the new file descriptor.
sendsz Specifies the size of the send buffer.
recvsz Specifies the size of the receive buffer.

Return Values

Item Description
a valid UDP client handle successful
a null value unsuccessful

Error Codes

Item Description
RPC_PROGNOTREGISTERED The program is not registered.
RPC_SYSTEMERROR The file descriptor is not valid.

Examples

In the following example, the clntudp_bufcreate subroutine creates and returns a UDP/IP client transport handle.

#include <stdlib.h>
#include <rpc/rpc.h>
#define ADDRBUFSIZE 255

int main()
{
    CLIENT *clnt;
    rpcprog_t PROGNUM = 0x3fffffffL;
    rpcvers_t PROGVER = 0x1L;
    int fd;
    struct timeval waittime = {25,0};
    struct sockaddr_in addr;
    char addrbuf[ADDRBUFSIZE];
    struct netbuf svcaddr;
    struct netconfig *nconf;
    uint_t sendsz, recvsz;
    char host[255] ; /* The remote host name */

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

    /* Get pointer to struct netconfig for tcp transport */
    nconf = getnetconfigent("udp");
    if (nconf == (struct netconfig *) NULL) {
        printf("getnetconfigent() failed\n");
        exit(1);
    }

    /* Get the address of remote service */    
    if (!rpcb_getaddr(PROGNUM, PROGVER, nconf, &svcaddr, host)) {
        printf("rpcb_getaddr() failed\n");
        exit(1);
    }
    memcpy(&addr, svcaddr.buf, sizeof(struct sockaddr_in));

    fd = ... /*    Code to obtain open and bound file descriptor on udp transport */

    clnt = (CLIENT *) clntudp_bufcreate(&addr, PROGNUM, PROGVER, waittime, &fd, sendsz, recvsz);

    /*
     * Make a call to clnt_call() subroutine
     */

    /* Destroy the client handle in the end */
    clnt_destroy(clnt);

    return 0;
}