Plan 9 from Bell Labs’s /usr/web/sources/patch/maybe/ape-updates/ntohl.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


unsigned long
ntohl(unsigned long x)
{
	unsigned long n;
	unsigned char *p;

	n = x;
	p = (unsigned char*)&n;
	return (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
}

unsigned long
htonl(unsigned long h)
{
	unsigned long n;
	unsigned char *p;

	p = (unsigned char*)&n;
	p[0] = h>>24;
	p[1] = h>>16;
	p[2] = h>>8;
	p[3] = h;
	return n;
}

unsigned short
ntohs(unsigned short x)
{
	unsigned short n;
	unsigned char *p;

	n = x;
	p = (unsigned char*)&n;
	return (p[0]<<8)|p[1];
}

unsigned short
htons(unsigned short h)
{
	unsigned short n;
	unsigned char *p;

	p = (unsigned char*)&n;
	p[0] = h>>8;
	p[1] = h;
	return n;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.