diff --git a/src/core/operations/ParseIPv4Header.mjs b/src/core/operations/ParseIPv4Header.mjs
index 84351cdc..0a897c08 100644
--- a/src/core/operations/ParseIPv4Header.mjs
+++ b/src/core/operations/ParseIPv4Header.mjs
@@ -33,6 +33,12 @@ class ParseIPv4Header extends Operation {
"name": "Input format",
"type": "option",
"value": ["Hex", "Raw"]
+ },
+ {
+ "name": "Output format",
+ "type": "option",
+ "value": ["Table", "Data (hex)", "Data (raw)"],
+ defaultIndex: 0,
}
];
}
@@ -44,6 +50,8 @@ class ParseIPv4Header extends Operation {
*/
run(input, args) {
const format = args[0];
+ const outputFormat = args[1];
+
let output;
if (format === "Hex") {
@@ -98,7 +106,10 @@ class ParseIPv4Header extends Operation {
checksumResult = givenChecksum + " (incorrect, should be " + correctChecksum + ")";
}
- output = `
Field | Value |
+ const data = input.slice(ihl * 4);
+
+ if (outputFormat == "Table") {
+ output = `Field | Value |
Version | ${version} |
Internet Header Length (IHL) | ${ihl} (${ihl * 4} bytes) |
Differentiated Services Code Point (DSCP) | ${dscp} |
@@ -116,13 +127,19 @@ class ParseIPv4Header extends Operation {
Protocol | ${protocol}, ${protocolInfo.protocol} (${protocolInfo.keyword}) |
Header checksum | ${checksumResult} |
Source IP address | ${ipv4ToStr(srcIP)} |
-Destination IP address | ${ipv4ToStr(dstIP)} |
`;
+Destination IP address | ${ipv4ToStr(dstIP)} |
+Data (hex) | ${toHex(data)} |
`;
- if (ihl > 5) {
- output += `Options | ${toHex(options)} |
`;
+ if (ihl > 5) {
+ output += `Options | ${toHex(options)} |
`;
+ }
+
+ return output + "
";
+ } else if (outputFormat === "Data (hex)") {
+ return toHex(data);
+ } else if (outputFormat == "Data (raw)") {
+ return Utils.byteArrayToChars(data);
}
-
- return output + "
";
}
}