From a28e0d77a1cd896a049dfd5b7a28d28f72cf73b6 Mon Sep 17 00:00:00 2001
From: Benoit Rat <benoit@sevensols.com>
Date: Tue, 15 May 2012 17:08:41 +0200
Subject: [PATCH 4/8] add DHCP retries by tom

---
 net/dhcp.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index ad32b53..88febea 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -607,6 +607,7 @@ static void dhcp_reset_env(void)
 static int do_dhcp(int argc, char *argv[])
 {
 	int ret, opt;
+	int retries=-1;
 
 	dhcp_reset_env();
 
@@ -627,6 +628,7 @@ static int do_dhcp(int argc, char *argv[])
 		}
 	}
 
+
 	dhcp_con = net_udp_new(0xffffffff, PORT_BOOTPS, dhcp_handler, NULL);
 	if (IS_ERR(dhcp_con)) {
 		ret = PTR_ERR(dhcp_con);
@@ -643,14 +645,25 @@ static int do_dhcp(int argc, char *argv[])
 	if (ret)
 		goto out1;
 
+	if(argc >= 2)
+		retries = simple_strtoul(argv[1], NULL, 10);
+
 	while (dhcp_state != BOUND) {
 		if (ctrlc())
 			break;
+		if (!retries) 
+		{
+			ret = ETIMEDOUT;
+			goto out1;
+		}
+		
 		net_poll();
 		if (is_timeout(dhcp_start, 3 * SECOND)) {
 			dhcp_start = get_time_ns();
 			printf("T ");
 			ret = bootp_request();
+			if(retries > 0)
+				retries--;
 			if (ret)
 				goto out1;
 		}
-- 
1.7.7.2

