Re: Can't see "localhost" machine when sending UDP broadcast on OS X
Re: Can't see "localhost" machine when sending UDP broadcast on OS X
- Subject: Re: Can't see "localhost" machine when sending UDP broadcast on OS X
- From: Vincent Lubet <email@hidden>
- Date: Mon, 4 Mar 2002 16:25:31 -0800
Martin,
This is not a well known problem and UDP broadcast works well for me
when both send and receiver are on the same host.
Vincent
On Monday, March 4, 2002, at 09:40 AM, Martin Bestmann wrote:
Hi,
I'm having a problem with OpenTransport UDP broadcasts on Mac OS X.
Here is the scenario.
I'm having a client and an app. To detect the client I'm sending an UDP
broadcast into the subnet where the client is located. Everything works
fine as long as the client and the app are not running on the same
machine. In the case of running both on the same machine the client
never receives the broadcast (my NotifierProc is never called).
The same code works fine on Mac OS 9.
Here are the code snippets of what I do.
------------------------
Client code
-----------
UInt16 theSocket=0x1234; // something for the snippet
xEndPoint=OTOpenEndpointInContext(OTCreateConfiguration(kUDPName),0,NULL,
&Ooops,gClientContext);
TBind reqBind;
InetAddress myAddress;
OTInitInetAddress(&myAddress,theSocket,0);
reqBind.addr.buf = (UInt8*)&myAddress;
reqBind.addr.len = sizeof(InetAddress);
reqBind.qlen = 1;
Ooops=xEndPoint->Bind(&reqBind,NULL);
REQUIRE(Ooops==kOTNoError,FailError);
Ooops=xEndPoint->InstallNotifier(xNotifyUUP,this);
REQUIRE(Ooops==kOTNoError,FailError);
Ooops=xEndPoint->SetBlocking();
REQUIRE(Ooops==kOTNoError,FailError);
Ooops=xEndPoint->SetAsynchronous(); // Ensure endpoint is async
REQUIRE(Ooops==kOTNoError,FailError);
The notifier never get's called.
AppCode
-------
xEndPoint=OTOpenEndpointInContext(OTCreateConfiguration(kUDPName),0,NULL,
&Ooops,gClientContext);
Ooops=xEndPoint->Bind(NULL,NULL);
REQUIRE(Ooops==kOTNoError,FailError);
this->NegotiateDatagramOptions(xEndPoint);
Ooops=xEndPoint->InstallNotifier(xNotifyUUP,this);
REQUIRE(Ooops==kOTNoError,FailError);
Ooops=xEndPoint->SetBlocking();
REQUIRE(Ooops==kOTNoError,FailError);
Ooops=xEndPoint->SetAsynchronous(); // Ensure endpoint is async
REQUIRE(Ooops==kOTNoError,FailError);
void NegotiateDatagramOptions(EndpointRef inEndpoint)
{
struct TOption : public TOptionHeader
{
UInt32 value;
}; // struct TSizeOption
OSErr Ooops=noErr;
TOption optionBuffer;
optionBuffer.len = sizeof(optionBuffer);
optionBuffer.level = INET_IP;
optionBuffer.name = IP_BROADCAST;
optionBuffer.status = 0;
optionBuffer.value = T_YES;
TOptMgmt optReq;
optReq.flags = T_NEGOTIATE;
optReq.opt.maxlen = sizeof(optionBuffer);
optReq.opt.len = sizeof(optionBuffer);
optReq.opt.buf = (UInt8*) &optionBuffer;
Ooops=inEndpoint->OptionManagement(&optReq, &optReq);
_DBW(if (Ooops!=noErr)
DebugMessage("COTTCPLookup::NegotiateDatagramOptions
error=%d\n",Ooops);)
_DBW(else DebugMessage("COTTCPLookup::NegotiateDatagramOptions
success!\n");)
_DBW(if (optionBuffer.status!=T_SUCCESS)
DebugMessage("COTTCPLookup::NegotiateDatagramOptions
optionBuffer.status=%d\n",optionBuffer.status);)
}
Sending the broadcast is done here
OTResult Ooops=noErr;
rUDPBroadcastServerData ServerData;
InetAddress BroadcastAddress;
TUnitData theUnitData;
OTInitInetAddress(&BroadcastAddress,xSocket,theNet);
theUnitData.addr.len=sizeof(BroadcastAddress);
theUnitData.addr.buf=(UInt8*)&BroadcastAddress;
theUnitData.opt.maxlen=0;
theUnitData.opt.len=0;
theUnitData.opt.buf=NULL;
theUnitData.udata.len=sizeof(ServerData);
theUnitData.udata.buf=(UInt8*)&ServerData;
Ooops=xEndPoint->SndUData(&theUnitData);
------------------------
Is this a known issue? Is there a workaround?
Best regards,
Martin
--
_________________________________________________________________________
Martin Bestmann Netopia Development GmbH
Phone: +49-9134-9942-0 Weingasse 26
Fax: +49-9134-997911 91077 Neunkirchen am
Brand
e-mail:email@hidden Germany
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.