Bug#47921: Getsockopt -- Operation Not Supported
Package: libc0.2-dev
Version: 2.1.2-0pre12
Using a native-compiled version of apt, it fails while attempting
to make an http connection to the debian archive server. The
failure occurs at this statement:
unsigned int Err;
unsigned int Len = sizeof(Err);
if (getsockopt(Fd,SOL_SOCKET,SO_ERROR,&Err,&Len) != 0)
return _error->Errno("getsockopt","Failed");
Where SOL_SOCKET and SO_ERROR are as defined in the socket.h header
file, and Fd is the socket descriptor (an int).
Failure is "Operation not supported".
=================================================================
(The routine in question)
// DoConnect - Attempt a connect operation
// ---------------------------------------------------------------------
/* This helper function attempts a connection to a single address. */
static bool DoConnect(struct addrinfo *Addr,string Host,
unsigned long TimeOut,int &Fd,pkgAcqMethod *Owner)
{
// Show a status indicator
char Name[NI_MAXHOST];
Name[0] = 0;
getnameinfo(Addr->ai_addr,Addr->ai_addrlen,
Name,sizeof(Name),0,0,NI_NUMERICHOST);
Owner->Status("Connecting to %s (%s)",Host.c_str(),Name);
// Get a socket
if ((Fd = socket(Addr->ai_family,Addr->ai_socktype,
Addr->ai_protocol)) < 0)
return _error->Errno("socket","Could not create a socket");
SetNonBlock(Fd,true);
if (connect(Fd,Addr->ai_addr,Addr->ai_addrlen) < 0 &&
errno != EINPROGRESS)
return _error->Errno("connect","Cannot initiate the connection "
"to %s (%s).",Host.c_str(),Name);
/* This implements a timeout for connect by opening the connection
nonblocking */
if (WaitFd(Fd,true,TimeOut) == false)
return _error->Error("Could not connect to %s (%s), "
"connection timed out",Host.c_str(),Name);
// Check the socket for an error condition
unsigned int Err;
unsigned int Len = sizeof(Err);
if (getsockopt(Fd,SOL_SOCKET,SO_ERROR,&Err,&Len) != 0)
return _error->Errno("getsockopt","Failed");
if (Err != 0)
return _error->Error("Could not connect to %s
(%s).",Host.c_str(),Name);
return true;
}
Reply to: