MCPcopy Create free account
hub / github.com/cuberite/cuberite / ConnectIPv4

Method ConnectIPv4

src/OSSupport/Socket.cpp:296–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

294
295
296bool cSocket::ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Port)
297{
298 // First try IP Address string to hostent conversion, because it's faster
299 unsigned long addr = inet_addr(a_HostNameOrAddr.c_str());
300 if (addr == INADDR_NONE)
301 {
302 // It is not an IP Address string, but rather a regular hostname, resolve:
303 hostent * hp = gethostbyname(a_HostNameOrAddr.c_str());
304 if (hp == NULL)
305 {
306 LOGWARNING("%s: Could not resolve hostname \"%s\"", __FUNCTION__, a_HostNameOrAddr.c_str());
307 CloseSocket();
308 return false;
309 }
310 // Should be optimised to a single word copy
311 memcpy(&addr, hp->h_addr, hp->h_length);
312 }
313
314 sockaddr_in server;
315 server.sin_addr.s_addr = addr;
316 server.sin_family = AF_INET;
317 server.sin_port = htons((unsigned short)a_Port);
318 return (connect(m_Socket, (sockaddr *)&server, sizeof(server)) == 0);
319}
320
321
322

Callers 1

RealMainFunction · 0.80

Calls 1

c_strMethod · 0.80

Tested by

no test coverage detected