diff options
author | Timothy Pearson <[email protected]> | 2014-10-05 16:00:42 -0500 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2014-10-05 16:00:42 -0500 |
commit | 03518d6339ad40346fdcf7ab4b66d8eb307a36a8 (patch) | |
tree | 55f88ec42581d6d1484db0da8c7ae749d6cc5799 /tdecore/network/kresolver.cpp | |
parent | 7cd4adc908abf8c5e3b391c4a88f0514ba8468c4 (diff) | |
parent | 3f5a4b419f7907ba61c6f63458e0413cccb74760 (diff) | |
download | tdelibs-03518d6339ad40346fdcf7ab4b66d8eb307a36a8.tar.gz tdelibs-03518d6339ad40346fdcf7ab4b66d8eb307a36a8.zip |
Merge branch 'master' of https://scm.trinitydesktop.org/scm/git/tdelibs
Diffstat (limited to 'tdecore/network/kresolver.cpp')
-rw-r--r-- | tdecore/network/kresolver.cpp | 121 |
1 files changed, 103 insertions, 18 deletions
diff --git a/tdecore/network/kresolver.cpp b/tdecore/network/kresolver.cpp index b9ac605c0..6ec0c5aba 100644 --- a/tdecore/network/kresolver.cpp +++ b/tdecore/network/kresolver.cpp @@ -66,6 +66,10 @@ TQMutex getXXbyYYmutex; #endif +#ifdef __OpenBSD__ +#define USE_OPENBSD 1 +#endif + using namespace KNetwork; using namespace KNetwork::Internal; @@ -616,17 +620,28 @@ TQStrList KResolver::protocolName(int protonum) pe = getprotobynumber(protonum); #else +# ifdef USE_OPENBSD // OpenBSD uses an HP/IBM/DEC API + struct protoent protobuf; + struct protoent_data pdata; + ::memset(&pdata, 0, sizeof pdata); + + if (getprotobynumber_r(protonum, &protobuf, &pdata) == 0) + pe = &protobuf; + else + pe = 0; + +# else size_t buflen = 1024; struct protoent protobuf; char *buf; do { buf = new char[buflen]; -# ifdef USE_SOLARIS // Solaris uses a 4 argument getprotobynumber_r which returns struct *protoent or NULL +# ifdef USE_SOLARIS // Solaris uses a 4 argument getprotobynumber_r which returns struct *protoent or NULL if ((pe = getprotobynumber_r(protonum, &protobuf, buf, buflen)) && (errno == ERANGE)) -# else +# else if (getprotobynumber_r(protonum, &protobuf, buf, buflen, &pe) == ERANGE) -# endif +# endif { pe = 0L; buflen += 1024; @@ -636,6 +651,7 @@ TQStrList KResolver::protocolName(int protonum) break; } while (pe == 0L); +# endif #endif // Do common processing @@ -648,7 +664,9 @@ TQStrList KResolver::protocolName(int protonum) } #ifdef HAVE_GETPROTOBYNAME_R +# ifndef USE_OPENBSD delete [] buf; +# endif #endif return lst; @@ -663,17 +681,28 @@ TQStrList KResolver::protocolName(const char *protoname) pe = getprotobyname(protoname); #else +# ifdef USE_OPENBSD // OpenBSD uses an HP/IBM/DEC API + struct protoent protobuf; + struct protoent_data pdata; + ::memset(&pdata, 0, sizeof pdata); + + if (getprotobyname_r(protoname, &protobuf, &pdata) == 0) + pe = &protobuf; + else + pe = 0; + +# else size_t buflen = 1024; struct protoent protobuf; char *buf; do { buf = new char[buflen]; -# ifdef USE_SOLARIS // Solaris uses a 4 argument getprotobyname_r which returns struct *protoent or NULL +# ifdef USE_SOLARIS // Solaris uses a 4 argument getprotobyname_r which returns struct *protoent or NULL if ((pe = getprotobyname_r(protoname, &protobuf, buf, buflen)) && (errno == ERANGE)) -# else +# else if (getprotobyname_r(protoname, &protobuf, buf, buflen, &pe) == ERANGE) -# endif +# endif { pe = 0L; buflen += 1024; @@ -683,6 +712,7 @@ TQStrList KResolver::protocolName(const char *protoname) break; } while (pe == 0L); +# endif #endif // Do common processing @@ -695,7 +725,9 @@ TQStrList KResolver::protocolName(const char *protoname) } #ifdef HAVE_GETPROTOBYNAME_R +# ifndef USE_OPENBSD delete [] buf; +# endif #endif return lst; @@ -710,17 +742,28 @@ int KResolver::protocolNumber(const char *protoname) pe = getprotobyname(protoname); #else +# ifdef USE_OPENBSD // OpenBSD uses an HP/IBM/DEC API + struct protoent protobuf; + struct protoent_data pdata; + ::memset(&pdata, 0, sizeof pdata); + + if (getprotobyname_r(protoname, &protobuf, &pdata) == 0) + pe = &protobuf; + else + pe = 0; + +# else size_t buflen = 1024; struct protoent protobuf; char *buf; do { buf = new char[buflen]; -# ifdef USE_SOLARIS // Solaris uses a 4 argument getprotobyname_r which returns struct *protoent or NULL +# ifdef USE_SOLARIS // Solaris uses a 4 argument getprotobyname_r which returns struct *protoent or NULL if ((pe = getprotobyname_r(protoname, &protobuf, buf, buflen)) && (errno == ERANGE)) -# else +# else if (getprotobyname_r(protoname, &protobuf, buf, buflen, &pe) == ERANGE) -# endif +# endif { pe = 0L; buflen += 1024; @@ -730,6 +773,7 @@ int KResolver::protocolNumber(const char *protoname) break; } while (pe == 0L); +# endif #endif // Do common processing @@ -738,7 +782,9 @@ int KResolver::protocolNumber(const char *protoname) protonum = pe->p_proto; #ifdef HAVE_GETPROTOBYNAME_R +# ifndef USE_OPENBSD delete [] buf; +# endif #endif return protonum; @@ -753,17 +799,27 @@ int KResolver::servicePort(const char *servname, const char *protoname) se = getservbyname(servname, protoname); #else +# ifdef USE_OPENBSD // OpenBSD uses an HP/IBM/DEC API + struct servent servbuf; + struct servent_data sdata; + ::memset(&sdata, 0, sizeof sdata); + if (getservbyname_r(servname, protoname, &servbuf, &sdata) == 0) + se = &servbuf; + else + se = 0; + +# else size_t buflen = 1024; struct servent servbuf; char *buf; do { buf = new char[buflen]; -# ifdef USE_SOLARIS // Solaris uses a 5 argument getservbyname_r which returns struct *servent or NULL +# ifdef USE_SOLARIS // Solaris uses a 5 argument getservbyname_r which returns struct *servent or NULL if ((se = getservbyname_r(servname, protoname, &servbuf, buf, buflen)) && (errno == ERANGE)) -# else +# else if (getservbyname_r(servname, protoname, &servbuf, buf, buflen, &se) == ERANGE) -# endif +# endif { se = 0L; buflen += 1024; @@ -773,6 +829,7 @@ int KResolver::servicePort(const char *servname, const char *protoname) break; } while (se == 0L); +# endif #endif // Do common processing @@ -781,7 +838,9 @@ int KResolver::servicePort(const char *servname, const char *protoname) servport = ntohs(se->s_port); #ifdef HAVE_GETSERVBYNAME_R +# ifndef USE_OPENBSD delete [] buf; +# endif #endif return servport; @@ -796,17 +855,27 @@ TQStrList KResolver::serviceName(const char* servname, const char *protoname) se = getservbyname(servname, protoname); #else +# ifdef USE_OPENBSD // OpenBSD uses an HP/IBM/DEC API + struct servent servbuf; + struct servent_data sdata; + ::memset(&sdata, 0, sizeof sdata); + if (getservbyname_r(servname, protoname, &servbuf, &sdata) == 0) + se = &servbuf; + else + se = 0; + +# else size_t buflen = 1024; struct servent servbuf; char *buf; do { buf = new char[buflen]; -# ifdef USE_SOLARIS // Solaris uses a 5 argument getservbyname_r which returns struct *servent or NULL +# ifdef USE_SOLARIS // Solaris uses a 5 argument getservbyname_r which returns struct *servent or NULL if ((se = getservbyname_r(servname, protoname, &servbuf, buf, buflen)) && (errno == ERANGE)) -# else +# else if (getservbyname_r(servname, protoname, &servbuf, buf, buflen, &se) == ERANGE) -# endif +# endif { se = 0L; buflen += 1024; @@ -816,6 +885,7 @@ TQStrList KResolver::serviceName(const char* servname, const char *protoname) break; } while (se == 0L); +# endif #endif // Do common processing @@ -828,7 +898,9 @@ TQStrList KResolver::serviceName(const char* servname, const char *protoname) } #ifdef HAVE_GETSERVBYNAME_R +# ifndef USE_OPENBSD delete [] buf; +# endif #endif return lst; @@ -843,17 +915,27 @@ TQStrList KResolver::serviceName(int port, const char *protoname) se = getservbyport(port, protoname); #else +# ifdef USE_OPENBSD // OpenBSD uses an HP/IBM/DEC API + struct servent servbuf; + struct servent_data sdata; + ::memset(&sdata, 0, sizeof sdata); + if (getservbyport_r(port, protoname, &servbuf, &sdata) == 0) + se = &servbuf; + else + se = 0; + +# else size_t buflen = 1024; struct servent servbuf; char *buf; do { buf = new char[buflen]; -# ifdef USE_SOLARIS // Solaris uses a 5 argument getservbyport_r which returns struct *servent or NULL +# ifdef USE_SOLARIS // Solaris uses a 5 argument getservbyport_r which returns struct *servent or NULL if ((se = getservbyport_r(port, protoname, &servbuf, buf, buflen)) && (errno == ERANGE)) -# else +# else if (getservbyport_r(port, protoname, &servbuf, buf, buflen, &se) == ERANGE) -# endif +# endif { se = 0L; buflen += 1024; @@ -863,6 +945,7 @@ TQStrList KResolver::serviceName(int port, const char *protoname) break; } while (se == 0L); +# endif #endif // Do common processing @@ -875,7 +958,9 @@ TQStrList KResolver::serviceName(int port, const char *protoname) } #ifdef HAVE_GETSERVBYPORT_R +# ifndef USE_OPENBSD delete [] buf; +# endif #endif return lst; |