summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2009-04-16 17:12:45 +0200
committerGravatar Matt Colyer2009-04-19 15:16:19 -0700
commitf104eb4371c2da6bac81f283d9943cdb800a6f95 (patch)
tree3ce8c59cbd70c3002216831b0cfd7394878ff415
parent6b1c3e363adff39ce15e57217ab97ae2d692247c (diff)
downloadlibimobiledevice-f104eb4371c2da6bac81f283d9943cdb800a6f95.tar.gz
libimobiledevice-f104eb4371c2da6bac81f283d9943cdb800a6f95.tar.bz2
Add tool to relay the syslog from a device to stdout
[#30] Signed-off-by: Matt Colyer <matt@colyer.name>
-rw-r--r--dev/Makefile.am7
-rw-r--r--dev/syslog_relay.c159
2 files changed, 165 insertions, 1 deletions
diff --git a/dev/Makefile.am b/dev/Makefile.am
index 00a6e3a..8afe2f9 100644
--- a/dev/Makefile.am
+++ b/dev/Makefile.am
@@ -3,7 +3,7 @@ INCLUDES = -I$(top_srcdir)/include
AM_CFLAGS = $(GLOBAL_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS)
AM_LDFLAGS = $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS)
-bin_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneinfo
+bin_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneinfo iphonesyslog
iphoneclient_SOURCES = main.c
iphoneclient_LDADD = ../src/libiphone.la
@@ -27,3 +27,8 @@ iphoneinfo_SOURCES = iphoneinfo.c
iphoneinfo_CFLAGS = $(AM_CFLAGS)
iphoneinfo_LDFLAGS = $(AM_LDFLAGS)
iphoneinfo_LDADD = ../src/libiphone.la
+
+iphonesyslog_SOURCES = syslog_relay.c
+iphonesyslog_CFLAGS = $(AM_CFLAGS)
+iphonesyslog_LDFLAGS = $(AM_LDFLAGS)
+iphonesyslog_LDADD = ../src/libiphone.la
diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c
new file mode 100644
index 0000000..56cf56c
--- /dev/null
+++ b/dev/syslog_relay.c
@@ -0,0 +1,159 @@
+/*
+ * syslog_relay.c
+ * Relay the syslog of a device to stdout
+ *
+ * Copyright (c) 2009 Martin Szulecki All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <netinet/in.h>
+#include <signal.h>
+#include <usb.h>
+
+#include <libiphone/libiphone.h>
+
+static int quit_flag = 0;
+
+void print_usage(int argc, char **argv);
+
+/**
+ * signal handler function for cleaning up properly
+ */
+static void clean_exit(int sig)
+{
+ fprintf(stderr, "Exiting...\n");
+ quit_flag++;
+}
+
+int main(int argc, char *argv[])
+{
+ iphone_lckd_client_t control = NULL;
+ iphone_device_t phone = NULL;
+ iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ int i;
+ int bus_n = -1, dev_n = -1;
+ int port = 0;
+
+ signal(SIGINT, clean_exit);
+ signal(SIGQUIT, clean_exit);
+ signal(SIGTERM, clean_exit);
+ signal(SIGPIPE, SIG_IGN);
+
+ /* parse cmdline args */
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) {
+ iphone_set_debug_mask(DBGMASK_ALL);
+ continue;
+ }
+ else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--usb")) {
+ if (sscanf(argv[++i], "%d,%d", &bus_n, &dev_n) < 2) {
+ print_usage(argc, argv);
+ return 0;
+ }
+ continue;
+ }
+ else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
+ print_usage(argc, argv);
+ return 0;
+ }
+ else {
+ print_usage(argc, argv);
+ return 0;
+ }
+ }
+
+ if (bus_n != -1) {
+ ret = iphone_get_specific_device(bus_n, dev_n, &phone);
+ if (ret != IPHONE_E_SUCCESS) {
+ printf("No device found for usb bus %d and dev %d, is it plugged in?\n", bus_n, dev_n);
+ return -1;
+ }
+ }
+ else
+ {
+ ret = iphone_get_device(&phone);
+ if (ret != IPHONE_E_SUCCESS) {
+ printf("No device found, is it plugged in?\n");
+ return -1;
+ }
+ }
+
+ if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) {
+ iphone_free_device(phone);
+ return -1;
+ }
+
+ /* start syslog_relay service and retrieve port */
+ ret = iphone_lckd_start_service(control, "com.apple.syslog_relay", &port);
+ if ((ret == IPHONE_E_SUCCESS) && port) {
+ /* connect to socket relay messages */
+ iphone_umux_client_t syslog_client = NULL;
+
+ ret = iphone_mux_new_client(phone, 514, port, &syslog_client);
+ if (ret == IPHONE_E_SUCCESS) {
+ while (!quit_flag) {
+ char *receive = NULL;
+ uint32_t datalen = 0, bytes = 0, recv_bytes = 0;
+
+ ret = iphone_mux_recv(syslog_client, (char *) &datalen, sizeof(datalen), &bytes);
+ datalen = ntohl(datalen);
+
+ if (datalen == 0)
+ continue;
+
+ recv_bytes += bytes;
+ receive = (char *) malloc(sizeof(char) * datalen);
+
+ while (!quit_flag && (recv_bytes <= datalen)) {
+ ret = iphone_mux_recv(syslog_client, receive, datalen, &bytes);
+
+ if (bytes == 0)
+ break;
+
+ recv_bytes += bytes;
+
+ fwrite(receive, sizeof(char), bytes, stdout);
+ }
+
+ free(receive);
+ }
+ } else {
+ printf("ERROR: Could not open usbmux connection.\n");
+ }
+ iphone_mux_free_client(syslog_client);
+ } else {
+ printf("ERROR: Could not start service com.apple.syslog_relay.\n");
+ }
+
+ iphone_lckd_free_client(control);
+ iphone_free_device(phone);
+
+ return 0;
+}
+
+void print_usage(int argc, char **argv)
+{
+ printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1));
+ printf("Relay syslog of a connected iPhone/iPod Touch.\n\n");
+ printf(" -d, --debug\t\tenable communication debugging\n");
+ printf(" -u, --usb=BUS,DEV\ttarget specific device by usb bus/dev number\n");
+ printf(" -h, --help\t\tprints usage information\n");
+ printf("\n");
+}
+