EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
NetUtils.cpp File Reference
#include "eve-core.h"
#include "network/NetUtils.h"
Include dependency graph for NetUtils.cpp:

Go to the source code of this file.

Functions

uint32 ResolveIP (const char *hostname, char *errbuf)
 

Function Documentation

uint32 ResolveIP ( const char *  hostname,
char *  errbuf 
)

Definition at line 30 of file NetUtils.cpp.

References ERRBUF_SIZE, and snprintf.

30  {
31 #ifdef HAVE_WINSOCK2_H
32  static InitWinsock ws;
33 #endif /* !HAVE_WINSOCK2_H */
34  if( errbuf )
35  errbuf[0] = 0;
36 
37  if( hostname == NULL )
38  {
39  if( errbuf )
40  snprintf(errbuf, ERRBUF_SIZE, "ResolveIP(): hostname == NULL");
41  return 0;
42  }
43 
44  hostent* phostent = gethostbyname( hostname );
45  if( phostent == NULL)
46  {
47  if( errbuf )
48 #ifdef HAVE_WINSOCK2_H
49  snprintf( errbuf, ERRBUF_SIZE, "Unable to get the host name. Error: %i", WSAGetLastError() );
50 #else /* !HAVE_WINSOCK2_H */
51  snprintf( errbuf, ERRBUF_SIZE, "Unable to get the host name. Error: %s", strerror( errno ) );
52 #endif /* !HAVE_WINSOCK2_H */
53  return 0;
54  }
55 
56  in_addr addr;
57  memcpy( &addr, phostent->h_addr, phostent->h_length );
58 
59  return addr.s_addr;
60 }
#define ERRBUF_SIZE
Definition: NetUtils.h:30
#define snprintf
Definition: eve-compat.h:184