mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-12 14:20:13 +00:00
aeb25823d8
2002-06-05 Brian Youmans <3diff@gnu.org> * sysdeps/ia64/fpu/e_acos.S: Added text of Intel license. * sysdeps/ia64/fpu/e_acosf.S: Likewise. * sysdeps/ia64/fpu/e_acosl.S: Likewise. * sysdeps/ia64/fpu/e_asin.S: Likewise. * sysdeps/ia64/fpu/e_asinf.S: Likewise. * sysdeps/ia64/fpu/e_asinl.S: Likewise. * sysdeps/ia64/fpu/e_atan2.S: Likewise. * sysdeps/ia64/fpu/e_atan2f.S: Likewise. * sysdeps/ia64/fpu/e_cosh.S: Likewise. * sysdeps/ia64/fpu/e_coshf.S: Likewise. * sysdeps/ia64/fpu/e_coshl.S: Likewise. * sysdeps/ia64/fpu/e_exp.S: Likewise. * sysdeps/ia64/fpu/e_expf.S: Likewise. * sysdeps/ia64/fpu/e_fmod.S: Likewise. * sysdeps/ia64/fpu/e_fmodf.S: Likewise. * sysdeps/ia64/fpu/e_fmodl.S: Likewise. * sysdeps/ia64/fpu/e_hypot.S: Likewise. * sysdeps/ia64/fpu/e_hypotf.S: Likewise. * sysdeps/ia64/fpu/e_hypotl.S: Likewise. * sysdeps/ia64/fpu/e_log.S: Likewise. * sysdeps/ia64/fpu/e_logf.S: Likewise. * sysdeps/ia64/fpu/e_pow.S: Likewise. * sysdeps/ia64/fpu/e_powf.S: Likewise. * sysdeps/ia64/fpu/e_powl.S: Likewise. * sysdeps/ia64/fpu/e_remainder.S: Likewise. * sysdeps/ia64/fpu/e_remainderf.S: Likewise. * sysdeps/ia64/fpu/e_remainderl.S: Likewise. * sysdeps/ia64/fpu/e_scalb.S: Likewise. * sysdeps/ia64/fpu/e_scalbf.S: Likewise. * sysdeps/ia64/fpu/e_scalbl.S: Likewise. * sysdeps/ia64/fpu/e_sinh.S: Likewise. * sysdeps/ia64/fpu/e_sinhf.S: Likewise. * sysdeps/ia64/fpu/e_sinhl.S: Likewise. * sysdeps/ia64/fpu/e_sqrt.S: Likewise. * sysdeps/ia64/fpu/e_sqrtf.S: Likewise. * sysdeps/ia64/fpu/e_sqrtl.S: Likewise. * sysdeps/ia64/fpu/libm_atan2_req.S: Likewise. * sysdeps/ia64/fpu/libm_error.c: Likewise. * sysdeps/ia64/fpu/libm_frexp4.S: Likewise. * sysdeps/ia64/fpu/libm_frexp4f.S: Likewise. * sysdeps/ia64/fpu/s_frexpl.c: Likewise. * sysdeps/ia64/fpu/s_ilogb.S: Likewise. * sysdeps/ia64/fpu/s_ilogbf.S: Likewise. * sysdeps/ia64/fpu/s_ilogbl.S: Likewise. * sysdeps/ia64/fpu/s_ldexp.S: Likewise. * sysdeps/ia64/fpu/s_ldexpf.S: Likewise. * sysdeps/ia64/fpu/s_ldexpl.S: Likewise. * sysdeps/ia64/fpu/s_log1p.S: Likewise. * sysdeps/ia64/fpu/s_log1pf.S: Likewise. * sysdeps/ia64/fpu/s_log1pl.S: Likewise. * sysdeps/ia64/fpu/s_logb.S: Likewise. * sysdeps/ia64/fpu/s_logbf.S: Likewise. * sysdeps/ia64/fpu/s_logbl.S: Likewise. * sysdeps/ia64/fpu/s_modf.S: Likewise. * sysdeps/ia64/fpu/s_modff.S: Likewise. * sysdeps/ia64/fpu/s_modfl.S: Likewise. * sysdeps/ia64/fpu/s_nearbyint.S: Likewise. * sysdeps/ia64/fpu/s_nearbyintf.S: Likewise. * sysdeps/ia64/fpu/s_nearbyintl.S: Likewise. * sysdeps/ia64/fpu/s_rint.S: Likewise. * sysdeps/ia64/fpu/s_rintf.S: Likewise. * sysdeps/ia64/fpu/s_rintl.S: Likewise. * sysdeps/ia64/fpu/s_round.S: Likewise. * sysdeps/ia64/fpu/s_roundf.S: Likewise. * sysdeps/ia64/fpu/s_roundl.S: Likewise. * sysdeps/ia64/fpu/s_scalbn.S: Likewise. * sysdeps/ia64/fpu/s_scalbnf.S: Likewise. * sysdeps/ia64/fpu/s_scalbnl.S: Likewise. * sysdeps/ia64/fpu/s_significand.S: Likewise. * sysdeps/ia64/fpu/s_significandf.S: Likewise. * sysdeps/ia64/fpu/s_significandl.S: Likewise. * sysdeps/ia64/fpu/s_tan.S: Likewise. * sysdeps/ia64/fpu/s_tanf.S: Likewise. * sysdeps/ia64/fpu/s_tanl.S: Likewise. * sysdeps/ia64/fpu/s_trunc.S: Likewise. * sysdeps/ia64/fpu/s_truncf.S: Likewise. * sysdeps/ia64/fpu/s_truncl.S: Likewise. * sysdeps/ieee754/dbl-64/doasin.c: Changed copyright notice to reflect IBM donation of math library to FSF * sysdeps/ieee754/dbl-64/dosincos.c: Likewise. * sysdeps/ieee754/dbl-64/e_asin.c: Likewise. * sysdeps/ieee754/dbl-64/e_atan2.c: Likewise. * sysdeps/ieee754/dbl-64/e_exp.c: Likewise. * sysdeps/ieee754/dbl-64/e_log.c: Likewise. * sysdeps/ieee754/dbl-64/e_pow.c: Likewise. * sysdeps/ieee754/dbl-64/e_remainder.c: Likewise. * sysdeps/ieee754/dbl-64/e_sqrt.c: Likewise. * sysdeps/ieee754/dbl-64/halfulp.c: Likewise. * sysdeps/ieee754/dbl-64/mpa.c: Likewise. * sysdeps/ieee754/dbl-64/mpatan.c: Likewise. * sysdeps/ieee754/dbl-64/mpatan2.c: Likewise. * sysdeps/ieee754/dbl-64/mpexp.c: Likewise. * sysdeps/ieee754/dbl-64/mplog.c: Likewise. * sysdeps/ieee754/dbl-64/mpsqrt.c: Likewise. * sysdeps/ieee754/dbl-64/mptan.c: Likewise. * sysdeps/ieee754/dbl-64/s_atan.c: Likewise. * sysdeps/ieee754/dbl-64/s_sin.c: Likewise. * sysdeps/ieee754/dbl-64/s_tan.c: Likewise. * sysdeps/ieee754/dbl-64/sincos32.c: Likewise. * sysdeps/ieee754/dbl-64/slowexp.c: Likewise. * sysdeps/ieee754/dbl-64/slowpow.c: Likewise. * sysdeps/gnu/netinet/udp.h: Added BSD copying permission notice * sysdeps/vax/__longjmp.c: Likewise. * sysdeps/vax/setjmp.c: Likewise. * libio/filedoalloc.c: Fixed BSD copying permission notice to remove advertising clause * sysdeps/vax/htonl.s: Likewise. * sysdeps/vax/htons.s: Likewise. * libio/wfiledoalloc.c: Likewise. * stdlib/random.c: Likewise. * stdlib/random_r.c: Likewise. * sysdeps/mach/sys/reboot.h: Likewise. * inet/getnameinfo.c: Deleted advertising clause from Inner Net License * sysdeps/posix/getaddrinfo.c: Likewise. * sunrpc/des_impl.c: Updated license permission notice to Lesser GPL and corrected pointer to point to the correct license.
424 lines
9.8 KiB
C
424 lines
9.8 KiB
C
/* The Inner Net License, Version 2.00
|
|
|
|
The author(s) grant permission for redistribution and use in source and
|
|
binary forms, with or without modification, of the software and documentation
|
|
provided that the following conditions are met:
|
|
|
|
0. If you receive a version of the software that is specifically labelled
|
|
as not being for redistribution (check the version message and/or README),
|
|
you are not permitted to redistribute that version of the software in any
|
|
way or form.
|
|
1. All terms of the all other applicable copyrights and licenses must be
|
|
followed.
|
|
2. Redistributions of source code must retain the authors' copyright
|
|
notice(s), this list of conditions, and the following disclaimer.
|
|
3. Redistributions in binary form must reproduce the authors' copyright
|
|
notice(s), this list of conditions, and the following disclaimer in the
|
|
documentation and/or other materials provided with the distribution.
|
|
4. [The copyright holder has authorized the removal of this clause.]
|
|
5. Neither the name(s) of the author(s) nor the names of its contributors
|
|
may be used to endorse or promote products derived from this software
|
|
without specific prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY ITS AUTHORS AND CONTRIBUTORS ``AS IS'' AND ANY
|
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
If these license terms cause you a real problem, contact the author. */
|
|
|
|
/* This software is Copyright 1996 by Craig Metz, All Rights Reserved. */
|
|
|
|
#include <alloca.h>
|
|
#include <errno.h>
|
|
#include <netdb.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <arpa/inet.h>
|
|
#include <net/if.h>
|
|
#include <netinet/in.h>
|
|
#include <sys/param.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/types.h>
|
|
#include <sys/un.h>
|
|
#include <sys/utsname.h>
|
|
#include <bits/libc-lock.h>
|
|
|
|
#ifndef min
|
|
# define min(x,y) (((x) > (y)) ? (y) : (x))
|
|
#endif /* min */
|
|
|
|
|
|
static char *
|
|
internal_function
|
|
nrl_domainname (void)
|
|
{
|
|
static char *domain;
|
|
static int not_first;
|
|
|
|
if (! not_first)
|
|
{
|
|
__libc_lock_define_initialized (static, lock);
|
|
__libc_lock_lock (lock);
|
|
|
|
if (! not_first)
|
|
{
|
|
char *c;
|
|
struct hostent *h, th;
|
|
size_t tmpbuflen = 1024;
|
|
char *tmpbuf = alloca (tmpbuflen);
|
|
int herror;
|
|
|
|
not_first = 1;
|
|
|
|
while (__gethostbyname_r ("localhost", &th, tmpbuf, tmpbuflen, &h,
|
|
&herror))
|
|
{
|
|
if (herror == NETDB_INTERNAL && errno == ERANGE)
|
|
{
|
|
tmpbuflen *= 2;
|
|
tmpbuf = alloca (tmpbuflen);
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
|
|
if (h && (c = strchr (h->h_name, '.')))
|
|
domain = __strdup (++c);
|
|
else
|
|
{
|
|
/* The name contains no domain information. Use the name
|
|
now to get more information. */
|
|
while (__gethostname (tmpbuf, tmpbuflen))
|
|
{
|
|
tmpbuflen *= 2;
|
|
tmpbuf = alloca (tmpbuflen);
|
|
}
|
|
|
|
if ((c = strchr (tmpbuf, '.')))
|
|
domain = __strdup (++c);
|
|
else
|
|
{
|
|
/* We need to preserve the hostname. */
|
|
const char *hstname = strdupa (tmpbuf);
|
|
|
|
while (__gethostbyname_r (hstname, &th, tmpbuf, tmpbuflen,
|
|
&h, &herror))
|
|
{
|
|
if (herror == NETDB_INTERNAL && errno == ERANGE)
|
|
{
|
|
tmpbuflen *= 2;
|
|
tmpbuf = alloca (tmpbuflen);
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
|
|
if (h && (c = strchr(h->h_name, '.')))
|
|
domain = __strdup (++c);
|
|
else
|
|
{
|
|
struct in_addr in_addr;
|
|
|
|
in_addr.s_addr = htonl (INADDR_LOOPBACK);
|
|
|
|
while (__gethostbyaddr_r ((const char *) &in_addr,
|
|
sizeof (struct in_addr),
|
|
AF_INET, &th, tmpbuf,
|
|
tmpbuflen, &h, &herror))
|
|
{
|
|
if (herror == NETDB_INTERNAL && errno == ERANGE)
|
|
{
|
|
tmpbuflen *= 2;
|
|
tmpbuf = alloca (tmpbuflen);
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
|
|
if (h && (c = strchr (h->h_name, '.')))
|
|
domain = __strdup (++c);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
__libc_lock_unlock (lock);
|
|
}
|
|
|
|
return domain;
|
|
};
|
|
|
|
|
|
int
|
|
getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
|
|
socklen_t hostlen, char *serv, socklen_t servlen,
|
|
unsigned int flags)
|
|
{
|
|
int serrno = errno;
|
|
int tmpbuflen = 1024;
|
|
int herrno;
|
|
char *tmpbuf = alloca (tmpbuflen);
|
|
struct hostent th;
|
|
int ok = 0;
|
|
|
|
if (flags & ~(NI_NUMERICHOST|NI_NUMERICSERV|NI_NOFQDN|NI_NAMEREQD|NI_DGRAM))
|
|
return EAI_BADFLAGS;
|
|
|
|
if (sa == NULL || addrlen < sizeof (sa_family_t))
|
|
return EAI_FAMILY;
|
|
|
|
switch (sa->sa_family)
|
|
{
|
|
case AF_LOCAL:
|
|
if (addrlen < (socklen_t) (((struct sockaddr_un *) NULL)->sun_path))
|
|
return EAI_FAMILY;
|
|
break;
|
|
case AF_INET:
|
|
if (addrlen < sizeof (struct sockaddr_in))
|
|
return EAI_FAMILY;
|
|
break;
|
|
case AF_INET6:
|
|
if (addrlen < sizeof (struct sockaddr_in6))
|
|
return EAI_FAMILY;
|
|
break;
|
|
default:
|
|
return EAI_FAMILY;
|
|
}
|
|
|
|
if (host != NULL && hostlen > 0)
|
|
switch (sa->sa_family)
|
|
{
|
|
case AF_INET:
|
|
case AF_INET6:
|
|
if (!(flags & NI_NUMERICHOST))
|
|
{
|
|
struct hostent *h = NULL;
|
|
if (h == NULL)
|
|
{
|
|
if (sa->sa_family == AF_INET6)
|
|
{
|
|
while (__gethostbyaddr_r ((const void *) &(((const struct sockaddr_in6 *) sa)->sin6_addr),
|
|
sizeof(struct in6_addr),
|
|
AF_INET6, &th, tmpbuf, tmpbuflen,
|
|
&h, &herrno))
|
|
{
|
|
if (herrno == NETDB_INTERNAL)
|
|
{
|
|
if (errno == ERANGE)
|
|
{
|
|
tmpbuflen *= 2;
|
|
tmpbuf = alloca (tmpbuflen);
|
|
}
|
|
else
|
|
{
|
|
__set_h_errno (herrno);
|
|
__set_errno (serrno);
|
|
return EAI_SYSTEM;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
while (__gethostbyaddr_r ((const void *) &(((const struct sockaddr_in *)sa)->sin_addr),
|
|
sizeof(struct in_addr), AF_INET,
|
|
&th, tmpbuf, tmpbuflen,
|
|
&h, &herrno))
|
|
{
|
|
if (errno == ERANGE)
|
|
{
|
|
tmpbuflen *= 2;
|
|
tmpbuf = alloca (tmpbuflen);
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (h)
|
|
{
|
|
char *c;
|
|
if ((flags & NI_NOFQDN)
|
|
&& (c = nrl_domainname ())
|
|
&& (c = strstr (h->h_name, c))
|
|
&& (c != h->h_name) && (*(--c) == '.'))
|
|
{
|
|
strncpy (host, h->h_name,
|
|
min(hostlen, (size_t) (c - h->h_name)));
|
|
host[min(hostlen - 1, (size_t) (c - h->h_name))]
|
|
= '\0';
|
|
ok = 1;
|
|
}
|
|
else
|
|
{
|
|
strncpy (host, h->h_name, hostlen);
|
|
ok = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!ok)
|
|
{
|
|
if (flags & NI_NAMEREQD)
|
|
{
|
|
__set_errno (serrno);
|
|
return EAI_NONAME;
|
|
}
|
|
else
|
|
{
|
|
const char *c;
|
|
if (sa->sa_family == AF_INET6)
|
|
{
|
|
const struct sockaddr_in6 *sin6p;
|
|
uint32_t scopeid;
|
|
|
|
sin6p = (const struct sockaddr_in6 *) sa;
|
|
|
|
c = inet_ntop (AF_INET6,
|
|
(const void *) &sin6p->sin6_addr, host, hostlen);
|
|
scopeid = sin6p->sin6_scope_id;
|
|
if (scopeid != 0)
|
|
{
|
|
/* Buffer is >= IFNAMSIZ+1. */
|
|
char scopebuf[IFNAMSIZ + 1];
|
|
char *scopeptr;
|
|
int ni_numericscope = 0;
|
|
size_t real_hostlen = __strnlen (host, hostlen);
|
|
size_t scopelen = 0;
|
|
|
|
scopebuf[0] = SCOPE_DELIMITER;
|
|
scopebuf[1] = '\0';
|
|
scopeptr = &scopebuf[1];
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL (&sin6p->sin6_addr)
|
|
|| IN6_IS_ADDR_MC_LINKLOCAL (&sin6p->sin6_addr))
|
|
{
|
|
if (if_indextoname (scopeid, scopeptr) == NULL)
|
|
++ni_numericscope;
|
|
else
|
|
scopelen = strlen (scopebuf);
|
|
}
|
|
else
|
|
++ni_numericscope;
|
|
|
|
if (ni_numericscope)
|
|
scopelen = 1 + __snprintf (scopeptr,
|
|
(scopebuf
|
|
+ sizeof scopebuf
|
|
- scopeptr),
|
|
"%u", scopeid);
|
|
|
|
if (real_hostlen + scopelen + 1 > hostlen)
|
|
/* XXX We should not fail here. Simply enlarge
|
|
the buffer or return with out of memory. */
|
|
return EAI_SYSTEM;
|
|
memcpy (host + real_hostlen, scopebuf, scopelen + 1);
|
|
}
|
|
}
|
|
else
|
|
c = inet_ntop (AF_INET,
|
|
(const void *) &(((const struct sockaddr_in *) sa)->sin_addr),
|
|
host, hostlen);
|
|
if (c == NULL)
|
|
{
|
|
__set_errno (serrno);
|
|
return EAI_SYSTEM;
|
|
}
|
|
}
|
|
ok = 1;
|
|
}
|
|
break;
|
|
|
|
case AF_LOCAL:
|
|
if (!(flags & NI_NUMERICHOST))
|
|
{
|
|
struct utsname utsname;
|
|
|
|
if (!uname (&utsname))
|
|
{
|
|
strncpy (host, utsname.nodename, hostlen);
|
|
break;
|
|
};
|
|
};
|
|
|
|
if (flags & NI_NAMEREQD)
|
|
{
|
|
__set_errno (serrno);
|
|
return EAI_NONAME;
|
|
}
|
|
|
|
strncpy (host, "localhost", hostlen);
|
|
break;
|
|
|
|
default:
|
|
return EAI_FAMILY;
|
|
}
|
|
|
|
if (serv && (servlen > 0))
|
|
switch (sa->sa_family)
|
|
{
|
|
case AF_INET:
|
|
case AF_INET6:
|
|
if (!(flags & NI_NUMERICSERV))
|
|
{
|
|
struct servent *s, ts;
|
|
while (__getservbyport_r (((const struct sockaddr_in *) sa)->sin_port,
|
|
((flags & NI_DGRAM) ? "udp" : "tcp"),
|
|
&ts, tmpbuf, tmpbuflen, &s))
|
|
{
|
|
if (herrno == NETDB_INTERNAL)
|
|
{
|
|
if (errno == ERANGE)
|
|
{
|
|
tmpbuflen *= 2;
|
|
tmpbuf = __alloca (tmpbuflen);
|
|
}
|
|
else
|
|
{
|
|
__set_errno (serrno);
|
|
return EAI_SYSTEM;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
if (s)
|
|
{
|
|
strncpy (serv, s->s_name, servlen);
|
|
break;
|
|
}
|
|
}
|
|
__snprintf (serv, servlen, "%d",
|
|
ntohs (((const struct sockaddr_in *) sa)->sin_port));
|
|
break;
|
|
|
|
case AF_LOCAL:
|
|
strncpy (serv, ((const struct sockaddr_un *) sa)->sun_path, servlen);
|
|
break;
|
|
}
|
|
|
|
if (host && (hostlen > 0))
|
|
host[hostlen-1] = 0;
|
|
if (serv && (servlen > 0))
|
|
serv[servlen-1] = 0;
|
|
errno = serrno;
|
|
return 0;
|
|
}
|