Skip to content

Instantly share code, notes, and snippets.

@nikias
Last active October 21, 2016 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikias/5ebd5389e59e46e6832193efdd3229ef to your computer and use it in GitHub Desktop.
Save nikias/5ebd5389e59e46e6832193efdd3229ef to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <libimobiledevice/libimobiledevice.h>
#include <libimobiledevice/lockdown.h>
#ifdef WIN32
#include <windows.h>
#define sleep(x) Sleep(x*1000)
#endif
static int stopped = 0;
static void handle_connect(const char* udid, void *userdata)
{
idevice_t device = NULL;
idevice_new(&device, udid);
lockdownd_client_t lockdown = NULL;
lockdownd_error_t lerr;
lerr = lockdownd_client_new_with_handshake(device, &lockdown, NULL);
if (lerr != LOCKDOWN_E_SUCCESS) {
idevice_free(device);
return;
}
char* name = NULL;
lerr = lockdownd_get_device_name(lockdown, &name);
if (name) {
printf("Name: '%s'\n", name);
free(name);
} else {
printf("ERROR: Could not get device name, lockdown error %d\n", lerr);
}
lockdownd_client_free(lockdown);
idevice_free(device);
}
static void idevice_event(const idevice_event_t *event, void *userdata)
{
if (event->event == IDEVICE_DEVICE_ADD) {
printf("Connected: %s\n", event->udid);
handle_connect(event->udid, userdata);
} else if (event->event == IDEVICE_DEVICE_REMOVE) {
printf("Disconnected: %s\n", event->udid);
}
}
static void handle_signal(int sig)
{
stopped = 1;
}
int main(int argc, char **argv)
{
signal(SIGINT, handle_signal);
signal(SIGTERM, handle_signal);
#ifndef WIN32
signal(SIGQUIT, handle_signal);
#endif
idevice_event_subscribe(idevice_event, NULL);
while (!stopped) {
sleep(1);
}
idevice_event_unsubscribe();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment