Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
f56be59a0c | |||
64400c8740 | |||
46f7cd31b9 | |||
d290b44248 |
37
README.md
37
README.md
@ -412,12 +412,47 @@ autoadb scrcpy -s '{}'
|
|||||||
|
|
||||||
[AutoAdb]: https://github.com/rom1v/autoadb
|
[AutoAdb]: https://github.com/rom1v/autoadb
|
||||||
|
|
||||||
#### SSH tunnel
|
#### Tunnels
|
||||||
|
|
||||||
To connect to a remote device, it is possible to connect a local `adb` client to
|
To connect to a remote device, it is possible to connect a local `adb` client to
|
||||||
a remote `adb` server (provided they use the same version of the _adb_
|
a remote `adb` server (provided they use the same version of the _adb_
|
||||||
protocol).
|
protocol).
|
||||||
|
|
||||||
|
##### Remote ADB server
|
||||||
|
|
||||||
|
To connect to a remote ADB server, make the server listen on all interfaces:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
adb kill-server
|
||||||
|
adb -a nodaemon server start
|
||||||
|
# keep this open
|
||||||
|
```
|
||||||
|
|
||||||
|
**Warning: all communications between clients and ADB server are unencrypted.**
|
||||||
|
|
||||||
|
Suppose that this server is accessible at 192.168.1.2. Then, from another
|
||||||
|
terminal, run scrcpy:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export ADB_SERVER_SOCKET=tcp:192.168.1.2:5037
|
||||||
|
scrcpy --tunnel-host=192.168.1.2
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, scrcpy uses the local port used for `adb forward` tunnel
|
||||||
|
establishment (typically `27183`, see `--port`). It is also possible to force a
|
||||||
|
different tunnel port (it may be useful in more complex situations, when more
|
||||||
|
redirections are involved):
|
||||||
|
|
||||||
|
```
|
||||||
|
scrcpy --tunnel-port=1234
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
##### SSH tunnel
|
||||||
|
|
||||||
|
To communicate with a remote ADB server securely, it is preferable to use a SSH
|
||||||
|
tunnel.
|
||||||
|
|
||||||
First, make sure the ADB server is running on the remote computer:
|
First, make sure the ADB server is running on the remote computer:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -199,6 +199,7 @@ if get_option('buildtype') == 'debug'
|
|||||||
'tests/test_cli.c',
|
'tests/test_cli.c',
|
||||||
'src/cli.c',
|
'src/cli.c',
|
||||||
'src/options.c',
|
'src/options.c',
|
||||||
|
'src/util/net.c',
|
||||||
'src/util/str.c',
|
'src/util/str.c',
|
||||||
'src/util/strbuf.c',
|
'src/util/strbuf.c',
|
||||||
'src/util/term.c',
|
'src/util/term.c',
|
||||||
|
12
app/scrcpy.1
12
app/scrcpy.1
@ -203,6 +203,18 @@ Enable "show touches" on start, restore the initial value on exit.
|
|||||||
|
|
||||||
It only shows physical touches (not clicks from scrcpy).
|
It only shows physical touches (not clicks from scrcpy).
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BI "\-\-tunnel\-host " ip
|
||||||
|
Set the IP address of the adb tunnel to reach the scrcpy server. This option automatically enables --force-adb-forward.
|
||||||
|
|
||||||
|
Default is localhost.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BI "\-\-tunnel\-port " port
|
||||||
|
Set the TCP port of the adb tunnel to reach the scrcpy server. This option automatically enables --force-adb-forward.
|
||||||
|
|
||||||
|
Default is 0 (not forced): the local port used for establishing the tunnel will be used.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-v4l2-sink " /dev/videoN
|
.BI "\-\-v4l2-sink " /dev/videoN
|
||||||
Output to v4l2loopback device.
|
Output to v4l2loopback device.
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
|
#include "util/net.h"
|
||||||
#include "util/str.h"
|
#include "util/str.h"
|
||||||
#include "util/strbuf.h"
|
#include "util/strbuf.h"
|
||||||
#include "util/term.h"
|
#include "util/term.h"
|
||||||
@ -46,6 +47,8 @@
|
|||||||
#define OPT_V4L2_SINK 1027
|
#define OPT_V4L2_SINK 1027
|
||||||
#define OPT_DISPLAY_BUFFER 1028
|
#define OPT_DISPLAY_BUFFER 1028
|
||||||
#define OPT_V4L2_BUFFER 1029
|
#define OPT_V4L2_BUFFER 1029
|
||||||
|
#define OPT_TUNNEL_HOST 1030
|
||||||
|
#define OPT_TUNNEL_PORT 1031
|
||||||
|
|
||||||
struct sc_option {
|
struct sc_option {
|
||||||
char shortopt;
|
char shortopt;
|
||||||
@ -330,6 +333,25 @@ static const struct sc_option options[] = {
|
|||||||
"on exit.\n"
|
"on exit.\n"
|
||||||
"It only shows physical touches (not clicks from scrcpy).",
|
"It only shows physical touches (not clicks from scrcpy).",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.longopt_id = OPT_TUNNEL_HOST,
|
||||||
|
.longopt = "tunnel-host",
|
||||||
|
.argdesc = "ip",
|
||||||
|
.text = "Set the IP address of the adb tunnel to reach the scrcpy "
|
||||||
|
"server. This option automatically enables "
|
||||||
|
"--force-adb-forward.\n"
|
||||||
|
"Default is localhost.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.longopt_id = OPT_TUNNEL_PORT,
|
||||||
|
.longopt = "tunnel-port",
|
||||||
|
.argdesc = "port",
|
||||||
|
.text = "Set the TCP port of the adb tunnel to reach the scrcpy "
|
||||||
|
"server. This option automatically enables "
|
||||||
|
"--force-adb-forward.\n"
|
||||||
|
"Default is 0 (not forced): the local port used for "
|
||||||
|
"establishing the tunnel will be used.",
|
||||||
|
},
|
||||||
#ifdef HAVE_V4L2
|
#ifdef HAVE_V4L2
|
||||||
{
|
{
|
||||||
.longopt_id = OPT_V4L2_SINK,
|
.longopt_id = OPT_V4L2_SINK,
|
||||||
@ -1127,6 +1149,21 @@ parse_record_format(const char *optarg, enum sc_record_format *format) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
parse_ip(const char *optarg, uint32_t *ipv4) {
|
||||||
|
return net_parse_ipv4(optarg, ipv4);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
parse_port(const char *optarg, uint16_t *port) {
|
||||||
|
long value;
|
||||||
|
if (!parse_integer_arg(optarg, &value, false, 0, 0xFFFF, "port")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*port = (uint16_t) value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static enum sc_record_format
|
static enum sc_record_format
|
||||||
guess_record_format(const char *filename) {
|
guess_record_format(const char *filename) {
|
||||||
size_t len = strlen(filename);
|
size_t len = strlen(filename);
|
||||||
@ -1199,6 +1236,16 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case OPT_TUNNEL_HOST:
|
||||||
|
if (!parse_ip(optarg, &opts->tunnel_host)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OPT_TUNNEL_PORT:
|
||||||
|
if (!parse_port(optarg, &opts->tunnel_port)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
opts->control = false;
|
opts->control = false;
|
||||||
break;
|
break;
|
||||||
@ -1358,6 +1405,12 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if ((opts->tunnel_host || opts->tunnel_port) && !opts->force_adb_forward) {
|
||||||
|
LOGI("Tunnel host/port is set, "
|
||||||
|
"--force-adb-forward automatically enabled.");
|
||||||
|
opts->force_adb_forward = true;
|
||||||
|
}
|
||||||
|
|
||||||
int index = optind;
|
int index = optind;
|
||||||
if (index < argc) {
|
if (index < argc) {
|
||||||
LOGE("Unexpected additional argument: %s", argv[index]);
|
LOGE("Unexpected additional argument: %s", argv[index]);
|
||||||
|
@ -19,6 +19,8 @@ const struct scrcpy_options scrcpy_options_default = {
|
|||||||
.first = DEFAULT_LOCAL_PORT_RANGE_FIRST,
|
.first = DEFAULT_LOCAL_PORT_RANGE_FIRST,
|
||||||
.last = DEFAULT_LOCAL_PORT_RANGE_LAST,
|
.last = DEFAULT_LOCAL_PORT_RANGE_LAST,
|
||||||
},
|
},
|
||||||
|
.tunnel_host = 0,
|
||||||
|
.tunnel_port = 0,
|
||||||
.shortcut_mods = {
|
.shortcut_mods = {
|
||||||
.data = {SC_MOD_LALT, SC_MOD_LSUPER},
|
.data = {SC_MOD_LALT, SC_MOD_LSUPER},
|
||||||
.count = 2,
|
.count = 2,
|
||||||
|
@ -77,6 +77,8 @@ struct scrcpy_options {
|
|||||||
enum sc_record_format record_format;
|
enum sc_record_format record_format;
|
||||||
enum sc_keyboard_input_mode keyboard_input_mode;
|
enum sc_keyboard_input_mode keyboard_input_mode;
|
||||||
struct sc_port_range port_range;
|
struct sc_port_range port_range;
|
||||||
|
uint32_t tunnel_host;
|
||||||
|
uint16_t tunnel_port;
|
||||||
struct sc_shortcut_mods shortcut_mods;
|
struct sc_shortcut_mods shortcut_mods;
|
||||||
uint16_t max_size;
|
uint16_t max_size;
|
||||||
uint32_t bit_rate;
|
uint32_t bit_rate;
|
||||||
|
@ -345,6 +345,8 @@ scrcpy(struct scrcpy_options *options) {
|
|||||||
.log_level = options->log_level,
|
.log_level = options->log_level,
|
||||||
.crop = options->crop,
|
.crop = options->crop,
|
||||||
.port_range = options->port_range,
|
.port_range = options->port_range,
|
||||||
|
.tunnel_host = options->tunnel_host,
|
||||||
|
.tunnel_port = options->tunnel_port,
|
||||||
.max_size = options->max_size,
|
.max_size = options->max_size,
|
||||||
.bit_rate = options->bit_rate,
|
.bit_rate = options->bit_rate,
|
||||||
.max_fps = options->max_fps,
|
.max_fps = options->max_fps,
|
||||||
|
@ -202,8 +202,9 @@ execute_server(struct sc_server *server,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
connect_and_read_byte(struct sc_intr *intr, sc_socket socket, uint16_t port) {
|
connect_and_read_byte(struct sc_intr *intr, sc_socket socket,
|
||||||
bool ok = net_connect_intr(intr, socket, IPV4_LOCALHOST, port);
|
uint32_t tunnel_host, uint16_t tunnel_port) {
|
||||||
|
bool ok = net_connect_intr(intr, socket, tunnel_host, tunnel_port);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -220,13 +221,13 @@ connect_and_read_byte(struct sc_intr *intr, sc_socket socket, uint16_t port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static sc_socket
|
static sc_socket
|
||||||
connect_to_server(struct sc_server *server, uint32_t attempts, sc_tick delay) {
|
connect_to_server(struct sc_server *server, uint32_t attempts, sc_tick delay,
|
||||||
uint16_t port = server->tunnel.local_port;
|
uint32_t host, uint16_t port) {
|
||||||
do {
|
do {
|
||||||
LOGD("Remaining connection attempts: %d", (int) attempts);
|
LOGD("Remaining connection attempts: %d", (int) attempts);
|
||||||
sc_socket socket = net_socket();
|
sc_socket socket = net_socket();
|
||||||
if (socket != SC_SOCKET_NONE) {
|
if (socket != SC_SOCKET_NONE) {
|
||||||
bool ok = connect_and_read_byte(&server->intr, socket, port);
|
bool ok = connect_and_read_byte(&server->intr, socket, host, port);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
// it worked!
|
// it worked!
|
||||||
return socket;
|
return socket;
|
||||||
@ -352,9 +353,20 @@ sc_server_connect_to(struct sc_server *server, struct sc_server_info *info) {
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
uint32_t tunnel_host = server->params.tunnel_host;
|
||||||
|
if (!tunnel_host) {
|
||||||
|
tunnel_host = IPV4_LOCALHOST;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t tunnel_port = server->params.tunnel_port;
|
||||||
|
if (!tunnel_port) {
|
||||||
|
tunnel_port = tunnel->local_port;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t attempts = 100;
|
uint32_t attempts = 100;
|
||||||
sc_tick delay = SC_TICK_FROM_MS(100);
|
sc_tick delay = SC_TICK_FROM_MS(100);
|
||||||
video_socket = connect_to_server(server, attempts, delay);
|
video_socket = connect_to_server(server, attempts, delay, tunnel_host,
|
||||||
|
tunnel_port);
|
||||||
if (video_socket == SC_SOCKET_NONE) {
|
if (video_socket == SC_SOCKET_NONE) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@ -364,8 +376,8 @@ sc_server_connect_to(struct sc_server *server, struct sc_server_info *info) {
|
|||||||
if (control_socket == SC_SOCKET_NONE) {
|
if (control_socket == SC_SOCKET_NONE) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
bool ok = net_connect_intr(&server->intr, control_socket,
|
bool ok = net_connect_intr(&server->intr, control_socket, tunnel_host,
|
||||||
IPV4_LOCALHOST, tunnel->local_port);
|
tunnel_port);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ struct sc_server_params {
|
|||||||
const char *codec_options;
|
const char *codec_options;
|
||||||
const char *encoder_name;
|
const char *encoder_name;
|
||||||
struct sc_port_range port_range;
|
struct sc_port_range port_range;
|
||||||
|
uint32_t tunnel_host;
|
||||||
|
uint16_t tunnel_port;
|
||||||
uint16_t max_size;
|
uint16_t max_size;
|
||||||
uint32_t bit_rate;
|
uint32_t bit_rate;
|
||||||
uint16_t max_fps;
|
uint16_t max_fps;
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
// For inet_pton() on Windows
|
||||||
|
#define _WIN32_WINNT 0x0600
|
||||||
|
#define WINVER 0x0600
|
||||||
|
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -7,6 +11,7 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
# include <ws2tcpip.h>
|
||||||
typedef int socklen_t;
|
typedef int socklen_t;
|
||||||
typedef SOCKET sc_raw_socket;
|
typedef SOCKET sc_raw_socket;
|
||||||
#else
|
#else
|
||||||
@ -225,3 +230,15 @@ net_close(sc_socket socket) {
|
|||||||
return !close(raw_sock);
|
return !close(raw_sock);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
net_parse_ipv4(const char *s, uint32_t *ipv4) {
|
||||||
|
struct in_addr addr;
|
||||||
|
if (!inet_pton(AF_INET, s, &addr)) {
|
||||||
|
LOGE("Invalid IPv4 address: %s", s);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ipv4 = ntohl(addr.s_addr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -68,4 +68,10 @@ net_interrupt(sc_socket socket);
|
|||||||
bool
|
bool
|
||||||
net_close(sc_socket socket);
|
net_close(sc_socket socket);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse `ip` "xxx.xxx.xxx.xxx" to an IPv4 host representation
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
net_parse_ipv4(const char *ip, uint32_t *ipv4);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user