sm_gethost.c revision 80785
1/*
2 *  Copyright (c) 1999-2001 Sendmail, Inc. and its suppliers.
3 *	All rights reserved.
4 *
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
8 *
9 */
10
11#ifndef lint
12static char id[] = "@(#)$Id: sm_gethost.c,v 8.7.8.11 2001/07/21 00:10:23 gshapiro Exp $";
13#endif /* ! lint */
14
15#if _FFR_MILTER
16#include <sendmail.h>
17#if NETINET || NETINET6
18# include <arpa/inet.h>
19#endif /* NETINET || NETINET6 */
20
21/*
22**  MI_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX
23**
24**	Some operating systems have wierd problems with the gethostbyXXX
25**	routines.  For example, Solaris versions at least through 2.3
26**	don't properly deliver a canonical h_name field.  This tries to
27**	work around these problems.
28**
29**	Support IPv6 as well as IPv4.
30*/
31
32#if NETINET6 && NEEDSGETIPNODE
33
34# ifndef AI_ADDRCONFIG
35#  define AI_ADDRCONFIG	0	/* dummy */
36# endif /* ! AI_ADDRCONFIG */
37# ifndef AI_ALL
38#  define AI_ALL	0	/* dummy */
39# endif /* ! AI_ALL */
40# ifndef AI_DEFAULT
41#  define AI_DEFAULT	0	/* dummy */
42# endif /* ! AI_DEFAULT */
43
44static struct hostent *
45getipnodebyname(name, family, flags, err)
46	char *name;
47	int family;
48	int flags;
49	int *err;
50{
51	bool resv6 = TRUE;
52	struct hostent *h;
53
54	if (family == AF_INET6)
55	{
56		/* From RFC2133, section 6.1 */
57		resv6 = bitset(RES_USE_INET6, _res.options);
58		_res.options |= RES_USE_INET6;
59	}
60	SM_SET_H_ERRNO(0);
61	h = gethostbyname(name);
62	*err = h_errno;
63	if (family == AF_INET6 && !resv6)
64		_res.options &= ~RES_USE_INET6;
65	return h;
66}
67
68# if _FFR_FREEHOSTENT
69void
70freehostent(h)
71	struct hostent *h;
72{
73	/*
74	**  Stub routine -- if they don't have getipnodeby*(),
75	**  they probably don't have the free routine either.
76	*/
77
78	return;
79}
80# endif /* _FFR_FREEHOSTENT */
81#endif /* NEEDSGETIPNODE && NETINET6 */
82
83struct hostent *
84mi_gethostbyname(name, family)
85	char *name;
86	int family;
87{
88	struct hostent *h = NULL;
89#if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4))
90# if SOLARIS == 20300 || SOLARIS == 203
91	static struct hostent hp;
92	static char buf[1000];
93	extern struct hostent *_switch_gethostbyname_r();
94
95	h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno);
96# else /* SOLARIS == 20300 || SOLARIS == 203 */
97	extern struct hostent *__switch_gethostbyname();
98
99	h = __switch_gethostbyname(name);
100# endif /* SOLARIS == 20300 || SOLARIS == 203 */
101#else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
102# if NETINET6
103	int flags = AI_DEFAULT|AI_ALL;
104	int err;
105# endif /* NETINET6 */
106
107# if NETINET6
108#  if ADDRCONFIG_IS_BROKEN
109	flags &= ~AI_ADDRCONFIG;
110#  endif /* ADDRCONFIG_IS_BROKEN */
111	h = getipnodebyname(name, family, flags, &err);
112	SM_SET_H_ERRNO(err);
113# else /* NETINET6 */
114	h = gethostbyname(name);
115# endif /* NETINET6 */
116
117#endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
118	return h;
119}
120#endif /* _FFR_MILTER */
121