svn commit: r350993 - head/sbin/ping6

Enji Cooper (yaneurabeya) yaneurabeya at gmail.com
Tue Aug 13 16:50:20 UTC 2019


> On Aug 13, 2019, at 09:22, Alan Somers <asomers at freebsd.org> wrote:
> 
> Author: asomers
> Date: Tue Aug 13 16:22:43 2019
> New Revision: 350993
> URL: https://svnweb.freebsd.org/changeset/base/350993
> 
> Log:
>  Consistently use the byteorder functions in the correct direction
> 
>  Though ntohs and htons are functionally identical, they have different meanings.Using the correct one helps to document the code.

This statement is only true for BE platforms. For LE platforms like i386/x64, ntohs and htons actually does a endianness conversion:

sys/powerpc/include/endian.h:#define    __ntohs(x)      (__bswap16((__uint16_t)(x)))
sys/powerpc/include/endian.h:#define    __ntohs(x)      ((__uint16_t)(x))
sys/sparc64/include/endian.h:#define    __ntohs(x)      ((__uint16_t)(x))
sys/x86/include/endian.h:#define        __ntohs(x)      __bswap16(x)
sys/mips/include/endian.h:#define       __ntohs(x)      ((__uint16_t)(x))
sys/mips/include/endian.h:#define __ntohs(x)    (__bswap16((x)))
sys/arm/include/endian.h:#define __ntohs(x)     ((__uint16_t)(x))
sys/arm/include/endian.h:#define __ntohs(x)        (__bswap16(x))
sys/arm64/include/endian.h:#define      __ntohs(x)        (__bswap16(x))
sys/riscv/include/endian.h:#define      __ntohs(x)        (__bswap16(x))
sys/sys/param.h:#define ntohs(x)        __ntohs(x)
sys/netinet/in.h:#define        ntohs(x)        __ntohs(x)

Thanks,
-Enji


More information about the svn-src-all mailing list