(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.