资源简介
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
相关资源
- TCP/IP网络编程(随书代码)
- linux tcpmodbus服务端
- 局域网P2P通信根据TCP协议实现采用V
- TCP Sliding Window滑动窗口协议演示动画
- windows平台下socket编程之TCP
- Linux下利用TCPsocket传输图片
- QT基于TCP的服务器和客户端.rar
- Linux 下实现的聊天系统,TCP实现
- TCP Westwood源代码
- BSD的TCP/IP协议栈
- 全功能MODBUS-TCP从站仿真软件
- linux tcp udp 调试工具
- 网络调试助手,用了很多这个最好用
- Qt TCP客户端
- TCP收发json. 客户端和服务端
- Jpcap 64位,完整一套包括WinpcapJpcapjp
- 基于Socket的网络通信大作业 含可运行
- 采用UDP或者TCP编写一个网络程序,该
- TCP、UDP协议服务端
- TcpListener类与TcpClient类的使用
- 以太网ENC28J60 tcp udp
- 基于Linux平台的网络聊天室设计
- 许继103TCP规约解析
- CSocket类的使用,实现TCP/UDP在局域网内
- 基于TCP协议的QT聊天程序
- linux C TCP/UDP客户端服务端的相互实时
- Modbus Slave
- Qt下tcp和udp的编程
- qttcpsocket传送结构体
- TCP、IP不错的TCP协议开发 实现上位机
评论
共有 条评论