summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/idevicedebugserverproxy.13
-rw-r--r--tools/idevicedebugserverproxy.c26
2 files changed, 20 insertions, 9 deletions
diff --git a/docs/idevicedebugserverproxy.1 b/docs/idevicedebugserverproxy.1
index 37502eb..248c694 100644
--- a/docs/idevicedebugserverproxy.1
+++ b/docs/idevicedebugserverproxy.1
@@ -3,7 +3,7 @@
3idevicedebugserverproxy \- Remote debugging proxy. 3idevicedebugserverproxy \- Remote debugging proxy.
4.SH SYNOPSIS 4.SH SYNOPSIS
5.B idevicedebugserverproxy 5.B idevicedebugserverproxy
6[OPTIONS] PORT 6[OPTIONS] [PORT]
7 7
8.SH DESCRIPTION 8.SH DESCRIPTION
9 9
@@ -35,6 +35,7 @@ prints version information.
35.TP 35.TP
36.B PORT 36.B PORT
37The port under which the proxy should listen for connections from clients. 37The port under which the proxy should listen for connections from clients.
38If omitted, the next available port will be used and printed to stdout.
38 39
39.SH AUTHORS 40.SH AUTHORS
40Martin Szulecki 41Martin Szulecki
diff --git a/tools/idevicedebugserverproxy.c b/tools/idevicedebugserverproxy.c
index b190f63..79c2d38 100644
--- a/tools/idevicedebugserverproxy.c
+++ b/tools/idevicedebugserverproxy.c
@@ -44,6 +44,10 @@
44#include <libimobiledevice-glue/socket.h> 44#include <libimobiledevice-glue/socket.h>
45#include <libimobiledevice-glue/thread.h> 45#include <libimobiledevice-glue/thread.h>
46 46
47#ifndef ETIMEDOUT
48#define ETIMEDOUT 138
49#endif
50
47#define info(...) fprintf(stdout, __VA_ARGS__); fflush(stdout) 51#define info(...) fprintf(stdout, __VA_ARGS__); fflush(stdout)
48#define debug(...) if(debug_mode) fprintf(stdout, __VA_ARGS__) 52#define debug(...) if(debug_mode) fprintf(stdout, __VA_ARGS__)
49 53
@@ -76,9 +80,11 @@ static void print_usage(int argc, char **argv)
76 char *name = NULL; 80 char *name = NULL;
77 81
78 name = strrchr(argv[0], '/'); 82 name = strrchr(argv[0], '/');
79 printf("Usage: %s [OPTIONS] <PORT>\n", (name ? name + 1: argv[0])); 83 printf("Usage: %s [OPTIONS] [PORT]\n", (name ? name + 1: argv[0]));
80 printf("\n"); 84 printf("\n");
81 printf("Proxy debugserver connection from device to a local socket at PORT.\n"); 85 printf("Proxy debugserver connection from device to a local socket at PORT.\n");
86 printf("If PORT is omitted, the next available port will be used and printed\n");
87 printf("to stdout.\n");
82 printf("\n"); 88 printf("\n");
83 printf("OPTIONS:\n"); 89 printf("OPTIONS:\n");
84 printf(" -u, --udid UDID\ttarget specific device by UDID\n"); 90 printf(" -u, --udid UDID\ttarget specific device by UDID\n");
@@ -239,13 +245,6 @@ int main(int argc, char *argv[])
239 } 245 }
240 } 246 }
241 247
242 /* a PORT is mandatory */
243 if (!local_port) {
244 fprintf(stderr, "Please specify a PORT.\n");
245 print_usage(argc, argv);
246 goto leave_cleanup;
247 }
248
249 /* start services and connect to device */ 248 /* start services and connect to device */
250 ret = idevice_new_with_options(&device, udid, (use_network) ? IDEVICE_LOOKUP_NETWORK : IDEVICE_LOOKUP_USBMUX); 249 ret = idevice_new_with_options(&device, udid, (use_network) ? IDEVICE_LOOKUP_NETWORK : IDEVICE_LOOKUP_USBMUX);
251 if (ret != IDEVICE_E_SUCCESS) { 250 if (ret != IDEVICE_E_SUCCESS) {
@@ -266,6 +265,17 @@ int main(int argc, char *argv[])
266 goto leave_cleanup; 265 goto leave_cleanup;
267 } 266 }
268 267
268 if (local_port == 0) {
269 /* The user asked for any available port. Report the actual port. */
270 uint16_t port;
271 if (0 > socket_get_socket_port(server_fd, &port)) {
272 fprintf(stderr, "Could not determine socket port\n");
273 result = EXIT_FAILURE;
274 goto leave_cleanup;
275 }
276 printf("Listening on port %d\n", port);
277 }
278
269 while (!quit_flag) { 279 while (!quit_flag) {
270 debug("%s: Waiting for connection on local port %d\n", __func__, local_port); 280 debug("%s: Waiting for connection on local port %d\n", __func__, local_port);
271 281