Skip to content
Snippets Groups Projects
Commit 3a37dc1d authored by Lukas Güldenstein's avatar Lukas Güldenstein
Browse files

resolve hostnames

parent 3e7a17f3
No related branches found
No related tags found
No related merge requests found
......@@ -3,11 +3,13 @@
#include "proto.hpp"
#include "ui.hpp"
#include "util.hpp"
#include <arpa/inet.h>
#include <cstdio>
#include <cxxopts.hpp>
#include <future>
#include <iostream>
#include <mutex>
#include <netdb.h>
#include <sstream>
#include <stdexcept>
#include <string>
......@@ -204,8 +206,21 @@ int main(int argc, char *argv[]) {
std::cerr << usage << std::endl;
return EXIT_FAILURE;
}
auto server = result["server"].as<std::string>();
auto port = result["port"].as<int>();
// resolve dns
struct addrinfo *dnsResult, hints;
in_addr sin_addr;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
getaddrinfo(server.c_str(), std::to_string(port).c_str(), &hints, &dnsResult);
sin_addr = ((struct sockaddr_in *)dnsResult->ai_addr)->sin_addr;
freeaddrinfo(dnsResult);
// try to connect to server
cl = new Client(result["server"].as<std::string>(), result["port"].as<int>());
cl = new Client(inet_ntoa(sin_addr), port);
state.set(CONNECTING);
cl->onReceive(onReceive);
auto rc = cl->connectToServer();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment