summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jeffrey Hutzelman <jhutz@cmu.edu>2013-01-05 15:32:42 -0500
committerGravatar Jeffrey Hutzelman <jhutz@cmu.edu>2013-02-17 22:34:40 -0500
commitcd4c5dd5f96259710532c4beba7361badbe644a6 (patch)
tree920086049ec9f848b8eb8fada3b0c342ea23ca13
parent49ff374f565b46d63678d1ea92eba436eacaa8cc (diff)
Abstract out realm server hostname lookup
The task of looking up a server's hostname is moved into a separate function, which will make things cleaner when we start doing so in more than one place.
-rw-r--r--server/realm.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/server/realm.c b/server/realm.c
index 60b2783..fe7b20b 100644
--- a/server/realm.c
+++ b/server/realm.c
@@ -82,6 +82,22 @@ is_usable(ZRealm_server *srvr)
return srvr->got_addr;
}
+static void
+rlm_lookup_server_address(ZRealm_server *srvr)
+{
+ struct hostent *hp;
+
+ hp = gethostbyname(srvr->name->string);
+ if (hp) {
+ memmove(&srvr->addr.sin_addr, hp->h_addr, sizeof(struct in_addr));
+ /* use the server port */
+ srvr->addr.sin_port = srv_addr.sin_port;
+ srvr->addr.sin_family = AF_INET;
+ srvr->got_addr = 1;
+ } else
+ syslog(LOG_WARNING, "hostname failed, %s", srvr->name->string);
+}
+
static int
realm_get_idx_by_addr(ZRealm *realm,
struct sockaddr_in *who)
@@ -522,7 +538,6 @@ realm_init(void)
ZRealmname *rlmnames;
ZRealm *rlm;
int ii, jj, nrlmnames;
- struct hostent *hp;
char realm_list_file[128];
char rlmprinc[MAX_PRINCIPAL_SIZE];
@@ -584,18 +599,8 @@ realm_init(void)
/* convert names to addresses */
rlm->count = rlmnames[ii].nused;
rlm->srvrs = rlmnames[ii].servers;
- for (srvr = rlm->srvrs, jj = 0; jj < rlm->count; jj++, srvr++) {
- hp = gethostbyname(srvr->name->string);
- if (hp) {
- memmove(&srvr->addr.sin_addr, hp->h_addr,
- sizeof(struct in_addr));
- /* use the server port */
- srvr->addr.sin_port = srv_addr.sin_port;
- srvr->addr.sin_family = AF_INET;
- srvr->got_addr = 1;
- } else
- syslog(LOG_WARNING, "hostname failed, %s", srvr->name->string);
- }
+ for (srvr = rlm->srvrs, jj = 0; jj < rlm->count; jj++, srvr++)
+ rlm_lookup_server_address(srvr);
client = (Client *) malloc(sizeof(Client));
if (!client) {