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

Remove android-specific codepath for getifaddrs #1

Merged

Conversation

jamilbk
Copy link
Member

@jamilbk jamilbk commented Aug 22, 2023

Remove android-specific codepath for getifaddrs

This is not supported in Android 11+. Instead, use libc getifaddr which allegedly works with Android 7+.

See messense/if-addrs#14

This is not supported in Android 11+. Instead, use libc getifaddr which
works with Android 7+.

See messense/if-addrs#14
@jamilbk
Copy link
Member Author

jamilbk commented Aug 22, 2023

However, this issue on that same repo isn't very promising:

messense/if-addrs#21

@thomaseizinger
Copy link
Member

This is only deleting code. Is there a libc fallback that gets applied automatically?

@jamilbk
Copy link
Member Author

jamilbk commented Aug 23, 2023

@thomaseizinger That's a good question. This ffi is only for android, but the ifaces feature's unix codepath presumably calls getifaddr as well, so it's not clear to me. I do know it compiles and seems to run fine on Android.

getifaddr is defined like this:

extern "C" {
    pub fn getifaddrs(ifap: *mut *mut ifaddrs) -> ::std::os::raw::c_int;
}

I tried using libc::getifaddrs but that triggered a massive slew of refactoring that I attempted but ultimately gave up on.

This simple crate seems to do away with the need for this ifaces feature altogether: https://github.com/messense/if-addrs but it was taking me too long to refactor to that.

So I ended up with this PR.

@jamilbk
Copy link
Member Author

jamilbk commented Aug 23, 2023

One more good reason to roll our own minimal STUN/TURN client and do away with webrtc entirely.

@jamilbk
Copy link
Member Author

jamilbk commented Aug 23, 2023

@thomaseizinger This commit is successfully passing CI here: firezone/firezone#1930

So I assume that getifaddrs in libc is found because of the extern "C" block? 🙃

@conectado
Copy link

@thomaseizinger This commit is successfully passing CI here: firezone/firezone#1930

So I assume that getifaddrs in libc is found because of the extern "C" block? 🙃

This is similar to how C/C++ does it, extern blocks are just function declarations, then as part of the compilation the linker links to the declared functions if the library is included(which is in the case of glibc)

Here I wrote an example with the write function

Copy link

@conectado conectado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good, we are sacrificing Android's <7 support which released 6 years ago, I think this is acceptable.

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.

3 participants