10 Replies
      Latest reply: Feb 10, 2017 2:57 PM by eskimo RSS
      Aneesh Kumar P Level 1 Level 1 (0 points)

        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?

        • Re: Network interface names in iOS
          eskimo Apple Staff Apple Staff (7,005 points)

          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"

            • Re: Network interface names in iOS
              Aneesh Kumar P Level 1 Level 1 (0 points)

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

                • Re: Network interface names in iOS
                  NotMyName Level 4 Level 4 (650 points)

                  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?

                  • Re: Network interface names in iOS
                    eskimo Apple Staff Apple Staff (7,005 points)

                    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"

                      • Re: Network interface names in iOS
                        abotterell Level 1 Level 1 (0 points)

                        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.

                          • Re: Network interface names in iOS
                            KMT Level 8 Level 8 (8,660 points)

                            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.

                              • Re: Network interface names in iOS
                                abotterell Level 1 Level 1 (0 points)

                                Thanks for that.  Don't think I can guarantee that the WiFi will be isolated from the Internet, though.  The back end of this app would be an on-site appliance linked to a user's existing WiFi.  Nor can we count on the user manually turning off cellular data.  One imagines that the reason for having different interfaces is to allow selection according to application policy, but I guess that's not necessarily so.

                                  • Re: Network interface names in iOS
                                    NotMyName Level 4 Level 4 (650 points)

                                    iOS is a modified version of Darwin, and Darwin belongs to the POSIX family.  I think the decision to have different interfaces dates back to when programmers debated between BSD and System V.  If not earlier.


                                    On the other hand, the local networking Bonjour/mDNS seems like it would make your work easier. 

                                      • Re: Network interface names in iOS
                                        abotterell Level 1 Level 1 (0 points)

                                        Is that to say that nobody's given it any thought since SysV / BSD days?  Hmmm.  Anyway, if we're relying on that legacy I wonder what was considered the point way back then?

                                         

                                        All that aside, local-network discovery via Bonjour does look like it might be useful, although it seems like a somewhat roundabout approach to managing the iOS applications' network routing.

                                         

                                        Thanks!

                                  • Re: Network interface names in iOS
                                    eskimo Apple Staff Apple Staff (7,005 points)

                                    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"