This function will read out the NAT parameters for the network interface previously set by using the netSetNATParam function.
Input:
Iface : SINT
The network interface. (See Network)
Output:
Forward : BOOL
Determines whether requests from the interface will be forwarded to other interfaces
Gateway : BOOL
Determines whether the interface will be used as a gateway for requests.
Declaration:
FUNCTION_BLOCK netGetNATParam;
VAR_INPUT
Iface : MANDATORY SINT;
END_VAR;
VAR_OUTPUT
Forward : BOOL;
Gateway : BOOL;
END_VAR;
Example:
INCLUDE rtcu.inc
VAR
ap : netGetAPParam;
dhcp : netGetDHCPParam;
lan : netGetLANParam;
nat : netGetNATParam;
wpa : netWLANSecurityWPA;
END_VAR;
FUNCTION booltostr : STRING;
VAR_INPUT
v : BOOL;
END_VAR;
IF v THEN booltostr := "Yes"; ELSE booltostr := "No"; END_IF;
END_FUNCTION;
FUNCTION setup_lan;
netSetLANParam(iface := 2, DHCP := TRUE, AutoDNS := TRUE);
netSetNATParam(iface := 2, forward := FALSE, gateway := TRUE);
END_FUNCTION;
FUNCTION setup_ap;
wpa.phrase := "pass phrase";
netSetAPParam(
ssid := "RTCU network",
sec_config := ADDR(wpa),
hidden := FALSE,
chnl := 1,
Address := sockIPFromName(str := "192.168.1.1"),
Subnet := sockIPFromName(str := "255.255.255.0")
);
netSetNATParam(iface := 5, forward := TRUE, gateway := FALSE);
netSetDHCPParam(
iface := 5,
enable := ON,
time := 24,
first := sockIPFromName(str := "192.168.1.100"),
last := sockIPFromName(str := "192.168.1.200"),
dns_type := 1,
applynow := TRUE
);
END_FUNCTION;
FUNCTION show_lan;
DebugMsg(message := "===== LAN =====");
lan(iface := 2);
DebugMsg(message := " Network= IPv4");
DebugMsg(message := " DHCP= " + booltostr(v := lan.dhcp));
DebugMsg(message := " IP= " + sockIPToName(ip := lan.ip));
DebugMsg(message := " Subnet= " + sockIPToName(ip := lan.SubnetMask));
DebugMsg(message := " Gw= " + sockIPToName(ip := lan.Gateway));
DebugMsg(message := " Auto DNS= " + booltostr(v := lan.AutoDNS));
DebugMsg(message := " DNS= " + sockIPToName(ip := lan.DNS1));
DebugMsg(message := " DNS= " + sockIPToName(ip := lan.DNS2));
nat(iface := 2);
DebugMsg(message := " NAT");
DebugMsg(message := " forward= " + booltostr(v := nat.forward));
DebugMsg(message := " gateway= " + booltostr(v := nat.gateway));
END_FUNCTION;
FUNCTION show_ap;
DebugMsg(message := "===== Access Point =====");
ap();
DebugMsg(message := " SSID= " + ap.ssid);
IF ap.security = 0 THEN
DebugMsg(message := " Security= None");
ELSIF ap.security = 1 THEN
DebugFmt(message := " Security= WPA/WPA2 PSK");
netGetAPSecurity(sec_config := ADDR(wpa));
DebugMsg(message := " phrase= " + wpa.phrase);
ELSE
DebugFmt(message := " Security= Unknown (\1)", v1 := ap.security);
END_IF;
DebugMsg(message := " Network= IPv4");
DebugMsg(message := " Address= " + sockIPToName(ip := ap.Address));
DebugMsg(message := " Subnet= " + sockIPToName(ip := ap.Subnet));
nat(iface := 5);
DebugMsg(message := " NAT");
DebugMsg(message := " forward= " + booltostr(v := nat.forward));
DebugMsg(message := " gateway= " + booltostr(v := nat.gateway));
dhcp(iface := 5);
DebugMsg(message := " DHCP");
DebugMsg(message := " enable= " + booltostr(v := dhcp.enable));
DebugFmt(message := " lease time= \1 Hours", v1 := dhcp.time);
DebugMsg(message := " subnet= " + sockIPToName(ip := dhcp.Subnet));
DebugMsg(message := " range, start= " + sockIPToName(ip := dhcp.first));
DebugMsg(message := " range, end= " + sockIPToName(ip := dhcp.last));
IF dhcp.dns_type = 1 THEN
DebugMsg(message := " DNS type= Self/Auto");
ELSIF dhcp.dns_type = 2 THEN
DebugMsg(message := " DNS type= Static");
ELSE
DebugFmt(message := " DNS type= Unknown (\1)", v1 := dhcp.dns_type);
END_IF;
DebugMsg(message := " DNS= " + sockIPToName(ip := dhcp.DNS1));
DebugMsg(message := " DNS= " + sockIPToName(ip := dhcp.DNS2));
END_FUNCTION;
PROGRAM example;
setup_lan();
setup_ap();
show_lan();
show_ap();
netOpen(iface := 2);
netOpen(iface := 5);
BEGIN
END;
END_PROGRAM;
|