xmdp add scan time key (#636)

Thank you !
pull/637/head
cronyx 2023-02-05 11:03:51 +03:00 committed by GitHub
parent b5ffd31fe8
commit b984dd7b53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -1,4 +1,4 @@
CFLAGS=-Wall -Wpedantic
CFLAGS=-Os -Wall -Wpedantic
LDFLAGS=-lm
all: xmdp

View File

@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <arpa/inet.h>
#include <netdb.h>
@ -21,6 +22,8 @@
#define MIN(x, y) ((x) < (y) ? (x) : (y))
static int scansec = 0;
const char brpkt[] =
"\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfa\x05"
"\x00\x00\x00\x00";
@ -91,7 +94,10 @@ void sigalarm(int sig) {
}
}
int main() {
int scan() {
time_t start, current;
start = time(NULL);
bsock = socket(AF_INET, SOCK_DGRAM, 0);
if (bsock == -1) {
perror("socket");
@ -128,6 +134,12 @@ int main() {
uint32_t *seen_vec = malloc(seen_cap * sizeof(*seen_vec));
while (1) {
current = time(NULL);
if ((scansec > 0) && (current-start > scansec)) {
exit(EXIT_SUCCESS);
}
char buf[1024];
struct sockaddr_in their_addr;
socklen_t addr_len = sizeof their_addr;
@ -226,3 +238,18 @@ int main() {
free(seen_vec);
}
int main(int argc, char *argv[]) {
int opt;
while ((opt = getopt(argc, argv, "t:")) != -1) {
switch (opt) {
case 't':
scansec = atoi(optarg);
break;
default:
printf("Usage: %s [-t seconds]\n", argv[0]);
exit(EXIT_FAILURE);
}
}
return scan();
}