#include "mt.h"
#include <netdb.h>
#include <netdir.h>
#include <sys/types.h>
#include <nss_netdir.h>
#include <string.h>
extern struct netconfig *__rpc_getconfip();
extern struct hostent *
_switch_gethostbyname_r(const char *nam, struct hostent *result, char *buffer,
int buflen, int *h_errnop);
extern struct hostent *
_switch_gethostbyaddr_r(const char *addr, int length, int type,
struct hostent *result, char *buffer, int buflen, int *h_errnop);
#ifdef PIC
struct hostent *
_uncached_gethostbyname_r(const char *nam, struct hostent *result,
char *buffer, int buflen, int *h_errnop)
{
return (_switch_gethostbyname_r(nam, result,
buffer, buflen, h_errnop));
}
struct hostent *
_uncached_gethostbyaddr_r(const char *addr, int length, int type,
struct hostent *result, char *buffer, int buflen, int *h_errnop)
{
return (_switch_gethostbyaddr_r(addr, length, type,
result, buffer, buflen, h_errnop));
}
#endif
extern struct hostent *
gethostbyname_r(const char *nam, struct hostent *result, char *buffer,
int buflen, int *h_errnop);
extern struct hostent *
gethostbyaddr_r(const char *addr, int length, int type,
struct hostent *result, char *buffer, int buflen, int *h_errnop);
struct hostent *
gethostbyname_r(const char *nam, struct hostent *result, char *buffer,
int buflen, int *h_errnop)
{
struct netconfig *nconf;
struct nss_netdirbyname_in nssin;
union nss_netdirbyname_out nssout;
int neterr, dummy;
if (h_errnop == NULL)
h_errnop = &dummy;
if (strlen(nam) == 0) {
*h_errnop = HOST_NOT_FOUND;
return (NULL);
}
if ((nconf = __rpc_getconfip("udp")) == NULL &&
(nconf = __rpc_getconfip("tcp")) == NULL) {
*h_errnop = NO_RECOVERY;
return (NULL);
}
nssin.op_t = NSS_HOST;
nssin.arg.nss.host.name = nam;
nssin.arg.nss.host.buf = buffer;
nssin.arg.nss.host.buflen = buflen;
nssout.nss.host.hent = result;
nssout.nss.host.herrno_p = h_errnop;
neterr = _get_hostserv_inetnetdir_byname(nconf, &nssin, &nssout);
(void) freenetconfigent(nconf);
if (neterr != ND_OK)
return (NULL);
return (nssout.nss.host.hent);
}
struct hostent *
gethostbyaddr_r(const char *addr, int length, int type,
struct hostent *result, char *buffer, int buflen, int *h_errnop)
{
struct netconfig *nconf;
struct nss_netdirbyaddr_in nssin;
union nss_netdirbyaddr_out nssout;
int neterr, dummy;
if (h_errnop == NULL)
h_errnop = &dummy;
if (type != AF_INET) {
*h_errnop = HOST_NOT_FOUND;
return (NULL);
}
if ((nconf = __rpc_getconfip("udp")) == NULL &&
(nconf = __rpc_getconfip("tcp")) == NULL) {
*h_errnop = NO_RECOVERY;
return (NULL);
}
nssin.op_t = NSS_HOST;
nssin.arg.nss.host.addr = addr;
nssin.arg.nss.host.len = length;
nssin.arg.nss.host.type = type;
nssin.arg.nss.host.buf = buffer;
nssin.arg.nss.host.buflen = buflen;
nssout.nss.host.hent = result;
nssout.nss.host.herrno_p = h_errnop;
neterr = _get_hostserv_inetnetdir_byaddr(nconf, &nssin, &nssout);
(void) freenetconfigent(nconf);
if (neterr != ND_OK)
return (NULL);
return (nssout.nss.host.hent);
}