ws2_32: Add support and tests for WSARecvMsg and IP_PKTINFO.

Erich Hoover ehoover at
Sun Oct 17 16:51:22 CDT 2010

On Sat, Oct 16, 2010 at 1:41 PM, Mike Kaplinskiy
<mike.kaplinskiy at> wrote:
> On Thu, Oct 14, 2010 at 10:08 PM, Erich Hoover <ehoover at> wrote:
>> ...
>>     DWORD                               flags;
>>     unsigned int                        n_iovecs;
>>     unsigned int                        first_iovec;
>>+    WSABUF                             *control;
>>     struct iovec                        iovec[1];
>> } ws2_async;
> I would prefer control declared above n_iovecs purely for
> organizational purposes (params first, buffers and info about them
> last). Also you can't just store the passed in WSABUF pointer; it may
> be stack allocated and may disappear before the overlapped call
> completes. You could just add control and control_len instead of using

That's why in the original version I had those parameters split out;
however, I realized that since the length parameter gets modified by
WSARecvMsg that it is impossible for the WSAMSG structure (or any of
its parameters) to disappear before WSARecvMsg completes.  I have
re-written the tests (see patch 4 at the end) to show that this
structure gets modified even when an overlapped request is used and
results in modification of the structure at a later time, the results
from the test bot can be found here:

>>+        /* Insufficient room for control headers */
>>+        errno = EINVAL;
> This should probably be ENOMEM then. On that note, it would be nice to
> test what windows actually does when you don't give it enough space
> (like 1 byte). We should probably rewrite that function at some point
> since I'm not sure what errno it returns anymore.

This is odd, I must have copy-pasted the wrong error code from the
recvmsg() manual page.  I've investigated this issue more and
discovered that the code should actually be EMSGSIZE.  This change and
the corresponding tests can be found in my revised patches (at the
end), I've also included support for reporting back the MSG_CTRUNC

>>+#ifdef IP_PKTINFO
>>+        case WS_IP_PKTINFO:
> You probably don't need the ifdef. convert_sockopt will just fail.

I did this to match how IP_HDRINCL was done nearby, should this really
be changed?

>>+    hdr.Control.buf = pktbuf;
> .len = sizeof(pktbuf)?

The length parameter is declared within the loop, otherwise it gets
resized (as mentioned earlier) when WSARecvMsg is called.

Thank you so much for all your help, I hope you find the following to
be more to your liking.

[1/4] include: Add IP_PKTINFO response structure.
[2/4] include: Add macros for retrieving control message headers.
[3/4] ws2_32: Add support for WSARecvMsg and IP_PKTINFO.
[4/4] ws2_32/tests: Add regression tests for WSARecvMsg and IP_PKTINFO.

Erich Hoover
ehoover at

More information about the wine-devel mailing list