Skip to content
Snippets Groups Projects
Commit 6790d1ec authored by Adrien Béraud's avatar Adrien Béraud
Browse files

SockAddr: set service to null if string is empty

parent 4dc18479
No related branches found
No related tags found
No related merge requests found
...@@ -38,7 +38,7 @@ SockAddr::resolve(const std::string& host, const std::string& service) ...@@ -38,7 +38,7 @@ SockAddr::resolve(const std::string& host, const std::string& service)
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_DGRAM; hints.ai_socktype = SOCK_DGRAM;
addrinfo* info = nullptr; addrinfo* info = nullptr;
int rc = getaddrinfo(host.c_str(), service.c_str(), &hints, &info); int rc = getaddrinfo(host.c_str(), service.empty() ? nullptr : service.c_str(), &hints, &info);
if(rc != 0) if(rc != 0)
throw std::invalid_argument(std::string("Error: `") + host + ":" + service + "`: " + gai_strerror(rc)); throw std::invalid_argument(std::string("Error: `") + host + ":" + service + "`: " + gai_strerror(rc));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment