NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/58874: nonblocking connect() and getsockname() error conditions



The following reply was made to PR kern/58874; it has been noted by GNATS.

From: Christoph Badura <bad%bsd.de@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: kern/58874: nonblocking connect() and getsockname() error
 conditions
Date: Sun, 15 Dec 2024 12:10:59 +0100

 macOS doesn't have SOCK_NONBLOCK, so:
 
 --- sn.c,0	2024-12-15 11:39:56
 +++ sn.c	2024-12-15 11:59:50
 @@ -2,6 +2,7 @@
  
  #include <err.h>
  #include <errno.h>
 +#include <fcntl.h>
  #include <netdb.h>
  #include <stdio.h>
  #include <stdlib.h>
 @@ -30,12 +31,14 @@
  		socklen_t optlen;
  		socklen_t i;
  
 -		fd = socket(ai->ai_family, ai->ai_socktype|SOCK_NONBLOCK,
 +		fd = socket(ai->ai_family, ai->ai_socktype,
  		    ai->ai_protocol);
  		if (fd == -1) {
  			warn("socket");
  			continue;
  		}
 +		if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) 
 +			err(1, "fcntl can't F_SETFL O_NONBLOCK");
  		if (connect(fd, ai->ai_addr, ai->ai_addrlen) != -1) {
  			warnx("connect succeeded");
  			(void)close(fd);
 
 output (macOS 14.7.1, amd64):
 
 Script started on Sun Dec 15 12:03:09 2024
 Command: ./sn localhost 12345
 sn: first connect: Operation now in progress
 sn: second connect: Connection refused
 1c1ef713000000000000000000000000000000000000000100000000
 sn: connect SO_ERROR: Undefined error: 0
 sn: third connect: Invalid argument
 
 Command exit status: 0
 Script done on Sun Dec 15 12:03:09 2024
 
 --chris
 


Home | Main Index | Thread Index | Old Index