Changeset 387d299 for libpacketdump
- Timestamp:
- 07/04/14 11:37:25 (7 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- d14e23d
- Parents:
- 9ad7a35
- Location:
- libpacketdump
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
libpacketdump/eth_2048.c
r66ad025 r387d299 10 10 #include <netdb.h> 11 11 12 #define DISPLAY_EXP(x,fmt,exp) \13 if ((unsigned int)len>=((char*)&ip->x-(char*)ip+sizeof(ip->x))) \14 printf(fmt,exp); \15 else \16 return;17 18 #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,ip->x)19 20 #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(ip->x))21 #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&ip->x))22 23 12 DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len) 24 13 { … … 29 18 } 30 19 //DISPLAY(ip_tos," TOS %02x") 31 DISPLAY_EXP(ip _tos," DSCP %02x",ip->ip_tos >> 2)32 DISPLAY_EXP(ip _tos," ECN %x",ip->ip_tos & 0x2)33 DISPLAYS(ip _len," Total Length %i")20 DISPLAY_EXP(ip, ip_tos," DSCP %02x",ip->ip_tos >> 2); 21 DISPLAY_EXP(ip, ip_tos," ECN %x",ip->ip_tos & 0x2); 22 DISPLAYS(ip, ip_len," Total Length %i"); 34 23 printf("\n IP:"); 35 DISPLAYS(ip _id," Id %u");24 DISPLAYS(ip, ip_id," Id %u"); 36 25 37 26 if ((unsigned int)len >= ((char *)&ip->ip_ttl - (char *)ip - 2)) { … … 42 31 } 43 32 //printf("\n IP:"); 44 DISPLAY(ip _ttl,"\n IP: TTL %i");33 DISPLAY(ip, ip_ttl,"\n IP: TTL %i"); 45 34 if ((unsigned int)len>=((char*)&ip->ip_p-(char*)ip+sizeof(ip->ip_p))) { 46 35 struct protoent *ent=getprotobynumber(ip->ip_p); … … 55 44 return; 56 45 } 57 DISPLAYS(ip _sum," Checksum %i\n");58 DISPLAYIP(ip _src," IP: Source %s ");59 DISPLAYIP(ip _dst,"Destination %s\n");46 DISPLAYS(ip, ip_sum," Checksum %i\n"); 47 DISPLAYIP(ip, ip_src," IP: Source %s "); 48 DISPLAYIP(ip, ip_dst,"Destination %s\n"); 60 49 decode_next(packet+ip->ip_hl*4,len-ip->ip_hl*4,"ip",ip->ip_p); 61 50 return; -
libpacketdump/ip_1.c
rec0b927 r387d299 3 3 #include <dlfcn.h> 4 4 #include "libpacketdump.h" 5 6 #define STRUCT icmp7 8 #define SAFE(x) \9 ((unsigned int)len>=((char*)&STRUCT->x-(char*)STRUCT+sizeof(STRUCT->x)))10 #define DISPLAY_EXP(x,fmt,exp) \11 if (SAFE(x)) \12 printf(fmt,exp); \13 else \14 return;15 16 #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,STRUCT->x)17 18 #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(STRUCT->x))19 #define DISPLAYL(x,fmt) DISPLAY_EXP(x,fmt,htonl(STRUCT->x))20 #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&STRUCT->x))21 5 22 6 static char *unreach_types[]={ -
libpacketdump/ip_17.c
rc7062df r387d299 8 8 #include <netdb.h> 9 9 10 #define STRUCT udp11 12 #define SAFE(x) \13 ((unsigned int)len>=((char*)&STRUCT->x-(char*)STRUCT+sizeof(STRUCT->x)))14 #define DISPLAY_EXP(x,fmt,exp) \15 if (SAFE(x)) \16 printf(fmt,exp); \17 else \18 return;19 20 #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,STRUCT->x)21 22 #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(STRUCT->x))23 #define DISPLAYL(x,fmt) DISPLAY_EXP(x,fmt,htonl(STRUCT->x))24 #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&STRUCT->x))25 26 10 27 11 DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len) … … 29 13 struct libtrace_udp *udp = (struct libtrace_udp*)packet; 30 14 printf(" UDP:"); 31 if (SAFE( source)) {15 if (SAFE(udp, source)) { 32 16 struct servent *ent=getservbyport(udp->source,"udp"); 33 17 if(ent) { … … 41 25 return; 42 26 } 43 if (SAFE( dest)) {27 if (SAFE(udp, dest)) { 44 28 struct servent *ent=getservbyport(udp->dest,"udp"); 45 29 if(ent) { … … 54 38 } 55 39 printf("\n UDP:"); 56 DISPLAYS( len," Len %u");57 DISPLAYS( check," Checksum %u");40 DISPLAYS(udp, len," Len %u"); 41 DISPLAYS(udp, check," Checksum %u"); 58 42 printf("\n"); 59 43 if (htons(udp->source) < htons(udp->dest)) -
libpacketdump/ip_33.c
rc7062df r387d299 6 6 #include <netinet/tcp.h> 7 7 #include <netinet/in.h> 8 9 #define STRUCT dccp10 11 #define SAFE(x) \12 ((unsigned int)len>=((char*)&STRUCT->x-(char*)STRUCT+sizeof(STRUCT->x)))13 #define DISPLAY_EXP(x,fmt,exp) \14 if (SAFE(x)) \15 printf(fmt,exp); \16 else \17 return;18 19 #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,STRUCT->x)20 21 #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(STRUCT->x))22 #define DISPLAYL(x,fmt) DISPLAY_EXP(x,fmt,htonl(STRUCT->x))23 #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&STRUCT->x))24 8 25 9 struct dccphdr { … … 50 34 { 51 35 struct dccphdr *dccp = (struct dccphdr*)packet; 52 DISPLAYS( source," DCCP: Source %i");53 DISPLAYS(d est," Dest %i");36 DISPLAYS(dccp, source," DCCP: Source %i"); 37 DISPLAYS(dccp, dest," Dest %i"); 54 38 if (len>4) { 55 39 printf("\n DCCP: Type %i",dccp->type); … … 69 53 else 70 54 return; 71 DISPLAY(d off," DCCP: Dataoff: %i\n");55 DISPLAY(dccp, doff," DCCP: Dataoff: %i\n"); 72 56 if (len>9) 73 57 printf(" DCCP: NDP %i CsLen: %i\n",dccp->ndp,dccp->cslen); … … 75 59 return; 76 60 } 77 DISPLAY(check," DCCP: Checksum: %i\n"); 61 /* Should this be byteswapped??? */ 62 DISPLAY(dccp, check," DCCP: Checksum: %i\n"); 78 63 if (htons(dccp->source) < htons(dccp->dest)) 79 64 decode_next(packet+dccp->doff*4,len-dccp->doff*4,"dccp",htons(dccp->source)); -
libpacketdump/ip_6.c
r9ca0b29 r387d299 5 5 #include <assert.h> 6 6 #include <netdb.h> 7 8 #define SAFE(x) \9 ((unsigned int)len>=((char*)&tcp->x-(char*)tcp+sizeof(tcp->x)))10 #define DISPLAY_EXP(x,fmt,exp) \11 if (SAFE(x)) \12 printf(fmt,exp); \13 else \14 return;15 16 #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,tcp->x)17 18 #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(tcp->x))19 #define DISPLAYL(x,fmt) DISPLAY_EXP(x,fmt,htonl(tcp->x))20 #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&tcp->x))21 7 22 8 DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len) … … 27 13 libtrace_tcp_t *tcp = (libtrace_tcp_t *)packet; 28 14 printf(" TCP:"); 29 if (SAFE( source)) {15 if (SAFE(tcp, source)) { 30 16 struct servent *ent=getservbyport(tcp->source,"tcp"); 31 17 if(ent) { … … 39 25 return; 40 26 } 41 if (SAFE( dest)) {27 if (SAFE(tcp, dest)) { 42 28 struct servent *ent=getservbyport(tcp->dest,"tcp"); 43 29 if(ent) { … … 52 38 } 53 39 printf("\n TCP:"); 54 DISPLAYL( seq," Seq %u");40 DISPLAYL(tcp, seq," Seq %u"); 55 41 printf("\n TCP:"); 56 DISPLAYL( ack_seq," Ack %u");42 DISPLAYL(tcp, ack_seq," Ack %u"); 57 43 if ((char*)&tcp->window-(char *)tcp>len) { 58 44 printf("\n"); … … 71 57 if (tcp->ack) printf(" ACK"); 72 58 if (tcp->urg) printf(" URG"); 73 DISPLAYS( window," Window %i");59 DISPLAYS(tcp, window," Window %i"); 74 60 printf("\n TCP:"); 75 DISPLAYS( check," Checksum %i");76 DISPLAYS( urg_ptr," Urgent %i");61 DISPLAYS(tcp, check," Checksum %i"); 62 DISPLAYS(tcp, urg_ptr," Urgent %i"); 77 63 pkt = (unsigned char*)packet+sizeof(*tcp); 78 64 plen = (len-sizeof *tcp) < (tcp->doff*4-sizeof(*tcp))?(len-sizeof(*tcp)):(tcp->doff*4-sizeof *tcp); -
libpacketdump/ip_89.c
re224862 r387d299 10 10 static void dump_ospf_v2_header(libtrace_ospf_v2_t *hdr, unsigned len) { 11 11 12 printf(" OSPF Header: Version %u Type %u ",13 hdr->ospf_v, hdr->type);12 DISPLAY(hdr, ospf_v, " OSPF Header: Version %u"); 13 DISPLAY(hdr, type, " Type %u "); 14 14 switch(hdr->type) { 15 15 case TRACE_OSPF_HELLO: … … 29 29 break; 30 30 } 31 printf("\n"); 31 32 32 printf("\n OSPF Header: Length %u \n", ntohs(hdr->len)); 33 printf(" OSPF Header: Router Id %s ", inet_ntoa(hdr->router)); 34 printf("Area Id %s\n", inet_ntoa(hdr->area)); 35 printf(" OSPF Header: Checksum %u Auth Type %u\n", ntohs(hdr->sum), 36 ntohs(hdr->au_type)); 37 38 printf(" OSPF Header: Auth Key ID %u Auth Data Len %u\n", 39 hdr->au_key_id, hdr->au_data_len); 40 printf(" OSPF Header: Auth Crypto Seq %u\n", ntohl(hdr->au_seq_num)); 41 33 DISPLAYS(hdr, ospf_len, "OSPF Header: Length %u \n"); 34 DISPLAYIP(hdr, router, " OSPF Header: Router Id %s "); 35 DISPLAYIP(hdr, area, "Area Id %s\n"); 36 DISPLAYS(hdr, sum, " OSPF Header: Checksum %u "); 37 DISPLAYS(hdr, au_type, "Auth Type %u\n"); 38 DISPLAY(hdr, au_key_id, " OSPF Header: Auth Key ID %u "); 39 DISPLAY(hdr, au_data_len, "Auth Data Len %u\n"); 40 DISPLAYL(hdr, au_seq_num, " OSPF Header: Auth Crypto Seq %u\n"); 42 41 43 42 } -
libpacketdump/libpacketdump.h
r66ad025 r387d299 6 6 extern "C" { 7 7 #endif 8 9 #define SAFE(hdr,x) \ 10 ((unsigned int)len>=((char*)&hdr->x-(char*)hdr+sizeof(hdr->x))) 11 12 #define DISPLAY_EXP(hdr,x,fmt,exp) \ 13 if (SAFE(hdr, x)) \ 14 printf(fmt,exp); \ 15 else {\ 16 printf("(Truncated)\n"); \ 17 return; \ 18 } 19 20 #define DISPLAY(hdr,x,fmt) DISPLAY_EXP(hdr,x,fmt,hdr->x) 21 22 #define DISPLAYS(hdr,x,fmt) DISPLAY_EXP(hdr,x,fmt,htons(hdr->x)) 23 #define DISPLAYL(hdr,x,fmt) DISPLAY_EXP(hdr,x,fmt,htonl(hdr->x)) 24 #define DISPLAYIP(hdr,x,fmt) DISPLAY_EXP(hdr,x,fmt,inet_ntoa(*(struct in_addr*)&hdr->x)) 25 8 26 9 27 void trace_hexdump_packet(libtrace_packet_t *packet);
Note: See TracChangeset
for help on using the changeset viewer.