Bonjour,
je remarque que htons et ntohs appliqués à 0xd6e5, par exemple, font la même chose : 0xe5d6.
Donc je me dis que ces fonctions sont des alias d'une même fonction ?

J'ai trouvé dans /usr/include/netinet/in.h:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
...............
# else
#  if __BYTE_ORDER == __LITTLE_ENDIAN
#   define ntohl(x)	__bswap_32 (x)
#   define ntohs(x)	__bswap_16 (x)
#   define htonl(x)	__bswap_32 (x)
#   define htons(x)	__bswap_16 (x)
#  endif
..............
question 1:
dans quel fichier se trouve la fonction _bswap_16(x) ?

question2:
quelques lignes plus haut on voit:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
................
extern uint32_t ntohl (uint32_t __netlong) __THROW __attribute__ ((__const__));
extern uint16_t ntohs (uint16_t __netshort)
     __THROW __attribute__ ((__const__));
extern uint32_t htonl (uint32_t __hostlong)
     __THROW __attribute__ ((__const__));
extern uint16_t htons (uint16_t __hostshort)
     __THROW __attribute__ ((__const__));
.....................
dans quel fichier se trouvent ces fonctions et quel rapport avec htons/l ?

Merci d'avance.

rutabagas