Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPv6 hton layout does not match ipv6_mreq #63

Open
tenderlove opened this issue Nov 29, 2023 · 1 comment
Open

IPv6 hton layout does not match ipv6_mreq #63

tenderlove opened this issue Nov 29, 2023 · 1 comment

Comments

@tenderlove
Copy link
Member

Given this C program:

#include <netinet/in.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char * argv[])
{
        struct ipv6_mreq req;
        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(int i = 0; i < sizeof(req); i++) {
                fprintf(stderr, "\\%#02x", ptr[i]);
        }

        fprintf(stderr, "\n");
        return 0;
}

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"

p IPAddr.new("ff02::fb").hton

The 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.

@tenderlove
Copy link
Member Author

btw I'm not confident that I'm debugging this correctly, but I think the bytes should be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant