#include//close
unsigned short checksum(unsigned short *buf, int nword);//校验和函数
int main(int argc, char *argv[])
{
//1.创建通信用的原始套接字
int sock_raw_fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
//2.根据各种协议首部格式构建发送数据报
unsigned char send_msg[1024] = {
//--------------组MAC--------14------
0x8c, 0xec, 0x4b, 0x73, 0xae, 0x04, //dst_mac: E8-6A-64-17-CB-5C目的地址
0x8c, 0xec, 0x4b, 0x73, 0x79, 0xb5, //src_mac: 8c:ec:4b:73:79:b5源mac地址
0x08, 0x00, //类型:0x0800 IP协议
/*//--------------组IP---------20------
0x45, 0x00, 0x00, 0x00, //版本号:4, 首部长度:20字节, TOS:0, --总长度--:
0x00, 0x00, 0x00, 0x00,//16位标识、3位标志、13位片偏移都设置0
0x80, 17, 0x00, 0x00,//TTL:128、协议:UDP(17)、16位首部校验和
10, 221, 20, 11,//src_ip: 10.221.20.11
10, 221, 20, 10,//dst_ip: 10.221.20.10
//---