lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] [PATCH 2/2] lwip: clean up udpecho debug


From: address@hidden
Subject: [lwip-users] [PATCH 2/2] lwip: clean up udpecho debug
Date: Fri, 21 Sep 2007 02:16:24 +0000

lwip: clean up udpecho debug
- add ability to disable debug, default to off (like tcpecho)
- allocate a much smaller debug buffer on stack (4k will crash many stacks)
- range check length before copy to buffer
- show buffer with puts: some embedded printf() can't generate long output
  strings and don't check for buffer overflow...
---
 user/e7/comms/lwip/apps/udpecho.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/user/e7/comms/lwip/apps/udpecho.c 
b/user/e7/comms/lwip/apps/udpecho.c
index cb6c39f..82abca2 100644
--- a/user/e7/comms/lwip/apps/udpecho.c
+++ b/user/e7/comms/lwip/apps/udpecho.c
@@ -33,6 +33,8 @@
 #include "lwip/api.h"
 #include "lwip/sys.h"
 
+/* uncomment following line for verbose output */
+//#define BUF_LEN 256
 
/*-----------------------------------------------------------------------------------*/
 void 
 udpecho_thread(void *arg)
@@ -41,8 +43,11 @@ udpecho_thread(void *arg)
   static struct netbuf *buf;
   static struct ip_addr *addr;
   static unsigned short port;
-  char buffer[4096];
-  
+#if BUF_LEN
+  char buffer[BUF_LEN];
+  int len;
+#endif /* BUF_LEN */
+
   conn = netconn_new(NETCONN_UDP);
   netconn_bind(conn, NULL, 7);
 
@@ -51,10 +56,16 @@ udpecho_thread(void *arg)
     addr = netbuf_fromaddr(buf);
     port = netbuf_fromport(buf);
     netconn_connect(conn, addr, port);
-    netbuf_copy(buf, buffer, buf->p->tot_len);
-    buffer[buf->p->tot_len] = '\0';
+#if BUF_LEN
+    printf("len %d\n", buf->p->tot_len);
+    len = (buf->p->tot_len < (BUF_LEN-1)) ? buf->p->tot_len : (BUF_LEN-1);
+    netbuf_copy(buf, buffer, len);
+    buffer[len] = '\0';
+    netconn_send(conn, buf);
+    puts(buffer);
+#else  /* !BUF_LEN */
     netconn_send(conn, buf);
-    printf("got %s\n", buffer);
+#endif /* !BUF_LEN */
     netbuf_delete(buf);
   }
 }
-- 
1.5.2.1







reply via email to

[Prev in Thread] Current Thread [Next in Thread]