/* byteorder.c convert values between host and network byte order */ /* * Copyright (C) 1988, 1989,1990 by Frederic Hemmer * All rights reserved */ #define DEBUG 0 #if defined(vax) short htons(x) short x; { short y; ((char *)&y)[0] = ((char *)&x)[1]; ((char *)&y)[1] = ((char *)&x)[0]; return(y); } short ntohs(x) short x; { short y; ((char *)&y)[0] = ((char *)&x)[1]; ((char *)&y)[1] = ((char *)&x)[0]; return(y); } long htonl(x) long x; { long y; ((char *)&y)[0] = ((char *)&x)[3]; ((char *)&y)[1] = ((char *)&x)[2]; ((char *)&y)[2] = ((char *)&x)[1]; ((char *)&y)[3] = ((char *)&x)[0]; return(y); } long ntohl(x) long x; { long y; ((char *)&y)[0] = ((char *)&x)[3]; ((char *)&y)[1] = ((char *)&x)[2]; ((char *)&y)[2] = ((char *)&x)[1]; ((char *)&y)[3] = ((char *)&x)[0]; return(y); } #endif /* defined(vax) */