This function will read out a port forward rule previously set by the netPortForwardSet function.
Input:
index : INT (1..32)
The index of the rule to read.
Output:
Status : SINT
1
|
- Success.
|
0
|
- Not supported.
|
-1
|
- Illegal index.
|
dst_addr : DINT
This is the internal IP address where the communication is forwarded to.
dst_port : DINT
This is the internal port where the communication is forwarded to
src_port : DINT
This is the external port where the communication is forwarded from.
tcp : BOOL
This determines if TCP communication is forwarded.
udp : BOOL
This determines if UDP communication is forwarded.
Declaration:
FUNCTION_BLOCK netPortForwardGet;
VAR_INPUT
index : INT;
END_VAR;
VAR_OUTPUT
Status : SINT;
dst_addr : DINT;
dst_port : DINT;
src_port : DINT;
tcp : BOOL;
udp : BOOL;
END_VAR;
Example:
INCLUDE rtcu.inc
VAR
_rule_get_ : netPortForwardGet;
END_VAR;
FUNCTION pad_string : STRING;
VAR_INPUT
str : STRING;
len : INT;
END_VAR;
pad_string := str;
WHILE strLen(str := pad_string) < len DO
pad_string := pad_string + " ";
END_WHILE;
END_FUNCTION;
FUNCTION show_rule
VAR
str : STRING;
END_VAR;
IF _rule_get_.index < 10 THEN
str := pad_string(str := "", len := 3);
ELSE
str := pad_string(str := "", len := 2);
END_IF;
str := str + intToStr(v := _rule_get_.index);
str := str + ": ";
IF _rule_get_.status = 1 THEN
str := str + dintToStr(v := _rule_get_.src_port);
str := pad_string(str := str, len := 12);
str := str + "=> ";
str := str + sockIPToName(ip := _rule_get_.dst_addr);
str := str + ":";
str := str + dintToStr(v := _rule_get_.dst_port);
str := pad_string(str := str, len := 38);
IF _rule_get_.tcp THEN str := str + "[TCP]"; END_IF;
IF _rule_get_.udp THEN str := str + "[UDP]"; END_IF;
ELSE
str := str + "<NO RULE>";
END_IF;
DebugMsg(message := str);
END_FUNCTION;
FUNCTION show_rules
VAR
i : INT;
END_VAR;
DebugMsg(message := "------------------------------------------------------------");
DebugMsg(message := " Get port forwarding rules...");
FOR i := 1 TO 32 DO
_rule_get_(index := i);
show_rule();
END_FOR;
END_FUNCTION;
PROGRAM example;
VAR
rc : INT;
END_VAR;
rc := netPortForwardSet(
index := 1,
dst_addr := sockIPFromName(str := "192.168.1.153"),
dst_port := 5020,
src_port := 2000,
tcp := TRUE,
udp := FALSE
);
DebugFmt(message := "netPortForwardSet = \1", v1 := rc);
show_rules();
rc := netPortForwardSet(index := 1, src_port := 0);
DebugFmt(message := "netPortForwardSet = \1", v1 := rc);
show_rules();
BEGIN
END;
END_PROGRAM;
|