ref: 5969b872bb244f6f9083fd06779a50cf68078455
parent: 1454ec6425d0cc4f06f54d49df4b723a2f2fab1a
author: Jacob Moody <moody@posixcafe.org>
date: Wed Oct 30 17:46:39 EDT 2024
ip/tftpd: accept an address to announce to as an argument.
--- a/sys/man/8/dhcpd
+++ b/sys/man/8/dhcpd
@@ -46,6 +46,9 @@
.IR nsfile ]
.RB [ -m
.IR mapfile ]
+[
+.I addr
+]
.SH DESCRIPTION
These programs support booting over the Internet.
They should all be run on the same server to
@@ -295,6 +298,13 @@
It runs as user
.B none
and can only access files with global read permission.
+By default
+.I tftpd
+announces on all local IPs found on
+.IR netmtpt ,
+the
+.I addr
+argument may be used to specify a single local address to use.
The options are:
.TP
.B d
--- a/sys/src/cmd/ip/tftpd.c
+++ b/sys/src/cmd/ip/tftpd.c
@@ -119,7 +119,7 @@
void
usage(void)
{
- fprint(2, "usage: %s [-dr] [-h homedir] [-s svc] [-x netmtpt] [-n nsfile] [-m mapfile]\n",
+ fprint(2, "usage: %s [-dr] [-h homedir] [-s svc] [-x netmtpt] [-n nsfile] [-m mapfile] [addr]\n",
argv0);
exits("usage");
}
@@ -127,10 +127,11 @@
void
main(int argc, char **argv)
{
- char buf[64];
+ char buf[128];
char adir[64], ldir[64];
int cfd, lcfd, dfd;
- char *svc = "69";
+ char *svc = "tftp";
+ char *addr = "*";
setnetmtpt(net, sizeof net, nil);
ARGBEGIN{
@@ -158,6 +159,8 @@
default:
usage();
}ARGEND
+ if(argc)
+ addr = argv[0];
dirsllen = strlen(homedir);
while(dirsllen > 0 && homedir[dirsllen-1] == '/')
@@ -185,10 +188,11 @@
exits(0);
}
- snprint(buf, sizeof buf, "%s/udp!*!%s", net, svc);
+ snprint(buf, sizeof buf, "%s/udp!%s!%s", net, addr, svc);
cfd = announce(buf, adir);
if (cfd < 0)
sysfatal("announcing on %s: %r", buf);
+ procsetname("%s", buf);
syslog(dbg, flog, "tftpd started on %s dir %s", buf, adir);
for(;;) {
lcfd = listen(adir, ldir);
--
⑨