bli2007
驱动牛犊
驱动牛犊
  • 注册日期2009-05-23
  • 最后登录2009-07-11
  • 粉丝0
  • 关注0
  • 积分5分
  • 威望41点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:2286回复:7

网络驱动~~内附源码

楼主#
更多 发布于:2009-06-27 17:21
潜水细读了楚狂人等的大作后,写一个网络驱动.
以ping例程为蓝本,发送接收数据包,通过[windows API函数]: DeviceIoControl( )来控制读写. 贴上了源代码,请各位不吝赐教.
附件名称/大小 下载次数 最后更新
BrctEthernet.rar (3000KB)  219 2009-06-27 17:21
bli2007
驱动牛犊
驱动牛犊
  • 注册日期2009-05-23
  • 最后登录2009-07-11
  • 粉丝0
  • 关注0
  • 积分5分
  • 威望41点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2009-06-27 17:24
回 楼主(bli2007) 的帖子
请留几句你的意见.期待大家一起来讨论


与DeviceIoControl( )函数相关的代码.
NTSTATUS BrctEthernetDevice::DeviceControl(KIrp I)
{
    NTSTATUS status;

    t << "Entering BrctEthernetDevice::Device Control, " << I << EOL;
    switch (I.IoctlCode())
    {
        case BRCTETHERNET_IOCTL_Read:
            status = BRCTETHERNET_IOCTL_Read_Handler(I);
            break;

        case BRCTETHERNET_IOCTL_Write:
            status = BRCTETHERNET_IOCTL_Write_Handler(I);
            break;

        default:
            // Unrecognized IOCTL request
            status = STATUS_INVALID_PARAMETER;
            break;
    }

    // If the IRP was queued, or its IOCTL handler deferred processing using some
    // driver specific scheme, the status variable is set to STATUS_PENDING.
    // In this case we simply return that status, and the IRP will be completed
    // later.  Otherwise, complete the IRP using the status returned by the
    // IOCTL handler.
    if (status == STATUS_PENDING)
    {
        return status;
    }
    else
    {
        return I.PnpComplete(this, status);
    }
}

NTSTATUS BrctEthernetDevice::BRCTETHERNET_IOCTL_Read_Handler(KIrp I)
{
    NTSTATUS status = STATUS_SUCCESS;

    t << "Entering BrctEthernetDevice::BRCTETHERNET_IOCTL_Read_Handler, " << I << EOL;
// TODO:    Verify that the input parameters are correct
//            If not, return STATUS_INVALID_PARAMETER

// TODO:    Handle the the BRCTETHERNET_IOCTL_Read request, or
//            defer the processing of the IRP (i.e. by queuing) and set
//            status to STATUS_PENDING.

// TODO:    Assuming that the request was handled here. Set I.Information
//            to indicate how much data to copy back to the user.

    if(I.IoctlInputBufferSize() < sizeof(KS5920_PASSTHRU) ||
        !I.IoctlBuffer())
    {
        I.Information() = 0;
        return STATUS_INVALID_PARAMETER;
    }
    
    PKS5920_PASSTHRU pInput = static_cast<PKS5920_PASSTHRU>(I.IoctlBuffer());
    if(G_Flag_Read){
        pInput->Offset = G_thePacket_Read->Data[0];
        pInput->Data = G_thePacket_Read->Data[1];
        I.Information() = sizeof (KS5920_PASSTHRU);    
        return status;
    }
    else{
        I.Information() = 0;
        status = STATUS_INVALID_PARAMETER;
        return status;

    }

}

NTSTATUS BrctEthernetDevice::BRCTETHERNET_IOCTL_Write_Handler(KIrp I)
{
    NTSTATUS status = STATUS_SUCCESS;

    t << "Entering BrctEthernetDevice::BRCTETHERNET_IOCTL_Write_Handler, " << I << EOL;
// TODO:    Verify that the input parameters are correct
//            If not, return STATUS_INVALID_PARAMETER

// TODO:    Handle the the BRCTETHERNET_IOCTL_Write request, or
//            defer the processing of the IRP (i.e. by queuing) and set
//            status to STATUS_PENDING.

    if(I.IoctlInputBufferSize() < sizeof(KS5920_PASSTHRU) ||
        !I.IoctlBuffer())
    {
        I.Information() = 0;
        return STATUS_INVALID_PARAMETER;
    }

    PKS5920_PASSTHRU pInput = static_cast<PKS5920_PASSTHRU>(I.IoctlBuffer());
    
    
    
     //Get the bradcast address for our subnet
    ULONG BroadcastAddress = MySocket->GetBroadcastAddress();
    CHAR Buffer[16];
    inet_ntoa(ntohl(BroadcastAddress), (PCHAR)Buffer, 16);
    
    t << "Broadcast address = " << (PCHAR)Buffer << "\n";
        
     //Send a ping to our subnet
    t << "******Sending ping to subnet*******\n";
     MySocket->SendPing(BroadcastAddress, pInput);

// TODO:    Assuming that the request was handled here. Set I.Information
//            to indicate how much data to copy back to the user.
    I.Information() = sizeof(KS5920_PASSTHRU);    

    return status;
}
bli2007
驱动牛犊
驱动牛犊
  • 注册日期2009-05-23
  • 最后登录2009-07-11
  • 粉丝0
  • 关注0
  • 积分5分
  • 威望41点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2009-06-27 17:28
回 楼主(bli2007) 的帖子
还有一些与该驱动接口的应用程序代码
mikechen2010
驱动牛犊
驱动牛犊
  • 注册日期2009-04-19
  • 最后登录2016-01-09
  • 粉丝3
  • 关注0
  • 积分8分
  • 威望71点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2009-07-07 20:32
积极参与,一起讨论
longcheer00
驱动牛犊
驱动牛犊
  • 注册日期2009-09-02
  • 最后登录2009-09-02
  • 粉丝0
  • 关注0
  • 积分6分
  • 威望61点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2009-09-02 15:39
好贴
00我不知道
驱动牛犊
驱动牛犊
  • 注册日期2009-02-23
  • 最后登录2017-11-30
  • 粉丝0
  • 关注0
  • 积分15分
  • 威望141点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
  • 社区居民
5楼#
发布于:2009-09-03 11:37
积极顶帖,我也争相学习呢
live_eagle
驱动牛犊
驱动牛犊
  • 注册日期2009-09-17
  • 最后登录2009-10-18
  • 粉丝0
  • 关注0
  • 积分12分
  • 威望121点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2009-09-21 18:35
我编译了你的东东,按上去后就不能上网了。
我思故我在
hustsolo
驱动牛犊
驱动牛犊
  • 注册日期2009-06-02
  • 最后登录2012-12-04
  • 粉丝0
  • 关注0
  • 积分18分
  • 威望181点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2009-11-29 18:58
我也要潜水看书了~~~~~~~~~~··
游客

返回顶部