Hi, looking at the Python test suite output, I found an actual bug related to getpeername(). When called on non-connected sockets, it shall return ENOTCONN, but instead it returns -ENOTCONN. The attached testcase shows the issue: $ ./getpeername <socket value>, -1, -1073741881 vs 1073741881 while it should be: <socket value>, -1, 1073741881 vs 1073741881
Investigating a bit in the sources of hurd/pfinet, socket- ops.c:S_socket_peername() just return straight the return value of misc.c:make_sockaddr_port(). make_sockaddr_port() calls the getname function of the sock-ops of the current sock struct, which can be one of - linux-src/net/ipv6/af_inet6.c:inet6_getname() - linux-src/net/ipv4/af_inet.c:inet_getname() - linux-src/net/core/sock.c:sock_no_getname() all of them return negative errno values, which make_sockaddr_port() return straight those as well. Not totally sure about where to fix, i.e. a "return -err" in make_sockaddr_port() after the getname call, or in all the callers of make_sockaddr_port(). -- Pino Toscano
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
int main()
{
int s, e;
struct sockaddr_in ss;
socklen_t len;
s = socket(AF_INET, SOCK_STREAM, 0);
len = sizeof(ss);
e = getpeername(s, (struct sockaddr *)&ss, &len);
printf("%d, %d, %d vs %d\n", s, e, errno, ENOTCONN);
close(s);
return 0;
}
signature.asc
Description: This is a digitally signed message part.
