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
DEV9: Improve logic for getting MacAddress #10937
Conversation
@fjtrujy Status? |
Status? |
I will try to address these issues soon. |
2adc08a
to
34507bf
Compare
Hello @lightningterror @TheLastRar and @stenzek, could you take a look now? not sure if I did how you wanted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I note that you are iterating though all interfaces, returning the first MAC address found
This function should return the MAC address specific to the adapter
passed into it.
On non-windows platforms, Adapter
is typedefed to ifaddrs
I also noticed a few formatting errors, you should be able to use clang format to correct those.
Understood!! |
ded282a
to
b26ddf9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking better now overall
pcsx2/DEV9/AdapterUtils.cpp
Outdated
return macAddr; | ||
#elif defined(AF_LINK) | ||
struct ifaddrs *tempifs, *po; | ||
getifaddrs(&tempifs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will need to call freeifaddrs()
once you are done with tempifs
Alternatively, you can use a std::unique_ptr
with a custom deleter to handle this for you, like is done in the posix version of AdapterUtils::GetAdapter()
You may also want to check the return value of getifaddrs()
, as it could return -1
indicating an error.
Once again I have done some improvements, sorry for that, please take a look again |
Let me know if I need to something else. |
This is good to go if you're happy with it @stenzek |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I should've given this a proper review earlier.
pcsx2/DEV9/AdapterUtils.cpp
Outdated
Console.Error("DEV9: Failed to get MAC address for adapter using SIOCGENADDR"); | ||
return std::nullopt; | ||
} | ||
memcpy(&macAddr, &ifr.ifr_enaddr, 6); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memcpy(&macAddr, &ifr.ifr_enaddr, 6); | |
std::memcpy(&macAddr, &ifr.ifr_enaddr, sizeof(&macAddr)); |
Hello @stenzek ! Cheers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM
I have applied all your recommendations, it is way cleaner now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, untested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did test this on linux (which hit the SIOCGIFHWADDR
path) and it worked
However, when testing I noticed a small issue with how you had setup the pre processor conditions
Description of Changes
Improving logic for getting MacAddress, now it is working for Apple and FreeBSD
Previously on MacOS:
Now: