htons.c 146 字节
Newer Older
R
Rich Felker 已提交
1
#include <netinet/in.h>
2
#include <byteswap.h>
R
Rich Felker 已提交
3 4 5

uint16_t htons(uint16_t n)
{
6 7
	union { int i; char c; } u = { 1 };
	return u.c ? bswap_16(n) : n;
R
Rich Felker 已提交
8
}