From 16648a322ab23889a45f1425200f5ba7868909e9 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Fri, 5 Jan 1996 03:24:36 +0000 Subject: [PATCH] hostaddr.c (krb5_os_hostaddr): New function which takes a hostname and returns a list of krb5 addresses. (This is basically a glue routine that converts the result of gethostbyname() to krb5 addresses.) git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@7277 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/ChangeLog | 7 ++++ src/lib/krb5/os/Makefile.in | 2 + src/lib/krb5/os/hostaddr.c | 81 +++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/lib/krb5/os/hostaddr.c diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 8c3d5edcb..944826140 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,10 @@ +Thu Jan 4 22:23:04 1996 Theodore Y. Ts'o + + * hostaddr.c (krb5_os_hostaddr): New function which takes a + hostname and returns a list of krb5 addresses. (This is + basically a glue routine that converts the result of + gethostbyname() to krb5 addresses.) + Thu Dec 21 17:51:58 1995 Theodore Y. Ts'o * Makefile.in (t_an_to_ln): Use $(LD) instead of $(CC) to link diff --git a/src/lib/krb5/os/Makefile.in b/src/lib/krb5/os/Makefile.in index 9e1d67485..946430686 100644 --- a/src/lib/krb5/os/Makefile.in +++ b/src/lib/krb5/os/Makefile.in @@ -22,6 +22,7 @@ OBJS= \ genaddrs.$(OBJEXT) \ gen_rname.$(OBJEXT) \ gmt_mktime.$(OBJEXT) \ + hostaddr.$(OBJEXT) \ hst_realm.$(OBJEXT) \ init_os_ctx.$(OBJEXT) \ krbfileio.$(OBJEXT) \ @@ -61,6 +62,7 @@ SRCS= \ $(srcdir)/genaddrs.c \ $(srcdir)/gen_rname.c \ $(srcdir)/gmt_mktime.c \ + $(srcdir)/hostaddr.c \ $(srcdir)/hst_realm.c \ $(srcdir)/init_os_ctx.c \ $(srcdir)/krbfileio.c \ diff --git a/src/lib/krb5/os/hostaddr.c b/src/lib/krb5/os/hostaddr.c new file mode 100644 index 000000000..56833a098 --- /dev/null +++ b/src/lib/krb5/os/hostaddr.c @@ -0,0 +1,81 @@ +/* + * lib/krb5/os/hostaddr.c + * + * Copyright 1990,1991 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * This routine returns a list of krb5 addresses given a hostname. + * + */ + +#include "k5-int.h" + +#include + +krb5_error_code +krb5_os_hostaddr(context, name, ret_addrs) + krb5_context context; + const char *name; + krb5_address ***ret_addrs; +{ + krb5_error_code retval; + struct hostent *hp; + krb5_address **addrs; + int i; + + if (!name || !(hp = gethostbyname(name))) + return KRB5_ERR_BAD_HOSTNAME; + + /* Count elements */ + for(i=0; hp->h_addr_list[i]; i++); + + addrs = (krb5_address **) malloc ((i+1)*sizeof(*addrs)); + if (!addrs) + return ENOMEM; + + memset(addrs, 0, (i+1)*sizeof(*addrs)); + + for(i=0; hp->h_addr_list[i]; i++) { + addrs[i] = (krb5_address *) malloc(sizeof(krb5_address)); + if (!addrs[i]) { + retval = ENOMEM; + goto errout; + } + addrs[i]->addrtype = hp->h_addrtype; + addrs[i]->length = hp->h_length; + addrs[i]->contents = (unsigned char *)malloc(addrs[i]->length); + if (!addrs[i]->contents) { + retval = ENOMEM; + goto errout; + } + memcpy ((char *)addrs[i]->contents, hp->h_addr_list[i], + addrs[i]->length); + } + addrs[i] = 0; + + *ret_addrs = addrs; + return 0; + +errout: + if (addrs) + krb5_free_addresses(context, addrs); + return retval; + +} + -- 2.26.2