I was able to get the code to function properly on my CC100 751-9402 on FW30. I had to also use the SysSockGetHostName and SysSockGetHostByName functions for the pointers to function correctly. Without those I got the same exceptions. PROGRAM PLC_PRG VAR sHostName : STRING; Host : SysSocket.SOCK_HOSTENT; pIPAddress : POINTER TO DWORD; in_addr : SysSocket.INADDR; sIPAddress : STRING := ‘000.000.000.000’; // Variable to hold result result : Byte; END_VAR
// 1. Get own hostname
SysSocket.SysSockGetHostName(szHostName:=sHostName, diNameLen:=SIZEOF(sHostName));
// 2. Get own IP address by its name
SysSocket.SysSockGetHostByName(szHostName:=sHostName, pHost:= ADR(Host));
// 3. Select the adapter of addrList
pIPAddress := Host.pAddrList[1];
in_addr.ulAddr := pIPAddress^;
// 4. Convert the IP address from binary to string
SysSocket.SysSockInetNtoa(pInAddr := ADR(in_addr), szIPADDR := sIPAddress, diIPAddrSize:=SIZEOF(sIPAddress));