Skip to content

Commit

Permalink
- fixed : display packet after a ping
Browse files Browse the repository at this point in the history
  • Loading branch information
first-developer committed Oct 31, 2011
1 parent 62dc113 commit 569cb51
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 3 deletions.
Binary file modified Arrays/libarrays.a
Binary file not shown.
Binary file modified Events/libevents.a
Binary file not shown.
Binary file modified NetTAP/libtap.a
Binary file not shown.
Binary file modified Stack/netarp.o
Binary file not shown.
Binary file modified Stack/netether.o
Binary file not shown.
48 changes: 48 additions & 0 deletions Stack/neticmp.c
Expand Up @@ -48,13 +48,61 @@ unsigned char icmpDecodePacket(EventsEvent *event,EventsSelector *selector){

return 0;
}
/*
arraysSetValue(&icmp_infos,"type",&type,sizeof(unsigned char),0);
arraysSetValue(&icmp_infos,"code",&code,sizeof(unsigned char),0);
arraysSetValue(&icmp_infos,"data",data,reply_size,AARRAY_DONT_DUPLICATE);
arraysSetValue(&icmp_infos,"size",&reply_size,sizeof(int),0);
arraysSetValue(&icmp_infos,"ldst",&source,sizeof(IPv4Address),0);
unsigned char *data=(unsigned char *)arraysGetValue(infos,"data",NULL,0);
int size=*((int *)arraysGetValue(infos,"size",NULL,0));
arraysFreeArray(infos);
IPv4_fields *ip=(IPv4_fields *)data;
unsigned short int checksum=genericChecksum(data,4*IPv4_get_hlength(ip));
*/

//
// Send ICMPv4 packet
//

unsigned char icmpSendPacket(EventsEvent *event,EventsSelector *selector){

// Get icmp data from the selector
AssocArray *infos=(AssocArray *)selector->data_this;
/*
// Checking presence of ICMP attributes
if( arraysTestIndex(infos,"type",0)<0 ||
arraysTestIndex(infos,"code",0)<0)||
arraysTestIndex(infos,"size",0)<0)||
arraysTestIndex(infos,"data",0)<0) )
{ arraysFreeArray(infos); return 1; }
// Get ICMP attributes: type, code, data
unsigned char *type=(unsigned char *)arraysGetValue(infos,"type",NULL,0); //type
unsigned char *code=(unsigned char *)arraysGetValue(infos,"code",NULL,0); //code
unsigned char *size=(unsigned char *)arraysGetValue(infos,"size",NULL,0); //size
unsigned char *data=(unsigned char *)arraysGetValue(infos,"data",NULL,0); //data
// Compute checksum
unsigned short int checksum=genericChecksum(data,size);
// et icmp header size
int icmp_header_size = 4;
// Init and set icmp header
data=(unsigned char *)realloc(data, size+icmp_header_size);
memmove(data+4, data, size);
bzero(data,4);
arraysSetValue(&icmp_infos,"type",&type,sizeof(unsigned char),0);
arraysSetValue(&icmp_infos,"code",&code,sizeof(unsigned char),0);
arraysSetValue(&icmp_infos,"checksum",data,reply_size,AARRAY_DONT_DUPLICATE);
arraysSetValue(&icmp_infos,"size",&reply_size,sizeof(int),0);
arraysSetValue(&icmp_infos,"ldst",&source,sizeof(IPv4Address),0);
eventsTrigger(picmp->event_out,icmp_infos);
*/

return 0;
}
Binary file modified Stack/neticmp.o
Binary file not shown.
6 changes: 3 additions & 3 deletions Stack/netip.c
Expand Up @@ -119,7 +119,7 @@ if(checksum!=0){
if(ip->ttl==0){
#ifdef VERBOSE
fprintf(stderr,"IP packet: null TTL !\n");

#endif
// ------------------------------------------------------------------
// Sending ICMP Time exceeded packet to the sender if ip->ttl == 0
// ------------------------------------------------------------------
Expand All @@ -134,7 +134,7 @@ if(ip->ttl==0){
unsigned char type= ICMPV4_TYPE_TIME_EXCEEDED;

// Set the type of the ICMP message (ICMPV4_UNREACHABLE_CODE_NETWORK: 0)
unsigned char code= ICMPV4_UNREACHABLE_CODE_NETWORK;
unsigned char code= ICMPV4_CODE_NONE;

// Get src address and data of the datagram sent
IPv4Address source=ip->source;
Expand All @@ -152,8 +152,8 @@ if(ip->ttl==0){
arraysSetValue(&icmp_infos,"size",&reply_size,sizeof(int),0);
arraysSetValue(&icmp_infos,"ldst",&source,sizeof(IPv4Address),0);
eventsTrigger(picmp->event_out,icmp_infos);
}

#endif
free(data); return 0;
}
if(ntohs(ip->length)!=size){
Expand Down
Binary file modified Stack/netip.o
Binary file not shown.
Binary file modified Stack/netudp.o
Binary file not shown.
Binary file modified Stack/processes.o
Binary file not shown.
Binary file modified Stack/stack
Binary file not shown.
Binary file modified Stack/stack.o
Binary file not shown.

0 comments on commit 569cb51

Please sign in to comment.