delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/08/12/09:48:41

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_43,J_CHICKENPOX_48,RCVD_IN_DNSWL_LOW
X-Spam-Check-By: sourceware.org
Message-ID: <4A82C835.9030504@dronecode.org.uk>
Date: Wed, 12 Aug 2009 14:48:37 +0100
From: Jon TURNEY <jon DOT turney AT dronecode DOT org DOT uk>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.1) Gecko/20090715 Thunderbird/3.0b3
MIME-Version: 1.0
To: cygwin-xfree AT cygwin DOT com, cygwin AT cygwin DOT com
Subject: [1.7] IPv6 accept() fails if address_len is < sizeof(sockaddr_in6) [was Re: PATCH /usr/include/X11/Xtrans/Xtranssock.c [WAS: Re: xhost package not compiled for IPv6]]
References: <4A78A511 DOT 8020109 AT sipxx DOT com> <4A803D7C DOT 6070800 AT dronecode DOT org DOT uk> <4A825EE5 DOT 5020709 AT sipxx DOT com> <4A82BB83 DOT 1090908 AT dronecode DOT org DOT uk>
In-Reply-To: <4A82BB83.1090908@dronecode.org.uk>
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

--------------050808070908040806050602
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

On 12/08/2009 13:54, Jon TURNEY wrote:
> Hmmm... but if it's really the size of the sockname argument which is
> causing the accept() to fail, this would be a bug in cygwin's accept()
> implementation, as it's supposed to truncate the data written to the
> sockname, rather than fail if it won't fit [1]. If that actually is the
> case, since we don't actually use the peer address here, the code as
> stands is correct (if a little odd).
>
> I suppose I need to write a small test case to look at this...
>
> [1] http://www.opengroup.org/onlinepubs/009695399/functions/accept.html

A couple of small programs which hopefully demonstrate this problem.

(As is, the connection fails, but uncommenting the alternate definition of 
cliaddr in listener.c allows it to work)

I'd hazard a guess that perhaps this is because the underlying winsock 
accept() doesn't have this truncate behaviour and considers a too-small 
address_len an error.

--------------050808070908040806050602
Content-Type: text/plain;
 name="connector.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="connector.c"


#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <netinet/in.h>

//
// gcc connector.c -o connector
//

int
main(int argc, char **argv)
{
  int sockfd;
  struct sockaddr_in6 servaddr;

  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin6_family = AF_INET6;
  servaddr.sin6_addr = in6addr_loopback;
  servaddr.sin6_port = htons(13); /* daytime server */

  if ((sockfd = socket(AF_INET6, SOCK_STREAM, 0)) < 0)
     {
       printf("socket error\n");
       exit(1);
     }

  if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0)
     {
       printf("connect error\n");
       exit(1);
     }
}

--------------050808070908040806050602
Content-Type: text/plain;
 name="listener.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="listener.c"


#include <stdio.h>
#include <strings.h>
#include <netinet/in.h>

//
// gcc listener.c -o listener
//

int
main(int argc, char **argv)
{
  int listenfd, connfd;
  socklen_t len;
  struct sockaddr_in6 servaddr;
  struct sockaddr_in cliaddr;
//  struct sockaddr_in6 cliaddr;

  listenfd = socket(AF_INET6, SOCK_STREAM, 0);

  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin6_family = AF_INET6;
  servaddr.sin6_addr = in6addr_any;
  servaddr.sin6_port = htons(13); /* daytime server */

  bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
  listen(listenfd, 5);

  for (;;)
    {
      len = sizeof(cliaddr);
      connfd = accept(listenfd, (struct sockaddr *) &cliaddr, &len);
      if (connfd > 0)
        {
          printf("accept() succeeded\n");
        }
      else
        {
          printf("accept() failed\n");
        }
    }
}


--------------050808070908040806050602
Content-Type: text/plain; charset=us-ascii

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

- Raw text -


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