• 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: Receive UDP broadcast packets with OTRcvUData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Receive UDP broadcast packets with OTRcvUData


  • Subject: Re: Receive UDP broadcast packets with OTRcvUData
  • From: "Matthieu Beghin" <email@hidden>
  • Date: Thu, 4 Nov 2004 12:22:47 +0100

First thanks a lot for your help !

I added the SO_BROADCAST option but it doesn't solve my problem.
I still have a -3212 (Permission Denied) error when sending to
255.255.255.255 or 2.255.255.255
But no error when sending to non brodcast adresses: 2.x.x.x, even an adress
outside the subnet mask.
I get no error codes before the SendTo.

The FTP service is compiled as a Mach-O plugin, I suppose it links a Mach-O
open transport library... Tell me if I'm wrong. I suppose this is a problem
in my code but as it's a really simple behavior and I think I made all I
can, I begin to doubt.

I kept only the Carbon code here (my ftp service is OS9/OSX/Windows):

***********************************
whole initialisation
***********************************

sock = OTOpenEndpointInContext(OTCreateConfiguration(kUDPName), 0,
nil,&osErr_, NULL);
if(osErr_!=noErr || sock == kOTInvalidEndpointRef)
   ...

if((osErr_=OTSetSynchronous(sock))!=noErr)
    ...

OTInitInetAddress(&ipAddress, portNo, kOTAnyInetAddress);

TBind bindReq;
OTMemzero(&bindReq, sizeof(bindReq));
bindReq.addr.buf = (UInt8 *) &ipAddress;
bindReq.addr.len = sizeof(ipAddress);
bindReq.qlen = 1;

if((osErr_ = OTBind(sock, &bindReq, nil))!=noErr)
  ...

if((osErr_ = OTSetNonBlocking(sock))!=noErr)
  ...

UInt8 buf[kOTOptionHeaderSize + sizeof(TIPAddMulticast)];
TOption *OptBuf = (TOption *)buf;
TOptMgmt OptReq;

// enable sending broadcast
OTMemzero(OptBuf, sizeof(buf))
OptBuf->level = INET_IP;
OptBuf->name = SO_BROADCAST;
OptBuf->len = kOTFourByteOptionSize;
*(char*)(OptBuf->value) = 1;
OptReq.flags = T_NEGOTIATE;
OptReq.opt.buf = buf;
OptReq.opt.len = kOTFourByteOptionSize;
OptReq.opt.maxlen = kOTFourByteOptionSize;
osErr_ = OTOptionManagement (sock, &OptReq, &OptReq);
if (osErr_ < 0)
  ...
if (OptBuf->status != T_SUCCESS)
  ...

OTMemzero(OptBuf, sizeof(buf));
OptBuf->level = INET_IP;
OptBuf->name = IP_BROADCAST;
OptBuf->len = kOTFourByteOptionSize;
*(char*)(OptBuf->value) = 1;
OptReq.flags = T_NEGOTIATE;
OptReq.opt.buf = buf;
OptReq.opt.len = kOTFourByteOptionSize;
OptReq.opt.maxlen = kOTFourByteOptionSize;
osErr_ = OTOptionManagement (sock, &OptReq, &OptReq);
if (osErr_ < 0)
  ...
if (OptBuf->status != T_SUCCESS)
  ...

*****************************
SendTo
*****************************

TUnitData data;
InetAddress host;
OTInitInetAddress(&host, to_addr->port, to_addr->ip);
data.addr.len = sizeof(host);
data.addr.buf = (UInt8 *) &host;
data.opt.len = 0;
data.opt.buf = NULL;
data.udata.len = length;
data.udata.buf = (UInt8 *)buffer;
OSStatus status = OTSndUData(sock,&data);

if (status < 0)
   ...

-----------------------------

special thx to thoses who arrived here !



----- Original Message -----
From: "Cameron Kerr" <email@hidden>
Cc: "apple network dev" <email@hidden>
Sent: Wednesday, November 03, 2004 8:58 PM
Subject: Re: Receive UDP broadcast packets with OTRcvUData


> On 4/11/2004, at 2:50 AM, Matthieu Beghin wrote:
>
> > I create a Synchrone socket and set it non blockling. It receives
> > broadcast on 2.255.255.255.
> > Sometimes I have to answer by broadcast and I get the error
> >
> >  kEACCESErr
> > -3212
> > Permission denied
>
> I suspect this is coming from the Sockets layer (I've no experience
> with Mac programming, but plenty of Unix)
>
> In order to prevent people from accidentally sending to a broadcast
> socket, the socket option SO_BROADCAST must be turned on for a call to
> the bind() system call to work with a broadcast socket. Otherwise, you
> get Permission denied. This does not imply you need to be root, but
> rather that you haven't jumped through a particular hoop.
>
> > I successfully set the IP_BROADCAST option to my socket (no error &
> > status == T_SUCCESS).
>
> IP_BROADCAST would be different to SO_BROADCAST, as SO_BROADCAST is a
> option at the Socket layer, not the IP layer. I don't know what
> IP_BROADCAST for. I've not seen it in my training.
>
> What is the code you are using to turn the option on?
>
> > I create a Synchrone socket and set it non blockling.
>
> What is a Synchrone socket? (Please forgive my newliness ;^)
>
> --
> Cameron Kerr
> email@hidden; http://humbledown.org
>
>  _______________________________________________
> 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
>

 _______________________________________________
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

References: 
 >Re: Receive UDP broadcast packets with OTRcvUData (From: "Matthieu Beghin" <email@hidden>)
 >Re: Receive UDP broadcast packets with OTRcvUData (From: Cameron Kerr <email@hidden>)

  • Prev by Date: Re: Character device synchronization with network interface
  • Next by Date: Re: Character device synchronization with network interface
  • Previous by thread: Re: Receive UDP broadcast packets with OTRcvUData
  • Next by thread: Re: Receive UDP broadcast packets with OTRcvUData
  • Index(es):
    • Date
    • Thread