Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/telnet IPv6-ready telnet.



details:   https://anonhg.NetBSD.org/src/rev/42d2fcc68692
branches:  trunk
changeset: 474264:42d2fcc68692
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Jul 02 15:09:10 1999 +0000

description:
IPv6-ready telnet.
source route (telnet @localhost@localhost) works for IPv6 as well.

diffstat:

 usr.bin/telnet/Makefile   |   10 +-
 usr.bin/telnet/commands.c |  482 ++++++++++++++++++++++++++-------------------
 usr.bin/telnet/externs.h  |   12 +-
 usr.bin/telnet/main.c     |   26 ++-
 usr.bin/telnet/telnet.1   |   13 +-
 5 files changed, 325 insertions(+), 218 deletions(-)

diffs (truncated from 789 to 300 lines):

diff -r 0112e344dade -r 42d2fcc68692 usr.bin/telnet/Makefile
--- a/usr.bin/telnet/Makefile   Fri Jul 02 14:51:22 1999 +0000
+++ b/usr.bin/telnet/Makefile   Fri Jul 02 15:09:10 1999 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.16 1999/06/07 00:53:10 thorpej Exp $
+#      $NetBSD: Makefile,v 1.17 1999/07/02 15:09:10 itojun Exp $
 #
 # Copyright (c) 1990 The Regents of the University of California.
 # All rights reserved.
@@ -48,10 +48,9 @@
 CPPFLAGS+=-DTERMCAP -DKLUDGELINEMODE -DUSE_TERMIO -Dunix
 CPPFLAGS+=-DENV_HACK
 CPPFLAGS+=-I${.CURDIR}/../../lib
-LDADD+=        -ltermcap -ltelnet
+LDADD+= -ltermcap -ltelnet
 DPADD= ${LIBTERMCAP} ${LIBTELNET}
 
-
 SRCS=  authenc.c commands.c main.c network.c ring.c sys_bsd.c telnet.c \
        terminal.c tn3270.c utilities.c
 
@@ -70,5 +69,10 @@
 
 .endif # EXPORTABLE_SYSTEM
 
+CPPFLAGS+=-DIPSEC
+LDADD+=        -lipsec
+DPADD+=        ${LIBIPSEC}
+CPPFLAGS+=-DINET6
+
 nocrypt:
        @echo "Encryption code already removed."
diff -r 0112e344dade -r 42d2fcc68692 usr.bin/telnet/commands.c
--- a/usr.bin/telnet/commands.c Fri Jul 02 14:51:22 1999 +0000
+++ b/usr.bin/telnet/commands.c Fri Jul 02 15:09:10 1999 +0000
@@ -1,4 +1,33 @@
-/*     $NetBSD: commands.c,v 1.25 1998/11/06 19:54:18 christos Exp $   */
+/*     $NetBSD: commands.c,v 1.26 1999/07/02 15:09:10 itojun Exp $     */
+
+/*
+ * Copyright (C) 1997 and 1998 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) 1988, 1990, 1993
@@ -38,7 +67,7 @@
 #if 0
 static char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95";
 #else
-__RCSID("$NetBSD: commands.c,v 1.25 1998/11/06 19:54:18 christos Exp $");
+__RCSID("$NetBSD: commands.c,v 1.26 1999/07/02 15:09:10 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -160,6 +189,7 @@
 static void filestuff P((int));
 #endif
 static int status P((int, char *[]));
+static const char *sockaddr_ntop __P((struct sockaddr *));
 typedef int (*intrtn_t) P((int, char **));
 static int call P((intrtn_t, ...));
 static Command *getcmd P((char *));
@@ -2130,18 +2160,37 @@
 }
 #endif
 
+static const char *
+sockaddr_ntop(sa)
+    struct sockaddr *sa;
+{
+    void *addr;
+    static char addrbuf[INET6_ADDRSTRLEN];
+
+    switch (sa->sa_family) {
+    case AF_INET:
+       addr = &((struct sockaddr_in *)sa)->sin_addr;
+       break;
+    case AF_INET6:
+       addr = &((struct sockaddr_in6 *)sa)->sin6_addr;
+       break;
+    default:
+       return NULL;
+    }
+    return (char *)inet_ntop(sa->sa_family, addr, addrbuf, sizeof(addrbuf));
+}
+
     int
 tn(argc, argv)
     int argc;
     char *argv[];
 {
-    register struct hostent *host = 0;
-    struct sockaddr_in sin;
-    struct servent *sp = 0;
-    unsigned long temp;
+    struct addrinfo hints, *res;
+    int error;
 #if    defined(IP_OPTIONS) && defined(IPPROTO_IP)
     char *srp = 0;
     unsigned long srlen;
+    int proto, opt;
 #endif
     char *cmd, *hostp = 0, *portp = 0;
     const char *user = 0;
@@ -2149,9 +2198,6 @@
     (void) &user;
 #endif
 
-    /* clear the socket address prior to use */
-    memset((char *)&sin, 0, sizeof(sin));
-
     if (connected) {
        printf("?Already connected to %s\n", hostname);
        setuid(getuid());
@@ -2201,142 +2247,120 @@
     if (hostp == 0)
        goto usage;
 
-#if    defined(IP_OPTIONS) && defined(IPPROTO_IP)
+    (void) strcpy(_hostname, hostp);
     if (hostp[0] == '@' || hostp[0] == '!') {
-       if ((hostname = strrchr(hostp, ':')) == NULL)
-           hostname = strrchr(hostp, '@');
-       hostname++;
-       srp = 0;
-       temp = sourceroute(hostp, &srp, &srlen);
-       if (temp == 0) {
-           herror(srp);
-           setuid(getuid());
-           return 0;
-       } else if (temp == -1) {
-           printf("Bad source route option: %s\n", hostp);
+       char *p;
+       hostname = NULL;
+       for (p = hostp + 1; *p; p++) {
+           if (*p == ',' || *p == '@')
+               hostname = p;
+       }
+       if (hostname == NULL) {
+           fprintf(stderr, "%s: bad source route specification\n", hostp);
            setuid(getuid());
            return 0;
-       } else {
-           sin.sin_addr.s_addr = temp;
-           sin.sin_family = AF_INET;
        }
-    } else {
-#endif
-       temp = inet_addr(hostp);
-       if (temp != INADDR_NONE) {
-           sin.sin_addr.s_addr = temp;
-           sin.sin_family = AF_INET;
-           host = gethostbyaddr((char *)&temp, sizeof(temp), AF_INET);
-           if (host)
-               (void) strcpy(_hostname, host->h_name);
-           else
-               (void) strcpy(_hostname, hostp);
-           hostname = _hostname;
-       } else {
-           host = gethostbyname(hostp);
-           if (host) {
-               sin.sin_family = host->h_addrtype;
-#if    defined(h_addr)         /* In 4.3, this is a #define */
-               memmove((caddr_t)&sin.sin_addr,
-                               host->h_addr_list[0], host->h_length);
-#else  /* defined(h_addr) */
-               memmove((caddr_t)&sin.sin_addr, host->h_addr, host->h_length);
-#endif /* defined(h_addr) */
-               strncpy(_hostname, host->h_name, sizeof(_hostname));
-               _hostname[sizeof(_hostname)-1] = '\0';
-               hostname = _hostname;
-           } else {
-               herror(hostp);
-               setuid(getuid());
-               return 0;
-           }
-       }
-#if    defined(IP_OPTIONS) && defined(IPPROTO_IP)
+       *hostname++ = '\0';
+    } else
+       hostname = hostp;
+
+    if (!portp) {
+      telnetport = 1;
+      portp = "telnet";
     }
-#endif
-    if (portp) {
-       if (*portp == '-') {
-           portp++;
-           telnetport = 1;
-       } else
-           telnetport = 0;
-       sin.sin_port = atoi(portp);
-       if (sin.sin_port == 0) {
-           sp = getservbyname(portp, "tcp");
-           if (sp)
-               sin.sin_port = sp->s_port;
-           else {
-               printf("%s: bad port number\n", portp);
-               setuid(getuid());
-               return 0;
-           }
-       } else {
-#if    !defined(htons)
-           u_short htons P((unsigned short));
-#endif /* !defined(htons) */
-           sin.sin_port = htons(sin.sin_port);
-       }
+
+    memset(&hints, 0, sizeof(hints));
+    hints.ai_flags = AI_NUMERICHOST;
+    hints.ai_family = AF_UNSPEC;
+    hints.ai_socktype = SOCK_STREAM;
+    hints.ai_protocol = 0;
+    error = getaddrinfo(hostname, portp, &hints, &res);
+    if (!error) {
+       /*numeric*/
+       freeaddrinfo(res);
+       memset(&hints, 0, sizeof(hints));
+       hints.ai_flags = AI_CANONNAME;
+       hints.ai_family = AF_UNSPEC;
+       hints.ai_socktype = SOCK_STREAM;
+       hints.ai_protocol = 0;
+       error = getaddrinfo(hostname, portp, &hints, &res);
     } else {
-       if (sp == 0) {
-           sp = getservbyname("telnet", "tcp");
-           if (sp == 0) {
-               fprintf(stderr, "telnet: tcp/telnet: unknown service\n");
-               setuid(getuid());
-               return 0;
-           }
-           sin.sin_port = sp->s_port;
-       }
-       telnetport = 1;
+       /*non-numeric*/
+       memset(&hints, 0, sizeof(hints));
+       hints.ai_family = AF_UNSPEC;
+       hints.ai_socktype = SOCK_STREAM;
+       hints.ai_protocol = 0;
+       error = getaddrinfo(hostname, portp, &hints, &res);
     }
-    printf("Trying %s...\n", inet_ntoa(sin.sin_addr));
+    if (error) {
+      fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error));
+      setuid(getuid());
+      return 0;
+    }
+
+    if (res->ai_canonname)
+      (void) strcpy(_hostname, res->ai_canonname);
+    hostname = _hostname;
+
     do {
-       net = socket(AF_INET, SOCK_STREAM, 0);
+       printf("Trying %s...\n", sockaddr_ntop(res->ai_addr));
+       net = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
        setuid(getuid());
        if (net < 0) {
            perror("telnet: socket");
            return 0;
        }
-#if    defined(IP_OPTIONS) && defined(IPPROTO_IP)
-       if (srp && setsockopt(net, IPPROTO_IP, IP_OPTIONS, (char *)srp, srlen) < 0)
-               perror("setsockopt (IP_OPTIONS)");
-#endif
-#if    defined(IPPROTO_IP) && defined(IP_TOS)
-       {
-# if   defined(HAS_GETTOS)
-           struct tosent *tp;
-           if (tos < 0 && (tp = gettosbyname("telnet", "tcp")))
-               tos = tp->t_tos;
-# endif
-           if (tos < 0)



Home | Main Index | Thread Index | Old Index