diff --git a/commands/net.c b/commands/net.c index c7418264d..c079af132 100644 --- a/commands/net.c +++ b/commands/net.c @@ -151,6 +151,9 @@ static int do_dhcp (cmd_tbl_t *cmdtp, int argc, char *argv[]) { int size; + if (NetLoopInit(DHCP) < 0) + return 1; + if ((size = NetLoop(DHCP)) < 0) return 1; @@ -217,6 +220,9 @@ netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[]) safe_strncpy (BootFile, remotefile, sizeof(BootFile)); + if (NetLoopInit(proto) < 0) + goto out; + if ((size = NetLoop(proto)) < 0) { rcode = size; goto out; @@ -256,6 +262,9 @@ static int do_cdp (cmd_tbl_t *cmdtp, int argc, char *argv[]) { int r; + if (NetLoopInit(CDP) < 0) + return 1; + r = NetLoop(CDP); if (r < 0) { printf("cdp failed; perhaps not a CISCO switch?\n"); diff --git a/include/net.h b/include/net.h index add62733c..86c334000 100644 --- a/include/net.h +++ b/include/net.h @@ -315,6 +315,9 @@ extern IPaddr_t NetNtpServerIP; /* the ip address to NTP */ extern int NetTimeOffset; /* offset time from UTC */ /* Initialize the network adapter */ +int NetLoopInit(proto_t); + +/* Do the work */ int NetLoop(proto_t); /* Shutdown adapters and cleanup */ diff --git a/net/net.c b/net/net.c index 5aa51a5e0..7d94a3f73 100644 --- a/net/net.c +++ b/net/net.c @@ -238,8 +238,7 @@ void ArpTimeoutCheck(void) * Main network processing loop. */ -int -NetLoop(proto_t protocol) +int NetLoopInit(proto_t protocol) { struct eth_device *eth_current = eth_get_current(); IPaddr_t ip; @@ -292,6 +291,11 @@ NetLoop(proto_t protocol) NetOurNativeVLAN = getenv_VLAN("nvlan"); NetServerIP = dev_get_param_ip(ð_current->dev, "serverip"); + return 0; +} + +int NetLoop(proto_t protocol) +{ /* * Start the ball rolling with the given start function. From * here on, this code is a state machine driven by received diff --git a/net/ping.c b/net/ping.c index 1fef18ae0..26b777882 100644 --- a/net/ping.c +++ b/net/ping.c @@ -97,6 +97,9 @@ int do_ping (cmd_tbl_t *cmdtp, int argc, char *argv[]) return -1; } + if (NetLoopInit(PING) < 0) + return 1; + if (NetLoop(PING) < 0) { printf("ping failed; host %s is not alive\n", argv[1]); return 1; diff --git a/net/sntp.c b/net/sntp.c index df22caef2..3be166a37 100644 --- a/net/sntp.c +++ b/net/sntp.c @@ -110,6 +110,9 @@ int do_sntp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) if (toff == NULL) NetTimeOffset = 0; else NetTimeOffset = simple_strtol (toff, NULL, 10); + if (NetLoopInit(SNTP) < 0) + return 1; + if (NetLoop(SNTP) < 0) { printf("SNTP failed: host %s not responding\n", argv[1]); return 1;