We shouldn't pass the struct hostent returned from gethostbyname as
it's not thread-safe and isn't needed anyway.
This commit is contained in:
parent
a63acd71c8
commit
e6157dde9d
|
@ -1656,7 +1656,6 @@ HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
|
||||||
static const WCHAR szDefaultUsername[] = {'a','n','o','n','y','m','o','u','s','\0'};
|
static const WCHAR szDefaultUsername[] = {'a','n','o','n','y','m','o','u','s','\0'};
|
||||||
static const WCHAR szDefaultPassword[] = {'u','s','e','r','@','s','e','r','v','e','r','\0'};
|
static const WCHAR szDefaultPassword[] = {'u','s','e','r','@','s','e','r','v','e','r','\0'};
|
||||||
struct sockaddr_in socketAddr;
|
struct sockaddr_in socketAddr;
|
||||||
struct hostent *phe = NULL;
|
|
||||||
INT nsocket = -1;
|
INT nsocket = -1;
|
||||||
UINT sock_namelen;
|
UINT sock_namelen;
|
||||||
BOOL bSuccess = FALSE;
|
BOOL bSuccess = FALSE;
|
||||||
|
@ -1734,7 +1733,7 @@ HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
|
||||||
SendAsyncCallback(&hIC->hdr, dwContext, INTERNET_STATUS_RESOLVING_NAME,
|
SendAsyncCallback(&hIC->hdr, dwContext, INTERNET_STATUS_RESOLVING_NAME,
|
||||||
(LPWSTR) lpszServerName, strlenW(lpszServerName));
|
(LPWSTR) lpszServerName, strlenW(lpszServerName));
|
||||||
|
|
||||||
if (!GetAddress(lpszServerName, nServerPort, &phe, &socketAddr))
|
if (!GetAddress(lpszServerName, nServerPort, &socketAddr))
|
||||||
{
|
{
|
||||||
INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
|
INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
|
||||||
goto lerror;
|
goto lerror;
|
||||||
|
@ -1767,7 +1766,6 @@ HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
|
||||||
|
|
||||||
sock_namelen = sizeof(lpwfs->socketAddress);
|
sock_namelen = sizeof(lpwfs->socketAddress);
|
||||||
getsockname(nsocket, (struct sockaddr *) &lpwfs->socketAddress, &sock_namelen);
|
getsockname(nsocket, (struct sockaddr *) &lpwfs->socketAddress, &sock_namelen);
|
||||||
lpwfs->phostent = phe;
|
|
||||||
|
|
||||||
if (FTP_ConnectToHost(lpwfs))
|
if (FTP_ConnectToHost(lpwfs))
|
||||||
{
|
{
|
||||||
|
|
|
@ -813,7 +813,7 @@ HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
|
||||||
strlenW(lpwhs->lpszServerName)+1);
|
strlenW(lpwhs->lpszServerName)+1);
|
||||||
|
|
||||||
if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort,
|
if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort,
|
||||||
&lpwhs->phostent, &lpwhs->socketAddress))
|
&lpwhs->socketAddress))
|
||||||
{
|
{
|
||||||
INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
|
INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
|
||||||
InternetCloseHandle( handle );
|
InternetCloseHandle( handle );
|
||||||
|
@ -1397,7 +1397,7 @@ static BOOL HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr, LPCWSTR lpszUrl, LPCWST
|
||||||
strlenW(lpwhs->lpszServerName)+1);
|
strlenW(lpwhs->lpszServerName)+1);
|
||||||
|
|
||||||
if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort,
|
if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort,
|
||||||
&lpwhs->phostent, &lpwhs->socketAddress))
|
&lpwhs->socketAddress))
|
||||||
{
|
{
|
||||||
INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
|
INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -1917,7 +1917,7 @@ static BOOL HTTP_OpenConnection(LPWININETHTTPREQW lpwhr)
|
||||||
&(lpwhs->socketAddress),
|
&(lpwhs->socketAddress),
|
||||||
sizeof(struct sockaddr_in));
|
sizeof(struct sockaddr_in));
|
||||||
|
|
||||||
if (!NETCON_create(&lpwhr->netConnection, lpwhs->phostent->h_addrtype,
|
if (!NETCON_create(&lpwhr->netConnection, lpwhs->socketAddress.sin_family,
|
||||||
SOCK_STREAM, 0))
|
SOCK_STREAM, 0))
|
||||||
{
|
{
|
||||||
WARN("Socket creation failed\n");
|
WARN("Socket creation failed\n");
|
||||||
|
|
|
@ -168,7 +168,6 @@ typedef struct
|
||||||
LPWSTR lpszUserName;
|
LPWSTR lpszUserName;
|
||||||
INTERNET_PORT nServerPort;
|
INTERNET_PORT nServerPort;
|
||||||
struct sockaddr_in socketAddress;
|
struct sockaddr_in socketAddress;
|
||||||
struct hostent *phostent;
|
|
||||||
} WININETHTTPSESSIONW, *LPWININETHTTPSESSIONW;
|
} WININETHTTPSESSIONW, *LPWININETHTTPSESSIONW;
|
||||||
|
|
||||||
#define HDR_ISREQUEST 0x0001
|
#define HDR_ISREQUEST 0x0001
|
||||||
|
@ -214,7 +213,6 @@ typedef struct
|
||||||
LPWININETFILE download_in_progress;
|
LPWININETFILE download_in_progress;
|
||||||
struct sockaddr_in socketAddress;
|
struct sockaddr_in socketAddress;
|
||||||
struct sockaddr_in lstnSocketAddress;
|
struct sockaddr_in lstnSocketAddress;
|
||||||
struct hostent *phostent;
|
|
||||||
LPWSTR lpszPassword;
|
LPWSTR lpszPassword;
|
||||||
LPWSTR lpszUserName;
|
LPWSTR lpszUserName;
|
||||||
} WININETFTPSESSIONW, *LPWININETFTPSESSIONW;
|
} WININETFTPSESSIONW, *LPWININETFTPSESSIONW;
|
||||||
|
@ -420,7 +418,7 @@ HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
|
||||||
DWORD dwInternalFlags);
|
DWORD dwInternalFlags);
|
||||||
|
|
||||||
BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
|
BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
|
||||||
struct hostent **phe, struct sockaddr_in *psa);
|
struct sockaddr_in *psa);
|
||||||
|
|
||||||
void INTERNET_SetLastError(DWORD dwError);
|
void INTERNET_SetLastError(DWORD dwError);
|
||||||
DWORD INTERNET_GetLastError(void);
|
DWORD INTERNET_GetLastError(void);
|
||||||
|
|
|
@ -127,11 +127,12 @@ time_t ConvertTimeString(LPCWSTR asctime)
|
||||||
|
|
||||||
|
|
||||||
BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
|
BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
|
||||||
struct hostent **phe, struct sockaddr_in *psa)
|
struct sockaddr_in *psa)
|
||||||
{
|
{
|
||||||
WCHAR *found;
|
WCHAR *found;
|
||||||
char *name;
|
char *name;
|
||||||
int len, sz;
|
int len, sz;
|
||||||
|
struct hostent *phe;
|
||||||
|
|
||||||
TRACE("%s\n", debugstr_w(lpszServerName));
|
TRACE("%s\n", debugstr_w(lpszServerName));
|
||||||
|
|
||||||
|
@ -150,18 +151,18 @@ BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
|
||||||
name = HeapAlloc(GetProcessHeap(), 0, sz+1);
|
name = HeapAlloc(GetProcessHeap(), 0, sz+1);
|
||||||
WideCharToMultiByte( CP_UNIXCP, 0, lpszServerName, len, name, sz, NULL, NULL );
|
WideCharToMultiByte( CP_UNIXCP, 0, lpszServerName, len, name, sz, NULL, NULL );
|
||||||
name[sz] = 0;
|
name[sz] = 0;
|
||||||
*phe = gethostbyname(name);
|
phe = gethostbyname(name);
|
||||||
HeapFree( GetProcessHeap(), 0, name );
|
HeapFree( GetProcessHeap(), 0, name );
|
||||||
|
|
||||||
if (NULL == *phe)
|
if (NULL == phe)
|
||||||
{
|
{
|
||||||
TRACE("Failed to get hostname: (%s)\n", debugstr_w(lpszServerName) );
|
TRACE("Failed to get hostname: (%s)\n", debugstr_w(lpszServerName) );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(psa,0,sizeof(struct sockaddr_in));
|
memset(psa,0,sizeof(struct sockaddr_in));
|
||||||
memcpy((char *)&psa->sin_addr, (*phe)->h_addr, (*phe)->h_length);
|
memcpy((char *)&psa->sin_addr, phe->h_addr, phe->h_length);
|
||||||
psa->sin_family = (*phe)->h_addrtype;
|
psa->sin_family = phe->h_addrtype;
|
||||||
psa->sin_port = htons((u_short)nServerPort);
|
psa->sin_port = htons((u_short)nServerPort);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
Loading…
Reference in New Issue