This performs an ethernet sniff test. Copied from an existing ethernet sniff test and updated to work properly with the LISA, supporting output of content to the USB console. See also: http://mbed.org/users/rolf/code/ethsnif/

Dependencies:   C027-REVB mbed

Fork of ethsnif by Rolf Meyer

Revision:
1:a7a52d202638
Parent:
0:29e2df9de9f1
--- a/main.cpp	Fri Sep 04 12:24:03 2009 +0000
+++ b/main.cpp	Sat Dec 14 00:53:08 2013 +0000
@@ -1,43 +1,26 @@
 #include "mbed.h"
+#include "C027.h"
 #include "Ethernet.h"
 #include "hexview.h"
 
 using namespace mbed;
 
-DigitalOut led4(LED4);
+DigitalOut led4(LED);
 
 Ethernet eth;
-
-/*
-__packed struct eth {
-    unsigned char    dst[6];
-    unsigned char    src[6];
-    unsigned short   type;
-};
-
-void show(char *buffer, int size) {
-    eth *e = (eth *)buffer;
-    printf("Destination:  %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
-            e->dst[0], e->dst[1], e->dst[2], e->dst[3], e->dst[4], e->dst[5]);
-    printf("Source: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
-            e->src[0], e->src[1], e->src[2], e->src[3], e->src[4], e->src[5]);
-  
-    printf("Type %hd\n", eth->type);
-    hexview(buffer, size);
-}
-*/
+Serial pc(USBTX, USBRX);
 
 unsigned short htons(unsigned short n) {               // Host short to network shor
   return ((n & 0xff) << 8) | ((n & 0xff00) >> 8);      // Byte swapping
 }
 
 void show(char *buf, int size) {
-    printf("Destination:  %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
+    pc.printf("Destination:  %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n\r",
             buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
-    printf("Source: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
+    pc.printf("Source: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n\r",
             buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
   
-    printf("Type %hd\n", htons((short)buf[12]));
+    pc.printf("Type %hd\n\r", htons((short)buf[12]));
     
     hexview(buf, size);
 }
@@ -46,16 +29,31 @@
 int main() {
     char buffer[0x600];
     int size = 0;
+    int led_toggle_count = 5;
+    
+ #if 0
+    while(1) {
+        led4 = !led4;
+        wait(0.2);
+    }
+#else
+    while( led_toggle_count-- > 0 )
+    {
+        led4 = !led4;
+        wait(0.2);
+    }
+#endif
+
+   // open the PC serial port and (use the same baudrate)
+    pc.baud(MDMBAUD);
+    
+    pc.printf( "Start ETHERNET Sniff Testing\n\r");
     
     while(1) {
         if((size = eth.receive()) != 0) {
+            led4=!led4;
             eth.read(buffer, size);
             show(buffer, size);
         }
-        
-        led4 = 1;
-        wait(0.2);
-        led4 = 0;
-        wait(0.2);
     }
 }