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

ip_utils: allow to specify address family when resolving domains

parent f78d6edf
Branches
Tags
No related merge requests found
...@@ -104,12 +104,12 @@ ip_utils::addrToStr(const std::string& ip_str, bool include_port, bool force_ipv ...@@ -104,12 +104,12 @@ ip_utils::addrToStr(const std::string& ip_str, bool include_port, bool force_ipv
} }
pj_sockaddr pj_sockaddr
ip_utils::strToAddr(const std::string& str) ip_utils::strToAddr(const std::string& str, pj_uint16_t family)
{ {
pj_str_t pjstring; pj_str_t pjstring;
pj_cstr(&pjstring, str.c_str()); pj_cstr(&pjstring, str.c_str());
pj_sockaddr ip; pj_sockaddr ip;
auto status = pj_sockaddr_parse(pj_AF_UNSPEC(), 0, &pjstring, &ip); auto status = pj_sockaddr_parse(family, 0, &pjstring, &ip);
if (status != PJ_SUCCESS) if (status != PJ_SUCCESS)
ip.addr.sa_family = pj_AF_UNSPEC(); ip.addr.sa_family = pj_AF_UNSPEC();
return ip; return ip;
......
...@@ -59,10 +59,10 @@ namespace ip_utils { ...@@ -59,10 +59,10 @@ namespace ip_utils {
/** /**
* Convert a string representation of an IP adress to its binary counterpart. * Convert a string representation of an IP adress to its binary counterpart.
* *
* Performs hostname resolution if necessary. * Performs hostname resolution if necessary (with given address family).
* If conversion fails, returned adress will have its family set to PJ_AF_UNSPEC. * If conversion fails, returned adress will have its family set to PJ_AF_UNSPEC.
*/ */
pj_sockaddr strToAddr(const std::string& str); pj_sockaddr strToAddr(const std::string& str, pj_uint16_t family = pj_AF_UNSPEC());
/** /**
* Return the generic "any host" IP address of the specified family. * Return the generic "any host" IP address of the specified family.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment