Skip to content

Commit

Permalink
libcore: Parsing an IPv6 address
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 5b3fca7 commit cf88aae
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions doomsday/libs/core/src/net/address.cpp
Expand Up @@ -165,22 +165,11 @@ String Address::asText() const
Address Address::parse(String const &addressWithOptionalPort, duint16 defaultPort) // static
{
duint16 port = defaultPort;
String str = addressWithOptionalPort;
/*int portPosMin = 1;
if (str.beginsWith(DE_STR("::ffff:")))
{
// IPv4 address.
portPosMin = 8;
}
int pos = str.lastIndexOf(':');
if (pos >= portPosMin)
{
port = duint16(str.mid(pos + 1).toInt());
str = str.left(pos);
}*/
// Let's see if there is a port number included.
String str = addressWithOptionalPort;

// Let's see if there is a port number included (address is inside brackets).
static const RegExp ipPortRegex
("^(localhost|::1|(::ffff:)?[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+|[:A-Fa-f0-9]+[A-Fa-f0-9]):([0-9]+)$");
("^\\[(localhost|::1|(::ffff:)?[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+|[:A-Fa-f0-9]+[A-Fa-f0-9])\\]:([0-9]+)$");
//qDebug() << "matching:" << addressWithOptionalPort;
RegExpMatch match;
if (ipPortRegex.match(addressWithOptionalPort, match))
Expand Down

0 comments on commit cf88aae

Please sign in to comment.