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;
#endif
#ifdef __OpenBSD__
#define USE_OPENBSD 1
#endif
using namespace KNetwork;
using namespace KNetwork::Internal;
@ -615,6 +619,17 @@ 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;
@ -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;
@ -662,6 +680,17 @@ 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;
@ -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;
@ -709,6 +741,17 @@ 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;
@ -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;
@ -752,6 +798,16 @@ 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;
@ -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;
@ -795,6 +854,16 @@ 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;
@ -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;
@ -842,6 +914,16 @@ 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;
@ -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;

@ -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__)

Loading…
Cancel
Save