diff --git a/.gitignore b/.gitignore index f5c0c40..52ecfea 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ sql_test.o gtk_test.o sys_info.o show_dir.o -change_dir.o \ No newline at end of file +change_dir.o +update_check.o \ No newline at end of file diff --git a/main.c b/main.c index bda6411..85164db 100644 --- a/main.c +++ b/main.c @@ -16,6 +16,7 @@ #include "etc/logo.h" #include "utils/logger.h" #include "utils/sys_info.h" +#include "utils/update_check.h" #define VERSION "0.2.0" @@ -96,10 +97,10 @@ int main(int argc, char *argv[]){ logger("================================================"); snprintf(buffer, sizeof(buffer), "Starting netbenixCMD (Version: %s)", VERSION); logger(buffer); - log_Specs(); + log_Specs(); //Log system specs showLogo(); //Show the Logo logger("Logo Displayed."); - + checkForUpdate(VERSION); //Check for Update if(argc > 2){ printf("Too many arguments. Please use --help for more information.\n"); snprintf(buffer, sizeof(buffer), "[ERROR] Too many arguments. Argument count: %i", argc-1); diff --git a/makefile b/makefile index a744f86..39fabbd 100644 --- a/makefile +++ b/makefile @@ -2,7 +2,7 @@ CC= gcc ARGS= -export-dynamic -ansi -std=gnu99 CFLAGS= $(shell pkg-config --cflags gtk+-3.0) -I/usr/include/mysql LDLIBS= $(shell pkg-config --libs gtk+-3.0) -L/usr/lib/mysql -lmysqlclient -OBJ= main.o logo.o logger.o help.o sys_info.o gtk_test.o sql_test.o show_dir.o change_dir.o +OBJ= main.o logo.o logger.o help.o sys_info.o gtk_test.o sql_test.o show_dir.o change_dir.o update_check.o netbenixCMD: $(OBJ) $(CC) $(CFLAGS) $(ARGS) -o netbenixCMD $(OBJ) $(LDLIBS) @@ -23,4 +23,6 @@ sql_test.o: utils/sql_test.c show_dir.o: commands/show_dir.c $(CC) $(CFLAGS) -c commands/show_dir.c change_dir.o: commands/change_dir.c - $(CC) $(CFLAGS) -c commands/change_dir.c \ No newline at end of file + $(CC) $(CFLAGS) -c commands/change_dir.c +update_check.o: utils/update_check.c + $(CC) $(CFLAGS) -c utils/update_check.c diff --git a/utils/update_check.c b/utils/update_check.c new file mode 100644 index 0000000..353d8e1 --- /dev/null +++ b/utils/update_check.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include "update_check.h" +#include "logger.h" + +int checkForUpdate(char ver[10]){ + int sock; + struct sockaddr_in server; + char server_reply[2000]; + + //Create Socket + sock = socket(AF_INET, SOCK_STREAM, 0); + if( sock == -1){ + printf("Error while creating socket."); + logger("Error while creating socket"); + } + + server.sin_addr.s_addr = inet_addr("127.0.0.1"); + server.sin_family = AF_INET; + server.sin_port = htons( 34000 ); + + //Connect to Server + if(connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0){ + perror("Error. Connnection failed."); + logger("[ERROR] Connection to update server failed."); + return 1; + } + + if( send(sock, ver, strlen(ver), 0) < 0){ + puts("Error while communicating with server."); + logger("[ERROR] Send to server failed."); + } + + if( recv(sock, server_reply, 2000, 0) < 0){ + puts("Error while communicating with server."); + logger("[ERROR] Receive from server failed."); + } + if(!strcmp(server_reply, "VERSION_OUTDATED")){ + printf("\033[0;31mYour client is outdated. Please update your client.\033[0m\n"); + logger("[WARNING] Client is outdated."); + } + + if(!strcmp(server_reply, "VERSION_OK")){ + logger("[INFO] Client is up-to-date."); + } + close(sock); + return 0; +} \ No newline at end of file diff --git a/utils/update_check.h b/utils/update_check.h new file mode 100644 index 0000000..55d7232 --- /dev/null +++ b/utils/update_check.h @@ -0,0 +1,6 @@ +#ifndef _UPDATE_CHECK_H_ +#define _UPDATE_CHECK_H_ + +int checkForUpdate(char ver[10]); + +#endif \ No newline at end of file