Add support for openbsd in kresolver

(cherry picked from commit 439f3ba7ea)
v3.5.13-sru
François Andriot 10 years ago committed by Slávek Banko
parent 4ade6a8e20
commit 2e79465b10

@ -66,6 +66,10 @@
TQMutex getXXbyYYmutex; TQMutex getXXbyYYmutex;
#endif #endif
#ifdef __OpenBSD__
#define USE_OPENBSD 1
#endif
using namespace KNetwork; using namespace KNetwork;
using namespace KNetwork::Internal; using namespace KNetwork::Internal;
@ -616,17 +620,28 @@ TQStrList KResolver::protocolName(int protonum)
pe = getprotobynumber(protonum); pe = getprotobynumber(protonum);
#else #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; size_t buflen = 1024;
struct protoent protobuf; struct protoent protobuf;
char *buf; char *buf;
do do
{ {
buf = new char[buflen]; 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)) if ((pe = getprotobynumber_r(protonum, &protobuf, buf, buflen)) && (errno == ERANGE))
# else # else
if (getprotobynumber_r(protonum, &protobuf, buf, buflen, &pe) == ERANGE) if (getprotobynumber_r(protonum, &protobuf, buf, buflen, &pe) == ERANGE)
# endif # endif
{ {
pe = 0L; pe = 0L;
buflen += 1024; buflen += 1024;
@ -636,6 +651,7 @@ TQStrList KResolver::protocolName(int protonum)
break; break;
} }
while (pe == 0L); while (pe == 0L);
# endif
#endif #endif
// Do common processing // Do common processing
@ -648,7 +664,9 @@ TQStrList KResolver::protocolName(int protonum)
} }
#ifdef HAVE_GETPROTOBYNAME_R #ifdef HAVE_GETPROTOBYNAME_R
# ifndef USE_OPENBSD
delete [] buf; delete [] buf;
# endif
#endif #endif
return lst; return lst;
@ -663,17 +681,28 @@ TQStrList KResolver::protocolName(const char *protoname)
pe = getprotobyname(protoname); pe = getprotobyname(protoname);
#else #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; size_t buflen = 1024;
struct protoent protobuf; struct protoent protobuf;
char *buf; char *buf;
do do
{ {
buf = new char[buflen]; 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)) if ((pe = getprotobyname_r(protoname, &protobuf, buf, buflen)) && (errno == ERANGE))
# else # else
if (getprotobyname_r(protoname, &protobuf, buf, buflen, &pe) == ERANGE) if (getprotobyname_r(protoname, &protobuf, buf, buflen, &pe) == ERANGE)
# endif # endif
{ {
pe = 0L; pe = 0L;
buflen += 1024; buflen += 1024;
@ -683,6 +712,7 @@ TQStrList KResolver::protocolName(const char *protoname)
break; break;
} }
while (pe == 0L); while (pe == 0L);
# endif
#endif #endif
// Do common processing // Do common processing
@ -695,7 +725,9 @@ TQStrList KResolver::protocolName(const char *protoname)
} }
#ifdef HAVE_GETPROTOBYNAME_R #ifdef HAVE_GETPROTOBYNAME_R
# ifndef USE_OPENBSD
delete [] buf; delete [] buf;
# endif
#endif #endif
return lst; return lst;
@ -710,17 +742,28 @@ int KResolver::protocolNumber(const char *protoname)
pe = getprotobyname(protoname); pe = getprotobyname(protoname);
#else #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; size_t buflen = 1024;
struct protoent protobuf; struct protoent protobuf;
char *buf; char *buf;
do do
{ {
buf = new char[buflen]; 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)) if ((pe = getprotobyname_r(protoname, &protobuf, buf, buflen)) && (errno == ERANGE))
# else # else
if (getprotobyname_r(protoname, &protobuf, buf, buflen, &pe) == ERANGE) if (getprotobyname_r(protoname, &protobuf, buf, buflen, &pe) == ERANGE)
# endif # endif
{ {
pe = 0L; pe = 0L;
buflen += 1024; buflen += 1024;
@ -730,6 +773,7 @@ int KResolver::protocolNumber(const char *protoname)
break; break;
} }
while (pe == 0L); while (pe == 0L);
# endif
#endif #endif
// Do common processing // Do common processing
@ -738,7 +782,9 @@ int KResolver::protocolNumber(const char *protoname)
protonum = pe->p_proto; protonum = pe->p_proto;
#ifdef HAVE_GETPROTOBYNAME_R #ifdef HAVE_GETPROTOBYNAME_R
# ifndef USE_OPENBSD
delete [] buf; delete [] buf;
# endif
#endif #endif
return protonum; return protonum;
@ -753,17 +799,27 @@ int KResolver::servicePort(const char *servname, const char *protoname)
se = getservbyname(servname, protoname); se = getservbyname(servname, protoname);
#else #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; size_t buflen = 1024;
struct servent servbuf; struct servent servbuf;
char *buf; char *buf;
do do
{ {
buf = new char[buflen]; 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)) if ((se = getservbyname_r(servname, protoname, &servbuf, buf, buflen)) && (errno == ERANGE))
# else # else
if (getservbyname_r(servname, protoname, &servbuf, buf, buflen, &se) == ERANGE) if (getservbyname_r(servname, protoname, &servbuf, buf, buflen, &se) == ERANGE)
# endif # endif
{ {
se = 0L; se = 0L;
buflen += 1024; buflen += 1024;
@ -773,6 +829,7 @@ int KResolver::servicePort(const char *servname, const char *protoname)
break; break;
} }
while (se == 0L); while (se == 0L);
# endif
#endif #endif
// Do common processing // Do common processing
@ -781,7 +838,9 @@ int KResolver::servicePort(const char *servname, const char *protoname)
servport = ntohs(se->s_port); servport = ntohs(se->s_port);
#ifdef HAVE_GETSERVBYNAME_R #ifdef HAVE_GETSERVBYNAME_R
# ifndef USE_OPENBSD
delete [] buf; delete [] buf;
# endif
#endif #endif
return servport; return servport;
@ -796,17 +855,27 @@ TQStrList KResolver::serviceName(const char* servname, const char *protoname)
se = getservbyname(servname, protoname); se = getservbyname(servname, protoname);
#else #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; size_t buflen = 1024;
struct servent servbuf; struct servent servbuf;
char *buf; char *buf;
do do
{ {
buf = new char[buflen]; 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)) if ((se = getservbyname_r(servname, protoname, &servbuf, buf, buflen)) && (errno == ERANGE))
# else # else
if (getservbyname_r(servname, protoname, &servbuf, buf, buflen, &se) == ERANGE) if (getservbyname_r(servname, protoname, &servbuf, buf, buflen, &se) == ERANGE)
# endif # endif
{ {
se = 0L; se = 0L;
buflen += 1024; buflen += 1024;
@ -816,6 +885,7 @@ TQStrList KResolver::serviceName(const char* servname, const char *protoname)
break; break;
} }
while (se == 0L); while (se == 0L);
# endif
#endif #endif
// Do common processing // Do common processing
@ -828,7 +898,9 @@ TQStrList KResolver::serviceName(const char* servname, const char *protoname)
} }
#ifdef HAVE_GETSERVBYNAME_R #ifdef HAVE_GETSERVBYNAME_R
# ifndef USE_OPENBSD
delete [] buf; delete [] buf;
# endif
#endif #endif
return lst; return lst;
@ -843,17 +915,27 @@ TQStrList KResolver::serviceName(int port, const char *protoname)
se = getservbyport(port, protoname); se = getservbyport(port, protoname);
#else #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; size_t buflen = 1024;
struct servent servbuf; struct servent servbuf;
char *buf; char *buf;
do do
{ {
buf = new char[buflen]; 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)) if ((se = getservbyport_r(port, protoname, &servbuf, buf, buflen)) && (errno == ERANGE))
# else # else
if (getservbyport_r(port, protoname, &servbuf, buf, buflen, &se) == ERANGE) if (getservbyport_r(port, protoname, &servbuf, buf, buflen, &se) == ERANGE)
# endif # endif
{ {
se = 0L; se = 0L;
buflen += 1024; buflen += 1024;
@ -863,6 +945,7 @@ TQStrList KResolver::serviceName(int port, const char *protoname)
break; break;
} }
while (se == 0L); while (se == 0L);
# endif
#endif #endif
// Do common processing // Do common processing
@ -875,7 +958,9 @@ TQStrList KResolver::serviceName(int port, const char *protoname)
} }
#ifdef HAVE_GETSERVBYPORT_R #ifdef HAVE_GETSERVBYPORT_R
# ifndef USE_OPENBSD
delete [] buf; delete [] buf;
# endif
#endif #endif
return lst; return lst;

@ -48,6 +48,7 @@ extern TQMutex getXXbyYYmutex;
#endif #endif
/* some systems have the functions, but don't declare them */ /* some systems have the functions, but don't declare them */
#ifndef __OpenBSD__
#if defined(HAVE_GETSERVBYNAME_R) && !HAVE_DECL_GETSERVBYNAME_R #if defined(HAVE_GETSERVBYNAME_R) && !HAVE_DECL_GETSERVBYNAME_R
extern "C" { extern "C" {
struct servent; struct servent;
@ -69,6 +70,7 @@ extern "C" {
struct protoent** result); struct protoent** result);
} }
#endif #endif
#endif
/* decide whether res_init is thread-safe or not */ /* decide whether res_init is thread-safe or not */
#if defined(__GLIBC__) #if defined(__GLIBC__)

Loading…
Cancel
Save