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

Using socket to get IP instead of getifaddrs #4920

Draft
wants to merge 1 commit into
base: 2.7.0
Choose a base branch
from

Conversation

advancenXX
Copy link

I am using fastdds v2.7.0 on Android 12.
create_participant is invoked whenever my target network interface enabled, and I check it through some java framework api like,
Enumeration nifs = NetworkInterface.getNetworkInterfaces();
while (nifs.hasMoreElements()) {
NetworkInterface nif = nifs.nextElement();

        Enumeration<InetAddress> addresses = nif.getInetAddresses();
        while (addresses.hasMoreElements()) {
            InetAddress addr = addresses.nextElement();
    
            if (addr instanceof Inet4Address) {
                String host = addr.getHostAddress();
                // host equals("1.2.3.4")
            }
        }
    }

I use NetworkInterface to ensure my participant can find the target ip before it started, but I still find it has no ip sometimes according to tcpdump.
I searched from internet and found two ways to get ip,

  • getifaddrs, getnameinfo. which may miss if ip is assigned but no any actual socket IO;
  • socket. Android use this one, from InterfaceController::getCfg;

I am wondering if it can be used to get ip by socket instead of getifaddrs, as I have tested it on my own environment, especially for Android 12.

Signed-off-by: advancenOO <[email protected]>
@advancenXX
Copy link
Author

hi @EduPonz , could you please review this PR, currently it is a draft patch to fix my problem only, but I can complete it if you think it is useful for Android 12.
Thanks

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.

1 participant