From: Mart Lubbers Date: Wed, 14 Dec 2016 11:39:35 +0000 (+0100) Subject: add tracinc X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=340daaadd4e458ba3fd8d83bb765cb790381d69f;p=mTask.git add tracinc --- diff --git a/int/int.c b/int/int.c index 9d6fde3..37859cc 100644 --- a/int/int.c +++ b/int/int.c @@ -12,8 +12,6 @@ #include "mTaskSymbols.h" -#define PORT 8123 - #define MAXTASKS 5 #define MAXTASKSIZE 1024 #define MAXSDS 50 @@ -44,6 +42,7 @@ struct task { struct task tasks[MAXTASKS] = {0}; int sock_fd = -1; int fd = -1; +int port = 8123; void killHandler(int i) { @@ -246,7 +245,7 @@ void open_filedescriptors() bzero((char *) &sa, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_addr.s_addr = INADDR_ANY; - sa.sin_port = htons(PORT); + sa.sin_port = htons(port); if((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) pdie("socket"); @@ -255,13 +254,22 @@ void open_filedescriptors() if(listen(sock_fd, 10) == -1) pdie("bind\n"); - printf("Listening on %d\n", PORT); + printf("Listening on %d\n", port); fflush(stdout); if((fd = accept(sock_fd, (struct sockaddr*)NULL, NULL)) == -1) pdie("accept"); } -int main(void) +void usage(FILE *o, char *arg0){ + fprintf(o, + "Usage: %s [opts]\n" + "\n" + "Options\n" + "-p PORT Custom port number, default: 8123\n" + , arg0); +} + +int main(int argc, char *argv[]) { int ct; @@ -273,6 +281,25 @@ int main(void) die("Couldn't register signal handler...\n"); } + //Command line arguments + int opt; + while((opt = getopt(argc, argv, "hp:")) != -1){ + switch(opt){ + case 'p': + port = atoi(optarg); + if(port < 1) + die("Port numbers are > 1\n"); + break; + case 'h': + usage(stdout, argv[0]); + exit(EXIT_SUCCESS); + default: + usage(stderr, argv[0]); + exit(EXIT_FAILURE); + } + + } + open_filedescriptors(); while(true){