summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Tso <tytso@mit.edu>1996-01-05 03:24:36 +0000
committerTheodore Tso <tytso@mit.edu>1996-01-05 03:24:36 +0000
commit16648a322ab23889a45f1425200f5ba7868909e9 (patch)
tree99cbc2b0a3d8d8942eb96cc9afd4060f3af231f0
parentc64ae2fcabf9f2add6af92b9496da4a3dfce12f1 (diff)
downloadkrb5-16648a322ab23889a45f1425200f5ba7868909e9.tar.gz
krb5-16648a322ab23889a45f1425200f5ba7868909e9.tar.xz
krb5-16648a322ab23889a45f1425200f5ba7868909e9.zip
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
-rw-r--r--src/lib/krb5/os/ChangeLog7
-rw-r--r--src/lib/krb5/os/Makefile.in2
-rw-r--r--src/lib/krb5/os/hostaddr.c81
3 files changed, 90 insertions, 0 deletions
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 <tytso@dcl>
+
+ * 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 <tytso@dcl>
* 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 <netdb.h>
+
+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;
+
+}
+