阅读:2037回复:4
请求tdi client源码
以前网上有pcausa的代码,后来被删掉了,谁那儿有备份啊,能不能发送一份啊,特别着急的说。我的邮件是jiangyh@svainfo.com
谢谢啊!真的很着急。给分的说。23分是我的最多可给的分了,您别嫌少 啊 |
|
最新喜欢:linwn |
沙发#
发布于:2003-03-20 21:17
//1.创建一个AdressObject,供其他函数调用,TDI client必须的
NTSTATUS CreateAddress(PHANDLE Handle, PFILE_OBJECT *FileObject) { UNICODE_STRING Name; OBJECT_ATTRIBUTES Attr; CHAR Buffer[sizeof(FILE_FULL_EA_INFORMATION)+TDI_TRANSPORT_ADDRESS_LENGTH+sizeof(TA_IP_ADDRESS)]; PFILE_FULL_EA_INFORMATION Ea; PTA_IP_ADDRESS Sin; IO_STATUS_BLOCK IoStatus; NTSTATUS Status; RtlInitUnicodeString(&Name, L\"\\\\Device\\\\Udp\"); InitializeObjectAttributes(&Attr, &Name, OBJ_CASE_INSENSITIVE, 0, 0); Ea=(PFILE_FULL_EA_INFORMATION)ExAllocatePool(NonPagedPool,sizeof(FILE_FULL_EA_INFORMATION)+TDI_TRANSPORT_ADDRESS_LENGTH+sizeof(TA_IP_ADDRESS)); Ea->NextEntryOffset = 0; Ea->Flags = 0; Ea->EaNameLength = TDI_TRANSPORT_ADDRESS_LENGTH; Ea->EaValueLength = sizeof(TA_IP_ADDRESS); RtlCopyMemory(Ea->EaName, TdiTransportAddress, Ea->EaNameLength + 1); Sin=(PTA_IP_ADDRESS)(Ea->EaName + Ea->EaNameLength + 1); Sin->TAAddressCount = 1; Sin->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP; Sin->Address[0].AddressType = TDI_ADDRESS_TYPE_IP; Sin->Address[0].Address[0].sin_port = 0; // Sin->Address[0].Address[0].in_addr = 0; //本地自动 RtlZeroMemory(Sin->Address[0].Address[0].sin_zero, sizeof(Sin->Address[0].Address[0].sin_zero)); Status= ZwCreateFile(Handle, 0, &Attr, &IoStatus, 0,FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, 0, Ea, sizeof(Buffer)); ExFreePool( (PVOID )Ea ); //释放内存 if (!NT_SUCCESS(Status)) { return Status; } return ObReferenceObjectByHandle(*Handle, GENERIC_READ | GENERIC_WRITE, 0, KernelMode,(PVOID *)FileObject, 0); } //----------------------------------------------------------------------- //2.发UDP包,TdiBuildSendDatagram //------------------------------------------------------------------------- NTSTATUS SendDatagram(PFILE_OBJECT FileObject, PVOID Data, ULONG Length,TDI_CONNECTION_INFORMATION SendDatagramInfo) { KEVENT Event; IO_STATUS_BLOCK IoStatus; PDEVICE_OBJECT DeviceObject; PIRP Irp ; PMDL Mdl; NTSTATUS Status; KeInitializeEvent(&Event, NotificationEvent, FALSE); DeviceObject = IoGetRelatedDeviceObject(FileObject); Irp = TdiBuildInternalDeviceControlIrp(TDI_SEND_DATAGRAM , DeviceObject, FileObject, &Event, &IoStatus); //------分配一个TDI_SEND_DATAGRAM的i/o请求------ if (Irp == 0) { return STATUS_INSUFFICIENT_RESOURCES; } Mdl = IoAllocateMdl(Data, Length, FALSE, FALSE, Irp); if (Mdl == 0) { return STATUS_INSUFFICIENT_RESOURCES; } MmProbeAndLockPages(Mdl, KernelMode, IoModifyAccess); TdiBuildSendDatagram(Irp, DeviceObject, FileObject, 0,0,Mdl,Length,&SendDatagramInfo); //----在传输层驱动中建立i/o栈 Status = IoCallDriver(DeviceObject, Irp); //-----向下层发出i/o请求 if (Status == STATUS_PENDING) { Status = KeWaitForSingleObject(&Event, UserRequest, KernelMode, FALSE, 0); } return Status == STATUS_SUCCESS ? IoStatus.Status : Status; } //------------------------------------------------------ //3.发送一个udp包 NTSTATUS Send2Server(){ PFILE_OBJECT AddressFileObject; HANDLE AddressHandle; char tmp[3]=\"\"; NTSTATUS Status; int i; TA_IP_ADDRESS DstAddr = {1, {TDI_ADDRESS_LENGTH_IP, TDI_ADDRESS_TYPE_IP, {13568,3551212212}}}; TDI_CONNECTION_INFORMATION connInfo = {0, 0, 0, 0, sizeof(DstAddr), &DstAddr}; Status = CreateAddress(&AddressHandle, &AddressFileObject); //开地址 if (!NT_SUCCESS(Status)) { return Status; } Status = SendDatagram(AddressFileObject, strKeys, (2*i+4)*sizeof(char),connInfo); //length改为2*i+1+3// ObDereferenceObject(AddressFileObject); ZwClose(AddressHandle); return STATUS_SUCCESS; } [编辑 - 3/20/03 by sufeng] |
|
板凳#
发布于:2003-03-25 19:12
可惜没有pcausa的源代码,不过真的很谢谢的说。给您10分,要是过两天还没有源代码,全给你的说
|
|
地板#
发布于:2003-03-26 09:08
上面的代码是我自己写的,没有仔细研究过pcausa,代码我给你发过来了,你自己研究吧。
我也在上海,以后可以多切磋。 |
|
地下室#
发布于:2003-03-26 13:14
PCAUSA的源代码,这个是以前在这里下载的,谁有最新的也放上来吧
|
|
|