netRouteDelete (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

All

Firmware version:

1.80.00


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;
 
  // Show header
  DebugMsg(message := " Destination      Gateway          Subnet mask      Metric  Iface  Status");
 
  // Iterate routes
  FOR i := 1 TO 100 DO
    // Get route
    _route_(index := i);
    IF _route_.status < 1 THEN EXIT; END_IF;
 
    // Build output
    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);
 
    // Show
    DebugMsg(message := str);
 
  END_FOR;
END_FUNCTION;
 
PROGRAM example;
VAR
  rc    : INT;
END_VAR;
 
  // Add route
  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;
 
  // List routes
  route_list();
 
  // Remove route
  rc := netRouteDelete(index := 1);
  IF rc < 1 THEN
    DebugFmt(message := "  netRouteDel=\1", v1 := rc);
    RETURN;
  END_IF;
 
BEGIN
END;
END_PROGRAM;