diff options
author | François Andriot <francois.andriot@free.fr> | 2014-10-05 16:31:25 +0200 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2014-10-05 16:31:25 +0200 |
commit | 439f3ba7ea9aa0b850f70b520081d6bac8c83752 (patch) | |
tree | c5b2d8ea3504efdc59e88277737bbe84032f074a | |
parent | e61585edf09d3136c92e255e26dc054d3e22cd7d (diff) | |
download | tdelibs-439f3ba7ea9aa0b850f70b520081d6bac8c83752.tar.gz tdelibs-439f3ba7ea9aa0b850f70b520081d6bac8c83752.zip |
Add support for openbsd in kresolver
-rw-r--r-- | tdecore/network/kresolver.cpp | 121 | ||||
-rw-r--r-- | tdecore/network/kresolver_p.h | 2 |
2 files changed, 105 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; diff --git a/tdecore/network/kresolver_p.h b/tdecore/network/kresolver_p.h index 7f74c6fe6..9cc139458 100644 --- a/tdecore/network/kresolver_p.h +++ b/tdecore/network/kresolver_p.h @@ -48,6 +48,7 @@ extern TQMutex getXXbyYYmutex; #endif /* some systems have the functions, but don't declare them */ +#ifndef __OpenBSD__ #if defined(HAVE_GETSERVBYNAME_R) && !HAVE_DECL_GETSERVBYNAME_R extern "C" { struct servent; @@ -69,6 +70,7 @@ extern "C" { struct protoent** result); } #endif +#endif /* decide whether res_init is thread-safe or not */ #if defined(__GLIBC__) |