158d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui/* $NetBSD: hostent.h,v 1.2 2013/08/27 09:56:12 christos Exp $ */ 258d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui 358d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui/*- 458d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * Copyright (c) 2013 The NetBSD Foundation, Inc. 558d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * All rights reserved. 658d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * 758d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * This code is derived from software contributed to The NetBSD Foundation 858d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * by Christos Zoulas. 958d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * 1058d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * Redistribution and use in source and binary forms, with or without 1158d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * modification, are permitted provided that the following conditions 1258d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * are met: 1358d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * 1. Redistributions of source code must retain the above copyright 1458d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * notice, this list of conditions and the following disclaimer. 1558d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * 2. Redistributions in binary form must reproduce the above copyright 1658d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * notice, this list of conditions and the following disclaimer in the 1758d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * documentation and/or other materials provided with the distribution. 1858d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * 1958d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2058d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2158d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2258d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2358d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2458d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2558d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2658d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2758d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2858d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2958d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * POSSIBILITY OF SUCH DAMAGE. 3058d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui */ 3158d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui#ifndef _DNS_NET_HOSTENT_H 3258d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui#define _DNS_NET_HOSTENT_H 3358d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui 3458d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui#include <stdio.h> 3558d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui#include <netdb.h> 3658d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui#include <stdarg.h> 3758d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui 3858d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui/* 3958d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * These are not being advertised because the interfaces are non-standard. 4058d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * There are versions by linux, aix, qnx, sun, etc. Our versions are used 4158d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * internally to provide thread safety; they mostly resemble qnx. 4258d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui */ 4358d33a51f336d6823ef1ec915949a5884699ff5fYabin Cuivoid sethostent_r(FILE **); 4458d33a51f336d6823ef1ec915949a5884699ff5fYabin Cuistruct hostent *netbsd_gethostent_r(FILE *, struct hostent *, char *, size_t, int *); 4558d33a51f336d6823ef1ec915949a5884699ff5fYabin Cuivoid endhostent_r(FILE **); 4658d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui 4758d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui/* 4858d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui * The following are internal API's and are used only for testing. 4958d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui */ 5058d33a51f336d6823ef1ec915949a5884699ff5fYabin Cuistruct getnamaddr { 5158d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui struct hostent *hp; 5258d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui char *buf; 5358d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui size_t buflen; 5458d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui int *he; 5558d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui}; 5658d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui 5758d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui/* /etc/hosts lookup */ 5858d33a51f336d6823ef1ec915949a5884699ff5fYabin Cuiint _hf_gethtbyaddr(void *, void *, va_list); 5958d33a51f336d6823ef1ec915949a5884699ff5fYabin Cuiint _hf_gethtbyname(void *, void *, va_list); 6058d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui 6158d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui#ifdef YP 6258d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui/* NIS lookup */ 6358d33a51f336d6823ef1ec915949a5884699ff5fYabin Cuiint _yp_gethtbyaddr(void *, void *, va_list); 6458d33a51f336d6823ef1ec915949a5884699ff5fYabin Cuiint _yp_gethtbyname(void *, void *, va_list); 6558d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui#endif 6658d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui 6758d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui#define HENT_ARRAY(dst, anum, ptr, len) \ 6858d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui do { \ 6958d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui size_t _len = (anum + 1) * sizeof(*dst); \ 7058d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui if (_len > len) \ 7158d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui goto nospc; \ 7258d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui dst = (void *)ptr; \ 7358d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui ptr += _len; \ 7458d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui len -= _len; \ 7558d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui } while (/*CONSTCOND*/0) 7658d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui 7758d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui#define HENT_COPY(dst, src, slen, ptr, len) \ 7858d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui do { \ 7958d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui if ((size_t)slen > len) \ 8058d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui goto nospc; \ 8158d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui memcpy(ptr, src, (size_t)slen); \ 8258d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui dst = ptr; \ 8358d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui ptr += slen; \ 8458d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui len -= slen; \ 8558d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui } while (/* CONSTCOND */0) 8658d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui 8758d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui#define HENT_SCOPY(dst, src, ptr, len) \ 8858d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui do { \ 8958d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui size_t _len = strlen(src) + 1; \ 9058d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui HENT_COPY(dst, src, _len, ptr, len); \ 9158d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui } while (/* CONSTCOND */0) 9258d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui 9358d33a51f336d6823ef1ec915949a5884699ff5fYabin Cui#endif /* _DNS_NET_HOSTENT_H */ 94