2 Replies
      Latest reply: Oct 19, 2016 7:02 PM by VerbalYan RSS
      VerbalYan Level 1 Level 1 (0 points)

        Dear All,

         

        I attemp to write some UDP broadcast function into app via WiFi,

        But the broadcast packet can't send to other device while ios sets static ip and doesn't fill DNS information.

         

        Is right that ios can't send broadcast packet while DNS is nil?

         

        Verbal Yan

        • Re: UDP broadcast fail while DNS doesn't setting
          eskimo Apple Staff Apple Staff (6,665 points)

          In my experience problems like this are usually caused by you not specifying the interface for the broadcast (using IP_BOUND_IF).  Do you do that?  If not, give it a try and let us know what you see.

          There’s an example of how to use IP_BOUND_IF in this thread.

          Share and Enjoy

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

            • Re: UDP broadcast fail while DNS doesn't setting
              VerbalYan Level 1 Level 1 (0 points)

              Dear eskimo,

               

              when I add line1 and line 11, the application can work fine.

              Thank you

               

              1.     wifiInterface = if_nametoindex("en0");
              2.     assert(wifiInterface != 0);
              3.     fd = socket(AF_INET, SOCK_DGRAM, 0);
              4.     assert(fd >= 0);
              5.     static const int kOne = 1;
              6.     success = setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &kOne, sizeof(kOne)) == 0;
              7.     assert(success);
              8.     success = setsockopt(fd, IPPROTO_IP, IP_BOUND_IF, &wifiInterface, sizeof(wifiInterface)) == 0;
              9.     assert(success);

               

              Verbal Yan