1 #include <string.h> 2 #include <stdlib.h> 3 #include <pcap.h> 4 #include <netinet/in.h> 5 #include "packet_header.h" 6 7 #define MAXBYTE2CAPTURE 2048 8 9 int isprint(char c) 10 { 11 return 0; 12 } 13 14 void print_buf(u_char* pBuf, u_int32 len) 15 { 16 if (!pBuf) 17 { 18 return; 19 } 20 21 for(int i=0; i<len; i++) 22 { 23 printf("%02x ", (u_char*)pBuf[i]); 24 25 if ((i%16 == 0 && i!=0) || i == len-1) 26 { 27 printf("\r\n"); 28 } 29 } 30 } 31 32 void parse_ethII(u_char* pData, u_int32 len) 33 { 34 if (!pData || len <14) 35 { 36 return; 37 } 38 39 printf("eth II frame: \r\n"); 40 print_buf(pData, 14); 41 42 /* parse src mac and dst mac */ 43 EthHeader_t* pEth = (EthHeader_t*)pData; 44 printf("destination: %02x:%02x:%02x:%02x:%02x:%02x ", 45 pEth->dest_hwaddr[0], 46 pEth->dest_hwaddr[1], 47 pEth->dest_hwaddr[2], 48 pEth->dest_hwaddr[3], 49 pEth->dest_hwaddr[4], 50 pEth->dest_hwaddr[5]); 51 52 printf("source : %02x:%02x:%02x:%02x:%02x:%02x", 53 pEth->source_hwaddr[0], 54 pEth->source_hwaddr[1], 55 pEth->source_hwaddr[2], 56 pEth->source_hwaddr[3], 57 pEth->source_hwaddr[4], 58 pEth->source_hwaddr[5]); 59 60 /* parse frame type */ 61 printf("\r\nframe type: 0x%x
libpcap报文解析: ipv4、ipv6(待优化)
最新推荐文章于 2024-05-22 12:32:05 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)