Wireshark for Nokia LCD

Dependencies:   NokiaLCD mbed

Fork of Wireshark by Alvin McNair

main.cpp

Committer:
ichoudhury6
Date:
2013-03-01
Revision:
1:c0d6b1d426e8
Parent:
0:126d1599825c

File content as of revision 1:c0d6b1d426e8:

#include "mbed.h"
#include <string>
#include "NokiaLCD.h"

NokiaLCD lcd(p5, p7, p8, p9, NokiaLCD::LCD6610); // mosi, sclk, cs, rst, type


DigitalOut myled(LED1);

Ethernet eth;

string Protocol(int num){
string s;
switch(num){
    case 17 : 
    s="UDP";
    break;
    case 1 : 
    s="ICMP";
    break;
    case 6 : 
    s="TCP";
    break;
    case 89 : 
    s="OSPF";
    break;
    case 2 : 
    s="IGMP";
    break;
    case 103 : 
    s="PIM";
    break;
    default :
    s="None";
    }



return s;

}
 
int main() {
    int number=0;
    int type;
    char ver, prot;
    char hlen;
    char servtype;
    short tot_len,ident;
    string k;
    myled=1;
    int loc = 1;
    char buf[0x600];
    
    int* length=(int *)(buf+12);
 
    while(1) {
        myled=!myled;
       
        int size = eth.receive();
        if(size > 0) {
            loc=1;
            eth.read(buf, size);
            type=(buf[12]<<8|buf[13]);
            ver= buf[14]>>4;
            hlen=buf[14]&0xF;
            servtype=buf[15];
            tot_len=(buf[16]<<8|buf[17]);
            ident=(buf[18]<<8|buf[19]);
            prot=buf[23];
            
            //lcd.fill(2, 51, 128, 10, 0x00FF00);
            //lcd.fill(50, 1, 10, 128, 0xFF0000);
    
                    //ip packet starts at 14
                    // the IP address starts at 
            
            if(type==0x800){
            lcd.background(0x0000FF);
            lcd.cls();
            lcd.locate(0,1);
            lcd.printf("Wireshark on Nokia");
            loc+=2;
            lcd.locate(0, loc);
            number++;
            lcd.printf("Number:%i",number);
            loc+=1;
            lcd.locate(0, loc);
            lcd.printf("Source:  ");
            loc++;
            lcd.locate(0, loc);
            lcd.printf("%d.%d.%d.%d", buf[26], buf[27], buf[28], buf[29]);
            loc+=2;
            lcd.locate(0, loc);
            lcd.printf("Destination: ");
            
            loc++;
            lcd.locate(0, loc);
            lcd.printf("%d.%d.%d.%d", buf[30], buf[31], buf[32], buf[33]);
            loc++;
            lcd.locate(0, loc);
             k=Protocol(prot);
            lcd.printf("Protocol %s",k);
            loc+=2;
            lcd.locate(0, loc);
            lcd.printf("Length:%i",size);
            
             
                    
            
                    
              
            
            //printf("IP Source:  %i.%i.%i.%i\r\n",
            //        buf[26], buf[27], buf[28], buf[29]);
           // printf("IP Destination : %i.%i.%i.%i\r\n",
             //       buf[30], buf[31], buf[32], buf[33]);}
            
                    
        }else{printf("No Connection\r\n");}
 
        wait(1);
    }
}
}