Application Examples • 179
Example Program for a CGI Application
WAGO-I/O-SYSTEM 750
Linux Fieldbus Coupler
The function
read_IP()
reads the IP address that is currently used from the
Ethernet device eth0. It is irrelevant whether the address was assigned
dynamically, for example via DHPC, or if it is a fixed IP address.
main_info()
calls the above-mentioned functions and writes the HTML code
to the standard console stdout.
Source code description:
ether.c
The TCP/IP configuration page of the Linux fieldbus coupler is generated in
the
ether.c
file. The file includes five functions:
•
read_envvar()
•
write_envvar()
•
read_file()
•
write_file()
•
main_ether()
The static HTML code is stored in the string
pucHtmlEthernet[]
, the
dynamic values "%s" being replaced by a variable value directly in the
printf
command.
The function
read_envvar()
reads values from the highest flash memory
sector. If a fixed IP address is used, these are the IP address, the subnet mask,
the gateway and the host name. If the IP address is assigned dynamically via
DHCP or BootP it is only the host name. The other values are set to default
values.
The function
write_envvar()
writes values into the highest flash memory
sector. If a fixed IP address is used, these are the IP address, the subnet mask,
the gateway and the host name. In case of a dynamic IP address assignment
via DHCP or BootP only the host name is saved. The other parameters keep
their old values. All parameters are entered as a string into the environment
variable
ipmode
which belongs to the start parameters of the Linux kernel.
These environment variables are in the highest flash memory sector and are
read by the boot loader (U-Boot).
read_file()
reads the IP addresses of the name servers from the
/etc/resolv.conf
file.
The function
write_file()
writes the IP addresses of the name servers into
the
/etc/resolv.conf
file.