Source-Changes-HG archive

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

[src/trunk]: src IPv6 support.



details:   https://anonhg.NetBSD.org/src/rev/c5bbcebd01ef
branches:  trunk
changeset: 474617:c5bbcebd01ef
user:      itojun <itojun%NetBSD.org@localhost>
date:      Mon Jul 12 20:17:09 1999 +0000

description:
IPv6 support.

diffstat:

 etc/inetd.conf         |   3 +-
 libexec/tftpd/Makefile |   5 +++-
 libexec/tftpd/tftpd.8  |   3 +-
 libexec/tftpd/tftpd.c  |  56 ++++++++++++++++++++++++++-----------------------
 4 files changed, 38 insertions(+), 29 deletions(-)

diffs (176 lines):

diff -r 96a9901155fa -r c5bbcebd01ef etc/inetd.conf
--- a/etc/inetd.conf    Mon Jul 12 19:47:40 1999 +0000
+++ b/etc/inetd.conf    Mon Jul 12 20:17:09 1999 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: inetd.conf,v 1.25 1999/07/02 06:32:32 itojun Exp $
+#      $NetBSD: inetd.conf,v 1.26 1999/07/12 20:17:09 itojun Exp $
 #
 # Internet server configuration database
 #
@@ -63,3 +63,4 @@
 ftp            stream  tcp6    nowait  root    /usr/libexec/ftpd       ftpd -ll
 telnet         stream  tcp6    nowait  root    /usr/libexec/telnetd    telnetd
 finger         stream  tcp6    nowait  nobody  /usr/libexec/fingerd    fingerd
+#tftp          dgram   udp6    wait    root    /usr/libexec/tftpd      tftpd -s /tftpboot
diff -r 96a9901155fa -r c5bbcebd01ef libexec/tftpd/Makefile
--- a/libexec/tftpd/Makefile    Mon Jul 12 19:47:40 1999 +0000
+++ b/libexec/tftpd/Makefile    Mon Jul 12 20:17:09 1999 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.7 1997/10/22 06:03:55 lukem Exp $
+#      $NetBSD: Makefile,v 1.8 1999/07/12 20:17:09 itojun Exp $
 #      from: @(#)Makefile      8.1 (Berkeley) 6/4/93
 
 PROG=  tftpd
@@ -7,4 +7,7 @@
 CPPFLAGS+=-I${.CURDIR}/../../usr.bin/tftp
 .PATH: ${.CURDIR}/../../usr.bin/tftp
 
+# for portability across old sockaddr_storage definition
+CPPFLAGS+=-Dss_len=__ss_len -Dss_family=__ss_family
+
 .include <bsd.prog.mk>
diff -r 96a9901155fa -r c5bbcebd01ef libexec/tftpd/tftpd.8
--- a/libexec/tftpd/tftpd.8     Mon Jul 12 19:47:40 1999 +0000
+++ b/libexec/tftpd/tftpd.8     Mon Jul 12 20:17:09 1999 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: tftpd.8,v 1.10 1999/03/22 18:25:48 garbled Exp $
+.\"    $NetBSD: tftpd.8,v 1.11 1999/07/12 20:17:09 itojun Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -169,6 +169,7 @@
 .Fl u
 flags appeared in
 .Nx 1.4 .
+IPv6 support was implemented by WIDE/KAME project in 1999.
 .Sh SECURITY CONSIDERATIONS
 You are
 .Em strongly
diff -r 96a9901155fa -r c5bbcebd01ef libexec/tftpd/tftpd.c
--- a/libexec/tftpd/tftpd.c     Mon Jul 12 19:47:40 1999 +0000
+++ b/libexec/tftpd/tftpd.c     Mon Jul 12 20:17:09 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tftpd.c,v 1.17 1999/06/23 15:41:48 carrel Exp $        */
+/*     $NetBSD: tftpd.c,v 1.18 1999/07/12 20:17:09 itojun Exp $        */
 
 /*
  * Copyright (c) 1983, 1993
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)tftpd.c    8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: tftpd.c,v 1.17 1999/06/23 15:41:48 carrel Exp $");
+__RCSID("$NetBSD: tftpd.c,v 1.18 1999/07/12 20:17:09 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -91,7 +91,7 @@
 #define        PKTSIZE SEGSIZE+4
 char   buf[PKTSIZE];
 char   ackbuf[PKTSIZE];
-struct sockaddr_in from;
+struct sockaddr_storage from;
 int    fromlen;
 
 /*
@@ -116,7 +116,7 @@
 static void tftp __P((struct tftphdr *, int));
 static const char *errtomsg __P((int));
 static void nak __P((int));
-static char *verifyhost __P((struct sockaddr_in *));
+static char *verifyhost __P((struct sockaddr *));
 static void usage __P((void));
 void timer __P((int));
 void sendfile __P((struct formats *));
@@ -157,7 +157,7 @@
        int n = 0;
        int ch, on;
        int fd = 0;
-       struct sockaddr_in sin;
+       struct sockaddr_storage me;
        int len;
        char *tgtuser, *tgtgroup, *ep;
        uid_t curuid, tgtuid;
@@ -344,34 +344,42 @@
                }
        }
 
-       from.sin_len = sizeof(struct sockaddr_in);
-       from.sin_family = AF_INET;
-
        /*
         * remember what address this was sent to, so we can respond on the
         * same interface
         */
-       len = sizeof(sin);
-       if (getsockname(fd, (struct sockaddr *)&sin, &len) == 0)
-               sin.sin_port = 0;
-       else {
-               memset(&sin, 0, sizeof(sin));
-               sin.sin_family = AF_INET;
+       len = sizeof(me);
+       if (getsockname(fd, (struct sockaddr *)&me, &len) == 0) {
+               switch (me.ss_family) {
+               case AF_INET:
+                       ((struct sockaddr_in *)&me)->sin_port = 0;
+                       break;
+               case AF_INET6:
+                       ((struct sockaddr_in6 *)&me)->sin6_port = 0;
+                       break;
+               default:
+                       /* unsupported */
+                       break;
+               }
+       } else {
+               memset(&me, 0, sizeof(me));
+               me.ss_family = from.ss_family;
+               me.ss_len = from.ss_len;
        }
 
        alarm(0);
        close(fd);
        close(1);
-       peer = socket(AF_INET, SOCK_DGRAM, 0);
+       peer = socket(from.ss_family, SOCK_DGRAM, 0);
        if (peer < 0) {
                syslog(LOG_ERR, "socket: %m");
                exit(1);
        }
-       if (bind(peer, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+       if (bind(peer, (struct sockaddr *)&me, me.ss_len) < 0) {
                syslog(LOG_ERR, "bind: %m");
                exit(1);
        }
-       if (connect(peer, (struct sockaddr *)&from, sizeof(from)) < 0) {
+       if (connect(peer, (struct sockaddr *)&from, from.ss_len) < 0) {
                syslog(LOG_ERR, "connect: %m");
                exit(1);
        }
@@ -424,7 +432,7 @@
        ecode = (*pf->f_validate)(&filename, tp->th_opcode);
        if (logging) {
                syslog(LOG_INFO, "%s: %s request for %s: %s",
-                       verifyhost(&from),
+                       verifyhost((struct sockaddr *)&from),
                        tp->th_opcode == WRQ ? "write" : "read",
                        filename, errtomsg(ecode));
        }
@@ -788,14 +796,10 @@
 
 static char *
 verifyhost(fromp)
-       struct sockaddr_in *fromp;
+       struct sockaddr *fromp;
 {
-       struct hostent *hp;
+       static char hbuf[MAXHOSTNAMELEN];
 
-       hp = gethostbyaddr((char *)&fromp->sin_addr, sizeof (fromp->sin_addr),
-                           fromp->sin_family);
-       if (hp)
-               return hp->h_name;
-       else
-               return inet_ntoa(fromp->sin_addr);
+       getnameinfo(fromp, fromp->sa_len, hbuf, sizeof(hbuf), NULL, 0, 0);
+       return hbuf;
 }



Home | Main Index | Thread Index | Old Index