14ecbd6dmarkm/*
233f661cstas * Copyright (c) 1999 Kungliga Tekniska H��gskolan
34ecbd6dmarkm * (Royal Institute of Technology, Stockholm, Sweden).
44ecbd6dmarkm * All rights reserved.
533f661cstas *
64ecbd6dmarkm * Redistribution and use in source and binary forms, with or without
74ecbd6dmarkm * modification, are permitted provided that the following conditions
84ecbd6dmarkm * are met:
933f661cstas *
104ecbd6dmarkm * 1. Redistributions of source code must retain the above copyright
114ecbd6dmarkm *    notice, this list of conditions and the following disclaimer.
1233f661cstas *
134ecbd6dmarkm * 2. Redistributions in binary form must reproduce the above copyright
144ecbd6dmarkm *    notice, this list of conditions and the following disclaimer in the
154ecbd6dmarkm *    documentation and/or other materials provided with the distribution.
1633f661cstas *
174ecbd6dmarkm * 3. Neither the name of the Institute nor the names of its contributors
184ecbd6dmarkm *    may be used to endorse or promote products derived from this software
194ecbd6dmarkm *    without specific prior written permission.
2033f661cstas *
214ecbd6dmarkm * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
224ecbd6dmarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
234ecbd6dmarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
244ecbd6dmarkm * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
254ecbd6dmarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
264ecbd6dmarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
274ecbd6dmarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
284ecbd6dmarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
294ecbd6dmarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
304ecbd6dmarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
314ecbd6dmarkm * SUCH DAMAGE.
324ecbd6dmarkm */
334ecbd6dmarkm
344ecbd6dmarkm#include <config.h>
354ecbd6dmarkm
364ecbd6dmarkm#include "roken.h"
374ecbd6dmarkm
384ecbd6dmarkm#ifndef HAVE_H_ERRNO
394ecbd6dmarkmstatic int h_errno = NO_RECOVERY;
404ecbd6dmarkm#endif
414ecbd6dmarkm
424ecbd6dmarkm/*
434ecbd6dmarkm * lookup `name' (address family `af') in DNS and return a pointer
444ecbd6dmarkm * to a malloced struct hostent or NULL.
454ecbd6dmarkm */
464ecbd6dmarkm
4733f661cstasROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
484ecbd6dmarkmgetipnodebyname (const char *name, int af, int flags, int *error_num)
494ecbd6dmarkm{
504ecbd6dmarkm    struct hostent *tmp;
514ecbd6dmarkm
524ecbd6dmarkm#ifdef HAVE_GETHOSTBYNAME2
534ecbd6dmarkm    tmp = gethostbyname2 (name, af);
544ecbd6dmarkm#else
554ecbd6dmarkm    if (af != AF_INET) {
564ecbd6dmarkm	*error_num = NO_ADDRESS;
574ecbd6dmarkm	return NULL;
584ecbd6dmarkm    }
594ecbd6dmarkm    tmp = gethostbyname (name);
604ecbd6dmarkm#endif
614ecbd6dmarkm    if (tmp == NULL) {
624ecbd6dmarkm	switch (h_errno) {
634ecbd6dmarkm	case HOST_NOT_FOUND :
644ecbd6dmarkm	case TRY_AGAIN :
654ecbd6dmarkm	case NO_RECOVERY :
664ecbd6dmarkm	    *error_num = h_errno;
674ecbd6dmarkm	    break;
684ecbd6dmarkm	case NO_DATA :
694ecbd6dmarkm	    *error_num = NO_ADDRESS;
704ecbd6dmarkm	    break;
714ecbd6dmarkm	default :
724ecbd6dmarkm	    *error_num = NO_RECOVERY;
734ecbd6dmarkm	    break;
744ecbd6dmarkm	}
754ecbd6dmarkm	return NULL;
764ecbd6dmarkm    }
774ecbd6dmarkm    tmp = copyhostent (tmp);
784ecbd6dmarkm    if (tmp == NULL) {
794ecbd6dmarkm	*error_num = TRY_AGAIN;
804ecbd6dmarkm	return NULL;
814ecbd6dmarkm    }
824ecbd6dmarkm    return tmp;
834ecbd6dmarkm}
84