netRouteAdd (Function) |
Top Previous Next |
This function adds a network route to the system.
The routes tells the system how to send socket data to the receiver. Normally the system handles it automatically based on the subnet for each network, using the NAT Gateway as the default route, see netSetNATParam. When using more complex networks (Multiple subnets, VPN, or similar) it may be necessary to access devices on different subnets that can not use the default route. In these cases, the netRouteAdd function can be used to create new routes for specific IP address ranges. It is also possible to create multiple prioritized routes to the same destination by using different metric values, providing automatic fallback when an interface is disconnected.
The routes added with this function are not persistent across reset.
Input: index : INT (1..25) The index of the route.
iface : SINT The network interface to use for the route. (See Network for available interfaces)
ip : DINT The destination IP address or network for the route. This is used in conjunction with the netmask to define the IP ranges handled by this route. To match a single IP address, set ip to the IP address and netmask to 255.255.255.255. To mach an IP range, set netmask to the netmask for the range and IP to the first IP address that matches the mask, i.e. if using the netmask 255.255.255.0, the IP address could be 192.168.1.0 and would match 192.168.1.1 - 192.168.1.254.
netmask : DINT (default -1 ( 255.255.255.255 )) The subnet mask that, when combined with the destination IP address, determines the subnet which the route applies to.
gateway : DINT (default -1) The IP address of the gateway to route the communication through. When the gateway is all zeros, no gateway will be used and the destination IP range must be directly available on the network interface. If set to -1, the gateway address of the network interface is used automatically. If the gateway to the destination is on a different subnet than the directly attached network, a route must first be created to that gateway.
metric : INT (0..32000, default 0) The metric of the route, which determines which route to use. Lower values give higher priority.
Returns:
Declaration: FUNCTION netRouteAdd;
Example: INCLUDE rtcu.inc |