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
32#include <stdio.h>
33#include <netdb.h>
34#include <stdarg.h>
35
36/*
37 * These are not being advertised because the interfaces are non-standard.
38 * There are versions by linux, aix, qnx, sun, etc. Our versions are used
39 * internally to provide thread safety; they mostly resemble qnx.
40 */
41void sethostent_r(FILE **);
42struct hostent	*gethostent_r(FILE *, struct hostent *, char *, size_t, int *);
43void endhostent_r(FILE **);
44
45struct hostent *gethostbyname_r(const char *, struct hostent *, char *, int,
46	int *);
47struct hostent *gethostbyname2_r(const char *, int, struct hostent *, char *,
48    size_t, int *);
49struct hostent *gethostbyaddr_r(const void *, int, int, struct hostent *,
50	char *, int, int *);
51
52extern FILE *_h_file;
53
54/*
55 * The following are internal API's and are used only for testing.
56 */
57struct getnamaddr {
58	struct hostent *hp;
59	char *buf;
60	size_t buflen;
61	int *he;
62};
63
64/* /etc/hosts lookup */
65void _hf_sethostsfile(const char *);
66int _hf_gethtbyaddr(void *, void *, va_list);
67int _hf_gethtbyname(void *, void *, va_list);
68
69/* DNS lookup */
70int _dns_gethtbyaddr(void *, void *, va_list);
71int _dns_gethtbyname(void *, void *, va_list);
72
73#ifdef YP
74/* NIS lookup */
75int _yp_gethtbyaddr(void *, void *, va_list);
76int _yp_gethtbyname(void *, void *, va_list);
77#endif
78
79#define HENT_ARRAY(dst, anum, ptr, len) \
80	do { \
81		size_t _len = (anum + 1) * sizeof(*dst); \
82		if (_len > len) \
83			goto nospc; \
84		dst = (void *)ptr; \
85		ptr += _len; \
86		len -= _len; \
87	} while (/*CONSTCOND*/0)
88
89#define HENT_COPY(dst, src, slen, ptr, len) \
90	do { \
91		if ((size_t)slen > len) \
92			goto nospc; \
93		memcpy(ptr, src, (size_t)slen); \
94		dst = ptr; \
95		ptr += slen; \
96		len -= slen; \
97	} while (/* CONSTCOND */0)
98
99#define HENT_SCOPY(dst, src, ptr, len) \
100	do { \
101		size_t _len = strlen(src) + 1; \
102		HENT_COPY(dst, src, _len, ptr, len); \
103	} while (/* CONSTCOND */0)
104
105#define	MAXALIASES	35
106#define	MAXADDRS	35
107