Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/vs/workbench/api/node/extHostTunnelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function loadListeningPorts(...stdouts: string[]): { socket: number; ip:
];
}

function parseIpAddress(hex: string): string {
export function parseIpAddress(hex: string): string {
let result = '';
if (hex.length === 8) {
for (let i = hex.length - 2; i >= 0; i -= 2) {
Expand All @@ -71,10 +71,21 @@ function parseIpAddress(hex: string): string {
}
}
} else {
for (let i = hex.length - 4; i >= 0; i -= 4) {
result += parseInt(hex.substr(i, 4), 16).toString(16);
if (i !== 0) {
result += ':';
// Nice explanation of host format in tcp6 file: https://serverfault.com/questions/592574/why-does-proc-net-tcp6-represents-1-as-1000
for (let i = 0; i < hex.length; i += 8) {
const word = hex.substring(i, i + 8);
let subWord = '';
for (let j = 8; j >= 2; j -= 2) {
subWord += word.substring(j - 2, j);
if ((j === 6) || (j === 2)) {
// Trim leading zeros
subWord = parseInt(subWord, 16).toString(16);
result += `${subWord}`;
subWord = '';
if (i + j !== hex.length - 6) {
result += ':';
}
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/vs/workbench/api/test/node/extHostTunnelService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
import { findPorts, getRootProcesses, getSockets, loadConnectionTable, loadListeningPorts, tryFindRootPorts } from 'vs/workbench/api/node/extHostTunnelService';
import { findPorts, getRootProcesses, getSockets, loadConnectionTable, loadListeningPorts, parseIpAddress, tryFindRootPorts } from 'vs/workbench/api/node/extHostTunnelService';

const tcp =
` sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
Expand Down Expand Up @@ -278,4 +278,9 @@ suite('ExtHostTunnelService', () => {
assert.strictEqual(result[0].port, 3002);
assert.strictEqual(result[0].detail, 'http-server');
});

test('parseIpAddress', function () {
assert.strictEqual(parseIpAddress('00000000000000000000000001000000'), '0:0:0:0:0:0:0:1');
assert.strictEqual(parseIpAddress('0000000000000000FFFF0000040510AC'), '0:0:0:0:0:ffff:ac10:504');
});
});