#include <sm/gen.h>
SM_RCSID("@(#)$Id: sm_gethost.c,v 8.27 2004/08/20 21:12:37 ca Exp $")
#include <sendmail.h>
#if NETINET || NETINET6
# include <arpa/inet.h>
#endif
#include "libmilter.h"
#if NETINET6 && NEEDSGETIPNODE
static struct hostent *getipnodebyname __P((char *, int, int, int *));
# ifndef AI_ADDRCONFIG
# define AI_ADDRCONFIG 0
# endif
# ifndef AI_ALL
# define AI_ALL 0
# endif
# ifndef AI_DEFAULT
# define AI_DEFAULT 0
# endif
static struct hostent *
getipnodebyname(name, family, flags, err)
char *name;
int family;
int flags;
int *err;
{
bool resv6 = true;
struct hostent *h;
if (family == AF_INET6)
{
resv6 = bitset(RES_USE_INET6, _res.options);
_res.options |= RES_USE_INET6;
}
SM_SET_H_ERRNO(0);
h = gethostbyname(name);
if (family == AF_INET6 && !resv6)
_res.options &= ~RES_USE_INET6;
*err = h_errno;
return h;
}
void
freehostent(h)
struct hostent *h;
{
return;
}
#endif
struct hostent *
mi_gethostbyname(name, family)
char *name;
int family;
{
struct hostent *h = NULL;
#if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4))
# if SOLARIS == 20300 || SOLARIS == 203
static struct hostent hp;
static char buf[1000];
extern struct hostent *_switch_gethostbyname_r();
h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno);
# else
extern struct hostent *__switch_gethostbyname();
h = __switch_gethostbyname(name);
# endif
#else
# if NETINET6
int flags = AI_DEFAULT|AI_ALL;
int err;
# endif
# if NETINET6
# if ADDRCONFIG_IS_BROKEN
flags &= ~AI_ADDRCONFIG;
# endif
h = getipnodebyname(name, family, flags, &err);
SM_SET_H_ERRNO(err);
# else
h = gethostbyname(name);
# endif
#endif
return h;
}
#if NETINET6
int
mi_inet_pton(family, src, dst)
int family;
const char *src;
void *dst;
{
if (family == AF_INET6 &&
strncasecmp(src, "IPv6:", 5) == 0)
src += 5;
return inet_pton(family, src, dst);
}
#endif