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:mime-version:from:date:message-id:subject:to :content-type; q=dns; s=default; b=E9cc5jsh34jXerts5x2QcdQyVqeEt HbeFHfjOEWX6zWSM+LScd6VGvbhYLtr9pBATzHs9YV9GJSC3l8I5aIlKbS0qKkSG 0HMDyIIpFSCiaCA0yvXou8U2dRQlxIcoo5HM87V3GDS512Jwr/V6wzghq5QpTSfc rG4zGsDHkc0gGE= 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:mime-version:from:date:message-id:subject:to :content-type; s=default; bh=hCW9jTyUMT7379Rf8UIANgi0Sf4=; b=JKG PeYWEeRBJM/EZRIhYg1PIUNz+0kIMyROUIzDqmK1z8iPcQaVnScB6TAL6lcLwLSI bmBFQcAhvlFlvTMBvzPiXK+fdqfF+kKotl1v2gCLTClpop7Itv7OwQ0X+RSvTuQC yTmsFyWXV7sdKc8gDkGa3/LlL5ut61wUqzbWaGj0= 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=-0.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-HELO: mail-lb0-f176.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to:content-type; bh=i2O7XV8TaLZ9QviXcrbsakFs1+BaCmisovsNLeOqrnc=; b=ky2XE6TcraVUICP99iTUTjSz1g9Ja88Ayn/XpNs7wp46b/IInpIdUTnQbqE+brXQP0 QEOvT96sYA7Z3mtG810yZHke9r5qw4yBmO7+qTSpfB9GRrMbGGz1MXWP0kVhz5rZw6jB wJFQjSjBhy0t8WWAtNcYO5Q5i0glP8x1FsJMcOUOnmHw9tp/s7NAb2f4rGC+wJ9ueeaJ hs165w325ByrLSm/9z24Wb60QNbFcWjuKZO2FAy51oc9KGXWDic4G8Et9u8ogIpv7Usq bxpPgZBfQI+44p4L37DbCzh3oPFqEzih/kObqkjgIK/hCML7ssyU2XUwiLDEuJ+mq/n3 6YEg== X-Gm-Message-State: ALoCoQkmgOaPCk2n5vOXHs0uXAZU2F5nuDH5C4JJcc+e+pWi8S/q09S3aoxlyLdaAtRHLY6LGAIx X-Received: by 10.112.150.102 with SMTP id uh6mr42359997lbb.66.1419829460172; Sun, 28 Dec 2014 21:04:20 -0800 (PST) MIME-Version: 1.0 From: Kenton Varda Date: Sun, 28 Dec 2014 21:03:59 -0800 Message-ID: Subject: bug: struct cmsghdr does not match system on cygwin64 To: cygwin Content-Type: text/plain; charset=UTF-8 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. 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. 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