diff options
Diffstat (limited to 'tools/idevicesetlocation.c')
-rw-r--r-- | tools/idevicesetlocation.c | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/tools/idevicesetlocation.c b/tools/idevicesetlocation.c index d2b8864..69fbaf5 100644 --- a/tools/idevicesetlocation.c +++ b/tools/idevicesetlocation.c @@ -21,6 +21,9 @@ #ifdef HAVE_CONFIG_H #include <config.h> #endif + +#define TOOL_NAME "idevicesetlocation" + #include <stdio.h> #include <stdlib.h> #include <stdint.h> @@ -48,32 +51,36 @@ static void print_usage(int argc, char **argv, int is_error) fprintf(is_error ? stderr : stdout, "Usage: %s [OPTIONS] -- <LAT> <LONG>\n", bname); fprintf(is_error ? stderr : stdout, " %s [OPTIONS] reset\n", bname); - fprintf(is_error ? stderr : stdout, "\n" \ - "OPTIONS:\n" \ - " -u, --udid UDID target specific device by UDID\n" \ - " -n, --network connect to network device even if available via USB\n" \ - " -h, --help prints usage information\n" \ - " -d, --debug enable communication debugging\n" \ - "\n" - "Homepage: <" PACKAGE_URL ">\n" + fprintf(is_error ? stderr : stdout, + "\n" + "OPTIONS:\n" + " -u, --udid UDID target specific device by UDID\n" + " -n, --network connect to network device\n" + " -d, --debug enable communication debugging\n" + " -h, --help prints usage information\n" + " -v, --version prints version information\n" + "\n" + "Homepage: <" PACKAGE_URL ">\n" + "Bug Reports: <" PACKAGE_BUGREPORT ">\n" ); } int main(int argc, char **argv) { + int c = 0; const struct option longopts[] = { - { "help", no_argument, NULL, 'h' }, - { "udid", required_argument, NULL, 'u' }, - { "debug", no_argument, NULL, 'd' }, - { "network", no_argument, NULL, 'n' }, + { "help", no_argument, NULL, 'h' }, + { "udid", required_argument, NULL, 'u' }, + { "debug", no_argument, NULL, 'd' }, + { "network", no_argument, NULL, 'n' }, + { "version", no_argument, NULL, 'v' }, { NULL, 0, NULL, 0} }; uint32_t mode = 0; - char *udid = NULL; - enum idevice_options lookup_opts = IDEVICE_LOOKUP_USBMUX | IDEVICE_LOOKUP_NETWORK; + const char *udid = NULL; + int use_network = 0; - int c = 0; - while ((c = getopt_long(argc, argv, "dhu:n", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "dhu:nv", longopts, NULL)) != -1) { switch (c) { case 'd': idevice_set_debug_level(1); @@ -84,15 +91,17 @@ int main(int argc, char **argv) print_usage(argc, argv, 1); return 2; } - free(udid); - udid = strdup(optarg); + udid = optarg; break; case 'n': - lookup_opts |= IDEVICE_LOOKUP_PREFER_NETWORK; + use_network = 1; break; case 'h': print_usage(argc, argv, 0); return 0; + case 'v': + printf("%s %s\n", TOOL_NAME, PACKAGE_VERSION); + return 0; default: print_usage(argc, argv, 1); return 2; @@ -120,7 +129,7 @@ int main(int argc, char **argv) idevice_t device = NULL; - if (idevice_new_with_options(&device, udid, lookup_opts) != IDEVICE_E_SUCCESS) { + if (idevice_new_with_options(&device, udid, (use_network) ? IDEVICE_LOOKUP_NETWORK : IDEVICE_LOOKUP_USBMUX) != IDEVICE_E_SUCCESS) { if (udid) { printf("ERROR: Device %s not found!\n", udid); } else { @@ -130,13 +139,14 @@ int main(int argc, char **argv) } lockdownd_client_t lockdown; - lockdownd_client_new_with_handshake(device, &lockdown, NULL); + lockdownd_client_new_with_handshake(device, &lockdown, TOOL_NAME); lockdownd_service_descriptor_t svc = NULL; - if (lockdownd_start_service(lockdown, DT_SIMULATELOCATION_SERVICE, &svc) != LOCKDOWN_E_SUCCESS) { + lockdownd_error_t lerr = lockdownd_start_service(lockdown, DT_SIMULATELOCATION_SERVICE, &svc); + if (lerr != LOCKDOWN_E_SUCCESS) { lockdownd_client_free(lockdown); idevice_free(device); - printf("ERROR: Could not start the simulatelocation service. Make sure a developer disk image is mounted!\n"); + printf("ERROR: Could not start the simulatelocation service: %s\nMake sure a developer disk image is mounted!\n", lockdownd_strerror(lerr)); return -1; } lockdownd_client_free(lockdown); @@ -175,7 +185,7 @@ int main(int argc, char **argv) s = 0; service_send(service, buf, len, &s); } - + idevice_free(device); return 0; |