阅读:2343回复:7
网络驱动~~内附源码
潜水细读了楚狂人等的大作后,写一个网络驱动.
以ping例程为蓝本,发送接收数据包,通过[windows API函数]: DeviceIoControl( )来控制读写. 贴上了源代码,请各位不吝赐教. |
|
|
沙发#
发布于: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; } |
|
板凳#
发布于:2009-06-27 17:28
回 楼主(bli2007) 的帖子
还有一些与该驱动接口的应用程序代码 |
|
地板#
发布于:2009-07-07 20:32
积极参与,一起讨论
|
|
地下室#
发布于:2009-09-02 15:39
好贴
顶 |
|
5楼#
发布于:2009-09-03 11:37
积极顶帖,我也争相学习呢
|
|
6楼#
发布于:2009-09-21 18:35
我编译了你的东东,按上去后就不能上网了。
|
|
|
7楼#
发布于:2009-11-29 18:58
我也要潜水看书了~~~~~~~~~~··
|
|