//原始套接字学习笔记之代码结构
/*
*host端程序结构
*/#include <>
#define ..//主函数
int main()
{
//建立发送线程
pthread_t pthread_send;
//建立接收线程
pthread_t pthread_recv;
//维持线程
while(1)
{ }
}//发送线程函数
void *thread_send()
{
//创建socket
sock_send=socket(PF_PACKET,SOCK_PACKET,htons(ETH_P_ALL));
//设置包头 //设置发包地址
struct sockaddr send_addr;
//创建发送程序
while(1)
{
//合并包头
makepkg(sendbuf,header);
//发送数据包
sendto();
}
}//创建接收线程
void *thread_recv()
{
//创建socket
//调用ethernet_setpormisc函数设置网卡为混杂模式
//使用ifreq函数获取物理网卡接口索引,设置绑定物理网卡 //接收数据包
while(1)
{
//包头判定
//数据输出
}
}//网卡设置混杂模式函数
void ethernet_setpormisc(int fd, int i_flags)//合并包头函数
void makepkg(char buffer[], char header[])本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-03/128819.htm