htons or htonl
Prototype:
#include <resolv.h>
unsigned short int htons(unsigned short int host_short);
unsigned long int htonl(unsigned long int host_long);
General Description: Convert host-byte order binary data to network-byte order. On a little-endian processor, the call swaps the bytes around. A big-endian host does nothing but return the value.
Return Value: (none)
Parameters
host_short The 16-bit host value.
host_long The 32-bit host value.
Possible Errors
(none)
Examples
struct sockaddr_in addr;
addr.sin_port = htons(1023);

struct sockaddr_in addr;
addr.sin_addr.s_addr = hton(0x8001200A);