Skip to content

Commit 4ef0098

Browse files
committed
STUN IP addresses
1 parent af9ec19 commit 4ef0098

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

src/inspectors/stun.tsx

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,63 @@ ATTRIBUTE_PARSERS.set(0x0001, {
2020
let family = value.bytes(1, 1);
2121
let port = value.bytes(2, 2);
2222

23-
// TODO: Actually decode the IP addresses.
24-
23+
let ipTree: Array<Tree> = [];
2524
let familyName = "UNKNOWN";
2625
switch (family.readUIntBE()) {
2726
case 1:
2827
familyName = "IPv4";
28+
29+
let ip = value.bytes(4, 4);
30+
// prettier-ignore
31+
let ipString = (ip.bytes(0, 1).readUIntBE()).toString() +
32+
"." + (ip.bytes(1, 1).readUIntBE()).toString() +
33+
"." + (ip.bytes(2, 1).readUIntBE()).toString() +
34+
"." + (ip.bytes(3, 1).readUIntBE()).toString();
35+
36+
ipTree = [new Tree(`IP: ${ipString}`, ip)];
2937
break;
3038
case 2:
3139
familyName = "IPv6";
40+
// TODO: Decode IPv6 address
3241
break;
3342
}
3443
return [
3544
new Tree(`Family: ${familyName} (0x${family.toHex()})`, family),
3645
new Tree(`Port: ${port.readUIntBE()}`, port)
37-
];
46+
].concat(ipTree);
47+
}
48+
});
49+
50+
ATTRIBUTE_PARSERS.set(0x0020, {
51+
name: "XOR-MAPPED-ADDRESS",
52+
parse: (value: ByteRange) => {
53+
let family = value.bytes(1, 1);
54+
let port = value.bytes(2, 2);
55+
56+
let ipTree: Array<Tree> = [];
57+
let familyName = "UNKNOWN";
58+
switch (family.readUIntBE()) {
59+
case 1:
60+
familyName = "IPv4";
61+
62+
let ip = value.bytes(4, 4);
63+
// prettier-ignore
64+
let ipString = (ip.bytes(0, 1).readUIntBE() ^ 0x21).toString() +
65+
"." + (ip.bytes(1, 1).readUIntBE() ^ 0x12).toString() +
66+
"." + (ip.bytes(2, 1).readUIntBE() ^ 0xa4).toString() +
67+
"." + (ip.bytes(3, 1).readUIntBE() ^ 0x42).toString();
68+
69+
ipTree = [new Tree(`IP: ${ipString}`, ip)];
70+
break;
71+
case 2:
72+
familyName = "IPv6";
73+
// TODO: Decode IPv6 address
74+
break;
75+
}
76+
return [
77+
new Tree(`Family: ${familyName} (0x${family.toHex()})`, family),
78+
new Tree(`Port: ${port.readUIntBE() ^ 0x2112}`, port)
79+
].concat(ipTree);
3880
}
3981
});
4082

0 commit comments

Comments
 (0)