From d089bc54e88d7fa70be9f0c228403c6d02248b52 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Tue, 28 Jul 2009 10:58:50 +0200 Subject: Move production ready tools into tools/ and do not install the dev/ ones --- tools/iphone_id.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 tools/iphone_id.c (limited to 'tools/iphone_id.c') diff --git a/tools/iphone_id.c b/tools/iphone_id.c new file mode 100644 index 0000000..f68fc8b --- /dev/null +++ b/tools/iphone_id.c @@ -0,0 +1,94 @@ +#include +#include +#include +#include +#include +#include +#include + +static void usage() +{ + printf("usage: iphone_id \n" + "\tdevice_uuid is the 40-digit hexadecimal UUID of the device\n" + "\tfor which the name should be retrieved.\n\n" + "usage: iphone_id -l\n" + "\tList all attached devices.\n"); + exit(0); +} + +int main(int argc, char **argv) +{ + iphone_device_t phone = NULL; + lockdownd_client_t client = NULL; + usbmuxd_scan_result *dev_list; + char *devname = NULL; + int ret = 0; + int c; + int i; + int opt_list = 0; + + while ((c = getopt(argc, argv, "lh")) != -1) { + switch (c) { + case 'l': + opt_list = 1; + break; + case 'h': + default: + usage(); + } + } + + if (argc < 2) { + usage(); + } + + argc -= optind; + argv += optind; + + if ((!opt_list) && (strlen(argv[0]) != 40)) { + usage(); + } + + if (opt_list) { + if (usbmuxd_scan(&dev_list) < 0) { + fprintf(stderr, "ERROR: usbmuxd is not running!\n"); + return -1; + } + for (i = 0; dev_list[i].handle > 0; i++) { + printf("handle=%d product_id=%04x uuid=%s\n", dev_list[i].handle, dev_list[i].product_id, dev_list[i].serial_number); + } + return 0; + } + + iphone_set_debug_level(0); + + iphone_get_device_by_uuid(&phone, argv[0]); + if (!phone) { + fprintf(stderr, "ERROR: No device with UUID=%s attached.\n", argv[0]); + return -2; + } + + if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { + iphone_device_free(phone); + fprintf(stderr, "ERROR: Connecting to device failed!\n"); + return -2; + } + + if ((LOCKDOWN_E_SUCCESS != lockdownd_get_device_name(client, &devname)) || !devname) { + fprintf(stderr, "ERROR: Could not get device name!\n"); + ret = -2; + } + + lockdownd_client_free(client); + iphone_device_free(phone); + + if (ret == 0) { + printf("%s\n", devname); + } + + if (devname) { + free(devname); + } + + return ret; +} -- cgit v1.1-32-gdbae