summaryrefslogtreecommitdiff
path: root/lib/libc/arpa/htons.c
blob: 9cfa42f6eafed37104da483ebdad9f446065e970 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <arpa/inet.h> // for htons
#include <byteswap.h>  // for bswap16
#include <stdint.h>    // for uint16_t

uint16_t htons(uint16_t hostshort)
{
	union {
		int i;
		char c;
	} u = { 1 };

	return u.c ? bswap16(hostshort) : hostshort;
}