Finished message address checking, worked on SIGINT handling
This commit is contained in:
23
main.c
23
main.c
@@ -4,6 +4,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "message.h"
|
||||
#include "user.h"
|
||||
@@ -14,11 +15,15 @@
|
||||
#define BUFFER_SIZE 10000
|
||||
#define MAX_CONNECTIONS 100
|
||||
|
||||
int num_of_lines(char* filename);
|
||||
char* file_to_string(char* filename);
|
||||
User* create_user_list(char* filename);
|
||||
void sigint_handler(int dummy);
|
||||
|
||||
bool stop_running = false;
|
||||
|
||||
int main() {
|
||||
|
||||
signal(SIGINT,sigint_handler);
|
||||
|
||||
struct sockaddr temp_addr;
|
||||
socklen_t temp_addrlen;
|
||||
|
||||
@@ -73,6 +78,9 @@ int main() {
|
||||
if (check_ip_ver(dest_address[i]) == -1) {
|
||||
printf("Invalid address: %s\n",dest_address[i]);
|
||||
exit(242);
|
||||
} else {
|
||||
printf("Valid IPv%d addres: %s\n",check_ip_ver(dest_address[i]),dest_address[i]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -91,6 +99,13 @@ int main() {
|
||||
}
|
||||
|
||||
|
||||
if (stop_running) {
|
||||
for (int i=0; i< MAX_CONNECTIONS; i++) {
|
||||
close(conn_sockets[i]);
|
||||
}
|
||||
exit(130);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -125,3 +140,7 @@ User* create_user_list(char* filename) {
|
||||
return users;
|
||||
|
||||
}
|
||||
|
||||
void sigint_handler(int dummy) {
|
||||
stop_running = true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user