Repository navigation
correctly detect multiple IP addresses on the same interface - #96
Merged
Merged
Conversation
mbhangui
approved these changes
Aug 31, 2019
The problem was that the code did another ioctl() to check if the link is actually up, and when doing this overwrites the information it is currently looking at. The code when sa_len is available copies the current IP address out before checking if the link is up. Reorder the code so both branches share more code and both work.
DerDakon
force-pushed
the
Dakon-ipme
branch
from
September 22, 2019 09:13
183f4ee to
9d6c05d
Compare
schmonz
approved these changes
Sep 22, 2019
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.
This affects only platforms where
struct sockaddrhas no member sa_len. The only system family that we found so far where this is the case and where you indeed can configure multiple IP addresses on the same interface is Linux.Historically this has not been the case, back in the days of Linux 2.0 and 2.2 you had to create virtual interfaces per physical interface (I remember having "eth0:0" around).
Reason for this is that the code overwrites the IP address in the buffer when checking if the interface is actually up. The code for the sa_len case copied the IP address out to a different buffer first. Moving that code out of the
#ifdefand deleting the wrong code is enough for the fix.Unrelated to the bug is a change to use a better algorithm to get the needed buffer size in the first place. If you pass an empty buffer to SIOCGIFCONF it will tell you the needed buffer size, but the current code tried to scale it in a look until it is big enough.
Fixes #95.