[Winpcap-users] WriteFile fails with ERROR_GEN_FAILURE

Eli Iser eli.iser at gmail.com
Mon Nov 6 14:51:11 GMT 2006


I'm having a problem with using the Packet32 code in my application. When
sending a packet using PacketSendPacket it sometimes failes with
GetLastError returning 31 - ERROR_GEN_FAILURE.

A little more detail:

I'm running WinXP SP2 on a P4 with a copy of Packet32 obtained from the
WinPCap site from the 3.1 developer's pack.
I'm using the code directly in my appliction, and not in a separate dll.
Also, I've made several small changes to the code, most of little concern,
but I did change the way to open the adapter to overlapped. Accordingly,
I've modified all of the appropriate function calls that are affected by
overlapped to use the overlapped structure (WriteFile, ReadFile and
DeviveIoCtl).
I've added three overlapped structures to the ADAPTER struct - one for
reading, one for writing and one for DeviveIoCtl.
The relavent changes from the overlapped are in the PacketReceivePacket and
the PacketSendPacket:

The applications basic design is as like a bridge - read a packet from
adapter A and write it to adapter B; read a packet from adapter B and write
it to adapter A. I have two threads that perform the receives - one for each
adapter.

When sending a packet I first call GetOverlappedResult with *bWait* being
TRUE to make sure no IO is pending, so that I can send my packet. The I
check if the WriteFile returns FALSE, and if so check the GetLastError(). If
it's ERROR_IO_PENDING I return TRUE from the PacketSendPacket. Else I return
FALSE. Here I don't care if the packet was actually sent already. I want to
return to doing my own stuff.

When receiving a packet I call the ReadFile fucntion, and then call
GetOverlappedResult with *bWait* being TRUE to make sure I get the packet. I
must have the packet, since I have nothing else to do while waiting for it.

On quite rare occasions the WriteFile in the PacketSendPacket fails with
GetLastError() returning 31 - ERROR_GEN_FAILURE. After this happens all
calls to function with this adapter's handle fails. Furthermore, because I
wait before sending I get stuck on the GetOverlappedResult (bWait is true -
so I'm stuck until any IO is complete, which obviosly ain't gonna
happen...).

Any suggestions will be welcomed.
Maybe it's all the overlapped's fault? I found that it gave quite a
performance boost, so I'd rather not return to non-overlapped working.
Maybe I'm using the overlapped wrong? Something I forgot to do? I'm not well
versed in working with overlapped.

Thanks much,

Eli Iser
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winpcap.org/pipermail/winpcap-users/attachments/20061106/235a6bf3/attachment.htm


More information about the Winpcap-users mailing list