delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/07/31/12:44:48

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,SPF_HELO_PASS,TW_CV,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
X-IronPortListener: Outbound_SMTP
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: Av0EAM8JGFCcKEcV/2dsb2JhbABFuXiBB4InEhUTUQEVJwIvEyYBBBsah2uadIRGnVeRcmADjRaOLooQgns
From: "Lavrentiev, Anton (NIH/NLM/NCBI) [C]" <lavr AT ncbi DOT nlm DOT nih DOT gov>
To: "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
Date: Tue, 31 Jul 2012 12:43:59 -0400
Subject: Using recvmsg() with non-unicast datagram (UDP) socket: inconsistent results
Message-ID: <A9D8BF3D8A74DF4A925FB541C0F39D2A16C25F128A@NIHMLBX15.nih.gov>
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id q6VGijle002054

Hi,

Observed is an inconsistent result when recvmsg() is used on a
UDP socket with or without ancillary control message parameters.

Here's is an example:

    static char buf[1 << 16];
    struct sockaddr_in sin;
    struct msghdr msg;
    struct iovec iov;
#ifndef CYGWIN_BUG
    char cmsgbuf[32];
#endif /*CYGWIN_BUG*/
    int n;

    iov.iov_base       = buf;
    iov.iov_len        = sizeof(buf);
    memset(&sin, 0, sizeof(sin));
    memset(&msg, 0, sizeof(msg));
    msg.msg_name       = (caddr_t) &sin;
    msg.msg_namelen    = sizeof(sin);
    msg.msg_iov        = &iov;
    msg.msg_iovlen     = 1;
#ifndef CYGWIN_BUG
    memset(cmsgbuf, 0, sizeof(cmsgbuf));
    msg.msg_control    = cmsgbuf;
    msg.msg_controllen = sizeof(cmsgbuf);
#endif /*CYGWIN_BUG*/

    if ((n = recvmsg(sock, &msg, 0/*no special flags*/)) <= 0) {
	   /* Handle error */
        return;
    }

    /* HERE: msg.msg_flags is inconsistent here for non-unicast UDP sockets */

For a non-unicast socket "sock", the returned msg.msg_flags will have proper WSA
bits (MSG_BCAST or MSG_MCAST) set if CYGWIN_BUG is not defined (i.e. the recvmag()
call is passed non-zero msg.msg_controllen).  Otherwise, msg.msg_flags will always
get returned 0.

The relevant code from CYGWIN source suggests that the native WSA flags should
have got preserved (fhandler_socket.cc, fhandler_socket::recvmsg):

	msg->msg_flags = wsamsg.dwFlags;

yet apparently this had slipped away in fhandler_socket::recv_internal, which
branches on the presence of msg_controllen (and opts out for use other WSA API
call if that is not set, even for non-stream sockets):

     if (wsamsg->Control.len > 0)
       {
         ...
         use_recvmsg = true;
       }

Can this please be rectified?

Thanks,

Anton Lavrentiev
Contractor NIH/NLM/NCBI


--
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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019