Home | History | Annotate | Download | only in net
      1 /*	$OpenBSD: htonl.c,v 1.7 2014/07/21 01:51:10 guenther Exp $ */
      2 /*
      3  * Written by J.T. Conklin <jtc (at) netbsd.org>.
      4  * Public domain.
      5  */
      6 
      7 #include <sys/types.h>
      8 #include <endian.h>
      9 
     10 #undef htonl
     11 
     12 u_int32_t
     13 htonl(u_int32_t x)
     14 {
     15 #if BYTE_ORDER == LITTLE_ENDIAN
     16 	u_char *s = (u_char *)&x;
     17 	return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
     18 #else
     19 	return x;
     20 #endif
     21 }
     22