Hello,
We use DUnit on Delphi 2006/Windows XP to do automated unit tests on our code.
We updated from release 32 (I think) to release 37 and several UDP unit tests
are now failing.
The unit tests are making sure that UDP multicast works. The tests are failing
because an attempt to AddMulticast('224.0.51.52') is returning with a winsock
10049 error (which is something like "address unavailable/invalid").
The DUnit code is:
...
// set up UDP listener
mxTestUDPSocket := TUDPBlockSocket.Create;
mxTestUDPSocket.Bind('0.0.0.0', C_SCRIPT_MULTICAST_PORT);
mxTestUDPSocket.AddMulticast(C_SCRIPT_MULTI_CAST_BROADCAST_IP);
Assert(mxTestUDPSocket.LastError = 0);
...
So the assert fails because LastError is 10049
THE OLD CODE:
Tracing into AddMulticast('224.0.51.52') with the code that works (release 32)
shows it uses inet_addr()
procedure TUDPBlockSocket.AddMulticast(MCastIP: string);
begin
...
Multicast.imr_multiaddr.S_addr := synsock.inet_addr(PChar(MCastIP));
Multicast.imr_interface.S_addr := u_long(INADDR_ANY);
SockCheck(synsock.SetSockOpt(FSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP,
pchar(@Multicast), SizeOf(Multicast)));
...
end;
S_addr is 875757792. I guess Windows must reverse the bits in the IP address
because this is backwards. Still, this is the case that works.
THE NEW CODE:
The new code uses a Synapse function to convert the IP dot notation to an
integer. This doesn't work:
procedure TUDPBlockSocket.AddMulticast(MCastIP: string);
begin
...
Multicast.imr_multiaddr.S_addr := strtoip(MCastIP);
Multicast.imr_interface.S_addr := INADDR_ANY;
SockCheck(synsock.SetSockOpt(FSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP,
pchar(@Multicast), SizeOf(Multicast)));
...
end;
S_addr is -536857804 (as an integer - or 3758109492 as an unsigned int).
This is what I'd expect 224.0.51.52 to convert to (224 is the most significate
by I believe). I'm assuming Intel big/little endian junk factors into the
problem here.
There is a difference between new and old code. New code doesn't work. Is
this a bug or did I miss something?
Jon B.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public