Get the network interface from a socket address.
Input:
address : STRING
The socket address.
Returns: SINT
The network interface. 1 = Mobile network, 2 = LAN network, etc. (See Network).
0
|
- The function is not supported.
|
-2
|
- One or more parameters are illegal.
|
-17
|
- Generic error.
|
Declaration:
FUNCTION soAddrToInterface : SINT;
VAR_INPUT
address : STRING;
END_VAR;
Example:
INCLUDE rtcu.inc
PROGRAM udp_example;
VAR
handle : SYSHANDLE;
address : STRING;
buf : ARRAY [1..230] OF SINT;
size : DINT;
local : STRING;
remote : STRING;
rc : INT;
port : DINT;
host : STRING;
str : STRING;
END_VAR;
netOpen(iface := _NET_IFACE_LAN1);
rc := soCreate(type := _SO_TYPE_DGRAM, protocol := _SO_PROT_UDP, socket := handle);
IF rc < 1 THEN
DebugFmt(message := "soCreate=\1", v1 := rc);
END_IF;
soAddrInetSet(address := address, port := 5022);
rc := soBind(socket := handle, address := address);
IF rc < 1 THEN
DebugFmt(message := "soBind=\1", v1 := rc);
END_IF;
BEGIN
rc := soRecvFrom(
socket := handle,
data := ADDR(buf),
maxsize := SIZEOF(buf),
size := size,
local := local,
remote := remote
);
IF rc < 1 THEN
END_IF;
soAddrInetGet(address := remote, host := host, port := port);
str := strFromMemory(src := ADDR(buf), len := INT(size));
DebugFmt(message := " soRecvFrom = \1", v1 := rc);
DebugFmt(message := " interface = \1", v1 := soAddrToInterface(address := local));
DebugMsg(message := " IP address = " + host);
DebugFmt(message := " IP port = \4", v4 := port);
DebugMsg(message := " data = [" + str + "]");
END;
END_PROGRAM;
|