sm_gethost.c revision 73188
164562Sgshapiro/*
273188Sgshapiro *  Copyright (c) 1999-2001 Sendmail, Inc. and its suppliers.
364562Sgshapiro *	All rights reserved.
464562Sgshapiro *
564562Sgshapiro * By using this file, you agree to the terms and conditions set
664562Sgshapiro * forth in the LICENSE file which can be found at the top level of
764562Sgshapiro * the sendmail distribution.
864562Sgshapiro *
964562Sgshapiro */
1064562Sgshapiro
1164562Sgshapiro#ifndef lint
1273188Sgshapirostatic char id[] = "@(#)$Id: sm_gethost.c,v 8.7.8.6 2001/02/14 04:07:23 gshapiro Exp $";
1364562Sgshapiro#endif /* ! lint */
1464562Sgshapiro
1564562Sgshapiro#if _FFR_MILTER
1664562Sgshapiro#include <sendmail.h>
1764562Sgshapiro#if NETINET || NETINET6
1864562Sgshapiro# include <arpa/inet.h>
1964562Sgshapiro#endif /* NETINET || NETINET6 */
2064562Sgshapiro
2164562Sgshapiro/*
2264562Sgshapiro**  MI_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX
2364562Sgshapiro**
2464562Sgshapiro**	Some operating systems have wierd problems with the gethostbyXXX
2564562Sgshapiro**	routines.  For example, Solaris versions at least through 2.3
2664562Sgshapiro**	don't properly deliver a canonical h_name field.  This tries to
2764562Sgshapiro**	work around these problems.
2864562Sgshapiro**
2964562Sgshapiro**	Support IPv6 as well as IPv4.
3064562Sgshapiro*/
3164562Sgshapiro
3264562Sgshapiro#if NETINET6 && NEEDSGETIPNODE && __RES < 19990909
3364562Sgshapiro
3464562Sgshapiro# ifndef AI_V4MAPPED
3564562Sgshapiro#  define AI_V4MAPPED	0	/* dummy */
3664562Sgshapiro# endif /* ! AI_V4MAPPED */
3764562Sgshapiro# ifndef AI_ALL
3864562Sgshapiro#  define AI_ALL	0	/* dummy */
3964562Sgshapiro# endif /* ! AI_ALL */
4064562Sgshapiro
4164562Sgshapirostatic struct hostent *
4266494Sgshapirogetipnodebyname(name, family, flags, err)
4364562Sgshapiro	char *name;
4464562Sgshapiro	int family;
4564562Sgshapiro	int flags;
4664562Sgshapiro	int *err;
4764562Sgshapiro{
4864562Sgshapiro	bool resv6 = TRUE;
4964562Sgshapiro	struct hostent *h;
5064562Sgshapiro
5164562Sgshapiro	if (family == AF_INET6)
5264562Sgshapiro	{
5364562Sgshapiro		/* From RFC2133, section 6.1 */
5464562Sgshapiro		resv6 = bitset(RES_USE_INET6, _res.options);
5564562Sgshapiro		_res.options |= RES_USE_INET6;
5664562Sgshapiro	}
5773188Sgshapiro	SM_SET_H_ERRNO(0);
5864562Sgshapiro	h = gethostbyname(name);
5964562Sgshapiro	*err = h_errno;
6064562Sgshapiro	if (family == AF_INET6 && !resv6)
6164562Sgshapiro		_res.options &= ~RES_USE_INET6;
6264562Sgshapiro	return h;
6364562Sgshapiro}
6471345Sgshapiro
6571345Sgshapiro# if _FFR_FREEHOSTENT
6671345Sgshapirovoid
6771345Sgshapirofreehostent(h)
6871345Sgshapiro	struct hostent *h;
6971345Sgshapiro{
7071345Sgshapiro	/*
7171345Sgshapiro	**  Stub routine -- if they don't have getipnodeby*(),
7271345Sgshapiro	**  they probably don't have the free routine either.
7371345Sgshapiro	*/
7471345Sgshapiro
7571345Sgshapiro	return;
7671345Sgshapiro}
7771345Sgshapiro# endif /* _FFR_FREEHOSTENT */
7864562Sgshapiro#endif /* NEEDSGETIPNODE && NETINET6 && __RES < 19990909 */
7964562Sgshapiro
8064562Sgshapirostruct hostent *
8164562Sgshapiromi_gethostbyname(name, family)
8264562Sgshapiro	char *name;
8364562Sgshapiro	int family;
8464562Sgshapiro{
8564562Sgshapiro	struct hostent *h = NULL;
8664562Sgshapiro#if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4))
8764562Sgshapiro# if SOLARIS == 20300 || SOLARIS == 203
8864562Sgshapiro	static struct hostent hp;
8964562Sgshapiro	static char buf[1000];
9064562Sgshapiro	extern struct hostent *_switch_gethostbyname_r();
9164562Sgshapiro
9264562Sgshapiro	h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno);
9364562Sgshapiro# else /* SOLARIS == 20300 || SOLARIS == 203 */
9464562Sgshapiro	extern struct hostent *__switch_gethostbyname();
9564562Sgshapiro
9664562Sgshapiro	h = __switch_gethostbyname(name);
9764562Sgshapiro# endif /* SOLARIS == 20300 || SOLARIS == 203 */
9864562Sgshapiro#else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
9964562Sgshapiro# if NETINET6
10064562Sgshapiro	int err;
10164562Sgshapiro# endif /* NETINET6 */
10264562Sgshapiro
10364562Sgshapiro# if NETINET6
10466494Sgshapiro	h = getipnodebyname(name, family, AI_V4MAPPED|AI_ALL, &err);
10573188Sgshapiro	SM_SET_H_ERRNO(err);
10664562Sgshapiro# else /* NETINET6 */
10764562Sgshapiro	h = gethostbyname(name);
10864562Sgshapiro# endif /* NETINET6 */
10964562Sgshapiro
11064562Sgshapiro#endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
11164562Sgshapiro	return h;
11264562Sgshapiro}
11364562Sgshapiro#endif /* _FFR_MILTER */
114