mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
* http.c (connect_server): Try all A records for names with multiple
addresses until one answers (not MINGW32).
This commit is contained in:
parent
76846b74e4
commit
c5faf2270a
2 changed files with 22 additions and 4 deletions
21
util/http.c
21
util/http.c
|
@ -756,6 +756,7 @@ connect_server( const char *server, ushort port )
|
|||
#else
|
||||
struct sockaddr_in addr;
|
||||
struct hostent *host;
|
||||
int i=0;
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
|
@ -763,16 +764,28 @@ connect_server( const char *server, ushort port )
|
|||
if( !host )
|
||||
return -1;
|
||||
|
||||
addr.sin_addr = *(struct in_addr*)host->h_addr;
|
||||
|
||||
sd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if( sd == -1 )
|
||||
return -1;
|
||||
|
||||
if( connect( sd, (struct sockaddr *)&addr, sizeof addr) == -1 ) {
|
||||
/* Try all A records until one responds. TODO: do this on the
|
||||
MINGW32 side as well. */
|
||||
do
|
||||
{
|
||||
addr.sin_addr = *(struct in_addr*)host->h_addr_list[i];
|
||||
if(connect( sd, (struct sockaddr *)&addr, sizeof addr) == 0)
|
||||
break;
|
||||
|
||||
i++;
|
||||
}
|
||||
while(addr.sin_addr.s_addr!=0);
|
||||
|
||||
if(addr.sin_addr.s_addr==0)
|
||||
{
|
||||
sock_close(sd);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return sd;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue