[En-Nut-Discussion] Change the IP/gateway

Ole Reinhardt ole.reinhardt at kernelconcepts.de
Wed Nov 24 17:37:15 CET 2004


Hello,

> I want to change the IP from a webpage, then reboot the board with the new
> IP.

Yes, why not? The IP address will be configured in your initialisation
code. You can store the new IP address in the eeprom and restart the
board by using the whatchdog timer. Not read back the ip value from
eeprom and configure your board with the new address...

I do it like this:

    if (sysconfig.network.usedhcp) {
        fprintf_P(uart, PSTR("Initialize Network. Sending DHCP
request..." NL));
        confnet.cdn_ip_addr = 0;
        confnet.cdn_ip_mask = 0;
        confnet.cdn_gateway = 0;

        if (NutDhcpIfConfig("eth0cs", sysconfig.network.mac, 10000)) {
            fprintf_P(uart, PSTR("no DHCP found. Using configured
defaults..." NL));
            NutNetIfConfig2("eth0cs", sysconfig.network.mac,
sysconfig.network.ip_addr, sysconfig.network.netmask,
                            sysconfig.network.gateway);
            NutIpRouteAdd(0, 0, sysconfig.network.gateway, &devEth0cs);
            NutNetSaveConfig();
        }
    } else {
        fprintf_P(uart, PSTR("Initialize Network..." NL));

        confnet.cdn_ip_addr = 0;
        confnet.cdn_ip_mask = 0;
        confnet.cdn_gateway = 0;

        NutNetIfConfig2("eth0cs", sysconfig.network.mac,
sysconfig.network.ip_addr, sysconfig.network.netmask,
                        sysconfig.network.gateway);
        NutIpRouteAdd(0, 0, sysconfig.network.gateway, &devEth0cs);
        NutNetSaveConfig();
    }


Bye,

Ole

-- 
kernel concepts    Tel: +49-271-771091-14
Dreisbachstr. 24   Fax: +49-271-771091-19
D-57250 Netphen    E+ : +49-177-7420433
--





More information about the En-Nut-Discussion mailing list