xref: /haiku/src/system/libnetwork/netresolv/net/hostent.h (revision 75e1de3c2369b5acb868c2a66e526dce183c7892)
1*75e1de3cSAugustin Cavalier /*	$NetBSD: hostent.h,v 1.2 2013/08/27 09:56:12 christos Exp $	*/
2*75e1de3cSAugustin Cavalier 
3*75e1de3cSAugustin Cavalier /*-
4*75e1de3cSAugustin Cavalier  * Copyright (c) 2013 The NetBSD Foundation, Inc.
5*75e1de3cSAugustin Cavalier  * All rights reserved.
6*75e1de3cSAugustin Cavalier  *
7*75e1de3cSAugustin Cavalier  * This code is derived from software contributed to The NetBSD Foundation
8*75e1de3cSAugustin Cavalier  * by Christos Zoulas.
9*75e1de3cSAugustin Cavalier  *
10*75e1de3cSAugustin Cavalier  * Redistribution and use in source and binary forms, with or without
11*75e1de3cSAugustin Cavalier  * modification, are permitted provided that the following conditions
12*75e1de3cSAugustin Cavalier  * are met:
13*75e1de3cSAugustin Cavalier  * 1. Redistributions of source code must retain the above copyright
14*75e1de3cSAugustin Cavalier  *    notice, this list of conditions and the following disclaimer.
15*75e1de3cSAugustin Cavalier  * 2. Redistributions in binary form must reproduce the above copyright
16*75e1de3cSAugustin Cavalier  *    notice, this list of conditions and the following disclaimer in the
17*75e1de3cSAugustin Cavalier  *    documentation and/or other materials provided with the distribution.
18*75e1de3cSAugustin Cavalier  *
19*75e1de3cSAugustin Cavalier  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*75e1de3cSAugustin Cavalier  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*75e1de3cSAugustin Cavalier  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*75e1de3cSAugustin Cavalier  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*75e1de3cSAugustin Cavalier  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*75e1de3cSAugustin Cavalier  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*75e1de3cSAugustin Cavalier  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*75e1de3cSAugustin Cavalier  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*75e1de3cSAugustin Cavalier  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*75e1de3cSAugustin Cavalier  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*75e1de3cSAugustin Cavalier  * POSSIBILITY OF SUCH DAMAGE.
30*75e1de3cSAugustin Cavalier  */
31*75e1de3cSAugustin Cavalier 
32*75e1de3cSAugustin Cavalier #include <stdio.h>
33*75e1de3cSAugustin Cavalier #include <netdb.h>
34*75e1de3cSAugustin Cavalier #include <stdarg.h>
35*75e1de3cSAugustin Cavalier 
36*75e1de3cSAugustin Cavalier /*
37*75e1de3cSAugustin Cavalier  * These are not being advertised because the interfaces are non-standard.
38*75e1de3cSAugustin Cavalier  * There are versions by linux, aix, qnx, sun, etc. Our versions are used
39*75e1de3cSAugustin Cavalier  * internally to provide thread safety; they mostly resemble qnx.
40*75e1de3cSAugustin Cavalier  */
41*75e1de3cSAugustin Cavalier void sethostent_r(FILE **);
42*75e1de3cSAugustin Cavalier struct hostent	*gethostent_r(FILE *, struct hostent *, char *, size_t, int *);
43*75e1de3cSAugustin Cavalier void endhostent_r(FILE **);
44*75e1de3cSAugustin Cavalier 
45*75e1de3cSAugustin Cavalier struct hostent *gethostbyname_r(const char *, struct hostent *, char *, int,
46*75e1de3cSAugustin Cavalier 	int *);
47*75e1de3cSAugustin Cavalier struct hostent *gethostbyname2_r(const char *, int, struct hostent *, char *,
48*75e1de3cSAugustin Cavalier     size_t, int *);
49*75e1de3cSAugustin Cavalier struct hostent *gethostbyaddr_r(const void *, int, int, struct hostent *,
50*75e1de3cSAugustin Cavalier 	char *, int, int *);
51*75e1de3cSAugustin Cavalier 
52*75e1de3cSAugustin Cavalier extern FILE *_h_file;
53*75e1de3cSAugustin Cavalier 
54*75e1de3cSAugustin Cavalier /*
55*75e1de3cSAugustin Cavalier  * The following are internal API's and are used only for testing.
56*75e1de3cSAugustin Cavalier  */
57*75e1de3cSAugustin Cavalier struct getnamaddr {
58*75e1de3cSAugustin Cavalier 	struct hostent *hp;
59*75e1de3cSAugustin Cavalier 	char *buf;
60*75e1de3cSAugustin Cavalier 	size_t buflen;
61*75e1de3cSAugustin Cavalier 	int *he;
62*75e1de3cSAugustin Cavalier };
63*75e1de3cSAugustin Cavalier 
64*75e1de3cSAugustin Cavalier /* /etc/hosts lookup */
65*75e1de3cSAugustin Cavalier void _hf_sethostsfile(const char *);
66*75e1de3cSAugustin Cavalier int _hf_gethtbyaddr(void *, void *, va_list);
67*75e1de3cSAugustin Cavalier int _hf_gethtbyname(void *, void *, va_list);
68*75e1de3cSAugustin Cavalier 
69*75e1de3cSAugustin Cavalier /* DNS lookup */
70*75e1de3cSAugustin Cavalier int _dns_gethtbyaddr(void *, void *, va_list);
71*75e1de3cSAugustin Cavalier int _dns_gethtbyname(void *, void *, va_list);
72*75e1de3cSAugustin Cavalier 
73*75e1de3cSAugustin Cavalier #ifdef YP
74*75e1de3cSAugustin Cavalier /* NIS lookup */
75*75e1de3cSAugustin Cavalier int _yp_gethtbyaddr(void *, void *, va_list);
76*75e1de3cSAugustin Cavalier int _yp_gethtbyname(void *, void *, va_list);
77*75e1de3cSAugustin Cavalier #endif
78*75e1de3cSAugustin Cavalier 
79*75e1de3cSAugustin Cavalier #define HENT_ARRAY(dst, anum, ptr, len) \
80*75e1de3cSAugustin Cavalier 	do { \
81*75e1de3cSAugustin Cavalier 		size_t _len = (anum + 1) * sizeof(*dst); \
82*75e1de3cSAugustin Cavalier 		if (_len > len) \
83*75e1de3cSAugustin Cavalier 			goto nospc; \
84*75e1de3cSAugustin Cavalier 		dst = (void *)ptr; \
85*75e1de3cSAugustin Cavalier 		ptr += _len; \
86*75e1de3cSAugustin Cavalier 		len -= _len; \
87*75e1de3cSAugustin Cavalier 	} while (/*CONSTCOND*/0)
88*75e1de3cSAugustin Cavalier 
89*75e1de3cSAugustin Cavalier #define HENT_COPY(dst, src, slen, ptr, len) \
90*75e1de3cSAugustin Cavalier 	do { \
91*75e1de3cSAugustin Cavalier 		if ((size_t)slen > len) \
92*75e1de3cSAugustin Cavalier 			goto nospc; \
93*75e1de3cSAugustin Cavalier 		memcpy(ptr, src, (size_t)slen); \
94*75e1de3cSAugustin Cavalier 		dst = ptr; \
95*75e1de3cSAugustin Cavalier 		ptr += slen; \
96*75e1de3cSAugustin Cavalier 		len -= slen; \
97*75e1de3cSAugustin Cavalier 	} while (/* CONSTCOND */0)
98*75e1de3cSAugustin Cavalier 
99*75e1de3cSAugustin Cavalier #define HENT_SCOPY(dst, src, ptr, len) \
100*75e1de3cSAugustin Cavalier 	do { \
101*75e1de3cSAugustin Cavalier 		size_t _len = strlen(src) + 1; \
102*75e1de3cSAugustin Cavalier 		HENT_COPY(dst, src, _len, ptr, len); \
103*75e1de3cSAugustin Cavalier 	} while (/* CONSTCOND */0)
104*75e1de3cSAugustin Cavalier 
105*75e1de3cSAugustin Cavalier #define	MAXALIASES	35
106*75e1de3cSAugustin Cavalier #define	MAXADDRS	35
107