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 12 static char id[] = "@(#)$Id: sm_gethost.c,v 8.7.8.10 2001/05/09 20:57:12 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_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 SM_SET_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 65 # if _FFR_FREEHOSTENT 66 void 67 freehostent(h) 68 struct hostent *h; 69 { 70 /* 71 ** Stub routine -- if they don't have getipnodeby*(), 72 ** they probably don't have the free routine either. 73 */ 74 75 return; 76 } 77 # endif /* _FFR_FREEHOSTENT */ 78 #endif /* NEEDSGETIPNODE && NETINET6 */ 79 80 struct hostent * 81 mi_gethostbyname(name, family) 82 char *name; 83 int family; 84 { 85 struct hostent *h = NULL; 86 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) 87 # if SOLARIS == 20300 || SOLARIS == 203 88 static struct hostent hp; 89 static char buf[1000]; 90 extern struct hostent *_switch_gethostbyname_r(); 91 92 h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno); 93 # else /* SOLARIS == 20300 || SOLARIS == 203 */ 94 extern struct hostent *__switch_gethostbyname(); 95 96 h = __switch_gethostbyname(name); 97 # endif /* SOLARIS == 20300 || SOLARIS == 203 */ 98 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */ 99 # if NETINET6 100 int err; 101 # endif /* NETINET6 */ 102 103 # if NETINET6 104 h = getipnodebyname(name, family, AI_V4MAPPED|AI_ALL, &err); 105 SM_SET_H_ERRNO(err); 106 # else /* NETINET6 */ 107 h = gethostbyname(name); 108 # endif /* NETINET6 */ 109 110 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */ 111 return h; 112 } 113 #endif /* _FFR_MILTER */ 114