source: trunk/athena/bin/gms/get_servername.c @ 1484

Revision 1484, 1.6 KB checked in by eichin, 36 years ago (diff)
Initial revision
Line 
1/* This file is part of the Project Athena Global Message System.
2 * Created by: Mark W. Eichin <eichin@athena.mit.edu>
3 * $Source: /afs/dev.mit.edu/source/repository/athena/bin/gms/get_servername.c,v $
4 * $Author: eichin $
5 *
6 *      Copyright (c) 1988 by the Massachusetts Institute of Technology.
7 *      For copying and distribution information, see the file
8 *      "mit-copyright.h".
9 */
10#include <mit-copyright.h>
11#ifndef lint
12static char rcsid_get_servername_c[] = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/gms/get_servername.c,v 1.1 1988-09-26 15:39:47 eichin Exp $";
13#endif lint
14
15#include "globalmessage.h"
16#include <hesiod.h>
17
18Code_t get_servername(ret_name)
19     char ***ret_name;          /* pointer to array of string... */
20{
21  char **retval, **data;        /* for copying out the hesiod data */
22  int datacnt, i;               /* number of hesiod records returned */
23
24  /* Guard against NULL arguments */
25  if ((!ret_name)) {
26    return(GMS_NULL_ARG_ERR);
27  }
28 
29  /* Fetch the list of servers from Hesiod. */
30  data = hes_resolve(GMS_NAME_CLASS, GMS_NAME_TYPE);
31 
32  if(!data) {
33    /* deal with hesiod error */
34    return(hesiod_error());
35  }
36
37  /* Copy the Hesiod data into stable space. */
38  for(datacnt=0; data[datacnt++]; ); /* count the data */
39
40  retval = (char **)malloc(datacnt * sizeof(char *));
41  for(i=0; i<datacnt; i++) {
42    retval[i] = malloc(strlen(data[i])+1);
43    if(!retval[i]) {
44      /* malloc failed... */
45      for(;--i;free(retval[i]));
46      return(GMS_MALLOC_ERR);
47    }
48    strcpy(retval[i], data[i]);
49  }
50 
51  /* Clean up and return normally. */
52  *ret_name = retval;
53  return(0);
54}
Note: See TracBrowser for help on using the repository browser.