http://www.mengwuji.net/thread-3040-1-1.html
NTSTATUS TestConnect() { HANDLE Socket = NULL; PFILE_OBJECT pSocketObject = NULL; NTSTATUS st = STATUS_UNSUCCESSFUL; ULONG Address = 0x7F000001; USHORT Port = 0x5000; LARGE_INTEGER Timeout; ULONG RecvSize = 1024; CHAR Packet[1024] = {0}; CHAR szSendMessage[] = "娘子! "; st = CreateAddress(&Socket,&pSocketObject); if (!NT_SUCCESS(st)) { return st; } st = TdiSendDatagram(pSocketObject,Port,Address,szSendMessage,strlen(szSendMessage)); if (st != STATUS_SUCCESS) { ObDereferenceObject(pSocketObject); ZwClose(Socket); return st; } Timeout.QuadPart = 10*1000*(-10000); //10秒 st = TdiReceiveDatagram(pSocketObject,Port,&Address,&Packet,&RecvSize,&Timeout); if (st != STATUS_SUCCESS) { ObDereferenceObject(pSocketObject); ZwClose(Socket); return st; } KdPrint(("%s",Packet)); //这里随便你做什么啦 ObDereferenceObject(pSocketObject); ZwClose(Socket); return st; }