The clnt_broadcast() call broadcasts a remote program to all locally connected broadcast networks.
Syntax
#include <rpc\rpc.h> enum clnt_stat clnt_broadcast(prognum, versnum, procnum, inproc, in, outproc, out, eachresult) u_long prognum; u_long versnum; u_long procnum; xdrproc_t inproc; caddr_t in; xdrproc_t outproc; caddr_t out; resultproc_t eachresult;
Parameters
prognum
Note: resultproc_t is a type definition:
typedef bool_t (*resultproc_t) ();
Description
The clnt_broadcast() call broadcasts a remote program described by prognum, versnum, and procnum to all locally connected broadcast networks. Each time clnt_broadcast() receives a response, it calls eachresult().
The syntax and parameters of eachresult() are:
#include <netinet\in.h> #include <rpc\rpctypes.h> bool_t eachresult(out, addr) char *out; struct sockaddr_in *addr;
Return Values
If eachresult() returns 0, clnt_broadcast() waits for more replies; otherwise, eachresult() returns the appropriate status.
Note: Broadcast sockets are limited in size to the maximum transfer unit of the data link.
Examples
enum clnt_stat cs;u_long prognum, versnum;
...
cs = clnt_broadcast(prognum, versnum, NULLPROC, xdr_void,
(char *)NULL, xdr_void, (char *)NULL, eachresult);
if ((cs != RPC_SUCCESS) && (cs != RPC_TIMEDOUT))
{
fprintf( " broadcast failed: \n");
exit(-1);
}
...
bool_t
eachresult(out, addr)
void *out; /* Nothing comes back */
struct sockaddr_in *addr; /* Reply from whom */
{
register struct hostent *hp;
...
hp = gethostbyaddr((char *) &addr->sin_addr, sizeof addr->sin_addr,
AF_INET);
printf("%s %s\n", inet_ntoa(addr->sin_addr), hp->h_name);
...
return(FALSE);
}
Related Calls