xref: /netbsd-src/lib/libc/net/hostent.h (revision 388550b026d49b7f7b7480b1113bf82bb8d6a480)
1*388550b0Srillig /*	$NetBSD: hostent.h,v 1.3 2022/04/19 20:32:15 rillig Exp $	*/
202dd2447Schristos 
302dd2447Schristos /*-
402dd2447Schristos  * Copyright (c) 2013 The NetBSD Foundation, Inc.
502dd2447Schristos  * All rights reserved.
602dd2447Schristos  *
702dd2447Schristos  * This code is derived from software contributed to The NetBSD Foundation
802dd2447Schristos  * by Christos Zoulas.
902dd2447Schristos  *
1002dd2447Schristos  * Redistribution and use in source and binary forms, with or without
1102dd2447Schristos  * modification, are permitted provided that the following conditions
1202dd2447Schristos  * are met:
1302dd2447Schristos  * 1. Redistributions of source code must retain the above copyright
1402dd2447Schristos  *    notice, this list of conditions and the following disclaimer.
1502dd2447Schristos  * 2. Redistributions in binary form must reproduce the above copyright
1602dd2447Schristos  *    notice, this list of conditions and the following disclaimer in the
1702dd2447Schristos  *    documentation and/or other materials provided with the distribution.
1802dd2447Schristos  *
1902dd2447Schristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2002dd2447Schristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2102dd2447Schristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2202dd2447Schristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2302dd2447Schristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2402dd2447Schristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2502dd2447Schristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2602dd2447Schristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2702dd2447Schristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2802dd2447Schristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2902dd2447Schristos  * POSSIBILITY OF SUCH DAMAGE.
3002dd2447Schristos  */
3102dd2447Schristos 
3202dd2447Schristos #include <stdio.h>
3302dd2447Schristos #include <netdb.h>
3402dd2447Schristos #include <stdarg.h>
3502dd2447Schristos 
3602dd2447Schristos /*
3702dd2447Schristos  * These are not being advertised because the interfaces are non-standard.
3802dd2447Schristos  * There are versions by linux, aix, qnx, sun, etc. Our versions are used
3902dd2447Schristos  * internally to provide thread safety; they mostly resemble qnx.
4002dd2447Schristos  */
4102dd2447Schristos void sethostent_r(FILE **);
4202dd2447Schristos struct hostent	*gethostent_r(FILE *, struct hostent *, char *, size_t, int *);
4302dd2447Schristos void endhostent_r(FILE **);
4402dd2447Schristos 
4502dd2447Schristos struct hostent *gethostbyname_r(const char *, struct hostent *, char *, size_t,
4602dd2447Schristos     int *);
4702dd2447Schristos struct hostent *gethostbyname2_r(const char *, int, struct hostent *, char *,
4802dd2447Schristos     size_t, int *);
4902dd2447Schristos struct hostent *gethostbyaddr_r(const void *, socklen_t, int, struct hostent *,
5002dd2447Schristos     char *, size_t, int *);
5102dd2447Schristos 
5202dd2447Schristos extern FILE *_h_file;
5302dd2447Schristos 
5402dd2447Schristos /*
5502dd2447Schristos  * The following are internal API's and are used only for testing.
5602dd2447Schristos  */
5702dd2447Schristos struct getnamaddr {
5802dd2447Schristos 	struct hostent *hp;
5902dd2447Schristos 	char *buf;
6002dd2447Schristos 	size_t buflen;
6102dd2447Schristos 	int *he;
6202dd2447Schristos };
6302dd2447Schristos 
6402dd2447Schristos /* /etc/hosts lookup */
6502dd2447Schristos void _hf_sethostsfile(const char *);
6602dd2447Schristos int _hf_gethtbyaddr(void *, void *, va_list);
6702dd2447Schristos int _hf_gethtbyname(void *, void *, va_list);
6802dd2447Schristos 
6902dd2447Schristos /* DNS lookup */
7002dd2447Schristos int _dns_gethtbyaddr(void *, void *, va_list);
7102dd2447Schristos int _dns_gethtbyname(void *, void *, va_list);
7202dd2447Schristos 
7302dd2447Schristos #ifdef YP
7402dd2447Schristos /* NIS lookup */
7502dd2447Schristos int _yp_gethtbyaddr(void *, void *, va_list);
7602dd2447Schristos int _yp_gethtbyname(void *, void *, va_list);
7702dd2447Schristos #endif
784d322dedSchristos 
794d322dedSchristos #define HENT_ARRAY(dst, anum, ptr, len) \
804d322dedSchristos 	do { \
814d322dedSchristos 		size_t _len = (anum + 1) * sizeof(*dst); \
824d322dedSchristos 		if (_len > len) \
834d322dedSchristos 			goto nospc; \
844d322dedSchristos 		dst = (void *)ptr; \
854d322dedSchristos 		ptr += _len; \
864d322dedSchristos 		len -= _len; \
87*388550b0Srillig 	} while (0)
884d322dedSchristos 
894d322dedSchristos #define HENT_COPY(dst, src, slen, ptr, len) \
904d322dedSchristos 	do { \
914d322dedSchristos 		if ((size_t)slen > len) \
924d322dedSchristos 			goto nospc; \
934d322dedSchristos 		memcpy(ptr, src, (size_t)slen); \
944d322dedSchristos 		dst = ptr; \
954d322dedSchristos 		ptr += slen; \
964d322dedSchristos 		len -= slen; \
97*388550b0Srillig 	} while (0)
984d322dedSchristos 
994d322dedSchristos #define HENT_SCOPY(dst, src, ptr, len) \
1004d322dedSchristos 	do { \
1014d322dedSchristos 		size_t _len = strlen(src) + 1; \
1024d322dedSchristos 		HENT_COPY(dst, src, _len, ptr, len); \
103*388550b0Srillig 	} while (0)
1044d322dedSchristos 
1054d322dedSchristos #define	MAXALIASES	35
1064d322dedSchristos #define	MAXADDRS	35
107