]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/sendmail/libmilter/sm_gethost.c
Import of sendmail version 8.11.1 into vendor branch SENDMAIL with
[FreeBSD/FreeBSD.git] / contrib / sendmail / libmilter / sm_gethost.c
1 /*
2  *  Copyright (c) 1999-2000 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
12 static char id[] = "@(#)$Id: sm_gethost.c,v 8.7.8.2 2000/09/17 17:04:24 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 \f/*
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 && __RES < 19990909
33
34 # ifndef AI_V4MAPPED
35 #  define AI_V4MAPPED   0       /* dummy */
36 # endif /* ! AI_V4MAPPED */
37 # ifndef AI_ALL
38 #  define AI_ALL        0       /* dummy */
39 # endif /* ! AI_ALL */
40
41 static struct hostent *
42 getipnodebyname(name, family, flags, err)
43         char *name;
44         int family;
45         int flags;
46         int *err;
47 {
48         bool resv6 = TRUE;
49         struct hostent *h;
50
51         if (family == AF_INET6)
52         {
53                 /* From RFC2133, section 6.1 */
54                 resv6 = bitset(RES_USE_INET6, _res.options);
55                 _res.options |= RES_USE_INET6;
56         }
57         h_errno = 0;
58         h = gethostbyname(name);
59         *err = h_errno;
60         if (family == AF_INET6 && !resv6)
61                 _res.options &= ~RES_USE_INET6;
62         return h;
63 }
64 #endif /* NEEDSGETIPNODE && NETINET6 && __RES < 19990909 */
65
66 struct hostent *
67 mi_gethostbyname(name, family)
68         char *name;
69         int family;
70 {
71         struct hostent *h = NULL;
72 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4))
73 # if SOLARIS == 20300 || SOLARIS == 203
74         static struct hostent hp;
75         static char buf[1000];
76         extern struct hostent *_switch_gethostbyname_r();
77
78         h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno);
79 # else /* SOLARIS == 20300 || SOLARIS == 203 */
80         extern struct hostent *__switch_gethostbyname();
81
82         h = __switch_gethostbyname(name);
83 # endif /* SOLARIS == 20300 || SOLARIS == 203 */
84 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
85 # if NETINET6
86         int err;
87 # endif /* NETINET6 */
88
89 # if NETINET6
90         h = getipnodebyname(name, family, AI_V4MAPPED|AI_ALL, &err);
91         h_errno = err;
92 # else /* NETINET6 */
93         h = gethostbyname(name);
94 # endif /* NETINET6 */
95
96 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */
97         return h;
98 }
99 #endif /* _FFR_MILTER */