?? ethernet.c
字號:
#define ETHERNET_ENTITY
/*
*************************************************************
*
* ethernet.c
*
* 數據鏈路層:以太網協議
*created data 2008.8.21
*
*by g.m
*
**************************************************************
*/
#include "includes.h"
/*
**********************************************
*函數:INT8U Rec_Ethernet_Packet(INT8U *RecData)
*功能:
* 以太網層的接收函數:
* 1.負責更新arp表
* 2.將接收到的數據交給上層協議處理
*
*參數:
* 由rtl8019接收到的數據
*
*
*********************************************
*/
INT8U Rec_Ethernet_Packed(INT8U *RecData)
{
ipethernet *pnet;
pnet=(ipethernet*)RecData;
if((pnet->NextProtocal)==0x0008) //為ip數據報
{
RecData+=14;
//尚需添加
//************************************//
}
else if((pnet->NextProtocal)==0x0608) //arp 報
{
RecData+=14;
PROCESS_ARP_REC(RecData);
return 1;
}
return 3; //網絡層協議不支持ip
}
/*
*********************************************
*函數:uint8 Send_Ip_To_LLC(_pkst *TxData,uint8 *de_ip)
*功能:
* 以太網層的數據發送,由上層協議調用,ip協議
*
*參數:TxData 上層協議數據信息,
* de_ip ip地址
*注意:
* 該函數負責查詢arp表中是否有對應ip的mac信息,若有則調用
* Send_Ethernet_Fram()去發送數據,
* 否則則發送arp請求,并返回失敗標志
*
*
*********************************************
*/
INT8U Send_Ip_To_LLC(_pkst * TxData,INT8U *de_ip)
{
INT8U i;
//是否是本子網
if(de_ip[0]==My_Ip[0])
if(de_ip[1]==My_Ip[1])
if(de_ip[2]==My_Ip[2])
{
//表示可以發送,查找arp表找到對應的MAc地址進行發送
for(i=0;i<MAX_ARP_NUM;i++)
{
//OS_ENTER_CRITICAL();
if(de_ip[0]==My_Arp[i].IP_NUM[0])
if(de_ip[1]==My_Arp[i].IP_NUM[1])
if(de_ip[2]==My_Arp[i].IP_NUM[2])
if(de_ip[3]==My_Arp[i].IP_NUM[3])
if(My_Arp[i].TTL!=0)
{
My_Arp[i].TTL=100;
Send_ethernet_Frame(TxData,My_Arp[i].MAC_NUM,IP_PACKED);
//OS_EXIT_CRITICAL();
return 1;
}
}
//沒有找到對應的arp表項
//OS_EXIT_CRITICAL();
Arp_Request(de_ip); //發送arp請求
return 0;
}
//不是本子網,直接發給網管
Send_ethernet_Frame(TxData, My_GateArp.MAC_NUM,IP_PACKED);
return 1;
}
/*
****************************************************
*函數:uint8 Send_ethernet_Fram(_pkst TxData,uint8 *de_mac,uint8 protocal)
*功能:
* 以太網層發送協議
* 接收來字ip協議和arp協議
*
*參數:TxData 上層協議的數據
* de_mac 接收端的協議地址
* protocal 協議的類型,ip,arp
* 】
*
****************************************************
*/
INT8U Send_ethernet_Frame(_pkst * TxData,INT8U *de_mac,INT8U protocal)
{
ipethernet ethernet_head;
_pkst ethernet;
ethernet_head.DestMacId[0]=*de_mac++;
ethernet_head.DestMacId[1]=*de_mac++;
ethernet_head.DestMacId[2]=*de_mac++;
ethernet_head.DestMacId[3]=*de_mac++;
ethernet_head.DestMacId[4]=*de_mac++;
ethernet_head.DestMacId[5]=*de_mac;
ethernet_head.SourceMacId[0]=My_Mac[0];
ethernet_head.SourceMacId[1]=My_Mac[1];
ethernet_head.SourceMacId[2]=My_Mac[2];
ethernet_head.SourceMacId[3]=My_Mac[3];
ethernet_head.SourceMacId[4]=My_Mac[4];
ethernet_head.SourceMacId[5]=My_Mac[5];
if(protocal==ARP_PACKED)
{
ethernet_head.NextProtocal=0x0608;
}
else
{
ethernet_head.NextProtocal=0x0008;
}
//準備數據結構,將數據傳送到下層協議
ethernet.next=TxData;
ethernet.length=14;
ethernet.pdata=(INT8U *)ðernet_head;
//OS_ENTER_CRITICAL();
eth_send(ðernet);
//OS_EXIT_CRITICAL();
return 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -