查看: 1830|回复: 0
打印 上一主题 下一主题

开源一个,本人写的TCP服务器,求穿裤衩

[复制链接]
跳转到指定楼层
沙发
发表于 2016-4-18 21:44:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "DSP28_Gpio.h"
#include "DSP28_SysCtrl.h"
#include "DSP28_PieCtrl.h"
#include "DSP28_PieVect.h"
#include "DSP28_InitPeripherals.h"
#include "DSP28_Timers.h"
#include "DSP28_Gpio.h"
#include "arp.h"

#include "common.h"
#include "display.h"
#include "irigb.h"
#include "dm9k_ex.h"
#include "net.h"
#include "check.h"

extern struct        HostStructType          Machine;
extern union         NetCardUnionType         uNetPack_Rx; //接收缓存
extern union         NetCardUnionType         uNetPack_Tx; //发送缓冲

void initNet_Inf()
{
        if(vResetDM9K_EX())
        {
                vInitD9K_EX();
        }
        else
        {
                while(1); //网络芯片错误,两灯都不亮
        }
}

void initNet(void)
{
        initNet_Inf(); //先初始化网口,以便输出调试信息
}

void RecvFromNet_Ex()
{
        UINT16         uiLen;
        if (uiCheckNewPacket_EX())                //接收数据包
        {        
                if (uNetPack_Rx.stEtherFrame.uiProtocol == 0x0806)//表示收到一个arp请求包
                {
                        if(uNetPack_Rx.stArpFrame.Operation == 0X0001)//表示收到的数据包是一个ARP请求报文
                        {
                                Arp_Answer();                //ARP应答
                        }
                        else if(uNetPack_Rx.stArpFrame.Operation == 0X0002)//表示收到的数据包是一个ARP回答报文
                        {
                                ;
                        }
                }
                else if(uNetPack_Rx.stEtherFrame.uiProtocol == 0x0800)//表示接收到一个IP数据包
                {                                                        
                         if((uNetPack_Rx.stIpFrame.VersionToService & 0xf000) == 0x4000)//IP V4版本
                         {
                                if( Check_RxIpHeadCrc() )        //IP首部CRC校验,返回值恒为1.校验结果保存在 CheckFlag
                                {
                        
                                        switch(uNetPack_Rx.stIpFrame.TtlToNextP & 0x00ff)
                                        {
                                                case 0x01://表示收到的IP数据报为ICMP查询报文(本程序仅对PING操作进行处理)

                                                        if((uNetPack_Rx.stIcmpFrame.TypeOpt >> 8) == 0x08)        //表示收到的ICMP报文是一个ping的请求包
                                                        {
                                                                Icmp_Ping_Answer();

                                                        }//对PING应答
                                                        else if((uNetPack_Rx.stIcmpFrame.TypeOpt >> 8) == 0x00)//表示收到的ICMP报文是一个ping的应答包
                                                        {
                                                               
                                                        }
                                                break;
                                                case 0x06://IPFrame的下层协议字段为6表示下层协议为TCP,表示收到TCP报文

                                                        Tcp_Process();
                                                break;
                                                case 0x11://IPFrame的下层协议字段为17表示下层协议UDP,表示收到UDP报文
                                                
                                                        Udp_Process();
                                                break;
                                                default:
                                                break;                                                
                                        }
                                }
                         }
                }        
        }   
}




























回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入因仑

本版积分规则

快速回复 返回顶部 返回列表