diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-09-03 23:27:21 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-09-03 23:27:21 +0200 |
commit | cc3ef5cfbd9bcc00b78cda298c037a0e23d2ff72 (patch) | |
tree | 17a57a32e66f17d31742444ca69ddc45548d977b | |
parent | fca6c1a831393e173706a5b5c798c35dc5f7d3e6 (diff) | |
download | mad-cc3ef5cfbd9bcc00b78cda298c037a0e23d2ff72.tar mad-cc3ef5cfbd9bcc00b78cda298c037a0e23d2ff72.zip |
madc: Erlaube Angabe von Hostnamen
-rw-r--r-- | src/madc.cpp | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/madc.cpp b/src/madc.cpp index 762aa03..1017912 100644 --- a/src/madc.cpp +++ b/src/madc.cpp @@ -34,6 +34,8 @@ #include "Client/Authenticators/ChallengeResponseAuthenticator.h" #include "Client/Authenticators/PasswordAuthenticator.h" +#include <boost/regex.hpp> + #include <iostream> #ifdef EDITLINE_FOUND @@ -48,11 +50,11 @@ using namespace Mad; static void usage(const std::string &cmd) { - std::cerr << "Usage: " << cmd << " address" << std::endl; + std::cerr << "Usage: " << cmd << " [host[:port]]" << std::endl; } int main(int argc, char *argv[]) { - if(argc != 2) { + if(argc > 2) { usage(argv[0]); std::exit(1); } @@ -62,13 +64,31 @@ int main(int argc, char *argv[]) { application.getConfigManager()->finish(); Common::ClientConnection *connection = new Common::ClientConnection(&application); + application.getRequestManager()->registerConnection(connection); try { - application.getRequestManager()->registerConnection(connection); + std::string server = "localhost", port = "6666"; + + if(argc == 2) { + server = argv[1]; + } - connection->connect(boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(argv[1]), 6666)); + static const boost::regex r("(.+):(\\d+)", boost::regex_constants::perl); + + boost::smatch match; + if(boost::regex_match(server, match, r)) { + server = match[1].str(); + port = match[2].str(); + } - std::cerr << "Connecting to " << argv[1] << "..." << std::flush; + boost::asio::ip::tcp::resolver resolver(application.getIOService()); + boost::asio::ip::tcp::resolver::query query(server, port); + boost::asio::ip::tcp::resolver::iterator entry = resolver.resolve(query); + + + connection->connect(entry->endpoint()); + + std::cerr << "Connecting to " << entry->host_name() << "..." << std::flush; connection->waitWhileConnecting(); @@ -121,13 +141,12 @@ int main(int argc, char *argv[]) { connection->waitWhileConnected(); application.getUserManager()->unregisterBackend(networkUserBackend); - - application.getRequestManager()->unregisterConnection(connection); } catch(Core::Exception &e) { application.logf(Core::Logger::LOG_CRITICAL, "Error: %s", e.what()); } + application.getRequestManager()->unregisterConnection(connection); delete connection; return 0; |