summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authorshin <shin@FreeBSD.org>2000-01-25 14:52:10 +0000
committershin <shin@FreeBSD.org>2000-01-25 14:52:10 +0000
commitfc29f7bcf7236935ba5c171ea553ac7dca533e8c (patch)
tree13e93b815761d57bc661099e5a2b7bcb2882b762 /lib/libutil
parent4497b0fbabcff52472040173a4ea879ec212ecaa (diff)
downloadFreeBSD-src-fc29f7bcf7236935ba5c171ea553ac7dca533e8c.zip
FreeBSD-src-fc29f7bcf7236935ba5c171ea553ac7dca533e8c.tar.gz
several tcp apps IPv6 update
-inetd -rshd -rlogind -telnetd -rsh -rlogin Reviewed by: freebsd-arch, cvs-committers Obtained from: KAME project
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/Makefile3
-rw-r--r--lib/libutil/libutil.h3
-rw-r--r--lib/libutil/realhostname.33
-rw-r--r--lib/libutil/realhostname.c95
-rw-r--r--lib/libutil/realhostname_sa.3135
5 files changed, 237 insertions, 2 deletions
diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile
index f0e9fda..e79b4ad 100644
--- a/lib/libutil/Makefile
+++ b/lib/libutil/Makefile
@@ -5,6 +5,7 @@ LIB= util
SHLIB_MAJOR= 2
SHLIB_MINOR= 2
CFLAGS+=-Wall -DLIBC_SCCS -I${.CURDIR} -I${.CURDIR}/../../sys
+CFLAGS+=-DINET6
SRCS= login.c login_tty.c logout.c logwtmp.c pty.c setproctitle.c \
login_cap.c login_class.c login_auth.c login_times.c login_ok.c \
_secure_path.c uucplock.c property.c auth.c realhostname.c fparseln.c \
@@ -13,7 +14,7 @@ INCS= libutil.h login_cap.h
MAN3+= login.3 login_auth.3 login_tty.3 logout.3 logwtmp.3 pty.3 \
setproctitle.3 login_cap.3 login_class.3 login_times.3 login_ok.3 \
_secure_path.3 uucplock.3 property.3 auth.3 realhostname.3 \
- trimdomain.3 fparseln.3
+ realhostname_sa.3 trimdomain.3 fparseln.3
MAN5+= login.conf.5 auth.conf.5
MLINKS+= property.3 properties_read.3 property.3 properties_free.3
MLINKS+= property.3 property_find.3
diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h
index 4923700..927a384 100644
--- a/lib/libutil/libutil.h
+++ b/lib/libutil/libutil.h
@@ -60,6 +60,9 @@ void properties_free __P((properties list));
char *property_find __P((properties list, const char *name));
char *auth_getval __P((const char *name));
int realhostname __P((char *host, size_t hsize, const struct in_addr *ip));
+struct sockaddr;
+int realhostname_sa __P((char *host, size_t hsize, struct sockaddr *addr,
+ int addrlen));
#ifdef _STDIO_H_ /* avoid adding new includes */
char *fparseln __P((FILE *, size_t *, size_t *, const char[3], int));
#endif
diff --git a/lib/libutil/realhostname.3 b/lib/libutil/realhostname.3
index 1f2e6a9..acf370b 100644
--- a/lib/libutil/realhostname.3
+++ b/lib/libutil/realhostname.3
@@ -103,4 +103,5 @@ now contains the numeric value of
.Sh SEE ALSO
.Xr gethostbyaddr 3 ,
.Xr gethostbyname 3 ,
-.Xr inet_ntoa 3
+.Xr inet_ntoa 3 ,
+.Xr realhostname_sa 3
diff --git a/lib/libutil/realhostname.c b/lib/libutil/realhostname.c
index fa7f4b1..7236890 100644
--- a/lib/libutil/realhostname.c
+++ b/lib/libutil/realhostname.c
@@ -38,6 +38,17 @@
#include "libutil.h"
+/* wrapper for KAME-special getnameinfo() */
+#ifndef NI_WITHSCOPEID
+#define NI_WITHSCOPEID 0
+#endif
+
+struct sockinet {
+ u_char si_len;
+ u_char si_family;
+ u_short si_port;
+};
+
int
realhostname(char *host, size_t hsize, const struct in_addr *ip)
{
@@ -71,3 +82,87 @@ realhostname(char *host, size_t hsize, const struct in_addr *ip)
return result;
}
+
+int
+realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen)
+{
+ int result, error;
+
+ result = HOSTNAME_INVALIDADDR;
+
+ error = getnameinfo(addr, addrlen, host, hsize, NULL, 0, 0);
+ if (error == NULL) {
+ struct addrinfo hints, *res, *ores;
+ struct sockaddr *sa;
+
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_flags = AI_CANONNAME;
+
+ error = getaddrinfo(host, NULL, &hints, &res);
+ if (error) {
+ result = HOSTNAME_INVALIDNAME;
+ goto numeric;
+ } else for (ores = res; ; res = res->ai_next) {
+ if (res == NULL) {
+ freeaddrinfo(ores);
+ result = HOSTNAME_INCORRECTNAME;
+ goto numeric;
+ }
+ sa = res->ai_addr;
+ if (sa == NULL) {
+ freeaddrinfo(ores);
+ result = HOSTNAME_INCORRECTNAME;
+ goto numeric;
+ }
+ if (sa->sa_len == addrlen &&
+ sa->sa_family == addr->sa_family) {
+ u_int16_t port;
+
+ port = ((struct sockinet *)addr)->si_port;
+ ((struct sockinet *)addr)->si_port = 0;
+ if (!memcmp(sa, addr, sa->sa_len)) {
+ strncpy(host, res->ai_canonname,
+ hsize);
+ result = HOSTNAME_FOUND;
+ ((struct sockinet *)addr)->si_port =
+ port;
+ break;
+ }
+ ((struct sockinet *)addr)->si_port = port;
+ }
+#ifdef INET6
+ /*
+ * XXX IPv4 mapped IPv6 addr consideraton,
+ * specified in rfc2373.
+ */
+ if (sa->sa_family == AF_INET &&
+ addr->sa_family == AF_INET6) {
+ struct in_addr *in;
+ struct in6_addr *in6;
+
+ in = &((struct sockaddr_in *)sa)->sin_addr;
+ in6 = &((struct sockaddr_in6 *)addr)->sin6_addr;
+ if (IN6_IS_ADDR_V4MAPPED(in6) &&
+ !memcmp(&in6->s6_addr[12], in,
+ sizeof(*in))) {
+ strncpy(host, res->ai_canonname,
+ hsize);
+ result = HOSTNAME_FOUND;
+ break;
+ }
+ }
+#endif
+ }
+ freeaddrinfo(ores);
+ } else {
+ numeric:
+ getnameinfo(addr, addrlen, host, hsize, NULL, 0,
+ NI_NUMERICHOST|NI_WITHSCOPEID);
+ /* XXX: do 'error' check */
+ }
+
+ return result;
+}
+
+
diff --git a/lib/libutil/realhostname_sa.3 b/lib/libutil/realhostname_sa.3
new file mode 100644
index 0000000..6fef960
--- /dev/null
+++ b/lib/libutil/realhostname_sa.3
@@ -0,0 +1,135 @@
+.\" Copyright (C) 1995, 1996, 1997, 1998, 1999, and 2000 WIDE Project.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of the project 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 THE PROJECT 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 PROJECT 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.
+.\"
+.\" Copyright (c) 1999 Brian Somers <brian@Awfulhak.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd January 11, 2000
+.Os
+.Dt REALHOSTNAME_SA 3
+.Sh NAME
+.Nm realhostname_sa
+.Nd "convert an struct sockaddr to the real host name"
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <netinet/in.h>
+.Fd #include <libutil.h>
+.Ft int
+.Fn realhostname_sa "char *host" "size_t hsize" "struct sockaddr *addr" \
+"int addrlen"
+.Pp
+Link with
+.Va -lutil
+on the
+.Xr cc 1
+command line.
+.Sh DESCRIPTION
+The function
+.Fn realhostname_sa
+converts
+.Ar addr
+to the corresponding host name. This is done by resolving
+.Ar addr
+to a host name and then ensuring that the host name resolves
+back to
+.Ar addr .
+.Pp
+.Ar host
+must point to a buffer of at least
+.Ar hsize
+bytes, and will always be written to by this function.
+.Pp
+If the name resolution doesn't work both ways or if the host name is longer
+than
+.Ar hsize
+bytes,
+.Xr getnameinfo 3
+with NI_NUMERICHOST specified, is used to convert
+.Ar addr
+to an ASCII form.
+.Pp
+If the string written to
+.Ar host
+is
+.Ar hsize
+bytes long,
+.Ar host
+will not be NUL terminated.
+.Sh RETURN VALUES
+.Fn realhostname_sa
+will return one of the following constants which are defined in
+.Pa libutil.h :
+.Pp
+.Bl -tag -width XXX -offset XXX
+.It Li HOSTNAME_FOUND
+A valid host name was found.
+.It Li HOSTNAME_INCORRECTNAME
+A host name was found, but it did not resolve back to the passed
+.Ar ip .
+.Ar host
+now contains the numeric value of
+.Ar ip .
+.It Li HOSTNAME_INVALIDADDR
+.Ar ip
+could not be resolved.
+.Ar host
+now contains the numeric value of
+.Ar ip .
+.It Li HOSTNAME_INVALIDNAME
+A host name was found, but it could not be resolved back to any ip number.
+.Ar host
+now contains the numeric value of
+.Ar ip .
+.El
+.Sh SEE ALSO
+.Xr getaddrinfo 3 ,
+.Xr getnameinfo 3 ,
+.Xr realhostname 3
+
OpenPOWER on IntegriCloud