-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
79 lines (67 loc) · 2.33 KB
/
main.cpp
File metadata and controls
79 lines (67 loc) · 2.33 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//============================================================================
// ----------- PRACTICAS DE FUNDAMENTOS DE REDES Y COMUNICACIONES -----------
// ----------------------------- main.CPP ---------------------------------
//============================================================================
// AUTORES:
// Víctor Andrés Navareño Moza
// GRUPO 6 Prácticas - Miércoles 10:00 - 11:30
#include <stdio.h>
#include <iostream>
#include <fstream>
#include "linkLayer.h"
#include "seleccionInterfaz.h"
#include "enviarRecibir.h"
#include "paroYEspera.h"
#include "stdio_ext.h"
using namespace std;
// ejecuta el programa entero, llamando a métodos definidos en seleccionInterfaz.h
int main()
{
interface_t iface;
unsigned char mac_destino[6]; // Almacenará la mac que recibirá nuestros paquetes
unsigned char mac_src[6];
unsigned char type[2] = {0x30, 0x00};
// VARIABLES ENTREGA 3
int numeroGrupo; // almacenamos el numero de nuestro grupo aquí, lo introduce el usuario
int modoEstacion;
int modoEnvio;
imprimirSeleccionInterfaz();
usuarioIntroduceInterfaz();
iface = getInterfaz();
imprimirMac(iface);
numeroGrupo = SeleccionGrupo(type);
// abrir puerto
int puerto = OpenAdapter(&iface); // Puerto debe devolver 0 si no hay ningún problema al abrirse
if (puerto != 0)
{
cout << "Error al abrir el puerto" << endl;
}
else
{
cout << "Puerto abierto correctamente" << endl;
}
modoEstacion = SeleccionModoEstacion();
if (modoEstacion == 1)
{
cout << "Esperando a que se una la estación esclava..." << endl;
EnviarTramaMaestro(numeroGrupo, &iface, mac_destino);
cout << "Estación esclava encontrada. ";
ImprimirMacDestino(mac_destino);
}
else if (modoEstacion == 2)
{
cout << "Esperando a que se una la estación maestra..." << endl;
RecibirTramaEsclavo(numeroGrupo, &iface, mac_destino);
cout << "Estación maestra encontrada. ";
ImprimirMacDestino(mac_destino);
}
SeleccionModoEnvio(modoEstacion, numeroGrupo, &iface, mac_src, mac_destino, type);
// cerramos el puerto
if (CloseAdapter(&iface) == 0)
{
cout << "Puerto cerrado" << endl;
}
else
cout << " ### ERROR AL CERRAR EL PUERTO ### " << endl;
return 0;
}