歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> struct 結構

struct 結構

日期:2017/3/1 9:18:28   编辑:Linux編程

//原始套接字學習筆記之代碼結構
/*
*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[])

Copyright © Linux教程網 All Rights Reserved