Skip to content

Commit 5017369

Browse files
feat: Show ARP details (#244)
Closes #228 Now getDetails(layer: Layer) returns both Ethernet frame details and payload details when called at the Link layer, instead of only Ethernet details. This allows protocols like ARP to display their fields alongside Ethernet information. --------- Co-authored-by: Tomás Grüner <[email protected]>
1 parent 4b46a03 commit 5017369

File tree

6 files changed

+106
-5
lines changed

6 files changed

+106
-5
lines changed

src/graphics/renderables/packet_info.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export class PacketInfo extends BaseInfo {
115115
fields: Object.entries(packetDetails).map(([key, value]) => ({
116116
key: key,
117117
value: value,
118+
tooltip: key,
118119
})),
119120
toggleButtonText: {
120121
on: "Hide Packet Details",

src/packets/arp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export abstract class ArpPacket implements FramePayload {
9292
}
9393

9494
// eslint-disable-next-line
95-
getDetails(layer: number): Record<string, string | number | object> {
95+
getDetails(_layer: number): Record<string, string | number | object> {
9696
return {
9797
HTYPE: this.htype,
9898
PTYPE: this.ptype,

src/packets/ethernet.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,14 @@ export class EthernetFrame {
162162

163163
getDetails(layer: Layer) {
164164
if (layer == Layer.Link) {
165-
return {
166-
"Source MAC": this.source.toString(),
167-
"Destination MAC": this.destination.toString(),
165+
const ethernetDetails = {
168166
EtherType: this.type.toString(),
169167
};
168+
// Merge Ethernet details with payload details
169+
return {
170+
...ethernetDetails,
171+
...this.payload.getDetails(layer),
172+
};
170173
} else {
171174
return this.payload.getDetails(layer);
172175
}

src/packets/icmp.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Layer } from "../types/layer";
12
import {
23
ICMP_PROTOCOL_NUMBER,
34
IpPayload,
@@ -63,6 +64,11 @@ export abstract class IcmpPacket implements IpPayload {
6364
getPorts(): Ports {
6465
return null;
6566
}
67+
68+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
69+
getDetails(layer: Layer) {
70+
return {};
71+
}
6672
}
6773

6874
// 0 1 2 3

src/packets/ip.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export interface IpPayload {
139139
// Packet protocol name
140140
getPacketType(): string;
141141
// Get details of the payload
142-
getDetails?(layer: Layer): Record<string, string | number | object>;
142+
getDetails(layer: Layer): Record<string, string | number | object>;
143143
// Get ports of the payload (if any)
144144
getPorts(): Ports;
145145
// Get the payload data for Network layer

src/utils/constants/tooltips_constants.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,39 @@ export const TOOLTIP_KEYS = {
7171
PORT: "Port",
7272
SWITCHING_TABLE: "Switching Table",
7373
MULTI_EDGE_CONNECTED_DEVICES: "Multi Edge Connected Devices",
74+
ETHERTYPE: "EtherType",
75+
// ARP Details
76+
HTYPE: "Hardware Type",
77+
PTYPE: "Protocol Type",
78+
HLEN: "Hardware address Length",
79+
PLEN: "Protocol address Length",
80+
OP: "Operation code",
81+
SHA: "Sender Hardware Address",
82+
SPA: "Sender Protocol Address",
83+
THA: "Target Hardware Address",
84+
TPA: "Target Protocol Address",
85+
// TCP Details
86+
SEQ: "Seq Number",
87+
ACK: "Ack Number",
88+
WINDOW: "Window Size",
89+
// TCP Flags
90+
URG_FLAG: "Urg",
91+
ACK_FLAG: "Ack",
92+
PSH_FLAG: "Psh",
93+
RST_FLAG: "Rst",
94+
SYN_FLAG: "Syn",
95+
FIN_FLAG: "Fin",
96+
// IPV4 details
97+
VERSION: "Version",
98+
INTERNET_HEADER_LENGTH: "Internet Header Length",
99+
TYPE_OF_SERVICE: "Type of Service",
100+
TOTAL_LENGTH: "Total Length",
101+
IDENTIFICATION: "Identification",
102+
FRAGMENT_OFFSET: "Fragment Offset",
103+
TIME_TO_LIVE: "Time to Live",
104+
PROTOCOL: "Protocol",
105+
HEADER_CHECKSUM: "Header Checksum",
106+
PAYLOAD: "Payload",
74107
} as const;
75108

76109
// Tooltip Content
@@ -203,4 +236,62 @@ export const TOOLTIP_CONTENT = {
203236
"Send an ARP request to a specified IP address. This command is used to resolve the MAC address of a device in the same local network.",
204237
[TOOLTIP_KEYS.SERVE_HTTP_REQUESTS]:
205238
"Serve HTTP requests to clients. This command is used to respond to incoming HTTP requests with the appropriate data.",
239+
[TOOLTIP_KEYS.HTYPE]:
240+
"Hardware type. Specifies the type of hardware used for the network (e.g., 1 for Ethernet).",
241+
[TOOLTIP_KEYS.PTYPE]:
242+
"Protocol type. Specifies the protocol address type (e.g., 0x0800 for IPv4).",
243+
[TOOLTIP_KEYS.HLEN]:
244+
"Hardware address length. Indicates the length in bytes of a hardware address (e.g., 6 for MAC).",
245+
[TOOLTIP_KEYS.PLEN]:
246+
"Protocol address length. Indicates the length in bytes of a protocol address (e.g., 4 for IPv4).",
247+
[TOOLTIP_KEYS.OP]:
248+
"Operation code. Specifies the ARP operation: 1 for request, 2 for reply.",
249+
[TOOLTIP_KEYS.SHA]:
250+
"Sender hardware address (MAC). The MAC address of the sender.",
251+
[TOOLTIP_KEYS.SPA]:
252+
"Sender protocol address (IP). The IP address of the sender.",
253+
[TOOLTIP_KEYS.THA]:
254+
"Target hardware address (MAC). The MAC address of the target.",
255+
[TOOLTIP_KEYS.TPA]:
256+
"Target protocol address (IP). The IP address of the target.",
257+
[TOOLTIP_KEYS.ETHERTYPE]:
258+
"EtherType field. Specifies the protocol encapsulated in the payload of the frame.",
259+
[TOOLTIP_KEYS.SEQ]:
260+
"Sequence number. Used to identify the order of packets in a TCP stream.",
261+
[TOOLTIP_KEYS.ACK]:
262+
"Acknowledgment number. Used to confirm the receipt of packets in a TCP stream.",
263+
[TOOLTIP_KEYS.WINDOW]:
264+
"Window size. Indicates the amount of data that can be sent before receiving an acknowledgment.",
265+
[TOOLTIP_KEYS.URG_FLAG]:
266+
"Urgent flag. Indicates that the packet contains urgent data.",
267+
[TOOLTIP_KEYS.ACK_FLAG]:
268+
"Acknowledgment flag. Indicates that the acknowledgment number is valid.",
269+
[TOOLTIP_KEYS.PSH_FLAG]:
270+
"Push flag. Indicates that the receiver should pass the data to the application immediately.",
271+
[TOOLTIP_KEYS.RST_FLAG]:
272+
"Reset flag. Indicates that the connection should be reset.",
273+
[TOOLTIP_KEYS.SYN_FLAG]:
274+
"Synchronize flag. Used to initiate a TCP connection.",
275+
[TOOLTIP_KEYS.FIN_FLAG]:
276+
"Finish flag. Indicates that the sender has finished sending data and wants to close the connection.",
277+
[TOOLTIP_KEYS.VERSION]:
278+
"The version of the IP protocol. For IPv4, this value is always 4.",
279+
[TOOLTIP_KEYS.INTERNET_HEADER_LENGTH]:
280+
"The length of the IP header in 32-bit words. The minimum value is 5 (20 bytes), indicating no options are present.",
281+
[TOOLTIP_KEYS.TYPE_OF_SERVICE]:
282+
"Specifies the quality of service desired for this packet, such as precedence, delay, throughput, and reliability.",
283+
[TOOLTIP_KEYS.TOTAL_LENGTH]:
284+
"The total length of the IP packet, including both header and data, in bytes.",
285+
[TOOLTIP_KEYS.IDENTIFICATION]:
286+
"An identifying value assigned by the sender to aid in assembling the fragments of a datagram.",
287+
[TOOLTIP_KEYS.FRAGMENT_OFFSET]:
288+
"Indicates where in the datagram this fragment belongs. Used for reassembling fragmented packets.",
289+
[TOOLTIP_KEYS.TIME_TO_LIVE]:
290+
"The maximum number of hops (routers) the packet can pass through before being discarded. Prevents infinite loops.",
291+
[TOOLTIP_KEYS.PROTOCOL]:
292+
"Indicates the protocol used in the data portion of the IP datagram (e.g., TCP, UDP, ICMP).",
293+
[TOOLTIP_KEYS.HEADER_CHECKSUM]:
294+
"A checksum on the header only, used for error-checking of the header.",
295+
[TOOLTIP_KEYS.PAYLOAD]:
296+
"The encapsulated data carried by the IP packet. This could be a TCP segment, UDP datagram, or other protocol data.",
206297
} as const;

0 commit comments

Comments
 (0)