This function will delete a route previously set by the netRouteAdd function.
Input:
index : INT (1..25)
The index of the route.
Returns:
1
|
- Success.
|
0
|
- Not supported.
|
-1
|
- Illegal parameter.
|
-2
|
- Index is not used..
|
Declaration:
FUNCTION netRouteDelete;
VAR_INPUT
index : INT;
END_VAR;
Example:
INCLUDE rtcu.inc
VAR
_route_ : netRouteGet;
END_VAR;
FUNCTION show_iface : STRING;
VAR_INPUT
iface : SINT;
END_VAR;
CASE iface OF
1: show_iface := "Cellular";
2: show_iface := "LAN1";
3: show_iface := "LAN2";
4: show_iface := "WLAN";
5: show_iface := "AP";
ELSE
show_iface := "<unknown>";
END_CASE;
END_FUNCTION;
FUNCTION route_list;
VAR
str : STRING;
tmp : STRING;
i : INT;
END_VAR;
DebugMsg(message := " Destination Gateway Subnet mask Metric Iface Status");
FOR i := 1 TO 100 DO
_route_(index := i);
IF _route_.status < 1 THEN EXIT; END_IF;
str := " ";
tmp := sockIPToName(ip := _route_.ip);
WHILE strLen(str := tmp) < 17 DO tmp := tmp + " "; END_WHILE;
str := str + tmp;
tmp := sockIPToName(ip := _route_.gateway);
WHILE strLen(str := tmp) < 17 DO tmp := tmp + " "; END_WHILE;
str := str + tmp;
tmp := sockIPToName(ip := _route_.netmask);
WHILE strLen(str := tmp) < 17 DO tmp := tmp + " "; END_WHILE;
str := str + tmp;
tmp := intToStr(v := _route_.metric);
WHILE strLen(str := tmp) < 8 DO tmp := tmp + " "; END_WHILE;
str := str + tmp;
tmp := show_iface(iface := _route_.iface);
WHILE strLen(str := tmp) < 7 DO tmp := tmp + " "; END_WHILE;
str := str + tmp;
str := str + intToStr(v := _route_.status);
DebugMsg(message := str);
END_FOR;
END_FUNCTION;
PROGRAM example;
VAR
rc : INT;
END_VAR;
rc := netRouteAdd(
index := 1
,iface := 2
,ip := sockIPFromName(str := "10.0.0.0")
,netmask := sockIPFromName(str := "255.0.0.0")
,gateway := sockIPFromName(str := "192.168.1.1")
,metric := 100
);
IF rc < 1 THEN
DebugFmt(message := " netRouteAdd=\1", v1 := rc);
RETURN;
END_IF;
route_list();
rc := netRouteDelete(index := 1);
IF rc < 1 THEN
DebugFmt(message := " netRouteDel=\1", v1 := rc);
RETURN;
END_IF;
BEGIN
END;
END_PROGRAM;
|