ref: 84e67ffa88e4d07b2e5848d666296a3e41750da6
parent: 7b5cf8de2dccafa565a62908d307f2033ee69420
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Jan 14 14:32:13 EST 2018
listen(8): add -a option to restrict announce address, document tcp17019 and tcp17020
--- a/sys/man/8/listen
+++ b/sys/man/8/listen
@@ -1,6 +1,6 @@
.TH LISTEN 8
.SH NAME
-listen, listen1, tcp7, tcp9, tcp19, tcp21, tcp23, tcp25, tcp53, tcp110, tcp113, tcp143, tcp445, tcp513, tcp515, tcp564, tcp565, tcp566, tcp567, tcp993, tcp995, tcp1723, tcp17007, tcp17008, tcp17009, tcp17010, tcp17013 \- listen for calls on a network device
+listen, listen1, tcp7, tcp9, tcp19, tcp21, tcp23, tcp25, tcp53, tcp110, tcp113, tcp143, tcp445, tcp513, tcp515, tcp564, tcp565, tcp566, tcp567, tcp993, tcp995, tcp1723, tcp17007, tcp17008, tcp17009, tcp17010, tcp17013, tcp17019, tcp17020 \- listen for calls on a network device
.SH SYNOPSIS
.B aux/listen
.RB [ -iq ]
@@ -12,7 +12,9 @@
.IR namespace ]
.RB [ -p
.IR maxprocs ]
-.RI [ net ]
+.RB [ -a
+.IR addr ]
+.RI [ proto ]
.PP
.B aux/listen1
[
@@ -28,11 +30,18 @@
.I args...
]
.SH DESCRIPTION
-.I listen
+.I Listen
listens on a network for inbound calls to local services.
-.I Net
+.I Proto
is the network protocol on which to listen, by default
-.BR /net/tcp .
+.BR tcp .
+Incoming calls to any address
+.B *
+are accepted unless
+.I addr
+is specified with the
+.B -a
+option.
The services available are executable, non-empty files in
.I srvdir
or
@@ -144,6 +153,10 @@
and
.IR cpu (1)
using TLS for encryption.
+.TP
+.B tcp17020
+TLS encrypted 9P fileserver (t9fs) for
+.IR srvtls (4)
.TP
.B tcp7
echo any bytes received (bit mirror)
--- a/sys/src/cmd/aux/listen.c
+++ b/sys/src/cmd/aux/listen.c
@@ -28,9 +28,9 @@
int findserv(char*, char*, Service*, char*);
int getserv(char*, char*, Service*);
void error(char*);
-void scandir(char*, char*, char*);
+void scandir(char*, char*, char*, char*);
void becomenone(void);
-void listendir(char*, char*, int);
+void listendir(char*, char*, char*, int);
char listenlog[] = "listen";
@@ -40,6 +40,7 @@
int immutable;
char *cpu;
char *proto;
+char *addr;
Announce *announcements;
#define SEC 1000
@@ -48,8 +49,8 @@
void
usage(void)
{
- error("usage: aux/listen [-q] [-n namespace] [-d servdir] [-t trustdir] [-p maxprocs]"
- " [proto]");
+ error("usage: aux/listen [-iq] [-d srvdir] [-t trustsrvdir] [-n namespace] [-p maxprocs]"
+ " [-a addr] [proto]");
}
/*
@@ -85,6 +86,7 @@
char *trustdir;
char *servdir;
+ addr = "*";
servdir = 0;
trustdir = 0;
proto = "tcp";
@@ -97,6 +99,9 @@
error("can't get cputype");
ARGBEGIN{
+ case 'a':
+ addr = EARGF(usage());
+ break;
case 'd':
servdir = EARGF(usage());
break;
@@ -149,8 +154,8 @@
proto = protodir;
else
proto++;
- listendir(protodir, servdir, 0);
- listendir(protodir, trustdir, 1);
+ listendir(protodir, addr, servdir, 0);
+ listendir(protodir, addr, trustdir, 1);
/* command returns */
exits(0);
@@ -165,7 +170,7 @@
}
void
-listendir(char *protodir, char *srvdir, int trusted)
+listendir(char *protodir, char *addr, char *srvdir, int trusted)
{
int ctl, pid, start;
char dir[40], err[128], ds[128];
@@ -191,7 +196,7 @@
return;
}
- procsetname("%s %s %s", protodir, srvdir, namespace);
+ procsetname("%s %s %s %s", protodir, addr, srvdir, namespace);
if (!trusted)
becomenone();
@@ -198,7 +203,7 @@
notify(dingdong);
pid = getpid();
- scandir(proto, protodir, srvdir);
+ scandir(proto, protodir, addr, srvdir);
for(;;){
/*
* loop through announcements and process trusted services in
@@ -273,7 +278,7 @@
}
if(!immutable){
alarm(0);
- scandir(proto, protodir, srvdir);
+ scandir(proto, protodir, addr, srvdir);
}
start = 60 - (time(0)-start);
if(start > 0)
@@ -309,7 +314,7 @@
}
void
-scandir(char *proto, char *protodir, char *dname)
+scandir(char *proto, char *protodir, char *addr, char *dname)
{
Announce *a, **l;
int fd, i, n, nlen;
@@ -334,7 +339,7 @@
continue;
if(strncmp(nm, proto, nlen) != 0)
continue;
- snprint(ds, sizeof ds, "%s!*!%s", protodir, nm + nlen);
+ snprint(ds, sizeof ds, "%s!%s!%s", protodir, addr, nm + nlen);
addannounce(ds);
}
free(db);