本帖最后由 oyljerry 于 2012-08-06 15:38:36 编辑

解决方案 »

  1.   

    htonl
    The htonl function converts a u_long from host to TCP/IP network byte order (which is big-endian).u_long htonl(
      u_long hostlong  
    );==============================================
    htons
    The htons function converts a u_short from host to TCP/IP network byte order (which is big-endian).u_short htons(
      u_short hostshort  
    );
      

  2.   

    htonl:
    This function converts a u_long from host to TCP/IP network byte order, which is big-endian.u_long htonl(
      u_long hostlong
    );
    Parameters
    hostlong 
    [in] 32-bit number in host byte order. 
    Return Values
    This function returns the value in TCP/IP network byte order.
    htons:
    This function converts a u_short from host to TCP/IP network byte order, which is big-endian.u_short htons(
      u_short hostshort
    );
    Parameters
    hostshort 
    [in] 16-bit number in host byte order. 
    Res
    This function takes a 16-bit number in host byte order and returns a 16-bit number in network byte order used in TCP/IP networks.Return Values
    This function returns the value in TCP/IP network byte order.msdn如上解释,都是转换网络字节序的。一个是16字节主机字节序,一个是32字节主机字节序。
      

  3.   

    说白了就是分别转16位和32位无符号整数的字节序。如:
    htonl: 0x1248ABCD -> 0xCDAB4812
    htons: 0x1248 -> 0x4812