You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to comment on this issue because of discussions at RubyKaigi. I don't know if this PR is the correct fix, but I was having a problem with IPAddr and had to work around this bug here
@tenderlove I checked the difference in output between ipv6_mreq and IPAddr#hton.
I believe IPAddr#hton is actually returning the correct bytes,
but the comparison is currently between two different things.
IPAddr#hton returns the binary representation of the IPv6 address itself (16 bytes),
while the C example appears to dump the entire struct ipv6_mreq (20 bytes). The difference is visible here:
Bytes
0
1
2-14
15
16-19
ipv6_mreq
FF
02
...
FB
00 00 00 00
IPAddr#hton
FF
02
...
FB
(none)
The trailing 00 00 00 00 bytes are the ipv6mr_interface field (interface index, zeroed out), not part of the IPv6 address itself:
The trailing 00 00 00 00 bytes are the ipv6mr_interface field (interface index, zeroed out), not part of the IPv6 address itself:
Ah, interesting. I see.
If you need a ready-to-use ipv6_mreq binary for setsockopt,
you can append the interface index yourself for now:
Yes, I know I can assemble the bytes myself. But I guess my real question is "is the output of hton meant to be valid input for setsockopt?"
Maybe we need a new API or something? I don't expect most Ruby programmers to investigate the struct layout and manually assemble correct bytes for setsockopt. (I could be wrong though)
Thank you for looking at this by the way. I appreciate it!
Maybe we need a new API or something? I don't expect most Ruby programmers to investigate the struct layout and manually assemble correct bytes for setsockopt. (I could be wrong though)
I think that could make sense. Since setsockopt is a fairly low-level socket programming interface, it seems reasonable to have a higher-level API that doesn't require users to manually assemble the byte sequence.
That said, ipv6_mreq is part of the socket interface rather than an IP address abstraction.
So I think such an API would fit better as part of Socket, or perhaps a dedicated abstraction for multicast, rather than IPAddr.
Activity
tenderlove commentedon Nov 29, 2023
btw I'm not confident that I'm debugging this correctly, but I think the bytes should be the same.
tenderlove commentedon May 12, 2026
Hi,
I wanted to comment on this issue because of discussions at RubyKaigi. I don't know if this PR is the correct fix, but I was having a problem with IPAddr and had to work around this bug here
taketo1113 commentedon May 12, 2026
@tenderlove Thank you for the information.
I will look into it myself as well.
taketo1113 commentedon May 23, 2026
@tenderlove I checked the difference in output between
ipv6_mreqandIPAddr#hton.I believe
IPAddr#htonis actually returning the correct bytes,but the comparison is currently between two different things.
IPAddr#htonreturns the binary representation of the IPv6 address itself (16 bytes),while the C example appears to dump the entire
struct ipv6_mreq(20 bytes). The difference is visible here:ipv6_mreqIPAddr#htonThe trailing
00 00 00 00bytes are theipv6mr_interfacefield (interface index, zeroed out), not part of the IPv6 address itself:See also: https://datatracker.ietf.org/doc/html/rfc3493#section-5.2
The first 16 bytes are identical between the two outputs,
so this does not appear to be a bug.
If you need a ready-to-use
ipv6_mreqbinary forsetsockopt,you can append the interface index yourself for now:
tenderlove commentedon May 24, 2026
Ah, interesting. I see.
Yes, I know I can assemble the bytes myself. But I guess my real question is "is the output of
htonmeant to be valid input forsetsockopt?"Maybe we need a new API or something? I don't expect most Ruby programmers to investigate the struct layout and manually assemble correct bytes for
setsockopt. (I could be wrong though)Thank you for looking at this by the way. I appreciate it!
taketo1113 commentedon Jul 4, 2026
I think that could make sense. Since
setsockoptis a fairly low-level socket programming interface, it seems reasonable to have a higher-level API that doesn't require users to manually assemble the byte sequence.That said,
ipv6_mreqis part of the socket interface rather than an IP address abstraction.So I think such an API would fit better as part of
Socket, or perhaps a dedicated abstraction for multicast, rather thanIPAddr.