struct 结构

Linux大全评论923 views阅读模式

//原始套接字学习笔记之代码结构
/*
*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)

企鹅博客
  • 本文由 发表于 2019年8月2日 18:26:11
  • 转载请务必保留本文链接:https://www.qieseo.com/133285.html

发表评论