summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-11-07 23:29:00 +0100
committerGravatar Nikias Bassen2019-11-07 23:29:00 +0100
commit953c13961071a9836430a814159aae33502e2e0c (patch)
tree7b5b03a73007948909d64c8edc56f1079a26b2c9 /src
parent5390060ec90bed0f565698a389cebc57c09c3ac8 (diff)
downloadlibimobiledevice-953c13961071a9836430a814159aae33502e2e0c.tar.gz
libimobiledevice-953c13961071a9836430a814159aae33502e2e0c.tar.bz2
Add new idevice_get_device_list_extended() allowing to list all devices, including network
Instead of just returning a list of UDIDs (like idevice_get_device_list) this function will return idevice_info_t* records which also contains the type of the connection and the connection data.
Diffstat (limited to 'src')
-rw-r--r--src/idevice.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/idevice.c b/src/idevice.c
index d23c5b5..31a8d3a 100644
--- a/src/idevice.c
+++ b/src/idevice.c
@@ -227,6 +227,62 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_event_unsubscribe(void)
return IDEVICE_E_SUCCESS;
}
+LIBIMOBILEDEVICE_API idevice_error_t idevice_get_device_list_extended(idevice_info_t **devices, int *count)
+{
+ usbmuxd_device_info_t *dev_list;
+
+ *devices = NULL;
+ *count = 0;
+
+ if (usbmuxd_get_device_list(&dev_list) < 0) {
+ debug_info("ERROR: usbmuxd is not running!", __func__);
+ return IDEVICE_E_NO_DEVICE;
+ }
+
+ idevice_info_t *newlist = NULL;
+ int i, newcount = 0;
+
+ for (i = 0; dev_list[i].handle > 0; i++) {
+ newlist = realloc(*devices, sizeof(idevice_info_t) * (newcount+1));
+ newlist[newcount] = malloc(sizeof(struct idevice_info));
+ newlist[newcount]->udid = strdup(dev_list[i].udid);
+ if (dev_list[i].conn_type == CONNECTION_TYPE_USB) {
+ newlist[newcount]->conn_type = CONNECTION_USBMUXD;
+ newlist[newcount]->conn_data = NULL;
+ } else if (dev_list[i].conn_type == CONNECTION_TYPE_NETWORK) {
+ newlist[newcount]->conn_type = CONNECTION_NETWORK;
+ size_t addrlen = dev_list[i].conn_data[0];
+ newlist[newcount]->conn_data = malloc(addrlen);
+ memcpy(newlist[newcount]->conn_data, dev_list[i].conn_data, addrlen);
+ }
+ newcount++;
+ *devices = newlist;
+ }
+ usbmuxd_device_list_free(&dev_list);
+
+ *count = newcount;
+ newlist = realloc(*devices, sizeof(idevice_info_t) * (newcount+1));
+ newlist[newcount] = NULL;
+ *devices = newlist;
+
+ return IDEVICE_E_SUCCESS;
+}
+
+LIBIMOBILEDEVICE_API idevice_error_t idevice_device_list_extended_free(idevice_info_t *devices)
+{
+ if (devices) {
+ int i = 0;
+ while (devices[i]) {
+ free(devices[i]->udid);
+ free(devices[i]->conn_data);
+ free(devices[i]);
+ i++;
+ }
+ free(devices);
+ }
+ return IDEVICE_E_SUCCESS;
+}
+
LIBIMOBILEDEVICE_API idevice_error_t idevice_get_device_list(char ***devices, int *count)
{
usbmuxd_device_info_t *dev_list;