Added response back to client.

This commit is contained in:
Afonso Clerigo Mendes de Sousa 2025-02-27 11:53:03 +00:00
parent 3c4243ddcf
commit 7e212a99e6
2 changed files with 39 additions and 11 deletions

View File

@ -46,7 +46,7 @@ int main(void)
buffer = size(buffer, 256); buffer = size(buffer, 256);
emcryptText(buffer, password); emcryptText(buffer, password);
writel(PASS_FILE, buffer, 256 * sizeof(int)); writel(PASS_FILE, buffer, 256);
free(buffer); free(buffer);
} }

View File

@ -12,13 +12,14 @@
#include "ui/ui.h" #include "ui/ui.h"
#define SERVER_IP "192.168.1.120" #define SERVER_IP "192.168.1.120"
#define PASSWORDS "./files/KEYS.bin" #define PASSWORDS "./files/USER_PASSWORDS_L"
typedef struct Request typedef struct Request
{ {
unsigned char type; unsigned char type;
char *key; char *key;
int ID; int ID;
int level;
} Request; } Request;
int main(void) int main(void)
@ -55,26 +56,53 @@ int main(void)
struct sockaddr_in cli; struct sockaddr_in cli;
u_int32_t len = sizeof(cli); u_int32_t len = sizeof(cli);
int connfd = accept(sockfd, (struct sockaddr *)&cli, &len); char *buffer = create(char);
if (connfd < 0) buffer = size(buffer, 256);
{
fprintf(stderr, "Server accept failed\n");
close(sockfd);
return 1;
}
printf("Client connected\n"); u_int8_t isConnected = 0;
int connfd;
// Listen to the client requests // Listen to the client requests
while (1) while (1)
{ {
// Receive the request // Receive the request
if (!isConnected)
{
connfd = accept(sockfd, (struct sockaddr *)&cli, &len);
if (connfd < 0)
{
fprintf(stderr, "Server accept failed\n");
close(sockfd);
}
}
isConnected = 1;
printf("Client connected\n");
Request req; Request req;
int n = recv(connfd, &req, sizeof(Request), 0); int n = recv(connfd, &req, sizeof(Request), 0);
if (n <= 0) if (n <= 0)
{ {
fprintf(stderr, "Client disconnected\n"); fprintf(stderr, "Client disconnected\n");
break; isConnected = 0;
}
// TYPE == 0 is the equivelent of a GET
if (req.type == 0)
{
char *filepath = PASSWORDS;
sprintf(filepath, "%s%d.bin", filepath, req.level);
if (readl(filepath, buffer, 256) == -1)
{
Request aux;
aux.ID = req.ID;
aux.key = NULL;
aux.type = req.type;
aux.level = -1;
send();
}
} }
} }