Repository navigation
fix: sockaddr for ipv4 source addresses in ping probe - #1189
Merged
Merged
Conversation
rhodesn
force-pushed
the
rhodesn/ping-source-addr
branch
3 times, most recently
from
December 18, 2025 16:38
28fe1c0 to
cff23a0
Compare
Fixes a bug in the sockaddr function where configuring a specific IPv4 source_ip resulted in the probe binding to 0.0.0.0 (all interfaces) instead of the requested address. The `net.IP` is a 16-byte slice, IPv4 mapped IPv6 in the case of this bug. The previous implementation used `copy()` to transfer the slice into the 4-byte `syscall.SockaddrInet4.Addr` array, however `copy()` only transfers the minimum length, which in this case is the 4-byte `SockaddrInet4.Addr`. The resulting `sa.Addr` is the first 4-bytes of the `sourceIP (net.IP)` which is just `0.0.0.0`. So IPv4 source addresses were being ignored, and `0.0.0.0` was being bound to. Fix is to get respective byte ranges for IPv4 and IPv6 before the copy.
rhodesn
force-pushed
the
rhodesn/ping-source-addr
branch
from
December 18, 2025 16:45
cff23a0 to
5e43645
Compare
manugarg
approved these changes
Dec 19, 2025
manugarg
left a comment
Contributor
There was a problem hiding this comment.
Interesting. Thank you!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a bug in the sockaddr function where configuring a specific IPv4 source_ip resulted in the probe binding to 0.0.0.0 (all interfaces) instead of the requested address.
The
net.IPis a 16-byte slice, IPv4 mapped IPv6 in this case. The previous implementation usedcopy()to transfer the slice into the 4-bytesyscall.SockaddrInet4.Addrarray, howevercopy()only transfers the minimum length, which in this case is the 4-byteSockaddrInet4.Addr. The resultingsa.Addris the first 4-bytes of thesourceIP (net.IP)which is just0.0.0.0. So IPv4 source addresses were being ignored, and0.0.0.0was being bound to.Fix is to get respective byte ranges for IPv4 and IPv6 before the copy.