views:

191

answers:

1

I am calling WsKSendTo on an opened socket (irp returns success in callback). But WskSendTo on that socket returns c0000184, what is referenced to as STATUS_INVALID_DEVICE_STATE. What kind of errors are addressed by this?

Did I miss something in the send routine?

    psc->dstaddr.sin_family = AF_INET;
psc->dstaddr.sin_port = 0x6973;  // big endian
psc->dstaddr.sin_addr.S_un.S_un_b.s_b1 = 0x02;
psc->dstaddr.sin_addr.S_un.S_un_b.s_b2 = 
 psc->dstaddr.sin_addr.S_un.S_un_b.s_b3 = 0x17;
psc->dstaddr.sin_addr.S_un.S_un_b.s_b4 = 0x0a;

// create IRP
psc->pirp = IoAllocateIrp(1, FALSE);
if(!psc->pirp){
 DbgPrint("ShoutShout: IRP not allocated\n");
 FreeShoutContext(psc);
 return STATUS_UNSUCCESSFUL;
}
IoSetCompletionRoutine(
 psc->pirp,
 ShoutShoutComplete,
 psc,
 TRUE,
 TRUE,
 TRUE
 );

// initiate send
const WSK_PROVIDER_DATAGRAM_DISPATCH *dispatch = 
 (PWSK_PROVIDER_DATAGRAM_DISPATCH)sockContext->socket->Dispatch;
status = dispatch->WskSendTo(  
 sockContext->socket,       //PWSK_SOCKET
 &psc->buf,                 //__in PWSK_BUF
 NULL,                      // undocumented IN ULONG  Flags,   
 (PSOCKADDR)&psc->dstaddr,  // IN PSOCKADDR  RemoteAddress OPTIONAL, 
 0,      //  IN SIZE_T  ControlInfoLength, 
 0,      //  IN PCMSGHDR  ControlInfo OPTIONAL,  
 psc->pirp);     //  IN PIRP  Irp    );

Afterwards status and pirp->IoStatus->Status contain afore mentioned error code and nothing is sent (or reaching the destination). Any suggestions?

+1  A: 

c0000184 is returned if the socket is not fully initialised. For example if the socket is not yet bound to an address. The same problem existst in userland, always bind your socket! (Here using WskBind.)

It is also useful to synchronise the individual steps of the initialisation process: allocation of socket context, socket creation and binding using KEVENT (see KeInitializeEvent for a start).

Don Johe