Skip to content

Commit 0c22a77

Browse files
committed
Add ability to include port with IP address.
It is common to be able to specify a non-default port along with an IP address by using `addr:port` notation. This is useful in cases where port forwarding is needed. Fixes: #108
1 parent 74b988b commit 0c22a77

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to the "ev3dev-browser" extension will be documented in this
88
### Fixed
99
- Fixed Windows path separator in "program" in `.vscode/launch.json` not converted to UNIX path.
1010
- Fixed running files with `#!` and Windows line endings (CRLF vs. LF).
11+
- Fixed no way to specify port for user-specified IP address.
1112

1213
## v1.2.0 - 2020-07-20
1314
### Changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
},
109109
"ipAddress": {
110110
"type": "string",
111-
"pattern": "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
111+
"pattern": "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d{1,5})?"
112112
},
113113
"username": {
114114
"type": "string",
@@ -452,4 +452,4 @@
452452
"vscode-debugadapter": "^1.37.1",
453453
"zen-observable": "^0.5.2"
454454
}
455-
}
455+
}

src/device.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,15 @@ export class Device extends vscode.Disposable {
515515
const txt: dnssd.TxtRecords = {};
516516
txt['ev3dev.robot.user'] = device.username || 'robot';
517517
txt['ev3dev.robot.home'] = device.homeDirectory || `/home/${txt['ev3dev.robot.user']}`;
518+
519+
// device.ipAddress is validated, so this is safe
520+
const [address, port] = device.ipAddress.split(':');
521+
518522
return <dnssd.Service>{
519523
name: device.name,
520-
address: device.ipAddress,
524+
address,
521525
ipv: 'IPv4',
522-
port: 22,
526+
port: Number(port) || 22,
523527
service: 'sftp-ssh',
524528
transport: 'tcp',
525529
txt: txt
@@ -643,7 +647,7 @@ export class Device extends vscode.Disposable {
643647
prompt: "Enter the IP address of the device",
644648
placeHolder: 'Example: "192.168.137.3"',
645649
validateInput: (v) => {
646-
if (!/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v)) {
650+
if (!/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d{1,5})?$/.test(v)) {
647651
return 'Not a valid IP address';
648652
}
649653
return undefined;

0 commit comments

Comments
 (0)