Network interface names in iOS

I'm using "en0" string for comparing Wi-Fi interface and "pdp_ip0" for Cellular interface to get device IP addres using getifaddrs() API. Any other names which are equivalent to Wi-Fi & Cellular interfaces?

Are there any valid interface names to include in code that uses in iOS for networking?

Replies

Those names are not considered API. Right now, there is no reliably way to determine which interface fulfils which user-level role. Why do you need that information?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

To find device IP address when connected to different types of networks(Wi-Fi, Cellular etc.)

If you're building a diagnostic tool, why aren't you just displaying the addresses of all of the active interfaces instead of trying to guess?

To find device IP address when connected to different types of networks(Wi-Fi, Cellular etc.)

OK, but why are you trying to correlate IP addresses with user-visible network interfaces? Most folks who write networking code do one of two things:

  • they make an outgoing connection, in which case the system automatically chooses the source IP address for them

  • they listen for incoming connections, in which case the right thing to do is to listen on all interfaces

It’s relatively unusual for networking apps to care about the specific user-visible interface they’re using, so I’d like to understand the background to this before offering concrete advice.

Also, keep in mind that WWAN and Wi-Fi are not your only options:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi... revisiting this question with a slightly different requirement. My boss wants to know if it's possible/feasible in iOS to write an app that will only use WiFi for connectivity. The app will draw from an on-site server and we absolutely do not want it to use cellular data. I'm not at liberty to discuss why, but trust me, it's a serious and solid requirement.


My intuition is that doing that is probaly fairly straightforward, but scanning around I stumbled on this thread and it got me thinking I'd better double-check my assumption. Not to worry... we'll hire someone competent to actually develop the app... right now this is just a sanity check on a strategic direction.

I think in that example, basically all you have to do is connect the phone to a Wi-fi network that is isolated from the internet. I use apps that do this and as long as they are on that isolated network, they won't talk to the internet by any means - all of their network traffic/communication goes over the Wi-fi connection and any attempt by those apps to use the internet (cellular etc.) is blocked until that network is disconnected.


So yes, I'd say it's possible.

My boss wants to know if it's possible/feasible in iOS to write an app that will only use WiFi for connectivity.

This is definitely possible, but the mechanics can be tricky depending on the level you’re working at. Specifically:

  • For NSURLSession it’s very easy; when you create a session, clear

    allowsCellularAccess
    in the configuration you use to create the session and you’re good to go.
  • For BSD Sockets it’s possible, although there’s some pitfalls. You can force a connection to run over a specific interface by binding to that interface (typically using

    IP_BOUND_IF
    ). The problem is in identifying the Wi-Fi interface. There’s no guaranteed way to do that, although there are options that work reasonably well in practice (like
    CNCopySupportedInterfaces
    ).
  • For APIs in between — things like CFSocketStream — the story is less clear.

I'm not at liberty to discuss why, but trust me, it's a serious and solid requirement.

This sounds like a security thing and, honestly, is a concern. If you want security, implement end-to-end security. Trying to implement security at the link layer is generally not a good idea.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"