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

Improve the way to get default gateway on macOS #1379

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

zhengfeihe
Copy link

@zhengfeihe zhengfeihe commented May 2, 2024

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.

@zhengfeihe zhengfeihe requested a review from seladb as a code owner May 2, 2024 00:03
@zhengfeihe zhengfeihe marked this pull request as draft May 2, 2024 00:04
Copy link
Collaborator

@tigercosmos tigercosmos left a 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++/header/PcapLiveDevice.h Outdated Show resolved Hide resolved
{
PCPP_LOG_DEBUG("Error retrieving default gateway address: couldn't get netstat output");

#define ROUNDUP(a) \
Copy link
Collaborator

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

Pcap++/src/PcapLiveDevice.cpp Outdated Show resolved Hide resolved
Pcap++/src/PcapLiveDevice.cpp Outdated Show resolved Hide resolved
Pcap++/src/PcapLiveDevice.cpp Outdated Show resolved Hide resolved
Pcap++/src/PcapLiveDevice.cpp Outdated Show resolved Hide resolved
Pcap++/src/PcapLiveDevice.cpp Outdated Show resolved Hide resolved
Pcap++/src/PcapLiveDevice.cpp Show resolved Hide resolved
Pcap++/src/PcapLiveDevice.cpp Outdated Show resolved Hide resolved
Pcap++/src/PcapLiveDevice.cpp Outdated Show resolved Hide resolved
@tigercosmos
Copy link
Collaborator

@zhengfeihe next time don't resolve the issue yourself, so other people can easily track the issues. Also, could you let the tests pass?

@zhengfeihe zhengfeihe closed this May 5, 2024
@zhengfeihe zhengfeihe reopened this May 5, 2024
@zhengfeihe
Copy link
Author

@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];
Copy link
Collaborator

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));
Copy link
Collaborator

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.

@tigercosmos
Copy link
Collaborator

@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.

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.

None yet

2 participants