Skip to content

Commit e82a8c3

Browse files
authored
fix: set payload type when constructing packet (#153)
This PR makes ICMP responses yellow again.
1 parent 68befa8 commit e82a8c3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/types/packet.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Layer } from "../types/devices/layer";
1414
//import { EchoMessage } from "../packets/icmp";
1515
import { DeviceId, isRouter, isSwitch } from "./graphs/datagraph";
1616
import { EthernetFrame } from "../packets/ethernet";
17+
import { IPv4Packet } from "../packets/ip";
1718

1819
const contextPerPacketType: Record<string, GraphicsContext> = {
1920
IP: circleGraphicsContext(Colors.Green, 0, 0, 5),
@@ -287,6 +288,14 @@ export function sendRawPacket(
287288
);
288289
return;
289290
}
290-
const packet = new Packet(viewgraph, "ICMP-8", srcId, dstId, rawPacket);
291+
let type;
292+
if (rawPacket.payload instanceof IPv4Packet) {
293+
const payload = rawPacket.payload as IPv4Packet;
294+
type = payload.payload.getPacketType();
295+
} else {
296+
console.warn("Packet is not IPv4");
297+
type = "ICMP-8";
298+
}
299+
const packet = new Packet(viewgraph, type, srcId, dstId, rawPacket);
291300
packet.traverseEdge(firstEdge, srcId);
292301
}

0 commit comments

Comments
 (0)