44 #include "qplatformdefs.h" 47 #include "private/qnativesocketengine_p.h" 53 #include <private/qmutexpool_p.h> 54 #include <private/qnet_unix_p.h> 56 #include <sys/types.h> 58 #include <arpa/inet.h> 59 #if defined(Q_OS_VXWORKS) 65 #if defined (QT_NO_GETADDRINFO) 75 #if !defined(QT_SOCKOPTLEN_T) 76 # define QT_SOCKOPTLEN_T QT_SOCKLEN_T 81 #if defined(AI_ADDRCONFIG) && !defined(Q_OS_HPUX) 82 # define Q_ADDRCONFIG AI_ADDRCONFIG 97 #if !defined(QT_NO_LIBRARY) && !defined(Q_OS_QNX) 108 if (!local_res_ninit)
111 if (!local_res_ninit) {
128 #if defined(QHOSTINFO_DEBUG) 129 qDebug(
"QHostInfoAgent::fromName(%s) looking up...",
134 static volatile bool triedResolve =
false;
151 #if !defined (QT_NO_GETADDRINFO) && !defined (Q_OS_DARWIN) 159 sa = (sockaddr *)&sa4;
160 saSize =
sizeof(sa4);
161 memset(&sa4, 0,
sizeof(sa4));
162 sa4.sin_family = AF_INET;
167 sa = (sockaddr *)&sa6;
168 saSize =
sizeof(sa6);
169 memset(&sa6, 0,
sizeof(sa6));
171 memcpy(sa6.sin6_addr.s6_addr, address.
toIPv6Address().
c,
sizeof(sa6.sin6_addr.s6_addr));
176 if (sa && getnameinfo(sa, saSize, hbuf,
sizeof(hbuf), 0, 0, 0) == 0)
180 struct hostent *ent = gethostbyaddr((
const char *)&inetaddr,
sizeof(inetaddr), AF_INET);
202 #if !defined (QT_NO_GETADDRINFO) 206 struct addrinfo hints;
207 memset(&hints, 0,
sizeof(hints));
208 hints.ai_family = PF_UNSPEC;
210 hints.ai_flags = Q_ADDRCONFIG;
213 int result = getaddrinfo(aceHostname.
constData(), 0, &hints, &res);
215 if (result == EAI_BADFLAGS) {
218 result = getaddrinfo(aceHostname.
constData(), 0, &hints, &res);
223 addrinfo *node = res;
226 #ifdef QHOSTINFO_DEBUG 227 qDebug() <<
"getaddrinfo node: flags:" << node->ai_flags <<
"family:" << node->ai_family <<
"ai_socktype:" << node->ai_socktype <<
"ai_protocol:" << node->ai_protocol <<
"ai_addrlen:" << node->ai_addrlen;
229 if (node->ai_family == AF_INET) {
231 addr.
setAddress(ntohl(((sockaddr_in *) node->ai_addr)->sin_addr.s_addr));
236 else if (node->ai_family ==
AF_INET6) {
238 sockaddr_in6 *sa6 = (sockaddr_in6 *) node->ai_addr;
240 if (sa6->sin6_scope_id)
246 node = node->ai_next;
248 if (addresses.
isEmpty() && node == 0) {
257 }
else if (result == EAI_NONAME
258 || result == EAI_FAIL
261 || result == EAI_NODATA
278 hostent *result = gethostbyname(aceHostname.
constData());
280 if (result->h_addrtype == AF_INET) {
282 for (
char **p = result->h_addr_list; *p != 0; p++) {
293 #if !defined(Q_OS_VXWORKS) 294 }
else if (h_errno == HOST_NOT_FOUND || h_errno == NO_DATA
295 || h_errno == NO_ADDRESS) {
303 #endif // !defined (QT_NO_GETADDRINFO) 305 #if defined(QHOSTINFO_DEBUG) 307 qDebug(
"QHostInfoAgent::fromName(): error #%d %s",
312 for (
int i = 0; i < addresses.
count(); ++i) {
313 if (i != 0) tmp +=
", ";
316 qDebug(
"QHostInfoAgent::fromName(): found %i entries for \"%s\": {%s}",
327 if (gethostname(hostName,
sizeof(hostName)) == -1)
329 hostName[
sizeof(hostName) - 1] =
'\0';
335 #if !defined(Q_OS_VXWORKS) 341 memset(state, 0,
sizeof(*state));
355 #if defined(QT_NO_GETADDRINFO) 369 #if defined(_PATH_RESCONF) 378 while (!resolvconf.
atEnd()) {
386 int pos = searchDomain.
indexOf(
' ');
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setScopeId(const QString &id)
Sets the IPv6 scope ID of the address to id.
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
void truncate(int pos)
Truncates the byte array at index position pos.
void(* res_nclose_proto)(res_state_ptr)
Q_IPV6ADDR toIPv6Address() const
Returns the IPv6 address as a Q_IPV6ADDR structure.
#define QT_END_NAMESPACE
This macro expands to.
The QMutex class provides access serialization between threads.
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
void setErrorString(const QString &errorString)
Sets the human readable description of the error that occurred to str if the lookup failed...
Q_CORE_EXPORT void qFree(void *ptr)
The QByteArray class provides an array of bytes.
static res_state_ptr local_res
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
HostInfoError error() const
Returns the type of error that occurred if the host name lookup failed; otherwise returns NoError...
int count(const T &t) const
Returns the number of occurrences of value in the list.
Q_CORE_EXPORT void * qMalloc(size_t size)
quint32 toIPv4Address() const
Returns the IPv4 address as a number.
void * resolve(const char *symbol)
Returns the address of the exported symbol symbol.
The QString class provides a Unicode character string.
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
struct __res_state * res_state_ptr
QList< QHostAddress > addresses() const
Returns the list of IP addresses associated with hostName().
static void resolveLibrary()
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
Q_CORE_EXPORT void qDebug(const char *,...)
static QByteArray toAce(const QString &)
Returns the ASCII Compatible Encoding of the given domain name domain.
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
void setHostName(const QString &name)
Sets the host name of this QHostInfo to hostName.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void setAddresses(const QList< QHostAddress > &addresses)
Sets the list of addresses in this QHostInfo to addresses.
QString hostName() const
Returns the name of the host whose IP addresses were looked up.
QByteArray trimmed() const
Returns a byte array that has whitespace removed from the start and the end.
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
void prepend(const T &t)
Inserts value at the beginning of the list.
const T & at(int i) const
Returns the item at index position i in the list.
The QHostInfo class provides static functions for host name lookups.
int(* res_init_proto)(void)
QString toString() const
Returns the address as a string.
static QString localHostName()
Returns the host name of this machine.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
int(* res_ninit_proto)(res_state_ptr)
static res_init_proto local_res_init
static res_nclose_proto local_res_nclose
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
static res_ninit_proto local_res_ninit
void setError(HostInfoError error)
Sets the error type of this QHostInfo to error.
static QString fromAce(const QByteArray &)
Returns the Unicode form of the given domain name domain, which is encoded in the ASCII Compatible En...
const char * constData() const
Returns a pointer to the data stored in the byte array.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
QAbstractSocket::NetworkLayerProtocol protocol() const
Returns the network layer protocol of the host address.
bool load()
Loads the library and returns true if the library was loaded successfully; otherwise returns false...
void setAddress(quint32 ip4Addr)
Set the IPv4 address specified by ip4Addr.
The QFile class provides an interface for reading from and writing to files.
qint64 readLine(char *data, qint64 maxlen)
This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes...
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
static in_addr_t qt_safe_inet_addr(const char *cp)
void setLoadHints(LoadHints hints)
QString errorString() const
If the lookup failed, this function returns a human readable description of the error; otherwise "Unk...
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
The QHostAddress class provides an IP address.
static QHostInfo fromName(const QString &hostName)
bool atEnd() const
Returns true if the end of the file has been reached; otherwise returns false.
static QMutex * globalInstanceGet(const void *address)
Returns a QMutex from the global mutex pool.
void setFileName(const QString &name)
Sets the name of the file.
static QString localDomainName()
Returns the DNS domain of this machine.
The QLibrary class loads shared libraries at runtime.