Use xdr - library routines for external data representation.
>From the man page:
These routines allow C programmers to describe arbitrary
data structures in a machine-independent fashion. Data for
remote procedure calls are transmitted using these routines.