mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
better handling of IPv6 literal addresses
This commit is contained in:
parent
e621ebc91c
commit
6e68fe7d70
@ -439,7 +439,7 @@ namespace mongo {
|
||||
|
||||
string ip;
|
||||
int port;
|
||||
size_t idx = serverAddress.find( ":" );
|
||||
size_t idx = serverAddress.rfind( ":" );
|
||||
if ( idx != string::npos ) {
|
||||
port = strtol( serverAddress.substr( idx + 1 ).c_str(), 0, 10 );
|
||||
ip = serverAddress.substr( 0 , idx );
|
||||
@ -467,7 +467,7 @@ namespace mongo {
|
||||
|
||||
if ( !p->connect(*server) ) {
|
||||
stringstream ss;
|
||||
ss << "couldn't connect to server " << serverAddress << " " << ip << ":" << port;
|
||||
ss << "couldn't connect to server " << serverAddress << " {ip: \"" << ip << "\", port: " << port << '}';
|
||||
errmsg = ss.str();
|
||||
failed = true;
|
||||
return false;
|
||||
|
@ -769,6 +769,7 @@ namespace mongo {
|
||||
false was returned -- it will try to connect again.
|
||||
|
||||
@param serverHostname host to connect to. can include port number ( 127.0.0.1 , 127.0.0.1:5555 )
|
||||
If you use IPv6 you must add a port number ( ::1:27017 )
|
||||
@param errmsg any relevant error message will appended to the string
|
||||
@return false if fails to connect.
|
||||
*/
|
||||
|
@ -173,8 +173,8 @@ string fixHost( string url , string host , string port ){
|
||||
if ( url.find( "." ) != string::npos )
|
||||
return url + "/test";
|
||||
|
||||
if ( url.find( ":" ) != string::npos &&
|
||||
isdigit( url[url.find(":")+1] ) )
|
||||
if ( url.rfind( ":" ) != string::npos &&
|
||||
isdigit( url[url.rfind(":")+1] ) )
|
||||
return url + "/test";
|
||||
}
|
||||
return url;
|
||||
@ -191,6 +191,10 @@ string fixHost( string url , string host , string port ){
|
||||
string newurl = host;
|
||||
if ( port.size() > 0 )
|
||||
newurl += ":" + port;
|
||||
else if (host.find(':') != string::npos){
|
||||
// need to add port with IPv6 addresses
|
||||
newurl += ":27017";
|
||||
}
|
||||
|
||||
newurl += "/" + url;
|
||||
|
||||
|
@ -74,6 +74,9 @@ namespace mongo {
|
||||
if ( unknown == hostname )
|
||||
return unknown;
|
||||
|
||||
if (strchr(hostname, ':'))
|
||||
return hostname;
|
||||
|
||||
scoped_lock lk(sock_mutex);
|
||||
#if defined(_WIN32)
|
||||
if( inet_addr(hostname) != INADDR_NONE )
|
||||
|
Loading…
Reference in New Issue
Block a user