diff options
author | John Kohl <jtkohl@mit.edu> | 1990-02-20 17:16:23 +0000 |
---|---|---|
committer | John Kohl <jtkohl@mit.edu> | 1990-02-20 17:16:23 +0000 |
commit | 163bec8ceecc8ef466d57c9b82396bfe01a6224e (patch) | |
tree | 8c879d14c147d730e7d9be363d00979ffe3e3008 /src/lib/krb5 | |
parent | 98a05c44513c59831c37aec3a78b42d6911331d6 (diff) | |
download | krb5-163bec8ceecc8ef466d57c9b82396bfe01a6224e.tar.gz krb5-163bec8ceecc8ef466d57c9b82396bfe01a6224e.tar.xz krb5-163bec8ceecc8ef466d57c9b82396bfe01a6224e.zip |
*** empty log message ***
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@365 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/krb5')
-rw-r--r-- | src/lib/krb5/os/locate_kdc.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/lib/krb5/os/locate_kdc.c b/src/lib/krb5/os/locate_kdc.c new file mode 100644 index 0000000000..42c061149c --- /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 + * <krb5/mit-copyright.h>. + * + * get socket addresses for KDC. + */ + +#if !defined(lint) && !defined(SABER) +static char rcsid_locate_kdc_c[] = +"$Id$"; +#endif /* !lint & !SABER */ + +#include <krb5/copyright.h> +#include <krb5/krb5.h> + +#include <krb5/ext-proto.h> + +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> + +#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; +} |