Allow selecting a device from IP without port
Since the previous commit, if a serial is given via -s/--serial (either a real USB serial or an IP:port), a device is selected if its serial matches exactly. In addition, if the user pass an IP without a port, then select any device with this IP, regardless of the port (so that "192.168.1.1" matches any "192.168.1.1:port"). This is also the default behavior of adb. PR #3005 <https://github.com/Genymobile/scrcpy/pull/3005>
This commit is contained in:
parent
4692d13179
commit
0a619dc9ef
1 changed files with 18 additions and 0 deletions
|
@ -421,6 +421,24 @@ sc_adb_accept_device(const struct sc_adb_device *device, const char *serial) {
|
|||
return true;
|
||||
}
|
||||
|
||||
char *device_serial_colon = strchr(device->serial, ':');
|
||||
if (device_serial_colon) {
|
||||
// The device serial is an IP:port...
|
||||
char *serial_colon = strchr(serial, ':');
|
||||
if (!serial_colon) {
|
||||
// But the requested serial has no ':', so only consider the IP part
|
||||
// of the device serial. This allows to use "192.168.1.1" to match
|
||||
// any "192.168.1.1:port".
|
||||
size_t serial_len = strlen(serial);
|
||||
size_t device_ip_len = device_serial_colon - device->serial;
|
||||
if (serial_len != device_ip_len) {
|
||||
// They are not equal, they don't even have the same length
|
||||
return false;
|
||||
}
|
||||
return !strncmp(serial, device->serial, device_ip_len);
|
||||
}
|
||||
}
|
||||
|
||||
return !strcmp(serial, device->serial);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue