234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * All rights reserved.
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * Redistribution and use in source and binary forms, with or without
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * modification, are permitted provided that the following conditions
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * 1. Redistributions of source code must retain the above copyright
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * notice, this list of conditions and the following disclaimer.
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * 2. Redistributions in binary form must reproduce the above copyright
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * notice, this list of conditions and the following disclaimer in the
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * documentation and/or other materials provided with the distribution.
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * 3. Neither the name of the project nor the names of its contributors
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * may be used to endorse or promote products derived from this software
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * without specific prior written permission.
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * SUCH DAMAGE.
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * Issues to be discussed:
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * - Thread safe-ness must be checked
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * - Return values. There seems to be no standard for return value (RFC2553)
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 * but INRIA implementation returns EAI_xxx defined for getaddrinfo().
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 {PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6),
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 offsetof(struct sockaddr_in6, sin6_addr)},
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 {PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in),
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 if (len != afd->a_socklen) return ENI_SALEN;
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 port = ((struct sockinet *)sa)->si_port; /* network byte order */
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 /* what we should do? */
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 snprintf(numserv, sizeof(numserv), "%d", ntohs(port));
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 sp = getservbyport(port, (flags & NI_DGRAM) ? "udp" : "tcp");
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 v4a = ntohl(((struct sockaddr_in *)sa)->sin_addr.s_addr);
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a))
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr))
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 else if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 /* what should we do? */
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 /* NUMERICHOST and NAMEREQD conflicts with each other */
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr))
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 hp = getipnodebyaddr(addr, afd->a_addrlen, afd->a_af, &h_error);
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af);
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 if (p) *p = '\0';
234ef071da767c70518b887c5a913687b05b19e9Tatuya JINMEI 神明達哉 if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr))