资源简介
winpcap开源包,实现数据链路层,网络层,传输层,的封包技术!并发送出去!

代码片段和文件信息
#include “stdio.h“
#include “pcap.h“
#pragma comment(lib“wpcap.lib“)
#pragma comment(lib“WS2_32.lib“)
struct EthernetHeader
{
u_char DestMAC[6];
u_char SourMAC[6];
u_short EthType;
};
struct IpHeader
{
unsigned char Version_HLen;
unsigned char TOS;
short Length;
short Ident;
short Flags_Offset;
unsigned char TTL;
unsigned char Protocol;
short Checksum;
unsigned int SourceAddr;
unsigned int DestinationAddr;
};
struct PsdTcpHeader
{
unsigned long SourceAddr;
unsigned long DestinationAddr;
char Zero;
char Protcol;
unsigned short TcpLen;
};
struct TcpHeader
{
unsigned short SrcPort;
unsigned short DstPort;
unsigned int SequenceNum;
unsigned int Acknowledgment;
unsigned char HdrLen;
unsigned char Flags;
unsigned short AdvertisedWindow;
unsigned short Checksum;
unsigned short UrgPtr;
};
unsigned short checksum(unsigned short *data int length)
{
unsigned long temp = 0;
while (length > 1)
{
temp += *data++;
length -= sizeof(unsigned short);
}
if (length)
{
temp += *(unsigned short*)data;
}
temp = (temp >> 16) + (temp &0xffff);
temp += (temp >> 16);
return (unsigned short)(~temp);
}
int main(int argc char **argv)
{
struct EthernetHeader ethernet;
struct IpHeader ip;
struct TcpHeader tcp;
struct PsdTcpHeader ptcp;
int Result;
unsigned char SendBuffer[200];
char TcpData[] = “Tcp Data Test.“;
pcap_if_t *NetwokDevice;
pcap_t *WinpcapHandle;
pcap_if_t *Device;
char WinpcapError[PCAP_ERRBUF_SIZE];
int DeviceIndex = 0;
char DeviceName[100][1000];
int i;
Result = pcap_findalldevs(&NetwokDevice WinpcapError);
if (Result == - 1)
{
printf(“pcap_findalldevs Error“);
return 0;
} for (Device = NetwokDevice i = 0; Device && i < 10; Device = Device->next i++)
{
printf(“Number %d:“ i);
printf(“%s:“ Device->name);
printf(“%s\n“ Device->description);
sprintf(DeviceName[i] “%s“ Device->name);
}
for (;;)
{
printf(“Please Choose the Device Number:(0-%d)“ i - 1);
scanf(“%d“ &DeviceIndex);
if (DeviceIndex > i - 1 || DeviceIndex < 0)
{
printf(“Device Number Error\n“);
continue;
}
else
break;
}
WinpcapHandle = pcap_open_live(LPCTSTR(DeviceName[DeviceIndex]) 65535 1 1000 WinpcapError);
if (WinpcapHandle == NULL)
{
printf(“pcap_open_live error“);
pcap_freealldevs(NetwokDevice);
return 0;
}
memset(ðernet 0 sizeof(ethernet));
BYTE destmac[8];
destmac[0] = 0x00;
destmac[1] = 0x11;
destmac[2] = 0x22;
destmac[3] = 0x33;
destmac[4] = 0x44;
destmac[5] = 0x55;
memcpy(ethernet.DestMA
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6118 2011-12-05 17:05 maketcppacket.cpp
----------- --------- ---------- ----- ----
6118 1
相关资源
- Modbus协议官方文档中、英文全
- Omron ETN21模块进行modbustcp通讯
- 组态王中S7-300TCP驱动
- 基于Apache Mina实现的TCP长连接和短连接
- CVI下的TCP服务器和客户端
- 代码客:G-TcpServer(IOCP) 1.0 正式版及
- TCP 发包工具(windows)
- VxWorks TCPIP协议栈
- socket小工具(可方便建立TCP UDP的soc
- vc 编写的基于TCP协议的客户/服务器
- 基于CSocket的多人聊天室
- 采用WINSOCK2 编写的TCP/UDP通信程序
- Modbus TCP Client
- 易语言 TCP使用HTTP、SOCKES5代理IP。
- 西门子S7-1200 MODBUS-TCP通讯编程
- 200SMART Modbus-TCP通信程序演示-轮询(多
- TCP_UDP对结构体加密数据传输
- 基于PIC的TCP/IP网络协议和zigbee无线传
- 欧姆龙PLC tcp通信工具
- 欧姆龙以太网通讯TCP/UDP及欧姆龙PLC程
- 流媒体相关协议标准RTP/RTSP/RTCP PDF文档
- WinPcap+中文技术文档
- 航海模拟器中DCPA TCPA的算法
- TCPMP 支持ce6.0的播放器
- TCP/IP协议详解3卷全_高清_带书签
- stm32103c8t6ESP8266串口转WIFI模块TCP服务器
- DOS下的TCP-IP协议库文件原代码.rar
- 《TCP/IP详解卷2:实现》pdf
- 《TCP/IP:协议分析与应用编程》课后
- Modbus—TCP协议
评论
共有 条评论