struct sockaddr_in { u_char sin_len; u_char sin_family; /*----Internet address family, e.g. PF_UNIX or PF_INET */ u_short sin_port; /*----Port number */ struct in_addr sin_addr; /*----Holds the IP address */ char sin_zero[8]; /*----Filling */ };
typedef struct { int a; short b; } simple;this would do the trick
#include <rpc/rpc.h> #include "simple.h" bool_t xdr_Simple(XDR *xdrsp,simple *simplep) { if (!xdr_int(xdrsp,&simplep->a)) return(FALSE); if (!xdr_short(xdrsp,&simplep->b)) return (FALSE); return (TRUE); }
typedef struct { int *data; int array_length; } dynamic_array_type;Translate the array with xdr_array():
bool_t xdr_dynamic_array_type(XDR *xdrsp,dynamic_array_type *arrp) { return(xdr_array(xdrsp,(caddr_t)&arrp->data,(u_int *)&arrp->array_length, MAXLEN,sizeof(int),xdr_int)); }The arguments of xdr_array() are the XDR handle, a pointer to the array, a pointer to the size of the array, the maximum array size, the size of each array element, and a pointer to the XDR routine to translate each array element.
prompt> gcc Message_svc.c Message_svc_doit.c -o Message_svc
prompt> gcc Message_clnt.c Message_clnt_doit.c -o Message_clnt