Given this C program:
#include<netinet/in.h>#include<stdlib.h>#include<stdio.h>#include<string.h>intmain(intargc, char*argv[])
{
structipv6_mreqreq;
memset(&req, 0, sizeof(req));
req.ipv6mr_multiaddr.s6_addr[0] =0xFF;
req.ipv6mr_multiaddr.s6_addr[1] =0x02;
req.ipv6mr_multiaddr.s6_addr[15] =0xFB;
uint8_t*ptr= (uint8_t*)&req;
for(inti=0; i<sizeof(req); i++) {
fprintf(stderr, "\\%#02x", ptr[i]);
}
fprintf(stderr, "\n");
return0;
}The bytes of the ipv6_mreq struct are: \0xff\0x2\00\00\00\00\00\00\00\00\00\00\00\00\00\0xfb\00\00\00\00
However, if I use this Ruby program:
require"ipaddr"pIPAddr.new("ff02::fb").htonThe bytes are: "\xFF\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFB"
I think hton should match the ipv6_mreq layout.
Given this C program:
The bytes of the
ipv6_mreqstruct are:\0xff\0x2\00\00\00\00\00\00\00\00\00\00\00\00\00\0xfb\00\00\00\00However, if I use this Ruby program:
The bytes are:
"\xFF\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFB"I think
htonshould match theipv6_mreqlayout.