7 Replies
      Latest reply: Nov 11, 2016 2:56 AM by OriolOMM RSS
      OriolOMM Level 1 Level 1 (0 points)

        Hi to everyone!

         

        I'm trying to migrate a Linux/Android C app to macOS/iOS.

         

        I have this problem, this app uses libnl library some times, in the source code you can see includes like:

         

             #include <linux/netlink.h>

             #include <linux/rtnetlink.h>

             #include <linux/if_tun.h>

         

        These files are from libnl library, you can find information about this library here:

        https://www.infradead.org/~tgr/libnl/doc/core.html#_introduction

         

        I don't know what it's the equivalent in macOS and iOS. Maybe is the same but in another path?

         

        Also I tried to download libnl library and add it to /usr/local/include but it have other dependencies, this is why that I think that I'm in the wrong way...

         

        I found this guide https://developer.apple.com/library/content/documentation/Darwin/Conceptual/NKEConceptual/intro/intro.html#//apple_ref/doc/uid/TP40001858-CH225-SW1

         

        But this means that I need to rewrite all parts of the code that uses libnl?

         

        Any ideas?

         

        Thanks in advance!

        • Re: libnl on macOS and iOS
          eskimo Apple Staff Apple Staff (7,825 points)

          But this means that I need to rewrite all parts of the code that uses libnl?

          Probably.  In fact, it may be harder than that, in that you may need to completely rethink your approach.

          From reading the docs it seems that libnl seems very flexible, supporting both user space-to-kernel and user space-to-user space comms.  How does your product use this?  Critically, on iOS:

          • you can’t load code in the kernel at all

          • apps are generally restricted to one process

          which seems to obviate the need for this library completely.

          So, what features of the library are you using?  And what are you using them for?

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: libnl on macOS and iOS
              OriolOMM Level 1 Level 1 (0 points)

              Hi Eskimo,

               

               

              Thanks for your answer.

               

              I asked to C developers of the app what features are they using of libnl. They said me that they uses libnl to:

               

              - Get notifications of state changes of interfaces.

              - Get the interface address of the devices

              - Get routes of the devices of the devices

              - Get IP addresses of the interfaces.

              - Get the current route table.

               

              Then, do you think that the correct way is to first migrate the app to macOS and then to iOS? If we are able to make it run on macOS, then the migration to iOS it´s going to be easier? or maybe it's better to go directly to the iOS version?

               

               

              Because our objective is to make it run on iOS devices, but if the version for macOS is one necessary step is also OK, 2 jobs in one... do you underestand me?

               

               

              Just tos simplify my question, we are newbies in Apple world. Then we don't know exactly what is the correct way in general terms to migrate an application to this world.

               

               

              PD: we just received the entitlments for NetworkExtension framework for iOS.

               

               

              Thanks!!!

                • Re: libnl on macOS and iOS
                  eskimo Apple Staff Apple Staff (7,825 points)

                  They said me that they uses libnl to:

                  What does your product use this info for?

                  Most of these requirements are problematic on iOS.  Specifically:

                  • Get notifications of state changes of interfaces.

                  Hardware state changes?  Or IP address changes?  The former is going to be tricky.

                  • Get the interface address of the devices

                  If you’re talking about the hardware (MAC) address, this isn’t going to be possible due to sandboxing.  WWDC 2013 Session 714 Protecting your Users’ Privacy explains this.

                  • Get routes of the devices of the devices

                  I can’t parse this sentence but I suspect it’s covered by the last point.

                  • Get IP addresses of the interfaces.

                  This is something you can do with a fully supported API, namely getifaddrs.

                  • Get the current route table.

                  There’s no supported way to get this on iOS.

                  Share and Enjoy

                  Quinn “The Eskimo!”
                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                  let myEmail = "eskimo" + "1" + "@apple.com"

                    • Re: libnl on macOS and iOS
                      OriolOMM Level 1 Level 1 (0 points)

                      Hi!

                       

                      Basically we are using only this part of libnl http://man7.org/linux/man-pages/man7/rtnetlink.7.html

                       

                      • Get notifications of state changes of interfaces.

                      Hardware state changes?  Or IP address changes?  The former is going to be tricky.

                       

                      -> Link change, address change and route change. We want to detect changes like we have turn down/up wifi or we have changed the SSID where we are connected, we have received a new IP from DHCP server,  we moved from 3g/4g to wifi so the default route has changed.

                       

                      • Get the interface address of the devices

                      If you’re talking about the hardware (MAC) address, this isn’t going to be possible due to sandboxing.  WWDC 2013 Session 714 Protecting your Users’ Privacy explains this.

                       

                      -> MAC address to create a unique identifier of the device but we can use other techniques to obtain it. We also need to know the IP address of the interface, but this point as you said we can use getifaddrs.

                       

                      • Get routes of the devices of the devices

                      I can’t parse this sentence but I suspect it’s covered by the last point.

                       

                      -> We need to know the current gateway of the device in order to detect if it change in the future

                       

                      Is it more clear now?

                       

                      Thanks for your help!!!!

                        • Re: libnl on macOS and iOS
                          eskimo Apple Staff Apple Staff (7,825 points)

                          Earlier you wrote:

                          we just received the entitlments for NetworkExtension framework for iOS.

                          So, presumably you need all of this information as part of some sort of VPN thing, right?

                          If so, I recommend you rethink your approach.  It sounds like you’re trying to peer into the state of the networking stack so you can handle changes in the device state.  However, iOS provides high-level infrastructure for that sort of thing and thus doesn’t enable you to do it yourself (well, in some cases it’s not possible, and in others its just really hard).  Thus, I recommend that you use this high-level infrastructure.

                          For example, many Network Extension tunnel providers are built on top of NWTCPConnection or NWUDPSession, both of which provide an observable hasBetterPath which you can use to manage transitions in the networking state (like WWAN to Wi-Fi).  Alternatively, if you’re using BSD Sockets within your tunnel provider, you can use System Configuration framework’s reachability APIs (<SystemConfiguration/SCNetworkReachability.h>) to similar effect.

                          Share and Enjoy

                          Quinn “The Eskimo!”
                          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                          let myEmail = "eskimo" + "1" + "@apple.com"

                  • Re: libnl on macOS and iOS
                    Beast Level 3 Level 3 (125 points)

                    You will also run into licensing issues with the library.  LGPL isn't a very App Store compatible license.  You will want to check with your legal counsel before using the library.