All pastes #623845 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-07-17 21:39 UTC
rendered paste body
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <CoreFoundation/CoreFoundation.h>
#include <MobileDevice/MobileDevice.h>

void notification(struct am_device_notification_callback_info *info)
{
    char buf[256];
    int syslogh;
    ssize_t nread;
    struct am_device *dev = info->dev;

    if (info->msg != 1)
        return;

    fprintf(stderr, "iPhone attached. Connecting...\n");

    AMDeviceConnect(dev);
    AMDeviceIsPaired(dev);
    AMDeviceValidatePairing(dev);
    AMDeviceStartSession(dev);
    AMDeviceStartService(dev, AMSVC_SYSLOG_RELAY, &syslogh, NULL);
    AMDeviceStopSession(dev);

    while (1) {
        nread = recv(syslogh, buf, 256, 0);
        if (nread == -1) {
            fprintf(stderr, "recv error\n");
            break;
        }

        fwrite(buf, nread, 1, stdout);
        fflush(stdout);
    }
}

int main()
{
    struct am_device_notification *notif;

    AMDeviceNotificationSubscribe(notification, 0, 0, 0, &notif);

    fprintf(stderr, "This is syslogr-tool.\n");
    fprintf(stderr, "Please connect an iPhone in normal mode.\n"); 

    CFRunLoopRun();

    return 0;
}