Qt 4.8
Classes | Macros | Typedefs | Functions | Variables
qhostinfo_win.cpp File Reference
#include <winsock2.h>
#include "qhostinfo_p.h"
#include "private/qnativesocketengine_p.h"
#include <ws2tcpip.h>
#include <private/qsystemlibrary_p.h>
#include <qurl.h>
#include <qmutex.h>

Go to the source code of this file.

Classes

struct  qt_addrinfo
 

Macros

#define NI_MAXHOST   1024
 
#define QT_SOCKLEN_T   int
 

Typedefs

typedef int(__stdcall * freeaddrinfoProto) (qt_addrinfo *)
 
typedef int(__stdcall * getaddrinfoProto) (const char *, const char *, const qt_addrinfo *, qt_addrinfo **)
 
typedef int(__stdcall * getnameinfoProto) (const sockaddr *, QT_SOCKLEN_T, const char *, DWORD, const char *, DWORD, int)
 

Functions

static void resolveLibrary ()
 
static void translateWSAError (int error, QHostInfo *results)
 

Variables

static freeaddrinfoProto local_freeaddrinfo = 0
 
static getaddrinfoProto local_getaddrinfo = 0
 
static getnameinfoProto local_getnameinfo = 0
 

Macro Definition Documentation

◆ NI_MAXHOST

#define NI_MAXHOST   1024

Definition at line 71 of file qhostinfo_win.cpp.

Referenced by QHostInfoAgent::fromName(), and translateWSAError().

◆ QT_SOCKLEN_T

#define QT_SOCKLEN_T   int

Typedef Documentation

◆ freeaddrinfoProto

typedef int(__stdcall * freeaddrinfoProto) (qt_addrinfo *)

Definition at line 76 of file qhostinfo_win.cpp.

◆ getaddrinfoProto

typedef int(__stdcall * getaddrinfoProto) (const char *, const char *, const qt_addrinfo *, qt_addrinfo **)

Definition at line 75 of file qhostinfo_win.cpp.

◆ getnameinfoProto

typedef int(__stdcall * getnameinfoProto) (const sockaddr *, QT_SOCKLEN_T, const char *, DWORD, const char *, DWORD, int)

Definition at line 74 of file qhostinfo_win.cpp.

Function Documentation

◆ resolveLibrary()

static void resolveLibrary ( )
static

Definition at line 81 of file qhostinfo_win.cpp.

Referenced by translateWSAError().

82 {
83  // Attempt to resolve getaddrinfo(); without it we'll have to fall
84  // back to gethostbyname(), which has no IPv6 support.
85  static bool triedResolve = false;
86  if (triedResolve)
87  return;
88 
89 #if !defined(Q_OS_WINCE)
90  QSystemLibrary ws2lib(QLatin1String("ws2_32"));
91 #else
92  QSystemLibrary ws2lib(QLatin1String("ws2"));
93 #endif
94  if (ws2lib.load()) {
95  local_getaddrinfo = (getaddrinfoProto)ws2lib.resolve("getaddrinfo");
96  local_freeaddrinfo = (freeaddrinfoProto)ws2lib.resolve("freeaddrinfo");
97  local_getnameinfo = (getnameinfoProto)ws2lib.resolve("getnameinfo");
98  }
99 
100  triedResolve = true;
101 }
static freeaddrinfoProto local_freeaddrinfo
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int(__stdcall * getaddrinfoProto)(const char *, const char *, const qt_addrinfo *, qt_addrinfo **)
static getnameinfoProto local_getnameinfo
int(__stdcall * freeaddrinfoProto)(qt_addrinfo *)
static getaddrinfoProto local_getaddrinfo
int(__stdcall * getnameinfoProto)(const sockaddr *, QT_SOCKLEN_T, const char *, DWORD, const char *, DWORD, int)

◆ translateWSAError()

static void translateWSAError ( int  error,
QHostInfo results 
)
static

Definition at line 108 of file qhostinfo_win.cpp.

109 {
110  switch (error) {
111  case WSAHOST_NOT_FOUND: //authoritative not found
112  case WSATRY_AGAIN: //non authoritative not found
113  case WSANO_DATA: //valid name, no associated address
115  results->setErrorString(QHostInfoAgent::tr("Host not found"));
116  return;
117  default:
119  results->setErrorString(QHostInfoAgent::tr("Unknown error (%1)").arg(error));
120  return;
121  }
122 }
void setErrorString(const QString &errorString)
Sets the human readable description of the error that occurred to str if the lookup failed...
Definition: qhostinfo.cpp:465
#define error(msg)
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
void setError(HostInfoError error)
Sets the error type of this QHostInfo to error.
Definition: qhostinfo.cpp:423

Variable Documentation

◆ local_freeaddrinfo

freeaddrinfoProto local_freeaddrinfo = 0
static

Definition at line 79 of file qhostinfo_win.cpp.

Referenced by resolveLibrary(), and translateWSAError().

◆ local_getaddrinfo

getaddrinfoProto local_getaddrinfo = 0
static

Definition at line 78 of file qhostinfo_win.cpp.

Referenced by resolveLibrary(), and translateWSAError().

◆ local_getnameinfo

getnameinfoProto local_getnameinfo = 0
static

Definition at line 77 of file qhostinfo_win.cpp.

Referenced by resolveLibrary(), and translateWSAError().