CC 100 751-9402 FW 30 IP Address in Project Crash

Hello everyone,

I have the following issue that perhaps someone can help me with.

I have a 751-9402 here with FW 30, and it hangs or crashes at a specific part of the program.

The same program runs without issues on a CC100 751-9301 with FW 28 and FW 30.

Does anyone have an idea how I can read out the IP address?

Thanks,

Christoph

Hi, check value in Host.pAddrList[0].
May be you have only one Eth.
And add checks for NULL pointers everywhere..

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));