summaryrefslogtreecommitdiffstats
path: root/dev/iphone_id.c
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2009-05-24 00:25:03 +0200
committerGravatar Martin Szulecki2009-05-24 00:25:03 +0200
commit36ea32e0064f33d6a285684c3069f4d75bbac7a8 (patch)
tree039291b47e954fe8529f52e1fc71f7e924761a6a /dev/iphone_id.c
parent46f8d46845355e6a33a6dcb97ba11d4c4cab62eb (diff)
parent435f5feb4b5c501db52743a170908687d3ba6f60 (diff)
downloadlibimobiledevice-36ea32e0064f33d6a285684c3069f4d75bbac7a8.tar.gz
libimobiledevice-36ea32e0064f33d6a285684c3069f4d75bbac7a8.tar.bz2
Merge branch 'master' of git://github.com/MattColyer/libiphone into martin
Conflicts: src/Makefile.am
Diffstat (limited to 'dev/iphone_id.c')
-rw-r--r--dev/iphone_id.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/dev/iphone_id.c b/dev/iphone_id.c
new file mode 100644
index 0000000..c191608
--- /dev/null
+++ b/dev/iphone_id.c
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <libiphone/libiphone.h>
+#include <usbmuxd.h>
+
+static void usage()
+{
+ printf("usage: iphone_id <device_uuid>\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;
+ iphone_lckd_client_t control = 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(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 (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) {
+ iphone_free_device(phone);
+ fprintf(stderr, "ERROR: Connecting to device failed!\n");
+ return -2;
+ }
+
+ if ((IPHONE_E_SUCCESS != lockdownd_get_device_name(control, &devname)) || !devname) {
+ fprintf(stderr, "ERROR: Could not get device name!\n");
+ ret = -2;
+ }
+
+ iphone_lckd_free_client(control);
+ iphone_free_device(phone);
+
+ if (ret == 0) {
+ printf("%s\n", devname);
+ }
+
+ if (devname) {
+ free(devname);
+ }
+
+ return ret;
+}