fix parsing of interface index in packet info cmsg on big endian architectures (#5094)

This commit is contained in:
Zxilly
2025-04-30 10:30:35 +08:00
committed by GitHub
parent 41cc01890d
commit e4bb2dbd55
3 changed files with 3 additions and 3 deletions

View File

@@ -30,7 +30,7 @@ func parseIPv4PktInfo(body []byte) (ip netip.Addr, ifIndex uint32, ok bool) {
if len(body) != 12 {
return netip.Addr{}, 0, false
}
return netip.AddrFrom4(*(*[4]byte)(body[8:12])), binary.LittleEndian.Uint32(body), true
return netip.AddrFrom4(*(*[4]byte)(body[8:12])), binary.NativeEndian.Uint32(body), true
}
func isGSOEnabled(syscall.RawConn) bool { return false }

View File

@@ -58,7 +58,7 @@ func parseIPv4PktInfo(body []byte) (ip netip.Addr, ifIndex uint32, ok bool) {
if len(body) != 12 {
return netip.Addr{}, 0, false
}
return netip.AddrFrom4(*(*[4]byte)(body[8:12])), binary.LittleEndian.Uint32(body), true
return netip.AddrFrom4(*(*[4]byte)(body[8:12])), binary.NativeEndian.Uint32(body), true
}
// isGSOEnabled tests if the kernel supports GSO.

View File

@@ -222,7 +222,7 @@ func (c *oobConn) ReadPacket() (receivedPacket, error) {
// };
if len(body) == 20 {
p.info.addr = netip.AddrFrom16(*(*[16]byte)(body[:16])).Unmap()
p.info.ifIndex = binary.LittleEndian.Uint32(body[16:])
p.info.ifIndex = binary.NativeEndian.Uint32(body[16:])
} else {
invalidCmsgOnceV6.Do(func() {
log.Printf("Received invalid IPv6 packet info control message: %+x. "+