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