#define LOCAL_IP 0xC0A8015A
#define BROADCAST_IP 0xC0A801FF
#define IS_SYNCHRONE_SOCKET
static OTResult SetFourByteOption(EndpointRef ep,
OTXTILevel
level,
OTXTIName name,
UInt32 value)
{
OTResult
err;
TOption option;
TOptMgmt request;
TOptMgmt
result;
option.len = kOTFourByteOptionSize;
option.level =
level;
option.name = name;
option.status =
0;
option.value[0] = value;
request.opt.buf = (UInt8 *) &option;
request.opt.len =
sizeof(option);
request.flags = T_NEGOTIATE;
result.opt.buf = (UInt8 *) &option;
result.opt.maxlen =
sizeof(option);
err = OTOptionManagement(ep, &request, &result);
if (err == noErr) {
if (option.status != T_SUCCESS)
{
err = option.status;
}
}
return err;
}
int
main(void)
{
/***********************************
whole
initialisation
***********************************/
EndpointRef
sock;
long osErr_;
InetAddress
ipAddress;
if((osErr_ =
InitOpenTransportInContext(kInitOTForApplicationMask,
NULL))!=noErr)
return -1;
sock = OTOpenEndpointInContext(OTCreateConfiguration(kUDPName),
0,nil,&osErr_, NULL);
if(osErr_!=noErr || sock ==
kOTInvalidEndpointRef)
return -1;
#ifdef
IS_SYNCHRONE_SOCKET
if((osErr_=OTSetSynchronous(sock))!=noErr)
return
-1;
#endif
OTInitInetAddress(&ipAddress, 12345,
kOTAnyInetAddress);
osErr_ = SetFourByteOption(sock, INET_IP, IP_REUSEADDR,
1);
if (osErr_ != noErr)
return -1;
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)
return -1;
#define IP_BROADCAST_IFADDR 0x1018 /* Set interface addr for
broadcasts */
osErr_ = SetFourByteOption(sock, INET_IP, IP_BROADCAST_IFADDR,
LOCAL_IP);
if (osErr_ != noErr)
return
-1;
/*****************************
SendTo
*****************************/
TUnitData
data;
InetAddress host;
char buffer[512];
OTInitInetAddress(&host, 0x1936,
BROADCAST_IP);
data.addr.len = sizeof(host);
data.addr.buf =
(UInt8 *) &host;
data.opt.len = 0;
data.opt.buf =
NULL;
data.udata.len = 512;
data.udata.buf = (UInt8
*)buffer;
OSStatus status = OTSndUData(sock,&data);
if (status < 0)
return
-1;
return 0;
}
//-----------------------------------------------------------
----- Original Message -----
Sent: Thursday, November 04, 2004 12:09
AM
Subject: Re: Receive UDP broadcast
packets with OTRcvUData
At 14:50 +0100 3/11/04, 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
when calling
OTSndUData.
I just tried sending UDP broadcasts under OT on Mac OS X, and it worked
as easily as I remember. I'm not sure what's going on with your code,
but you might want to compare it with mine. I've included my test
program at the end of this email. Try it out on your machine and see
what you get.
You should just be able to paste it into an Xcode CoreServices command
line tool project.
S+E
--
Quinn "The
Eskimo!"
<http://www.apple.com/developer/>
Apple Developer Technical Support *
Networking, Communications, Hardware