• 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
UDP broadcast connection trouble with upgrade to Snow leopard
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

UDP broadcast connection trouble with upgrade to Snow leopard


  • Subject: UDP broadcast connection trouble with upgrade to Snow leopard
  • From: Andreas Holm <email@hidden>
  • Date: Tue, 9 Feb 2010 12:32:50 +0000 (GMT)

Hello,

I have an issue regarding UDP broadcast communication.

I would like to connect in an internal network to a device located at 10.0.0.201:2054, send a broadcast packet and wait for an answer. The switch in between has an external device that cannot have the broadcast packets, and the communication is therefore setup to be multicast as well.

The code given below does however work well on Leopard, and there has never been a problem with it there. The code has also been compiled in Leopard with xcode 3.1 and it works on Snow leopard. When I now compile it on Snow leopard using xcode 3.2.1, the code fails and I get error msg "Can't assign requested address" when I try the send command. If I run the Snow Leopard code on Leopard, the code works perfectly. 

So I am wondering if anyone can help me figure out this issue, and tell me if there are any differences between the two OS's. I will be grateful for any answer to this post, and if more information is needed, please ask.

Best regards
Andreas Holm

int retur = 0;

// open UDP IPv4 socket

int mSocketFd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

// set broadcast 

int broadcast = 1;

retur = setsockopt(mSocketFd, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast));

if(retur < 0){

  perror("setbroadcast failed");

  return false;

}

// set reuse address

int on = 1;

retur = setsockopt(mSocketFd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));

if(retur < 0){

  perror("setreuse failed");

  return false;

}

// set timeout

struct timeval timeout;

timeout.tv_sec = 1;

timeout.tv_usec = 0;

retur = setsockopt(mSocketFd, SOL_SOCKET, SO_RCVTIMEO,(struct timeval *)&timeout,sizeof(struct timeval));

if(retur < 0){

  perror("settimeout failed");

  return false;

}

// bind to broadcast

struct sockaddr_in addr;

memset(&addr,0,sizeof(addr));

addr.sin_port = htons(2054);

addr.sin_family = AF_INET;

inet_pton(AF_INET, "10.0.0.255", (void*)&addr.sin_addr);

retur = bind( mSocketFd, (struct sockaddr *)&addr, sizeof(addr) );

if(retur < 0){

  perror("bind failed");

  return false;

}

// connect to 10.0.0.201

memset(&addr,0,sizeof(addr));

addr.sin_port = htons(2054);

addr.sin_family = AF_INET;

inet_pton(AF_INET, "10.0.0.201", (void*)&addr.sin_addr);

retur = connect(mSocketFd, (struct sockaddr*) &addr, sizeof(addr));

if(retur < 0){

  perror("connect failed");

  return false;

}

// join multicast

struct ip_mreq mreq;

mreq.imr_multiaddr.s_addr = inet_addr("225.0.0.201");

mreq.imr_interface.s_addr = inet_addr("10.0.0.32"); // hardcoded for this test, but uses code to check

retur = setsockopt(mSocketFd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));

if(retur < 0){

  perror("multicast join failed");

  return false;

}

char data[512];

// fill data

int ret = send(mSocketFd, data, 512,0);

if(ret == 512){

  printf("UDP send success\n");

  return true;

}else {

  perror("UDP send failed");

  return false;

}


__________________________________________________
Bruker du Yahoo!?
Lei av spam? Yahoo! Mail har den beste spambeskyttelsen
http://no.mail.yahoo.com
 _______________________________________________
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

  • Prev by Date: Re: Checking firewall status
  • Next by Date: Re: Checking firewall status
  • Previous by thread: Re: Checking firewall status
  • Next by thread: need some inputs on SCNetworkConfiguration
  • Index(es):
    • Date
    • Thread