Roland Blom filed bug report #1481217

(http://curl.haxx.se/bug/view.cgi?id=1481217), with follow-ups by Michele Bini
and David Byron. libcurl previously wrongly used GetLastError() on windows to
get error details after socket-related function calls, when it really should
use WSAGetLastError() instead.

When changing to this, the former function Curl_ourerrno() is now instead
called Curl_sockerrno() as it is necessary to only use it to get errno from
socket-related functions as otherwise it won't work as intended on Windows.
This commit is contained in:
Daniel Stenberg
2006-05-04 22:39:47 +00:00
parent 758f6eed51
commit e85e30546c
18 changed files with 46 additions and 51 deletions

View File

@@ -29,7 +29,6 @@
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <errno.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -60,10 +59,6 @@
#endif
#endif
#if defined(WIN32) && defined(__GNUC__) || defined(__MINGW32__)
#include <errno.h>
#endif
#if (defined(NETWARE) && defined(__NOVELL_LIBC__))
#undef in_addr_t
#define in_addr_t unsigned long
@@ -492,7 +487,8 @@ CURLcode Curl_GetFTPResponse(ssize_t *nreadp, /* return number of bytes read */
switch (Curl_select(sockfd, CURL_SOCKET_BAD, interval_ms)) {
case -1: /* select() error, stop reading */
result = CURLE_RECV_ERROR;
failf(data, "FTP response aborted due to select() error: %d", errno);
failf(data, "FTP response aborted due to select() error: %d",
Curl_sockerrno());
break;
case 0: /* timeout */
if(Curl_pgrsUpdate(conn))
@@ -871,7 +867,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (portsock == CURL_SOCKET_BAD) {
error = Curl_ourerrno();
error = Curl_sockerrno();
continue;
}
break;
@@ -903,7 +899,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
((struct sockaddr_in6 *)sa)->sin6_port =0;
if(bind(portsock, (struct sockaddr *)sa, sslen) < 0) {
failf(data, "bind failed: %s", Curl_strerror(conn, Curl_ourerrno()));
failf(data, "bind failed: %s", Curl_strerror(conn, Curl_sockerrno()));
sclose(portsock);
return CURLE_FTP_PORT_FAILED;
}
@@ -914,14 +910,14 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
sslen = sizeof(ss);
if(getsockname(portsock, (struct sockaddr *)sa, &sslen)<0) {
failf(data, "getsockname() failed: %s",
Curl_strerror(conn, Curl_ourerrno()) );
Curl_strerror(conn, Curl_sockerrno()) );
return CURLE_FTP_PORT_FAILED;
}
/* step 4, listen on the socket */
if (listen(portsock, 1) < 0) {
error = Curl_ourerrno();
error = Curl_sockerrno();
sclose(portsock);
failf(data, "socket failure: %s", Curl_strerror(conn, error));
return CURLE_FTP_PORT_FAILED;