局域网抓包 c++写的抓包分析工具
2008-04-17 21:40:47|分类:默认分类|字号订阅
#include <iostream.h>
#include <pcap.h>
#include <winsock2.h>
#pragma comment(lib,"wpcap")
#pragma comment(lib,"wsock32")
#include <conio.h>
struct ETherNet{
u_char dhost[6];
u_char shost[6];
u_short ether_type;
};
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 bit 的版本信息 + 4 bits 的头长
u_char tos; // TOS 类型
u_short tlen; // 总长度
u_short identification; // Identification
u_short flags_fo; // Flags (3 bits) + Fragment offset (13 bits)
u_char ttl; // 生存期
u_char proto; // 后面的协议信息
u_short crc; // 校验和
ip_address saddr; // 源 IP
ip_address daddr; // 目的 IP
u_int op_pad; // Option + Padding
}ip_header;
/* UDP header*/
typedef struct udp_header{
u_short sport; // Source port
u_short dport; // Destination port
u_short len; // Datagram length