XDR Array Example 1

A user on a networked machine can be identified by the machine name (using the gethostname subroutine), the user's UID (using the geteuid subroutine), and the numbers of the group to which the user belongs (using the getgroups subroutine).

A structure with this information and its associated XDR subroutine could be coded as follows:

struct netuser {
   char    *nu_machinename;
   int     nu_uid;
   u_int   nu_glen;
   int     *nu_gids;
};
#define NLEN 255    /*  machine names < 256 chars  */
#define NGRPS 20    /*  user can't be in > 20 groups  */
bool_t
xdr_netuser(xdrs, nup)
   XDR *xdrs;
   struct netuser *nup;
{
   return(xdr_string(xdrs, &nup->nu_machinename, NLEN) &&
      xdr_int(xdrs, &nup->nu_uid) &&
      xdr_array(xdrs, &nup->nu_gids, &nup->nu_glen,
          NGRPS, sizeof (int), xdr_int));
}