Skip to content
Snippets Groups Projects
Commit 62f306ff authored by Razvan Cojocaru's avatar Razvan Cojocaru Committed by Daniel Stenberg
Browse files

getinfo: added CURLINFO_ACTIVESOCKET


This patch addresses known bug #76, where on 64-bit Windows SOCKET is 64
bits wide, but long is only 32, making CURLINFO_LASTSOCKET unreliable.

Signed-off-by: default avatarRazvan Cojocaru <rcojocaru@bitdefender.com>
parent 36f6f6f4
No related branches found
No related tags found
No related merge requests found
...@@ -63,11 +63,6 @@ may have been fixed since this was written! ...@@ -63,11 +63,6 @@ may have been fixed since this was written!
any file at all. Like when using FTP. any file at all. Like when using FTP.
http://curl.haxx.se/bug/view.cgi?id=1063 http://curl.haxx.se/bug/view.cgi?id=1063
76. The SOCKET type in Win64 is 64 bits large (and thus so is curl_socket_t on
that platform), and long is only 32 bits. It makes it impossible for
curl_easy_getinfo() to return a socket properly with the CURLINFO_LASTSOCKET
option as for all other operating systems.
75. NTLM authentication involving unicode user name or password only works 75. NTLM authentication involving unicode user name or password only works
properly if built with UNICODE defined together with the WinSSL/schannel properly if built with UNICODE defined together with the WinSSL/schannel
backend. The original problem was mentioned in: backend. The original problem was mentioned in:
......
...@@ -205,8 +205,19 @@ libcurl close the socket and cleanup other resources associated with the ...@@ -205,8 +205,19 @@ libcurl close the socket and cleanup other resources associated with the
handle. This is typically used in combination with handle. This is typically used in combination with
\fICURLOPT_CONNECT_ONLY(3)\fP. (Added in 7.15.2) \fICURLOPT_CONNECT_ONLY(3)\fP. (Added in 7.15.2)
NOTE: this API is not really working on win64, since the SOCKET type on win64 NOTE: this API is deprecated since it is not working on win64 where the SOCKET
is 64 bit large while its 'long' is only 32 bits. type is 64 bits large while its 'long' is 32 bits. Use the
\fICURLINFO_ACTIVESOCKET\fP instead, if possible.
.IP CURLINFO_ACTIVESOCKET
Pass a pointer to a curl_socket_t to receive the active socket used by this
curl session. If the socket is no longer valid, -1 is returned. When you
finish working with the socket, you must call curl_easy_cleanup() as usual and
let libcurl close the socket and cleanup other resources associated with the
handle. This is typically used in combination with
\fICURLOPT_CONNECT_ONLY(3)\fP.
NOTE: this is meant as a cross-platform, safe alternative to
\fICURLINFO_LASTSOCKET\fP, which does not work on win64.
.IP CURLINFO_FTP_ENTRY_PATH .IP CURLINFO_FTP_ENTRY_PATH
Pass a pointer to a char pointer to receive a pointer to a string holding the Pass a pointer to a char pointer to receive a pointer to a string holding the
path of the entry path. That is the initial path libcurl ended up in when path of the entry path. That is the initial path libcurl ended up in when
......
...@@ -199,6 +199,7 @@ CURLGSSAPI_DELEGATION_NONE 7.22.0 ...@@ -199,6 +199,7 @@ CURLGSSAPI_DELEGATION_NONE 7.22.0
CURLGSSAPI_DELEGATION_POLICY_FLAG 7.22.0 CURLGSSAPI_DELEGATION_POLICY_FLAG 7.22.0
CURLHEADER_SEPARATE 7.37.0 CURLHEADER_SEPARATE 7.37.0
CURLHEADER_UNIFIED 7.37.0 CURLHEADER_UNIFIED 7.37.0
CURLINFO_ACTIVESOCKET 7.45.0
CURLINFO_APPCONNECT_TIME 7.19.0 CURLINFO_APPCONNECT_TIME 7.19.0
CURLINFO_CERTINFO 7.19.1 CURLINFO_CERTINFO 7.19.1
CURLINFO_CONDITION_UNMET 7.19.4 CURLINFO_CONDITION_UNMET 7.19.4
...@@ -247,6 +248,7 @@ CURLINFO_RTSP_SESSION_ID 7.20.0 ...@@ -247,6 +248,7 @@ CURLINFO_RTSP_SESSION_ID 7.20.0
CURLINFO_SIZE_DOWNLOAD 7.4.1 CURLINFO_SIZE_DOWNLOAD 7.4.1
CURLINFO_SIZE_UPLOAD 7.4.1 CURLINFO_SIZE_UPLOAD 7.4.1
CURLINFO_SLIST 7.12.3 CURLINFO_SLIST 7.12.3
CURLINFO_SOCKET 7.45.0
CURLINFO_SPEED_DOWNLOAD 7.4.1 CURLINFO_SPEED_DOWNLOAD 7.4.1
CURLINFO_SPEED_UPLOAD 7.4.1 CURLINFO_SPEED_UPLOAD 7.4.1
CURLINFO_SSL_DATA_IN 7.12.1 CURLINFO_SSL_DATA_IN 7.12.1
......
...@@ -2091,6 +2091,7 @@ struct curl_tlssessioninfo { ...@@ -2091,6 +2091,7 @@ struct curl_tlssessioninfo {
#define CURLINFO_LONG 0x200000 #define CURLINFO_LONG 0x200000
#define CURLINFO_DOUBLE 0x300000 #define CURLINFO_DOUBLE 0x300000
#define CURLINFO_SLIST 0x400000 #define CURLINFO_SLIST 0x400000
#define CURLINFO_SOCKET 0x500000
#define CURLINFO_MASK 0x0fffff #define CURLINFO_MASK 0x0fffff
#define CURLINFO_TYPEMASK 0xf00000 #define CURLINFO_TYPEMASK 0xf00000
...@@ -2139,9 +2140,10 @@ typedef enum { ...@@ -2139,9 +2140,10 @@ typedef enum {
CURLINFO_LOCAL_IP = CURLINFO_STRING + 41, CURLINFO_LOCAL_IP = CURLINFO_STRING + 41,
CURLINFO_LOCAL_PORT = CURLINFO_LONG + 42, CURLINFO_LOCAL_PORT = CURLINFO_LONG + 42,
CURLINFO_TLS_SESSION = CURLINFO_SLIST + 43, CURLINFO_TLS_SESSION = CURLINFO_SLIST + 43,
CURLINFO_ACTIVESOCKET = CURLINFO_SOCKET + 44,
/* Fill in new entries below here! */ /* Fill in new entries below here! */
CURLINFO_LASTONE = 43 CURLINFO_LASTONE = 44
} CURLINFO; } CURLINFO;
/* CURLINFO_RESPONSE_CODE is the new name for the option previously known as /* CURLINFO_RESPONSE_CODE is the new name for the option previously known as
......
...@@ -334,6 +334,31 @@ static CURLcode getinfo_slist(struct SessionHandle *data, CURLINFO info, ...@@ -334,6 +334,31 @@ static CURLcode getinfo_slist(struct SessionHandle *data, CURLINFO info,
return CURLE_OK; return CURLE_OK;
} }
static CURLcode getinfo_socket(struct SessionHandle *data, CURLINFO info,
curl_socket_t *param_socketp)
{
curl_socket_t sockfd;
switch(info) {
case CURLINFO_ACTIVESOCKET:
sockfd = Curl_getconnectinfo(data, NULL);
/* note: this is not a good conversion for systems with 64 bit sockets and
32 bit longs */
if(sockfd != CURL_SOCKET_BAD)
*param_socketp = sockfd;
else
/* this interface is documented to return -1 in case of badness, which
may not be the same as the CURL_SOCKET_BAD value */
*param_socketp = -1;
break;
default:
return CURLE_BAD_FUNCTION_ARGUMENT;
}
return CURLE_OK;
}
CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...) CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
{ {
va_list arg; va_list arg;
...@@ -341,6 +366,7 @@ CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...) ...@@ -341,6 +366,7 @@ CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
double *param_doublep = NULL; double *param_doublep = NULL;
char **param_charp = NULL; char **param_charp = NULL;
struct curl_slist **param_slistp = NULL; struct curl_slist **param_slistp = NULL;
curl_socket_t *param_socketp = NULL;
int type; int type;
/* default return code is to error out! */ /* default return code is to error out! */
CURLcode result = CURLE_BAD_FUNCTION_ARGUMENT; CURLcode result = CURLE_BAD_FUNCTION_ARGUMENT;
...@@ -372,6 +398,11 @@ CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...) ...@@ -372,6 +398,11 @@ CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
if(param_slistp) if(param_slistp)
result = getinfo_slist(data, info, param_slistp); result = getinfo_slist(data, info, param_slistp);
break; break;
case CURLINFO_SOCKET:
param_socketp = va_arg(arg, curl_socket_t *);
if(param_socketp)
result = getinfo_socket(data, info, param_socketp);
break;
default: default:
break; break;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment