Discussion:
Multicast on Win2k
(too old to reply)
c***@gmail.com
2005-09-14 21:48:12 UTC
Permalink
Hello,

First Thanks for all the Work on NSPR, it has saved me a lot of work,

I am having an issue with MultiCast on Windows 2000
This Code works Fine on Linux but fails with WSAEADDRNOTAVAIL in
PR_Bind on the windows side. I have Tried to research as much as
possible about WSAEADDRNOTAVAIL but am not having a lot of luck.

If anyone has any ideas as to what I'm doing Wrong...Here are some Code
Snippets (sorry if its a bit messy this has been kicked around by
several different People)


--start Snippet
int UDPTemplate::InitSendChannel(void)
{
PRInt32 result;
PRSocketOptionData SockOptData;

UDP_Send_Socket = PR_NewUDPSocket();

//set the Outbound Address
SendAddress.inet.family = PR_AF_INET;
SendAddress.inet.port = PR_htons(m_SendTo_Port);
PR_StringToNetAddr(m_SendTo_IP, &SendAddress);

//set the Multicast NIC
SockOptData.option = PR_SockOpt_McastInterface;
//PR_StringToNetAddr(m_nic,&SockOptData.value.mcast_if);
SockOptData.value.mcast_if.inet.ip = PR_htonl(PR_INADDR_ANY);
PrintError(PR_SetSocketOption(UDP_Send_Socket, &SockOptData), "Send
Channel: Set Mcast NIC");

//Set the send Socket to be Reusable
SockOptData.option = PR_SockOpt_Reuseaddr;
SockOptData.value.reuse_addr = PR_TRUE;
PrintError( PR_SetSocketOption(UDP_Send_Socket, &SockOptData), "Send
Channel : Set Reusaddr");

//Set Non Blocking
SockOptData.option = PR_SockOpt_Nonblocking;
SockOptData.value.non_blocking = PR_TRUE;
PrintError( PR_SetSocketOption(UDP_Send_Socket, &SockOptData), "Send
Channel : Set Non Blocking");

//set the MultiCast Time to Live
SockOptData.option = PR_SockOpt_McastTimeToLive;
SockOptData.value.mcast_ttl = 120;
PrintError( PR_SetSocketOption(UDP_Send_Socket, &SockOptData), "Send
Channel : Set MultiCast TTL");

SockOptData.option = PR_SockOpt_IpTimeToLive;
SockOptData.value.ip_ttl = 120;
PrintError( PR_SetSocketOption(UDP_Send_Socket, &SockOptData),
"Send Channel : Set IP TTL");

//join the Group
PRMcastRequest myReq;
myReq.mcaddr = SendAddress;
myReq.ifaddr.inet.ip = PR_htonl(PR_INADDR_ANY);
//PR_StringToNetAddr(m_nic,&myReq.ifaddr);
SockOptData.option = PR_SockOpt_AddMember;
SockOptData.value.add_member = myReq;
PrintError(PR_SetSocketOption(UDP_Send_Socket, &SockOptData), "Send
Channel : Joining Group");

PrintError(PR_Bind(UDP_Send_Socket, &SendAddress), "Send Channel :
Binding to Socket");


return 0; //\todo Fix this to return meaningful info

}//end UDPTemplate::InitSendChannel(void)

int UDPTemplate::InitRecvChannel(void)
{
PRInt32 result;
PRSocketOptionData SockOptData;

UDP_Recv_Socket = PR_NewUDPSocket();

//set the Inbound Address
RecvAddress.inet.family = PR_AF_INET;
RecvAddress.inet.port = PR_htons(m_LocalRecv_Port);
PR_StringToNetAddr(m_LocalRecv_IP, &RecvAddress);

//set the Multicast NIC
SockOptData.option = PR_SockOpt_McastInterface;
//PR_StringToNetAddr(m_nic,&SockOptData.value.mcast_if );
SockOptData.value.mcast_if.inet.ip = PR_htonl(PR_INADDR_ANY);
result = PR_SetSocketOption(UDP_Recv_Socket, &SockOptData);

//Set the RECV Socket to be Reusable
SockOptData.option = PR_SockOpt_Reuseaddr;
SockOptData.value.reuse_addr = PR_TRUE;
result = PR_SetSocketOption(UDP_Recv_Socket, &SockOptData);

//Set Non Blocking
SockOptData.option = PR_SockOpt_Nonblocking;
SockOptData.value.non_blocking = PR_TRUE;
result = PR_SetSocketOption(UDP_Recv_Socket, &SockOptData);


//join the Group
PRMcastRequest myReq;
myReq.mcaddr = RecvAddress;
myReq.ifaddr.inet.ip = PR_htonl(PR_INADDR_ANY);
//PR_StringToNetAddr(m_nic,&myReq.ifaddr);
SockOptData.option = PR_SockOpt_AddMember;
SockOptData.value.add_member = myReq;

result = PR_SetSocketOption(UDP_Recv_Socket, &SockOptData);

result = PR_Bind(UDP_Recv_Socket, &RecvAddress);

return result;
}//end UDPTemplate::InitSendChannel(void)

--end Snippet
Wan-Teh Chang
2005-09-15 00:52:53 UTC
Permalink
Post by c***@gmail.com
Hello,
First Thanks for all the Work on NSPR, it has saved me a lot of work,
I am having an issue with MultiCast on Windows 2000
This Code works Fine on Linux but fails with WSAEADDRNOTAVAIL in
PR_Bind on the windows side. I have Tried to research as much as
possible about WSAEADDRNOTAVAIL but am not having a lot of luck.
Are you using the "WINNT" or "WIN95" configuration of NSPR?
What's the name of the NSPR DLL? libnspr4.dll or nspr4.dll?

Wan-Teh
c***@gmail.com
2005-09-15 01:30:07 UTC
Permalink
The dll is libnspr4.dll

I am using v4.6/WINNT5.0_OPT.OBJ or v4.6/WINNT5.0_DBG.OBJD

Do I need to set a preprocessor define for WINNT vs. WIN95?
Wan-Teh Chang
2005-09-15 01:41:42 UTC
Permalink
Post by c***@gmail.com
The dll is libnspr4.dll
I am using v4.6/WINNT5.0_OPT.OBJ or v4.6/WINNT5.0_DBG.OBJD
OK. You are using the "WINNT" configuration of NSPR.

Could you try the "WIN95" configuration of NSPR?
You will need to modify your makefile or project
to link with nspr4.lib instead of libnspr4.lib.
(Similarly for libplc4.lib and libplds4.lib, if you
use them.)
Post by c***@gmail.com
Do I need to set a preprocessor define for WINNT vs. WIN95?
No. We try very hard to make NSPR public header files
"self contained" so that you don't need to set any
preprocessor define when using our header files.

In any case, I am not that familiar with IP multicast,
and there is no IP multicast test in our test suite.
So if you can send me a small test program that reproduces
the bug, I'd appreciate it. Otherwise if you can try to
debug it yourself...

Wan-Teh
c***@gmail.com
2005-09-16 12:53:35 UTC
Permalink
I will get you a sample program and Ill continue to debug on my won
yesterday and to day I am unabelt o get near code so Sometime over the
weekend

Thank You

Loading...