From: Jon B. <Jo...@ci...> - 2006-11-30 17:56:04
|
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 :=3D TUDPBlockSocket.Create; mxTestUDPSocket.Bind('0.0.0.0', C_SCRIPT_MULTICAST_PORT); mxTestUDPSocket.AddMulticast(C_SCRIPT_MULTI_CAST_BROADCAST_IP); Assert(mxTestUDPSocket.LastError =3D 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 :=3D synsock.inet_addr(PChar(MCastIP)); Multicast.imr_interface.S_addr :=3D 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 :=3D strtoip(MCastIP); Multicast.imr_interface.S_addr :=3D 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. |