?? udp.c
字號:
//**********************************
//*版本: Test 1.0
//*作者: XUGUOHONG
//*E-MAIL: KK20Y@YAHOO.COM.CN
//*WEBSITE:microdesign.000webhost.com
//**********************************
#include <udp.h>
#include <icmp.h>
#include <ip.h>
#include <rtl8019as.h>
//**********************************
//* 系統(tǒng) MAC地址設定(根據(jù)需要修正)
//**********************************
extern unsigned char SYSMAC[6];
//**********************************
//* 系統(tǒng) IP地址設定(根據(jù)需要修正)
//**********************************
extern unsigned char SYSIP[4];
void udp(void);
void udp_reply_test(void);
void udp_rev(void);
void udp()
{
udp_rev();
}
//**********************************
//* UDP處理
//*處理子程序
//*根據(jù)不同的端口來處理不同的數(shù)據(jù)
//*0x9090為測試端口
//**********************************
void udp_rev(void)
{
unsigned int port; // udp port
port=read_62256(UDP_DES_PORT); // xxab
port=port<<8; // abxx
port=port+read_62256(UDP_DES_PORT+1); // abcd
if(port==0x0008)
//udp_p8(); // 執(zhí)行具體應用程序
;
else if(port==0x0088)
//udp_p88();
;
else if(port==0x0888)
//udp_p888();
;
else if(port==0x8888)
//udp_p8888();
;
else if(port==0x9090)
{
udp_reply_test(); // 原數(shù)據(jù)返回測試程序
}
else rtl8019as_init( );
}
//**********************************
//* UDP原數(shù)據(jù)返回測試程序
//**********************************
void udp_reply_test(void)
{
unsigned char temp0;
unsigned char temp1;
unsigned int temp2;
unsigned int temp3;
//修改ETHERNET數(shù)據(jù)包目標和源MAC地址
for(temp0=0;temp0<6;temp0++) // 1. 設置目標MAC地址,MAC地址交換
{
temp1=read_62256(SRCMAC0+temp0);
write_62256(DESMAC0+temp0,temp1);
}
for(temp0=0;temp0<6;temp0++) // 2. 設置本機MAC地址
write_62256(SRCMAC0+temp0,SYSMAC[temp0]);
//對IP數(shù)據(jù)頭進行處理,在已收到數(shù)據(jù)基礎上修改
temp2=read_62256(IP_ID_ADD); // 3. IP頭數(shù)據(jù)中IP標識區(qū)數(shù)據(jù)加1
temp1=read_62256(IP_ID_ADD+1);
temp2=(temp2<<8)+temp1;
temp2++;
write_62256(IP_ID_ADD+1,temp2);
write_62256(IP_ID_ADD,temp2>>8);
write_62256(IP_HDR_CSUM,0x00); // 4. IP頭CHECKSUM部分至0x0000
write_62256(IP_HDR_CSUM+1,0x00);
for(temp0=0;temp0<4;temp0++) // 5. 設置目標IP地址
{
temp1=read_62256(IP_SRC_IP0+temp0);
write_62256(IP_DES_IP0+temp0,temp1);
}
for(temp0=0;temp0<4;temp0++)
write_62256(IP_SRC_IP0+temp0,SYSIP[temp0]); // 4. 設置本機IP地址
temp2=ip_cal_csum(); // 5. IP頭chechsum計算
write_62256(IP_HDR_CSUM+1,temp2);
write_62256(IP_HDR_CSUM,temp2>>8);
//UDP數(shù)據(jù)段設置
write_62256(UDP_CSUM,0x00); // UDP CHECKSUM部分至0x0000 temp0=read_62256(UDP_SRC_PORT); // 端口互換
temp1=read_62256(UDP_DES_PORT);
write_62256(UDP_SRC_PORT,temp1);
write_62256(UDP_DES_PORT,temp0);
temp0=read_62256(UDP_SRC_PORT+1);
temp1=read_62256(UDP_DES_PORT+1);
write_62256(UDP_SRC_PORT+1,temp1);
write_62256(UDP_DES_PORT+1,temp0);
write_62256(UDP_CSUM+1,0x00); // UDP可以無chechsum
temp2=read_62256(IP_TOL_LEN); // IP,UDP數(shù)據(jù)總長度
temp1=read_62256(IP_TOL_LEN+1);
temp2=(temp2<<8)+temp1+0X0E;
if(temp2<60) // 最小數(shù)據(jù)包長度檢驗
{
temp0=60-temp2;
for(temp1=0;temp1<temp0;temp1++)
write_62256(temp2+temp1,0x00);
sendpacket(60);
}
else sendpacket(temp2); // 發(fā)送數(shù)據(jù)
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -