new files

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@6470 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1999-07-18 23:11:24 +00:00
parent c57514b379
commit 10b5112be2
4 changed files with 340 additions and 0 deletions

107
lib/roken/copyhostent.c Normal file
View File

@@ -0,0 +1,107 @@
/*
* Copyright (c) 1999 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Kungliga Tekniska
* H<>gskolan and its contributors.
*
* 4. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
RCSID("$Id$");
#endif
#include "roken.h"
/*
* return a malloced copy of `h'
*/
struct hostent *
copyhostent (const struct hostent *h)
{
struct hostent *res;
char **p;
int i, n;
res = malloc (sizeof (*res));
if (res == NULL)
return NULL;
res->h_name = NULL;
res->h_aliases = NULL;
res->h_addrtype = h->h_addrtype;
res->h_length = h->h_length;
res->h_addr_list = NULL;
res->h_name = strdup (h->h_name);
if (res->h_name == NULL) {
freehostent (res);
return NULL;
}
for (n = 0, p = h->h_aliases; *p != NULL; ++p)
++n;
res->h_aliases = malloc ((n + 1) * sizeof(*res->h_aliases));
if (res->h_aliases == NULL) {
freehostent (res);
return NULL;
}
for (i = 0; i < n + 1; ++i)
res->h_aliases[i] = NULL;
for (i = 0; i < n; ++i) {
res->h_aliases[i] = strdup (h->h_aliases[i]);
if (res->h_aliases[i] == NULL) {
freehostent (res);
return NULL;
}
}
for (n = 0, p = h->h_addr_list; *p != NULL; ++p)
++n;
res->h_addr_list = malloc ((n + 1) * sizeof(*res->h_addr_list));
if (res->h_addr_list == NULL) {
freehostent (res);
return NULL;
}
for (i = 0; i < n + 1; ++i) {
res->h_addr_list[i] = NULL;
}
for (i = 0; i < n; ++i) {
res->h_addr_list[i] = malloc (h->h_length);
if (res->h_addr_list[i] == NULL) {
freehostent (res);
return NULL;
}
memcpy (res->h_addr_list[i], h->h_addr_list[i], h->h_length);
}
return res;
}

67
lib/roken/freehostent.c Normal file
View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 1999 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Kungliga Tekniska
* H<>gskolan and its contributors.
*
* 4. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
RCSID("$Id$");
#endif
#include "roken.h"
/*
* free a malloced hostent
*/
void
freehostent (struct hostent *h)
{
char **p;
free (h->h_name);
if (h->h_aliases != NULL) {
for (p = h->h_aliases; *p != NULL; ++p)
free (*p);
free (h->h_aliases);
}
if (h->h_addr_list != NULL) {
for (p = h->h_addr_list; *p != NULL; ++p)
free (*p);
free (h->h_addr_list);
}
free (h);
}

View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 1999 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Kungliga Tekniska
* H<>gskolan and its contributors.
*
* 4. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
RCSID("$Id$");
#endif
#include "roken.h"
/*
* lookup `src, len' (address family `af') in DNS and return a pointer
* to a malloced struct hostent or NULL.
*/
struct hostent *
getipnodebyaddr (const void *src, size_t len, int af, int *error_num)
{
struct hostent *tmp;
tmp = gethostbyaddr (src, len, af);
if (tmp == NULL) {
switch (h_errno) {
case HOST_NOT_FOUND :
case TRY_AGAIN :
case NO_RECOVERY :
*error_num = h_errno;
break;
case NO_DATA :
*error_num = NO_ADDRESS;
break;
default :
*error_num = NO_RECOVERY;
break;
}
return NULL;
}
tmp = copyhostent (tmp);
if (tmp == NULL) {
*error_num = TRY_AGAIN;
return NULL;
}
return tmp;
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright (c) 1999 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Kungliga Tekniska
* H<>gskolan and its contributors.
*
* 4. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
RCSID("$Id$");
#endif
#include "roken.h"
#ifndef HAVE_H_ERRNO
static int h_errno = NO_RECOVERY;
#endif
/*
* lookup `name' (address family `af') in DNS and return a pointer
* to a malloced struct hostent or NULL.
*/
struct hostent *
getipnodebyname (const char *name, int af, int flags, int *error_num)
{
struct hostent *tmp;
if (af != AF_INET) {
*error_num = NO_ADDRESS;
return NULL;
}
tmp = gethostbyname (name);
if (tmp == NULL) {
switch (h_errno) {
case HOST_NOT_FOUND :
case TRY_AGAIN :
case NO_RECOVERY :
*error_num = h_errno;
break;
case NO_DATA :
*error_num = NO_ADDRESS;
break;
default :
*error_num = NO_RECOVERY;
break;
}
return NULL;
}
tmp = copyhostent (tmp);
if (tmp == NULL) {
*error_num = TRY_AGAIN;
return NULL;
}
return tmp;
}