#include "mTaskSymbols.h"
-#define PORT 8123
-
#define MAXTASKS 5
#define MAXTASKSIZE 1024
#define MAXSDS 50
struct task tasks[MAXTASKS] = {0};
int sock_fd = -1;
int fd = -1;
+int port = 8123;
void killHandler(int i)
{
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");
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;
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){