4
* Copyright 1988, 2001 by the Massachusetts Institute of Technology.
7
* Export of this software from the United States of America may
8
* require a specific license from the United States Government.
9
* It is the responsibility of any person or organization contemplating
10
* export to obtain such a license before exporting.
12
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13
* distribute this software and its documentation for any purpose and
14
* without fee is hereby granted, provided that the above copyright
15
* notice appear in all copies and that both that copyright notice and
16
* this permission notice appear in supporting documentation, and that
17
* the name of M.I.T. not be used in advertising or publicity pertaining
18
* to distribution of the software without specific, written prior
19
* permission. Furthermore if you modify this software you must label
20
* your software as modified software and not distribute it in such a
21
* fashion that it might be confused with the original M.I.T. software.
22
* M.I.T. makes no representations about the suitability of
23
* this software for any purpose. It is provided "as is" without express
24
* or implied warranty.
32
#include "port-sockets.h"
35
* This routine takes an alias for a host name and returns the first
36
* field, lower case, of its domain name. For example, if "menel" is
37
* an alias for host officially named "menelaus" (in /etc/hosts), for
38
* the host whose official name is "MENELAUS.MIT.EDU", the name "menelaus"
41
* This is done for historical Athena reasons: the Kerberos name of
42
* rcmd servers (rlogin, rsh, rcp) is of the form "rcmd.host@realm"
43
* where "host"is the lowercase for of the host name ("menelaus").
44
* This should go away: the instance should be the domain name
45
* (MENELAUS.MIT.EDU). But for now we need this routine...
47
* A pointer to the name is returned, if found, otherwise a pointer
48
* to the original "alias" argument is returned.
58
static char hostname_mem[MAXHOSTNAMELEN];
59
#ifdef DO_REVERSE_RESOLVE
60
char *rev_addr; int rev_type, rev_len;
63
if ((h=gethostbyname(alias)) != (struct hostent *)NULL ) {
64
#ifdef DO_REVERSE_RESOLVE
65
if (! h->h_addr_list ||! h->h_addr_list[0]) {
68
rev_type = h->h_addrtype;
69
rev_len = h->h_length;
70
rev_addr = malloc(rev_len);
71
_fmemcpy(rev_addr, h->h_addr_list[0], rev_len);
72
h = gethostbyaddr(rev_addr, rev_len, rev_type);
78
/* We don't want to return a *, so we copy to a safe location. */
79
strncpy (hostname_mem, h->h_name, sizeof (hostname_mem));
80
/* Bail out if h_name is too long. */
81
if (hostname_mem[MAXHOSTNAMELEN-1] != '\0')
83
p = strchr( hostname_mem, '.' );
86
ucp = (unsigned char *)hostname_mem;
88
if (isupper(*ucp)) *ucp=tolower(*ucp);