From 81c1b21e5d96dd045ea26406946d2bb3640fb4f3 Mon Sep 17 00:00:00 2001 From: "bernard.xiong" Date: Sun, 27 Dec 2009 06:44:47 +0000 Subject: [PATCH] cleanup ping code; git-svn-id: https://rt-thread.googlecode.com/svn/trunk@237 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- net/apps/ping.c | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/net/apps/ping.c b/net/apps/ping.c index 045b7d026d..1f0b82205c 100644 --- a/net/apps/ping.c +++ b/net/apps/ping.c @@ -20,20 +20,10 @@ #define PING_DEBUG LWIP_DBG_ON #endif -/** ping target - should be a "struct ip_addr" */ -#ifndef PING_TARGET -#define PING_TARGET (netif_default?netif_default->gw:ip_addr_any) -#endif - /** ping receive timeout - in milliseconds */ -#ifndef PING_RCV_TIMEO #define PING_RCV_TIMEO 1000 -#endif - /** ping delay - in milliseconds */ -#ifndef PING_DELAY #define PING_DELAY 100 -#endif /** ping identifier - must fit on a u16_t */ #ifndef PING_ID @@ -45,11 +35,6 @@ #define PING_DATA_SIZE 32 #endif -/** ping result action - no default action */ -#ifndef PING_RESULT -#define PING_RESULT(ping_ok) -#endif - /* ping variables */ static u16_t ping_seq_num; struct _ip_addr @@ -125,8 +110,6 @@ static void ping_recv(int s) iecho = (struct icmp_echo_hdr *)(buf+(IPH_HL(iphdr) * 4)); if ((iecho->id == PING_ID) && (iecho->seqno == htons(ping_seq_num))) { - /* do some ping result processing */ - PING_RESULT((ICMPH_TYPE(iecho) == ICMP_ER)); return; } else @@ -136,13 +119,10 @@ static void ping_recv(int s) } } - if (len == 0) + if (len <= 0) { - LWIP_DEBUGF( PING_DEBUG, ("ping: recv - %lu ms - timeout\n", (sys_now()-ping_time))); + rt_kprintf("ping: timeout\n"); } - - /* do some ping result processing */ - PING_RESULT(0); } rt_err_t ping(char* target, rt_uint32_t time, rt_size_t size) @@ -182,7 +162,7 @@ rt_err_t ping(char* target, rt_uint32_t time, rt_size_t size) } send_time ++; - if (send_time > time) break; /* send ping times reached, stop */ + if (send_time >= time) break; /* send ping times reached, stop */ rt_thread_delay(PING_DELAY); /* take a delay */ }