A simple Ethernet sniffer. A demonstration how to use the Ethernet interface.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hexview.h Source File

hexview.h

00001 /* Function: hexview
00002  *  Prints an array of char to stdout in hex.
00003  *  The data is grouped in two 8 byte groups per line.
00004  *  Each byte is displayed as 2 hex digits and every 
00005  *  line starts with the address of the first byte.
00006  *
00007  *  There is no text view of a line.
00008  *
00009  * Variables:
00010  *  buffer - The array to display.
00011  *  size - The length of buffer.
00012  */
00013 inline void hexview(char *buffer, unsigned int size) {
00014     for(int i = 0; i < size; ++i) {
00015         if((i%16)!=0) {
00016             printf(" ");
00017         } else {
00018             printf("%04X:  ", (i));
00019         }
00020         printf("%02hhx", buffer[i]);
00021         if((i%16) ==  7) { 
00022             printf(" ");
00023         }
00024         if((i%16) == 15) {
00025             printf("\n");
00026         }
00027     }
00028     printf("\n\n\n");
00029 }