-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon_arginfo.h
More file actions
51 lines (44 loc) · 1.83 KB
/
common_arginfo.h
File metadata and controls
51 lines (44 loc) · 1.83 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
46
47
48
49
50
51
// Copyright [2020]<Jonathan David Rosenblatt>
#ifndef COMMON_ARGINFO_H_
#define COMMON_ARGINFO_H_
#include <getopt.h>
#define SIZE_OF_STRINGS 32
#define SIZE_OF_METHOD SIZE_OF_STRINGS
#define SIZE_OF_KEY SIZE_OF_STRINGS
#define SIZE_OF_PORT SIZE_OF_STRINGS
#define SIZE_OF_IP SIZE_OF_STRINGS
typedef struct arginfo {
char method[SIZE_OF_METHOD];
char key[SIZE_OF_KEY];
char port[SIZE_OF_PORT];
char ip[SIZE_OF_IP];
} arginfo_t;
/*
* Dado un struct arginfo y los datos recibidos por argumento, inicializa el
* mismo asignandole los datos correspondientes.
* Precondiciones: info != NULL && argc == 4 o 5 && argv != NULL.
* Postcondiciones: deja el struct inicializado en función de los datos
* ingresados. Devuelve 0 en caso de error, 1 de lo contrario.
*/
int arginfo_init(arginfo_t* info, int argc, char* argv[]);
/*
* Dado un struct arginfo y los datos recibidos por argumento, les asigna la ip
* y puerto al mismo.
* Precondiciones: info != NULL && argc == 4 o 5 && argv != NULL.
* Postcondiciones: deja los campos de ip y puertos inicializados. Si no le
* corresponde tener una ip por ser cliente, se dejará el primer byte con un 0.
*/
void getPortAndIp(arginfo_t* info, int argc, char* argv[]);
/*
* Dado un struct arginfo, los datos recibidos por argumento y un struct opcion
* que representa las opciones válidas, les asigna el método de encriptación y
* key al mismo.
* Precondiciones: info != NULL && validArgs != NULL && argv != NULL.
* Postcondiciones: deja los campos de method y key inicializados. Si todo
* sale bien las variables "hayMetodo" y "hayLlave" serán 1, y se devolverá un
* AND entre estos dos para verificar que ninguno es cero. Devuelve 0 en caso
* de error.
*/
int getMethodAndKey(arginfo_t* info, const struct option validArgs[], int argc,
char* argv[]);
#endif // COMMON_ARGINFO_H_