]> git.tdb.fi Git - libs/net.git/blobdiff - source/resolve.cpp
Add IPv6 support
[libs/net.git] / source / resolve.cpp
index 121b152b154c12d5e47867352ceae68d78e9ea63..bfe7eaaa5cada587f0eef0e8585965670df526fd 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspnet
-Copyright © 2008  Mikkosoft Productions, Mikko Rasa
+Copyright © 2008, 2011  Mikkosoft Productions, Mikko Rasa
 Distributed under the LGPL
 */
 
@@ -23,14 +23,25 @@ namespace Net {
 SockAddr *resolve(const string &s, Family family)
 {
        string host, serv;
-       unsigned colon=s.find(':');
-       if(colon!=string::npos)
+       if(s[0]=='[')
        {
-               host=s.substr(0, colon);
-               serv=s.substr(colon+1);
+               unsigned bracket = s.find(']');
+               host = s.substr(1, bracket-1);
+               unsigned colon = s.find(':', bracket);
+               if(colon!=string::npos)
+                       serv = s.substr(colon+1);
        }
        else
-               host=s;
+       {
+               unsigned colon = s.find(':');
+               if(colon!=string::npos)
+               {
+                       host = s.substr(0, colon);
+                       serv = s.substr(colon+1);
+               }
+               else
+                       host = s;
+       }
 
        addrinfo hints={0, family, 0, 0, 0, 0, 0, 0};
        addrinfo *res;