-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_main.c
More file actions
45 lines (40 loc) · 1.21 KB
/
client_main.c
File metadata and controls
45 lines (40 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright [2020]<Jonathan David Rosenblatt>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include "client_tda.h"
#include "common_arginfo.h"
#include "common_cesar.h"
#define ERR_ARG_NRO "Error, argumento inválido.\n"
#define ERR_ARG_INIT "Error al parsear info de argumento.\n"
#define CONECT_ERROR "Error de conexión con el servidor.\n"
#define INIT_ERROR "Error de inicialización del socket.\n"
#define DESTROY_ERR "Error al destruir el cliente.\n"
int main(int argc, char* argv[]) {
if (argc != 5) {
fprintf(stderr, ERR_ARG_NRO);
return -1;
}
arginfo_t arginfo;
client_t self;
if (!arginfo_init(&arginfo, argc, argv)) {
fprintf(stderr, ERR_ARG_INIT);
return -1;
} else if (client_init(&self) == -1) {
fprintf(stderr, INIT_ERROR);
return -1;
} else if (client_connect(&self, arginfo.port, arginfo.ip) == -1) {
fprintf(stderr, CONECT_ERROR);
return -1;
} else if (cipher_and_send(&self, arginfo.method,
(unsigned char*)arginfo.key) == -1) {
return -1;
} else if (client_destroy(&self) == -1) {
fprintf(stderr, DESTROY_ERR);
return -1;
}
client_destroy(&self);
return 0;
}