summaryrefslogtreecommitdiffstats
path: root/tools/idevice_id.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/idevice_id.c')
-rw-r--r--tools/idevice_id.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/tools/idevice_id.c b/tools/idevice_id.c
new file mode 100644
index 0000000..1facb60
--- /dev/null
+++ b/tools/idevice_id.c
@@ -0,0 +1,107 @@
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4#include <libimobiledevice/libimobiledevice.h>
5#include <libimobiledevice/lockdown.h>
6
7#define MODE_NONE 0
8#define MODE_SHOW_ID 1
9#define MODE_LIST_DEVICES 2
10
11static void print_usage(int argc, char **argv)
12{
13 char *name = NULL;
14
15 name = strrchr(argv[0], '/');
16 printf("Usage: %s [OPTIONS] [UUID]\n", (name ? name + 1: argv[0]));
17 printf("Prints device name or a list of attached iPhone/iPod Touch devices.\n\n");
18 printf(" The UUID is a 40-digit hexadecimal number of the device\n");
19 printf(" for which the name should be retrieved.\n\n");
20 printf(" -l, --list\t\tlist UUID of all attached devices\n");
21 printf(" -d, --debug\t\tenable communication debugging\n");
22 printf(" -h, --help\t\tprints usage information\n");
23 printf("\n");
24}
25
26int main(int argc, char **argv)
27{
28 idevice_t phone = NULL;
29 lockdownd_client_t client = NULL;
30 char **dev_list = NULL;
31 char *devname = NULL;
32 int ret = 0;
33 int i;
34 int mode = MODE_SHOW_ID;
35 char uuid[41];
36 uuid[0] = 0;
37
38 /* parse cmdline args */
39 for (i = 1; i < argc; i++) {
40 if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) {
41 idevice_set_debug_level(1);
42 continue;
43 }
44 else if (!strcmp(argv[i], "-l") || !strcmp(argv[i], "--list")) {
45 mode = MODE_LIST_DEVICES;
46 continue;
47 }
48 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
49 print_usage(argc, argv);
50 return 0;
51 }
52 }
53
54 /* check if uuid was passed */
55 if (mode == MODE_SHOW_ID) {
56 i--;
57 if (!argv[i] || (strlen(argv[i]) != 40)) {
58 print_usage(argc, argv);
59 return 0;
60 }
61 strcpy(uuid, argv[i]);
62 }
63
64 switch (mode) {
65 case MODE_SHOW_ID:
66 idevice_new(&phone, uuid);
67 if (!phone) {
68 fprintf(stderr, "ERROR: No device with UUID=%s attached.\n", uuid);
69 return -2;
70 }
71
72 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client, "idevice_id")) {
73 idevice_free(phone);
74 fprintf(stderr, "ERROR: Connecting to device failed!\n");
75 return -2;
76 }
77
78 if ((LOCKDOWN_E_SUCCESS != lockdownd_get_device_name(client, &devname)) || !devname) {
79 fprintf(stderr, "ERROR: Could not get device name!\n");
80 ret = -2;
81 }
82
83 lockdownd_client_free(client);
84 idevice_free(phone);
85
86 if (ret == 0) {
87 printf("%s\n", devname);
88 }
89
90 if (devname) {
91 free(devname);
92 }
93
94 return ret;
95 case MODE_LIST_DEVICES:
96 default:
97 if (idevice_get_device_list(&dev_list, &i) < 0) {
98 fprintf(stderr, "ERROR: Unable to retrieve device list!\n");
99 return -1;
100 }
101 for (i = 0; dev_list[i] != NULL; i++) {
102 printf("%s\n", dev_list[i]);
103 }
104 idevice_device_list_free(dev_list);
105 return 0;
106 }
107}