summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authoritojun <itojun@NetBSD.org>1999-07-12 20:17:09 +0000
committeritojun <itojun@NetBSD.org>1999-07-12 20:17:09 +0000
commit47b0e5ff1de62650d723ee77451da009e109b681 (patch)
treecc6837af4d859ba72689adf7291c8a6995eb3227 /libexec
parente859716a798f7f6c1df7dbf501f053305f15926e (diff)
IPv6 support.
Diffstat (limited to 'libexec')
-rw-r--r--libexec/tftpd/Makefile5
-rw-r--r--libexec/tftpd/tftpd.83
-rw-r--r--libexec/tftpd/tftpd.c56
3 files changed, 36 insertions, 28 deletions
diff --git a/libexec/tftpd/Makefile b/libexec/tftpd/Makefile
index ee7a6497101..28ecfd3ee8e 100644
--- a/libexec/tftpd/Makefile
+++ b/libexec/tftpd/Makefile
@@ -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 @@ MAN= tftpd.8
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 --git a/libexec/tftpd/tftpd.8 b/libexec/tftpd/tftpd.8
index 621a498580c..9456184c3c3 100644
--- a/libexec/tftpd/tftpd.8
+++ b/libexec/tftpd/tftpd.8
@@ -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 @@ and
.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 --git a/libexec/tftpd/tftpd.c b/libexec/tftpd/tftpd.c
index 7c957dd2726..55b1572bc20 100644
--- a/libexec/tftpd/tftpd.c
+++ b/libexec/tftpd/tftpd.c
@@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
#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 @@ int maxtimeout = 5*TIMEOUT;
#define PKTSIZE SEGSIZE+4
char buf[PKTSIZE];
char ackbuf[PKTSIZE];
-struct sockaddr_in from;
+struct sockaddr_storage from;
int fromlen;
/*
@@ -116,7 +116,7 @@ struct formats;
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 @@ main(argc, argv)
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 @@ main(argc, argv)
}
}
- 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 @@ again:
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 @@ nak(error)
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;
}