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

udp: fix endianness for port #1194

Merged
merged 1 commit into from
Aug 14, 2024
Merged

udp: fix endianness for port #1194

merged 1 commit into from
Aug 14, 2024

Conversation

wadey
Copy link
Member

@wadey wadey commented Aug 12, 2024

If the host OS is already big endian, we were swapping bytes when we shouldn't have. Use the Go helper to make sure we do the endianness correctly

Fixes: #1189

If the host OS is already big endian, we were swapping bytes when we
shouldn't have. Use the Go helper to make sure we do the endianness
correctly

Fixes: #1189
@wadey wadey added this to the v1.10.0 milestone Aug 12, 2024
Copy link
Contributor

@JackDoanRivian JackDoanRivian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This made me curious how golang itself was handling portnumber-endianness, so I peeked into syscall_linux.go, this is very similar to what they do:

func (sa *SockaddrInet4) sockaddr() (unsafe.Pointer, _Socklen, error) {
	if sa.Port < 0 || sa.Port > 0xFFFF {
		return nil, 0, EINVAL
	}
	sa.raw.Family = AF_INET
	p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
	p[0] = byte(sa.Port >> 8)
	p[1] = byte(sa.Port)
	sa.raw.Addr = sa.Addr
	return unsafe.Pointer(&sa.raw), SizeofSockaddrInet4, nil
}

except the use of binary.Bigendian makes it nice and obvious what's happening.

@wadey
Copy link
Member Author

wadey commented Aug 13, 2024

This made me curious how golang itself was handling portnumber-endianness, so I peeked into syscall_linux.go, this is very similar to what they do:

@JackDoanRivian I still don't understand how that works if the host OS is big or little endian, it seems like they don't do anything to handle that? I'm still confused about that. It does also make me wonder how our code in 1.8 also worked.

@wadey
Copy link
Member Author

wadey commented Aug 13, 2024

I still don't understand how that works if the host OS is big or little endian

ah ok I understand it now

@wadey wadey merged commit 0736cfa into master Aug 14, 2024
8 checks passed
@wadey wadey deleted the udp-fix-endian-port branch August 14, 2024 16:53
@wadey wadey modified the milestones: v1.10.0, v1.9.4 Sep 3, 2024
wadey added a commit that referenced this pull request Sep 3, 2024
Non dependency changes:

- #1194
- #1191
- #1188
- #1185
- #1181
- #1173
- #1171
- #1164
- #1162
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 BUG: mips-softfloat endianness is incorrect for port numbers in the static host map.
3 participants