From 163bec8ceecc8ef466d57c9b82396bfe01a6224e Mon Sep 17 00:00:00 2001 From: John Kohl Date: Tue, 20 Feb 1990 17:16:23 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@365 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/locate_kdc.c | 96 ++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/lib/krb5/os/locate_kdc.c diff --git a/src/lib/krb5/os/locate_kdc.c b/src/lib/krb5/os/locate_kdc.c new file mode 100644 index 000000000..42c061149 --- /dev/null +++ b/src/lib/krb5/os/locate_kdc.c @@ -0,0 +1,96 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * get socket addresses for KDC. + */ + +#if !defined(lint) && !defined(SABER) +static char rcsid_locate_kdc_c[] = +"$Id$"; +#endif /* !lint & !SABER */ + +#include +#include + +#include + +#include +#include +#include +#include + +#define KRB5_UDP_PORT 8973 /* XXX */ + +/* + * returns count of number of addresses found + */ + +int krb5_locate_kdc(realm, addr_pp) + krb5_data *realm; + struct sockaddr **addr_pp; +{ + char **hostlist; + int code; + int i, j, out, count; + struct sockaddr *addr_p; + struct sockaddr_in *sin_p; + struct hostent *hp; + + hostlist = 0; + + code = krb5_get_krbhst (realm, &hostlist); + if (code != 0) + return 0; /* XXX losing error code */ + + for (i=0; hostlist[i]; i++) + ; + count = i; + + if (count == 0) + return 0; + + addr_p = (struct sockaddr *)malloc (sizeof (struct sockaddr) * count); + + for (i=0, out=0; hostlist[i]; i++) { + hp = gethostbyname(hostlist[i]); + if (hp != 0) { + switch (hp->h_addrtype) { + case AF_INET: + for (j=0; hp->h_addr_list[j]; j++) { + sin_p = (struct sockaddr_in *) &addr_p[out++]; + memset ((char *)sin_p, sizeof(struct sockaddr), 0); + sin_p->sin_family = hp->h_addrtype; + sin_p->sin_port = KRB5_UDP_PORT; + memcpy((char *)&sin_p->sin_addr, + (char *)hp->h_addr_list[j], + sizeof(struct in_addr)); + if (out >= count) { + count *= 2; + addr_p = (struct sockaddr *) + realloc ((char *)addr_p, + sizeof(struct sockaddr) * count); + } + } + break; + default: + break; + } + } + free(hostlist[i]); + hostlist[i] = 0; + } + free ((char *)hostlist); + /* + * XXX need to distinguish between + * "can't resolve KDC name" and + * "can't find any KDC names" + */ + *addr_pp = addr_p; + return out; +} -- 2.26.2