forked from extern/endlessh
Add -l to control banner line length
This commit is contained in:
parent
ce7e3e5914
commit
66c549c87c
@ -16,9 +16,10 @@ trap multiple clients at a time.
|
|||||||
Usage information is printed with `-h`.
|
Usage information is printed with `-h`.
|
||||||
|
|
||||||
```
|
```
|
||||||
Usage: endlessh [-vh] [-d MSECS] [-m LIMIT] [-p PORT]
|
Usage: endlessh [-vh] [-d MSECS] [-l LEN] [-m LIMIT] [-p PORT]
|
||||||
-d INT Message millisecond delay [10000]
|
-d INT Message millisecond delay [10000]
|
||||||
-h Print this help message and exit
|
-h Print this help message and exit
|
||||||
|
-l INT Maximum banner line length (3-255) [32]
|
||||||
-m INT Maximum number of clients [4096]
|
-m INT Maximum number of clients [4096]
|
||||||
-p INT Listening port [2222]
|
-p INT Listening port [2222]
|
||||||
-v Print diagnostics to standard output (repeatable)
|
-v Print diagnostics to standard output (repeatable)
|
||||||
|
24
endlessh.c
24
endlessh.c
@ -17,6 +17,7 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
#define DEFAULT_MAX_CLIENTS 4096
|
#define DEFAULT_MAX_CLIENTS 4096
|
||||||
|
#define DEFAULT_LINE_LENGTH 32
|
||||||
#define DEFAULT_PORT 2222
|
#define DEFAULT_PORT 2222
|
||||||
#define DEFAULT_DELAY 10000 // milliseconds
|
#define DEFAULT_DELAY 10000 // milliseconds
|
||||||
|
|
||||||
@ -220,9 +221,9 @@ check(int r)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
randline(char *line)
|
randline(char *line, int maxlen)
|
||||||
{
|
{
|
||||||
int len = 3 + rand() % 61;
|
int len = 3 + rand() % (maxlen - 2);
|
||||||
for (int i = 0; i < len - 2; i++)
|
for (int i = 0; i < len - 2; i++)
|
||||||
line[i] = 32 + rand() % 95;
|
line[i] = 32 + rand() % 95;
|
||||||
line[len - 2] = 13;
|
line[len - 2] = 13;
|
||||||
@ -244,10 +245,13 @@ sigterm_handler(int signal)
|
|||||||
static void
|
static void
|
||||||
usage(FILE *f)
|
usage(FILE *f)
|
||||||
{
|
{
|
||||||
fprintf(f, "Usage: endlessh [-vh] [-d MSECS] [-m LIMIT] [-p PORT]\n");
|
fprintf(f, "Usage: endlessh [-vh] [-d MSECS] [-l LEN] "
|
||||||
|
"[-m LIMIT] [-p PORT]\n");
|
||||||
fprintf(f, " -d INT Message millisecond delay ["
|
fprintf(f, " -d INT Message millisecond delay ["
|
||||||
XSTR(DEFAULT_DELAY) "]\n");
|
XSTR(DEFAULT_DELAY) "]\n");
|
||||||
fprintf(f, " -h Print this help message and exit\n");
|
fprintf(f, " -h Print this help message and exit\n");
|
||||||
|
fprintf(f, " -l INT Maximum banner line length (3-255) ["
|
||||||
|
XSTR(DEFAULT_LINE_LENGTH) "]\n");
|
||||||
fprintf(f, " -m INT Maximum number of clients ["
|
fprintf(f, " -m INT Maximum number of clients ["
|
||||||
XSTR(DEFAULT_MAX_CLIENTS) "]\n");
|
XSTR(DEFAULT_MAX_CLIENTS) "]\n");
|
||||||
fprintf(f, " -p INT Listening port [" XSTR(DEFAULT_PORT) "]\n");
|
fprintf(f, " -p INT Listening port [" XSTR(DEFAULT_PORT) "]\n");
|
||||||
@ -259,11 +263,12 @@ int
|
|||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int port = DEFAULT_PORT;
|
int port = DEFAULT_PORT;
|
||||||
|
int max_length = DEFAULT_LINE_LENGTH;
|
||||||
long delay = DEFAULT_DELAY;
|
long delay = DEFAULT_DELAY;
|
||||||
long max_clients = DEFAULT_MAX_CLIENTS;
|
long max_clients = DEFAULT_MAX_CLIENTS;
|
||||||
|
|
||||||
int option;
|
int option;
|
||||||
while ((option = getopt(argc, argv, "d:hm:p:v")) != -1) {
|
while ((option = getopt(argc, argv, "d:hl:m:p:v")) != -1) {
|
||||||
long tmp;
|
long tmp;
|
||||||
char *end;
|
char *end;
|
||||||
switch (option) {
|
switch (option) {
|
||||||
@ -278,6 +283,15 @@ main(int argc, char **argv)
|
|||||||
usage(stdout);
|
usage(stdout);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
break;
|
break;
|
||||||
|
case 'l':
|
||||||
|
tmp = strtol(optarg, &end, 10);
|
||||||
|
if (errno || *end || tmp < 3 || tmp > 255) {
|
||||||
|
fprintf(stderr, "endlessh: Invalid line length: %s\n",
|
||||||
|
optarg);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
max_length = tmp;
|
||||||
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
tmp = strtol(optarg, &end, 10);
|
tmp = strtol(optarg, &end, 10);
|
||||||
if (errno || *end || tmp < 0) {
|
if (errno || *end || tmp < 0) {
|
||||||
@ -411,7 +425,7 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
} else if (revents & POLLOUT) {
|
} else if (revents & POLLOUT) {
|
||||||
char line[256];
|
char line[256];
|
||||||
int len = randline(line);
|
int len = randline(line, max_length);
|
||||||
/* Don't really care if send is short */
|
/* Don't really care if send is short */
|
||||||
ssize_t out = send(fd, line, len, MSG_DONTWAIT);
|
ssize_t out = send(fd, line, len, MSG_DONTWAIT);
|
||||||
if (out < 0)
|
if (out < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user