能解析cap文件并发送原始数据报文,并进行统计
片段:
static int send_init(socket_message_t *socket_msg, char *dev_name)
{
memset(&socket_msg->addr, 0, sizeof(struct sockaddr_ll));
if(-1 == (socket_msg->sd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP)))){ //创建套接字 SOCK_RAW为原始套接字
return -2;
}
socket_msg->addr.sll_ifindex = inject_pkt_interface_index(socket_msg->sd, dev_name); //获取eth0接口的序号
if(socket_msg->addr.sll_ifindex < 1) {
return -3;
}
return 0;
}
1