• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problem sending UDP broadcast on OS/X 10.5 Leopard on MacPro1, 1
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem sending UDP broadcast on OS/X 10.5 Leopard on MacPro1, 1


  • Subject: Re: Problem sending UDP broadcast on OS/X 10.5 Leopard on MacPro1, 1
  • From: Vincent Lubet <email@hidden>
  • Date: Wed, 1 Dec 2010 10:53:51 -0800

Eigil,

You can force a UDP packet to be sent on a specific interface by biding the socket to an IP address assigned to that interface. You will want to use getaddrinfo(3) to get the list of addresses assigned to the interfaces and iterate through them in a loop.

Vincent

On Dec 1, 2010, at 5:22 AM, Eigil Krogh Sørensen wrote:

Hi,
 
I'm trying to send an UDP Broadcast package on all Ethernet interfaces on a MacPro1,1 with OS/X 10.5 Leopard. "Ethernet 1" and "Ethernet 2" interfaces are enabled, all other Ethernet interfaces are disabled.
 
The "Ethernet 1" interface is connected to the LAN in our department (and to the Internet from there).
The "Ethernet 2" interface is connected to a local net consisting of a switch with one PC and more other devices.
 
The problem is:
I want to UDP package to be sent on the "Ethernet 2" interface, but it is only sent on the "Ethernet 1" interface (that is connected to the LAN).
 
If I boot the MacPro1,1 to OS/X 10.6 Snow Leopard and run the same program, the UDP package is sent on both The "Ethernet 1" and "Ethernet 2" interface!
 
I I disable "Ethernet 1" the UDP package is sent OK on "Ethernet 2"
 
The program used to broadcast the UDP package is shown below. It prints “send ok”, but no UDP package is detected on the net connected to "Ethernet 2".
 
I have Wireshark running on a PC that is connected to the "Ethernet 2", and it shows no UDP packages.
 
Question:
·         What am I doing wrong?
·         How do I force the UDP package to be sent on a all Ethernet interfaces in OS/X 10.5 Leopard?
·         Can I force the UDP package to be sent on a specific interface?
 
 
Thanks in advance
 
Best regards
Eigil
 
 
 
The program used to broadcast the UDP Package:
"
void UDPBcast(  )
{
           int sock;
           struct sockaddr_in dest;
           struct sockaddr_in local;
 
           int broadcast = 1;
           printf("Entry\n");
 
           // local end point
           local.sin_family = AF_INET;
           local.sin_port = 0;
           local.sin_addr.s_addr = inet_addr("192.168.1.160"); // the IP address of the interface that the UDP package should be sent on
           //local.sin_addr.s_addr = INADDR_ANY; // Tried this also. Doesn't work either
           local.sin_len = sizeof(local);
 
           // destination
           dest.sin_family = AF_INET;
           dest.sin_port = htons(1235);
           dest.sin_addr.s_addr = INADDR_BROADCAST;
           dest.sin_len = sizeof(dest);
 
           if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
                      printf("fail\n");
                      return -1;
           }
 
 
           if(setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast)) < 0) {
                      printf("error setting socket option\n");
           }
 
 
           if(bind(sock, (struct sockaddr*)&local, sizeof(local)) <0) {
                      printf("error binding\n");
                      return -1;
           }    
 
 
           if(sendto(sock, "HELLO", sizeof("HELLO"), 0, (struct sockaddr*)&dest, sizeof(dest)) < 0) {    
                      printf("error sending\n");
           }
           else {
                      printf("send ok\n");
           }
}

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Problem sending UDP broadcast on OS/X 10.5 Leopard on MacPro1, 1
      • From: Vincent Lubet <email@hidden>
References: 
 >Problem sending UDP broadcast on OS/X 10.5 Leopard on MacPro1,1 (From: Eigil Krogh Sørensen <email@hidden>)

  • Prev by Date: Re: [OSX Core Foundation]How can I asynchronously upload a file though HTTP and get a callback called while sending bytes of the stream?
  • Next by Date: Re: Problem sending UDP broadcast on OS/X 10.5 Leopard on MacPro1, 1
  • Previous by thread: Problem sending UDP broadcast on OS/X 10.5 Leopard on MacPro1,1
  • Next by thread: Re: Problem sending UDP broadcast on OS/X 10.5 Leopard on MacPro1, 1
  • Index(es):
    • Date
    • Thread