阅读:1321回复:1
在passthru中能否用htons这个函数
各位大虾,在passthru中能否用htons这个函数,如果能是不是只在开头加#include <winsock.h>。如果不能得话,怎么将主机字节顺序转换成网络自己顺序。谢谢啦!!
|
|
沙发#
发布于:2007-10-11 10:53
ULONG htonl(ULONG hostlong)
{ ULONG ByteSwapped; ByteSwapped = ((hostlong & 0x00ff00ff) << 8) | ((hostlong & 0xff00ff00) >> 8); return (ByteSwapped << 16) | (ByteSwapped >> 16); } ULONG ntohl(ULONG netlong) { ULONG ByteSwapped; ByteSwapped = ((netlong & 0x00ff00ff) << 8) | ((netlong & 0xff00ff00) >> 8); return (ByteSwapped << 16) | (ByteSwapped >> 16); } USHORT htons(USHORT hostshort) { return ((hostshort << 8) | (hostshort >> 8)); } USHORT ntohs(USHORT netshort) { return ((netshort << 8) | (netshort >> 8)); } |
|
|