// Simple demo tcpdump http://anntguide.free.fr #include <EtherCard.h> // ethernet interface mac address, must be unique on the LAN byte mymac[] = { 0,1,2,3,4,5 }; byte Ethernet::buffer[700]; uint32_t timer; char website[] PROGMEM = "wolpoox;logsm.net" ; //"api.pachube.com"; static int sent=0; static int biglen; int ICMP=1; int TCP=0; void setup () { Serial.begin(9600); Serial.println("\n[TcpDump]"); if (ether.begin(sizeof Ethernet::buffer, mymac,10) == 0) Serial.println( "Failed to access Ethernet controller"); if (!ether.dhcpSetup()) Serial.println("DHCP failed"); ether.printIp("IP: ", ether.myip); ether.printIp("GW: ", ether.gwip); ether.printIp("DNS: ", ether.dnsip); if (!ether.dnsLookup(website)) Serial.println("DNS failed"); ether.printIp("SRV: ", ether.hisip); prtdump("andiamo",10); } void prhexa(int base,int nb, char *t){ for (int iii=0;iii<nb;iii=iii+1) { Serial.print((byte) ether.buffer[base+iii]); Serial.print(" "); } Serial.print("<-- "); Serial.println(t); } void dump (int deb, int fin){ for (int iii=deb;iii<fin;iii=iii+1) Serial.print ((char)ether.buffer[iii]); Serial.println(""); Serial.println("------------------"); for (int iii=deb;iii<fin;iii=iii+1) { Serial.print (ether.buffer[iii]); Serial.print(" "); } } void prtdump(char *tt,int tout){ Serial.println("------------------"); Serial.println(tt); Serial.println("------------------"); prhexa(0,6,"to mac "); prhexa(6,6,"from mac "); prhexa(12,2,"ehr type (8) "); prhexa(14,1," version "); prhexa(15,1," service "); prhexa(16,2," big len "); biglen=ether.buffer[16]*256+ether.buffer[17]; Serial.print(" "); Serial.print(biglen);Serial.println(" decimal "); prhexa(18,2," id "); prhexa(20,2," flag "); prhexa(22,1," ttl "); prhexa(23,1," next "); if (ether.buffer[23]==1){ ICMP=1;Serial.println("ICMP");} if (ether.buffer[23]==1) {TCP=1;Serial.print("TCP");} prhexa(24,2," chk "); prhexa(26,4," source ip "); prhexa(30,4," dest ip "); if (ICMP) { prhexa(34,1," type 8 "); prhexa(35,1," code 0 "); prhexa(36,2," chk "); prhexa(38,2," id 4019 "); prhexa(40,2," seq num "); dump (42,biglen); } if (TCP) { prhexa(34,2," source port "); prhexa(36,2," dest port "); prhexa(38,4," seq num "); prhexa(42,4," ack num "); prhexa(46,2," hdr len "); prhexa(48,2," reserved "); dump (50,biglen); } Serial.println(""); Serial.println("------------------"); } void loop () { word q= ether.packetReceive(); if (q>64) { prtdump("recu",q); } if (!sent){ sent=1; Stash::prepare(PSTR("Bonjour")); prtdump("envoi",10); ether.tcpSend(); } word resu= ether.packetLoop(q); if (resu>0){ Serial.print(resu); Serial.println("");} }