X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; q=dns; s=default; b=DA/PDfqcY61ODk9uNOW+GPXzhDBQEwU13aysHvFTJd1 v1flnu9Gtz8LodGkFjbapJ5P+jeRh4jcz9UOiIl67SUCfR4jVysVj/JHSORUQj1W OFgijqGJ7FfSUQmOggCeutgotOpXej+jvVU5EeRR7/LVSDht8WFMpMBqG1XHkymk = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; s=default; bh=vC5BzeLXXYclcI+jvpFq42mmgrA=; b=GTzyPrRVLjwv/E/Ou CDgm5bKHi50lEm7lFi3/ML94KrnLzP+hrDVJyC3wHttWj+m42SnjOJ2J7hTpQxZj qDXUeYDKjc404XXzCjtNOBf4fJY9K0ZEd7iUqoGyXVBD6N4nd9XfLZ71a8gj1zK9 NVC9k0YSTfR+1aEZoIKwxZcsGw= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_20,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f52.google.com X-Received: by 10.194.104.137 with SMTP id ge9mr103269461wjb.135.1419837211486; Sun, 28 Dec 2014 23:13:31 -0800 (PST) Message-ID: <54A0FF0A.5050701@gmail.com> Date: Mon, 29 Dec 2014 08:13:14 +0100 From: Marco Atzeri User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: bug: struct cmsghdr does not match system on cygwin64 References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes On 12/29/2014 6:03 AM, Kenton Varda wrote: > Hello Cygwin, > > Cygwin defines 'struct cmsghdr' (see recvmsg(2)) as follows (cygwin/socket.h): > > struct cmsghdr > { > socklen_t cmsg_len; /* Length of cmsghdr + data */ > int cmsg_level; /* Protocol */ > int cmsg_type; /* Protocol type */ > }; > > Unfortunately, Winsock defines its equivalent type as follows (ws2def.h): > > typedef struct _WSACMSGHDR { > SIZE_T cmsg_len; > INT cmsg_level; > INT cmsg_type; > /* followed by UCHAR cmsg_data[] */ > } WSACMSGHDR, *PWSACMSGHDR, FAR *LPWSACMSGHDR; > > As you can see, on a 64-bit build, the cmsg_len is 64 bits in the > Winsock struct. However, Cygwin's socklen_t is always 32 bits, > therefore cmsg_len is 32 bits in the Cygwin struct. http://pubs.opengroup.org/onlinepubs/7908799/xns/syssocket.h.html > Cygwin's recvmsg() calls WSARecvMsg() passing the control message > buffer pointer verbatim, expecting the system to fill the buffer > correctly. The system dutifully fills the buffer with control messages > that are not legible using Cygwin's definition of the struct, leaving > the calling application with apparent garbage data. > > sendmsg() likely has a similar problem, though I haven't checked. > > It seems like the best solution is to change the type of cmsg_len to > size_t. While this would technically violate standards (I think?), it > turns out the Linux headers define it this way, so presumably no one > will mind. https://cygwin.com/cygwin-ug-net/programming.html http://technet.microsoft.com/en-us/library/bb496995.aspx If I am not wrong, for 64bit, on windows sizeof (SIZE_T) =4 while on cygwin sizeof(size_t)=8 > The other option is to perform some sort of translation of the control > message buffer inside sendmsg() and recvmsg(), but that would > obviously be painful and error-prone. > > AFAICT, this bug breaks all users of the IP_PKTINFO and IPV6_PKTINFO > socket options on cygwin64. > > -Kenton > -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple