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

Revision 3213, 1.7 KB checked in by probe, 34 years ago (diff)
changes.71#248 PMAX port
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: probe $
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.2 1990-07-11 14:50:12 probe Exp $";
13#endif lint
14
15#include "globalmessage.h"
16#include <hesiod.h>
17#include "hesiod_err.h"
18
19Code_t get_servername(ret_name)
20     char ***ret_name;          /* pointer to array of string... */
21{
22  char **retval, **_data;       /* for copying out the hesiod data */
23  int datacnt, i;               /* number of hesiod records returned */
24
25  /* Guard against NULL arguments */
26  if ((!ret_name)) {
27    return(GMS_NULL_ARG_ERR);
28  }
29 
30  /* Fetch the list of servers from Hesiod. */
31  _data = hes_resolve(GMS_NAME_CLASS, GMS_NAME_TYPE);
32 
33  if(!_data) {
34    /* deal with hesiod error */
35    return(hesiod_error());
36  }
37
38  /* Copy the Hesiod data into stable space. */
39  for(datacnt=0; _data[datacnt]; datacnt++); /* count the data */
40
41  if (!datacnt) {
42      /* an answer, but no contents! */
43      return(HESIOD_ER_INVALID);        /* XXX */
44  }
45  retval = (char **)malloc(datacnt * sizeof(char *));
46  for(i=0; i<datacnt; i++) {
47    retval[i] = malloc(strlen(_data[i])+1);
48    if(!retval[i]) {
49      /* malloc failed... */
50      for(;--i;free(retval[i]));
51      return(GMS_MALLOC_ERR);
52    }
53    strcpy(retval[i], _data[i]);
54  }
55 
56  /* Clean up and return normally. */
57  *ret_name = retval;
58  return(0);
59}
Note: See TracBrowser for help on using the repository browser.