MCPcopy Create free account
hub / github.com/davisking/dlib / ip_to_hostname

Function ip_to_hostname

dlib/sockets/sockets_kernel_2.cpp:178–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176// -----------------
177
178 int
179 ip_to_hostname (
180 const std::string& ip,
181 std::string& hostname
182 )
183 {
184
185 try
186 {
187
188 if (ip.empty())
189 return OTHER_ERROR;
190
191 sockaddr_in sa;
192 sa.sin_family = AF_INET;
193 inet_pton(AF_INET,ip.c_str(),&sa.sin_addr);
194
195 char temp[NI_MAXHOST];
196 if ( getnameinfo (
197 reinterpret_cast<sockaddr*>(&sa),sizeof(sockaddr_in),
198 temp,
199 NI_MAXHOST,
200 0,
201 0,
202 NI_NAMEREQD
203 )
204 )
205 {
206 return OTHER_ERROR;
207 }
208
209 hostname.assign(temp);
210
211 }
212 catch (...)
213 {
214 return OTHER_ERROR;
215 }
216 return 0;
217 }
218#else
219 int
220 hostname_to_ip (

Callers

nothing calls this directly

Calls 2

emptyMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected