Skip to content

Commit 3817fe1

Browse files
authored
feat: enhance packet info with device identification (src - dest) (#243)
close #202
1 parent db5a70e commit 3817fe1

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/graphics/renderables/packet_info.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,41 @@ export class PacketInfo extends BaseInfo {
2929
const framePayload = this.packet.rawPacket.payload as IPv4Packet;
3030

3131
if (layer == Layer.Link) {
32+
const srcDevice = this.packet.viewgraph.getDeviceByMac(
33+
this.packet.rawPacket.source,
34+
);
35+
const dstDevice = this.packet.viewgraph.getDeviceByMac(
36+
this.packet.rawPacket.destination,
37+
);
38+
3239
this.information.addField(
3340
TOOLTIP_KEYS.SOURCE_MAC_ADDRESS,
34-
this.packet.rawPacket.source.toString(),
41+
`${this.packet.rawPacket.source.toString()}${srcDevice ? " (Device " + srcDevice.id + ")" : ""}`,
3542
TOOLTIP_KEYS.SOURCE_MAC_ADDRESS,
3643
);
3744
this.information.addField(
3845
TOOLTIP_KEYS.DESTINATION_MAC_ADDRESS,
39-
this.packet.rawPacket.destination.toString(),
46+
`${this.packet.rawPacket.destination.toString()}${dstDevice ? " (Device " + dstDevice.id + ")" : ""}`,
4047
TOOLTIP_KEYS.DESTINATION_MAC_ADDRESS,
4148
);
4249
}
4350

4451
if (layer >= Layer.Network) {
52+
const srcDevice = this.packet.viewgraph.getDeviceByIP(
53+
framePayload.sourceAddress,
54+
);
55+
const dstDevice = this.packet.viewgraph.getDeviceByIP(
56+
framePayload.destinationAddress,
57+
);
58+
4559
this.information.addField(
4660
TOOLTIP_KEYS.SOURCE_IP_ADDRESS,
47-
framePayload.sourceAddress.toString(),
61+
`${framePayload.sourceAddress.toString()}${srcDevice ? " (Device " + srcDevice.id + ")" : ""}`,
4862
TOOLTIP_KEYS.SOURCE_IP_ADDRESS,
4963
);
5064
this.information.addField(
5165
TOOLTIP_KEYS.DESTINATION_IP_ADDRESS,
52-
framePayload.destinationAddress.toString(),
66+
`${framePayload.destinationAddress.toString()}${dstDevice ? " (Device " + dstDevice.id + ")" : ""}`,
5367
TOOLTIP_KEYS.DESTINATION_IP_ADDRESS,
5468
);
5569
}

src/handlers/layerSelectorHandler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { layerToName } from "../types/layer";
44
import {
55
deselectElement,
66
isSelectedElementVisible,
7+
refreshElement,
78
saveToLocalStorage,
89
} from "../types/viewportManager";
910
import {
@@ -88,6 +89,8 @@ export class LayerHandler {
8889
this.leftBar.setButtonsByLayer(selectedLayer);
8990
if (!isSelectedElementVisible()) {
9091
deselectElement();
92+
} else {
93+
refreshElement();
9194
}
9295

9396
if (showAlert) {

src/types/graphs/viewgraph.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,14 @@ export class ViewGraph {
411411
return this.datagraph;
412412
}
413413

414+
// TODO: This should eventually be changed to use interfaces instead
414415
getDeviceByIP(ipAddress: IpAddress) {
415416
return this.getDevices().find((device) => {
416417
return device instanceof ViewNetworkDevice && device.ip.equals(ipAddress);
417418
});
418419
}
419420

421+
// TODO: This should eventually be changed to use interfaces instead
420422
getDeviceByMac(destination: MacAddress): ViewDevice {
421423
return this.getDevices().find((device) => {
422424
return device.mac.equals(destination);

0 commit comments

Comments
 (0)