-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface.cpp
More file actions
50 lines (42 loc) · 1.38 KB
/
Interface.cpp
File metadata and controls
50 lines (42 loc) · 1.38 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
#include "Interface.hpp"
#include "Link.hpp"
#include "Machines/IP_Machine.hpp"
// Méthode statique
void Basic_Interface::connect(Basic_Interface& i1, Basic_Interface& i2) noexcept {
Link* link = new Link(i1, i2);
i1.set_link(link);
i2.set_link(link);
};
bool Basic_Interface::send(Packet& P){
// Ne peut envoyer que des paquets Ethernet (couche 1)
if (is_linked()) {
if (P.type == Packet::Type::ETHERNET) {
_linked_to->forward(P, *this);
return true;
}
DEBUG("Impossible d'envoyer un paquet incomplet sur le réseau")
return false;
}
return false;
};
bool Basic_Interface::receipt(Packet& P) {
// DEBUG("L'interface recoit un paquet depuis le lien")
// Ne peut recevoir que des paquets Ethernet (couche 1)
if (is_linked()) {
if (P.type == Packet::Type::ETHERNET) {
_connected->receipt(P, _interface);
return true;
}
DEBUG("Impossible d'envoyer un paquet incomplet sur le réseau")
return false;
}
return false;
};
// Méthodes
IP_Machine* Interface::get_machine() {
return dynamic_cast<IP_Machine*>(_connected);
}
std::ostream& operator<< (std::ostream& o, const Interface& I){
o << IP_Machine::IPv42char(I._ip) << "/" << I._cidr << IP_Machine::MAC2char(I._mac) << "connecte à " << I._connected->get_label();
return o;
};