Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UDP broadcast message fails
#9
(07-18-2019, 10:22 PM)rlebeau Wrote: For instance, if your computer is assigned an IP of 192.168.0.5 with a subnet mask of 255.2255.255.0, then the subnet broadcast IP is 192.168.0.255.

If you look at the source code for TIdSocketHandle.Broadcast() in IdSocketHandle.pas, there is the following TODO comment:

Code:
if LIP = '' then begin
  if IPVersion = Id_IPv4 then begin
    // TODO: on Windows, use WSAIoctl(SIO_GET_BROADCAST_ADDRESS) instead.
    // On other platforms, use getifaddrs() or other suitable API to retreive
    // the broadcast IP if possible, or else the local IP/Subnet and then
    // calculate the broadcast IP manually...
    LIP := '255.255.255.255'; {Do not Localize}

Thank you, Gambit. Now I am frustrated with my last compiler from Borland (ver.6) - the 32-bit code it creates does not run as expected:

Code:
#include <winsock2.h>

WSADATA wsaData;
SOCKET sktUDP;
BOOL b;
BYTE buff[0x8000];
sockaddr_in sabrdcst;
int iWSAerr;
DWORD dw;
//error checking is omitted for a well known reason
  ::ZeroMemory(&wsaData, sizeof(wsaData));
  WSAStartup(0x0202, &wsaData);
  sktUDP = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  b = TRUE;
  setsockopt(sktUDP, SOL_SOCKET, SO_BROADCAST, (char*)&b, sizeof(b));
  ::ZeroMemory(&sabrdcst, sizeof(sabrdcst));
  iWSAerr = WSAIoctl(sktUDP, SIO_GET_BROADCAST_ADDRESS, NULL, 0, &sabrdcst, sizeof(sabrdcst), &dw, NULL, NULL);

The last line (WSAIoctl() call) causes an AV no matter what. Note: both pointers in the call are 16-byte aligned otherwise the return is error 10014.

This happens on win10-64 regardless of compatibility settings. Neither MS compilers nor 3rd party ones exhibit this problem.

Tried BCC32.exe v.5 & v.6, but v.4 is ok. I do need the code above to be used with BCC32 vers.5 & 6. What are my options?

Thanks in advance.
Reply


Messages In This Thread
UDP broadcast message fails - by Boba TC - 07-18-2019, 03:49 AM
RE: UDP broadcast message fails - by Boba TC - 07-18-2019, 05:51 PM
RE: UDP broadcast message fails - by rlebeau - 07-18-2019, 10:22 PM
RE: UDP broadcast message fails - by Boba TC - 07-19-2019, 02:26 AM
RE: UDP broadcast message fails - by rlebeau - 07-19-2019, 09:55 PM
RE: UDP broadcast message fails - by Boba TC - 07-20-2019, 02:08 AM
RE: UDP broadcast message fails - by Boba TC - 08-17-2019, 04:35 AM
RE: UDP broadcast message fails - by rlebeau - 08-17-2019, 07:22 AM
RE: UDP broadcast message fails - by Boba TC - 07-20-2019, 08:09 PM
RE: UDP broadcast message fails - by rlebeau - 07-23-2019, 09:35 PM
RE: UDP broadcast message fails - by Boba TC - 08-22-2019, 12:53 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)