/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* return the address of a host given its name
*/
#include "cslib.h"
union nl
{
unsigned char c[4];
uint32_t l;
};
static unsigned long local;
/*
* real name to address conversion
*/
static unsigned long
{
register int n;
register const char* s;
int r;
const char* t;
#if CS_LIB_SOCKET
#endif
s = name;
if (streq(s, CS_HOST_LOCAL))
{
messagef((state->id, NiL, -8, "realaddr(%s) = %s, flags = |%s%s%s", name, csntoa(state, local), (state->flags & CS_ADDR_LOCAL) ? "LOCAL|" : "", (state->flags & CS_ADDR_REMOTE) ? "REMOTE|" : "", (state->flags & CS_ADDR_SHARE) ? "SHARE|" : ""));
return local;
}
/*
* check for 0xX.X.X.X or n.n.n.n
*/
if (*s == '0' && *(s + 1) == 'x')
{
s += 2;
r = 16;
}
else r = 0;
addr.l = 0;
n = 0;
do
{
if (t == s) break;
s = t;
} while (++n < 4 && *s && *s++ == '.');
if (!*s && n == 4)
{
{
{
addr.c[0] = 127;
addr.c[1] = 0;
addr.c[2] = 0;
}
else
}
messagef((state->id, NiL, -8, "realaddr(%s) = %s, flags = |%s%s%s", name, csntoa(state, addr.l), (state->flags & CS_ADDR_LOCAL) ? "LOCAL|" : "", (state->flags & CS_ADDR_REMOTE) ? "REMOTE|" : "", (state->flags & CS_ADDR_SHARE) ? "SHARE|" : ""));
return addr.l;
}
/*
* local conversion
*/
#if CS_LIB_V10 || CS_LIB_SOCKET
#if CS_LIB_V10
addr.l = 0;
#else
addr.l = ((hp = gethostbyname(name)) && hp->h_addrtype == AF_INET && hp->h_length <= sizeof(struct in_addr)) ? (unsigned long)((struct in_addr*)hp->h_addr)->s_addr : 0;
#endif
{
else
}
messagef((state->id, NiL, -8, "realaddr(%s) = %s, flags = |%s%s%s", name, csntoa(state, addr.l), (state->flags & CS_ADDR_LOCAL) ? "LOCAL|" : "", (state->flags & CS_ADDR_REMOTE) ? "REMOTE|" : "", (state->flags & CS_ADDR_SHARE) ? "SHARE|" : ""));
#else
addr.l = 0;
#endif
return addr.l;
}
/*
* address conversion with CS_HOST_* aliases
* 0 returned on failure
* on success:
*
* state->flags CS_ADDR_* changed to match real host name
* state->host real host name after aliases and local truncation
*/
unsigned long
{
register char* s;
register unsigned long addr;
int userlen = 0;
int dot = 0;
long flags = 0;
char* user;
if (!local)
{
#if CS_LIB_SOCKET
#endif
}
if (!name)
{
goto ok;
}
{
name = s + 1;
}
{
case 0:
flags |= CS_ADDR_SHARE;
{
goto ok;
sp = 0;
}
goto ok;
case '.':
flags |= CS_ADDR_SHARE;
name += sizeof(CS_HOST_SHARE);
break;
}
goto ok;
{
char* sb;
char* se;
char* sx;
char* t;
char* te;
sb = s;
se = 0;
t = name;
while (*t && s < sx)
{
if (s - sb >= CS_MNT_MAX)
{
if (se)
{
s = se - 1;
t = te;
}
else
{
if (s >= sx) break;
if (*t == '.') t++;
}
*s++ = '/';
sb = s;
se = 0;
}
if ((*s++ = *t++) == '.')
{
se = s;
te = t;
}
}
*s = 0;
{
{
if (s = strchr(t, '@')) s++;
else s = t;
{
name = s;
if (!userlen && s != t)
{
userlen = s - t - 1;
user = t;
}
goto ok;
}
}
sp = 0;
}
{
goto ok;
}
{
goto ok;
}
}
return 0;
ok:
flags &= ~CS_ADDR_SHARE;
{
flags |= CS_ADDR_LOCAL;
}
{
{
else flags |= CS_ADDR_REMOTE;
}
flags |= CS_ADDR_REMOTE;
}
/*
* cache host name and user for possible CS_REMOTE_SHELL
*/
if (userlen)
{
}
state->flags &= ~(CS_ADDR_LOCAL|CS_ADDR_NOW|CS_ADDR_REMOTE|CS_ADDR_SHARE|CS_DAEMON_SLAVE|CS_ADDR_TEST|CS_ADDR_TRUST);
messagef((state->id, NiL, -8, "addr(%s) = %s, flags = |%s%s%s", aname, csntoa(state, addr), (state->flags & CS_ADDR_LOCAL) ? "LOCAL|" : "", (state->flags & CS_ADDR_REMOTE) ? "REMOTE|" : "", (state->flags & CS_ADDR_SHARE) ? "SHARE|" : ""));
return addr;
}
unsigned long
{
}