-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkAccess.java
More file actions
47 lines (39 loc) · 1.34 KB
/
NetworkAccess.java
File metadata and controls
47 lines (39 loc) · 1.34 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
import java.io.*;
import java.util.*;
public class NetworkAccess implements Printable, Connexion{
private Map<String, String> details;
private final Map<String, String> TYPES = Collections.unmodifiableMap(new TreeMap<String, String>() {{
put("0800", "IPV4");
put("0806", "ARP");
}});
NetworkAccess(byte[] frame){
details = new LinkedHashMap<>();
details.put("Mac_dest", Utils.byteToMac(Arrays.copyOfRange(frame, 0, 6)));
details.put("Mac_source", Utils.byteToMac(Arrays.copyOfRange(frame, 6, 12)));
details.put("Type", TYPES.get(Utils.byteToHex(Arrays.copyOfRange(frame, 12, 14))));
}
public boolean equals(NetworkAccess networkAccess){
return this.details.get("Mac_dest").equals(networkAccess.getDetails().get("Mac_dest")) &&
this.details.get("Mac_source").equals(networkAccess.getDetails().get("Mac_source")) &&
this.details.get("Type").equals(networkAccess.getDetails().get("Type"));
}
public Map<String, String> getDetails(){
return this.details;
}
public String tinyPrint(){
return details.get("Mac_source") + " -> " + details.get("Mac_dest") +
" Type :" +details.get("Type");
}
public String detailPrint(){
return tinyPrint();
}
public String getSource(){
return details.get("Mac_source");
}
public String getDest(){
return details.get("Mac_dest");
}
public String getProtocol(){
return "ETHERNET";
}
}