Changeset 120540d for libpacketdump
- Timestamp:
- 12/07/06 13:16:25 (14 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, 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:
- d4c8a518
- Parents:
- 0a62bba
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libpacketdump/eth_2054.c
r0a22046 r120540d 14 14 #include <string.h> 15 15 16 #define DISPLAY_EXP(x,fmt,exp) \ 17 if ((unsigned int)len>=((char*)&ip->x-(char*)ip+sizeof(ip->x))) \ 18 printf(fmt,exp); \ 19 else \ 20 return; 21 22 #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,ip->x) 23 24 #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(ip->x)) 25 #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&ip->x)) 26 27 static char *format(struct arphdr *arp, char *hrd, char *pro) 28 { 29 static char buffer[1024]; 30 char ether_buf[18] = {0, }; 16 /* 17 * Converts an ARP hardware address to a printable string. 18 * Takes an ARP header structure and a pointer to the start 19 * of the hardware address in the structure that we should 20 * attempt to decode. 21 */ 22 char *format_hrd(struct arphdr *arp, char *hrd) { 23 static char buffer[1024] = {0,}; 24 uint8_t *addr = (uint8_t *)hrd; 31 25 int i; 32 26 33 if (hrd==NULL) 34 return "Truncated (Truncated)"; 35 switch(arp->ar_hrd) { 27 if (!hrd) { 28 strncpy(buffer, "(Truncated)", sizeof(buffer)); 29 return buffer; 30 } 31 32 switch(ntohs(arp->ar_hrd)) { 36 33 case ARPHRD_ETHER: 37 strcpy(buffer,trace_ether_ntoa((uint8_t *)&hrd, 38 ether_buf)); 34 trace_ether_ntoa(hrd, buffer); 39 35 break; 40 36 default: … … 43 39 buffer,(unsigned char)hrd[i]); 44 40 } 41 break; 45 42 } 46 if (pro==NULL) { 47 strncat(buffer," (Truncated)",sizeof(buffer)); 43 44 return buffer; 45 } 46 47 /* 48 * Converts an ARP protocol address to a printable string. 49 * Takes an ARP header structure and a pointer to the start 50 * of the protocol address in the structure that we should 51 * attempt to decode. 52 */ 53 char *format_pro(struct arphdr *arp, char *pro) { 54 static char buffer[1024] = {0,}; 55 int i; 56 57 if (!pro) { 58 strncpy(buffer, "(Truncated)", sizeof(buffer)); 48 59 return buffer; 49 60 } 50 switch(arp->ar_pro) { 61 62 switch(ntohs(arp->ar_pro)) { 51 63 case 0x0800: 52 snprintf(buffer,sizeof(buffer),"%s (%s)",53 buffer,inet_ntoa(*(struct in_addr*)&pro));64 snprintf(buffer,sizeof(buffer),"%s", 65 inet_ntoa(*(struct in_addr*)pro)); 54 66 break; 55 67 default: … … 63 75 } 64 76 return buffer; 77 65 78 } 66 79 67 80 void decode(int link_type,char *packet,int len) 68 81 { … … 72 85 char *dest_hrd = NULL; 73 86 char *dest_pro = NULL; 74 if (len<8) 87 88 if (len < sizeof(struct arphdr)) { 89 printf(" ARP: (Truncated)\n"); 75 90 return; 76 if (sizeof(*arp)<=(unsigned int)len) 77 source_hrd=packet+sizeof(arp); 78 if (source_hrd && source_hrd-packet+arp->ar_hln<=len) 79 source_pro =source_hrd+arp->ar_hln; 80 if (source_pro && source_pro-packet+arp->ar_pln<=len) 81 dest_hrd =source_pro +arp->ar_pln; 82 if (dest_hrd && dest_hrd-packet+arp->ar_pln<=len) 83 dest_pro =dest_hrd +arp->ar_hln; 84 switch(arp->ar_op) { 91 } 92 93 if (len >= sizeof(struct arphdr) + arp->ar_hln) 94 source_hrd = packet + sizeof(struct arphdr); 95 if (len >= sizeof(struct arphdr) + arp->ar_hln + arp->ar_pln) 96 source_pro = source_hrd + arp->ar_hln; 97 if (len >= sizeof(struct arphdr) + arp->ar_hln * 2 + arp->ar_pln) 98 dest_hrd = source_pro + arp->ar_pln; 99 if (len >= sizeof(struct arphdr) + arp->ar_hln * 2 + arp->ar_pln * 2) 100 dest_pro = dest_hrd + arp->ar_hln; 101 102 switch(ntohs(arp->ar_op)) { 85 103 case ARPOP_REQUEST: 86 printf(" ARP: Who-has %s", 87 format(arp,source_hrd,source_pro)); 88 printf(" please tell %s", 89 format(arp,dest_hrd,dest_pro)); 104 printf(" ARP: who-has %s", format_pro(arp, dest_pro)); 105 printf(" tell %s (%s)\n", format_pro(arp, source_pro), 106 format_hrd(arp, source_hrd)); 107 break; 108 case ARPOP_REPLY: 109 printf(" ARP: reply %s", format_pro(arp, dest_pro)); 110 printf(" is-at %s\n", format_hrd(arp, dest_hrd)); 90 111 break; 91 112 default: 92 printf(" ARP: Unknown opcode (%i) from %s ",93 arp->ar_op,94 format (arp,source_hrd,source_pro));95 printf(" to %s",96 format(arp,dest_hrd,dest_pro)); 113 printf(" ARP: Unknown opcode (%i) from %s to %s\n", 114 ntohs(arp->ar_op), 115 format_pro(arp, source_pro), 116 format_pro(arp, dest_pro)); 117 97 118 break; 98 119 }
Note: See TracChangeset
for help on using the changeset viewer.