• 大小: 7.73KB
    文件类型: .cpp
    金币: 1
    下载: 0 次
    发布日期: 2021-03-27
  • 语言: 其他
  • 标签: 其他  

资源简介


使用Winpcap捕获并解析TCP报文 需要配置Winpcap的库和头文件

资源截图

代码片段和文件信息

#include “pcap.h“
//分析udp数据包


//6个字节的mac地址
typedef struct mac_address
{
    u_char byte1;
    u_char byte2;
    u_char byte3;
    u_char byte4;
    u_char byte5;
    u_char byte6;
}mac_address;

typedef struct mac_header
{
    mac_address  daddr;      // 目的地址(Destination address)
    mac_address  saddr;      // 源地址(Source address)
    u_short type;           //Type 默认是0x0800
}mac_header;


/* 4字节的IP地址 */
typedef struct ip_address
{
    u_char byte1;
    u_char byte2;
    u_char byte3;
    u_char byte4;
} ip_address;

/* IPv4 首部 */
typedef struct ip_header
{
    //u_char  ver_ihl;        // 版本 (4 bits) + 首部长度 (4 bits)

    u_char  ihl:4ver:4;///注意:由于字节序的缘故,这里定义的时候需要反过来
    u_char  tos;            // 服务类型(Type of service)
    u_short tlen;           // 总长(Total length)
    u_short identification; // 标识(Identification)
    u_short flags_fo;       // 标志位(Flags) (3 bits) + 段偏移量(Fragment offset) (13 bits)

    u_char  ttl;            // 存活时间(Time 

评论

共有 条评论