summaryrefslogtreecommitdiffstats
path: root/dev/iphone_id.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-05-19 13:15:11 +0200
committerGravatar Matt Colyer2009-05-19 07:30:34 -0700
commitb61667e9eae1a588815453ccdaa8721e228cc0b8 (patch)
tree7a14a6cb7af138abbca7be4bb822dda9df2dafb7 /dev/iphone_id.c
parent34b8e4d575876ace41b91fb6e25a5fa9f9290608 (diff)
downloadlibimobiledevice-b61667e9eae1a588815453ccdaa8721e228cc0b8.tar.gz
libimobiledevice-b61667e9eae1a588815453ccdaa8721e228cc0b8.tar.bz2
Adapted iphoneinfo and iphonesyslog to new API to allow device selection Added iphone_id tool to list devices attached and retrieve device name.
Signed-off-by: Matt Colyer <matt@colyer.name>
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 @@
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4#include <getopt.h>
5#include <libiphone/libiphone.h>
6#include <usbmuxd.h>
7
8static void usage()
9{
10 printf("usage: iphone_id <device_uuid>\n"
11 "\tdevice_uuid is the 40-digit hexadecimal UUID of the device\n"
12 "\tfor which the name should be retrieved.\n\n"
13 "usage: iphone_id -l\n"
14 "\tList all attached devices.\n");
15 exit(0);
16}
17
18int main(int argc, char **argv)
19{
20 iphone_device_t phone = NULL;
21 iphone_lckd_client_t control = NULL;
22 usbmuxd_scan_result *dev_list;
23 char *devname = NULL;
24 int ret = 0;
25 int c;
26 int i;
27 int opt_list = 0;
28
29 while ((c = getopt(argc, argv, "lh")) != -1) {
30 switch (c) {
31 case 'l':
32 opt_list = 1;
33 break;
34 case 'h':
35 default:
36 usage();
37 }
38 }
39
40 if (argc < 2) {
41 usage();
42 }
43
44 argc -= optind;
45 argv += optind;
46
47 if ((!opt_list) && (strlen(argv[0]) != 40)) {
48 usage();
49 }
50
51 if (opt_list) {
52 if (usbmuxd_scan(&dev_list) < 0) {
53 fprintf(stderr, "ERROR: usbmuxd is not running!\n");
54 return -1;
55 }
56 for (i = 0; dev_list[i].handle > 0; i++) {
57 printf("handle=%d product_id=%04x uuid=%s\n", dev_list[i].handle, dev_list[i].product_id, dev_list[i].serial_number);
58 }
59 return 0;
60 }
61
62 iphone_set_debug(0);
63
64 iphone_get_device_by_uuid(&phone, argv[0]);
65 if (!phone) {
66 fprintf(stderr, "ERROR: No device with UUID=%s attached.\n", argv[0]);
67 return -2;
68 }
69
70 if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) {
71 iphone_free_device(phone);
72 fprintf(stderr, "ERROR: Connecting to device failed!\n");
73 return -2;
74 }
75
76 if ((IPHONE_E_SUCCESS != lockdownd_get_device_name(control, &devname)) || !devname) {
77 fprintf(stderr, "ERROR: Could not get device name!\n");
78 ret = -2;
79 }
80
81 iphone_lckd_free_client(control);
82 iphone_free_device(phone);
83
84 if (ret == 0) {
85 printf("%s\n", devname);
86 }
87
88 if (devname) {
89 free(devname);
90 }
91
92 return ret;
93}