-
Notifications
You must be signed in to change notification settings - Fork 636
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
Improve the way to get default gateway on macOS #1379
base: dev
Are you sure you want to change the base?
Improve the way to get default gateway on macOS #1379
Conversation
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.
Thanks @zhengfeihe, it's a good start.
Could you address all comments on the PR, add a few remarks for the code, and add some testing for the PR?
Pcap++/src/PcapLiveDevice.cpp
Outdated
{ | ||
PCPP_LOG_DEBUG("Error retrieving default gateway address: couldn't get netstat output"); | ||
|
||
#define ROUNDUP(a) \ |
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.
use #undef after the usage of the macro
@zhengfeihe next time don't resolve the issue yourself, so other people can easily track the issues. Also, could you let the tests pass? |
Thanks for the reminder. I will watch out next time. |
//route message struct for communication in BSD / APPLE device | ||
struct BSDRoutingMessage{ | ||
struct rt_msghdr header; | ||
char messageSpace[512]; |
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.
wondering if 512
is a proper number?
return ; | ||
} | ||
|
||
bzero((char *)&routingMessage, sizeof(routingMessage)); |
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.
let's use reinterpret_cast
here.
@zhengfeihe As we previously discussed, it appears that FreeBSD cannot easily share its implementation with macOS. Therefore, let's separate the FreeBSD implementation from macOS, allowing the macOS implementation to be merged first. |
Implement thoughts from #1355
Follow the source code of route on a Mac to use a raw socket for retrieving default gateway information from the routing table, thus eliminating the need for system calls.
Test will be added accordingly.