summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS) 3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS)
4AM_LDFLAGS = $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) 4AM_LDFLAGS = $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS)
5 5
6bin_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneinfo 6bin_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneinfo iphonesyslog
7 7
8iphoneclient_SOURCES = main.c 8iphoneclient_SOURCES = main.c
9iphoneclient_LDADD = ../src/libiphone.la 9iphoneclient_LDADD = ../src/libiphone.la
@@ -27,3 +27,8 @@ iphoneinfo_SOURCES = iphoneinfo.c
27iphoneinfo_CFLAGS = $(AM_CFLAGS) 27iphoneinfo_CFLAGS = $(AM_CFLAGS)
28iphoneinfo_LDFLAGS = $(AM_LDFLAGS) 28iphoneinfo_LDFLAGS = $(AM_LDFLAGS)
29iphoneinfo_LDADD = ../src/libiphone.la 29iphoneinfo_LDADD = ../src/libiphone.la
30
31iphonesyslog_SOURCES = syslog_relay.c
32iphonesyslog_CFLAGS = $(AM_CFLAGS)
33iphonesyslog_LDFLAGS = $(AM_LDFLAGS)
34iphonesyslog_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 @@
1/*
2 * syslog_relay.c
3 * Relay the syslog of a device to stdout
4 *
5 * Copyright (c) 2009 Martin Szulecki All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <stdio.h>
23#include <string.h>
24#include <errno.h>
25#include <netinet/in.h>
26#include <signal.h>
27#include <usb.h>
28
29#include <libiphone/libiphone.h>
30
31static int quit_flag = 0;
32
33void print_usage(int argc, char **argv);
34
35/**
36 * signal handler function for cleaning up properly
37 */
38static void clean_exit(int sig)
39{
40 fprintf(stderr, "Exiting...\n");
41 quit_flag++;
42}
43
44int main(int argc, char *argv[])
45{
46 iphone_lckd_client_t control = NULL;
47 iphone_device_t phone = NULL;
48 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
49 int i;
50 int bus_n = -1, dev_n = -1;
51 int port = 0;
52
53 signal(SIGINT, clean_exit);
54 signal(SIGQUIT, clean_exit);
55 signal(SIGTERM, clean_exit);
56 signal(SIGPIPE, SIG_IGN);
57
58 /* parse cmdline args */
59 for (i = 1; i < argc; i++) {
60 if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) {
61 iphone_set_debug_mask(DBGMASK_ALL);
62 continue;
63 }
64 else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--usb")) {
65 if (sscanf(argv[++i], "%d,%d", &bus_n, &dev_n) < 2) {
66 print_usage(argc, argv);
67 return 0;
68 }
69 continue;
70 }
71 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
72 print_usage(argc, argv);
73 return 0;
74 }
75 else {
76 print_usage(argc, argv);
77 return 0;
78 }
79 }
80
81 if (bus_n != -1) {
82 ret = iphone_get_specific_device(bus_n, dev_n, &phone);
83 if (ret != IPHONE_E_SUCCESS) {
84 printf("No device found for usb bus %d and dev %d, is it plugged in?\n", bus_n, dev_n);
85 return -1;
86 }
87 }
88 else
89 {
90 ret = iphone_get_device(&phone);
91 if (ret != IPHONE_E_SUCCESS) {
92 printf("No device found, is it plugged in?\n");
93 return -1;
94 }
95 }
96
97 if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) {
98 iphone_free_device(phone);
99 return -1;
100 }
101
102 /* start syslog_relay service and retrieve port */
103 ret = iphone_lckd_start_service(control, "com.apple.syslog_relay", &port);
104 if ((ret == IPHONE_E_SUCCESS) && port) {
105 /* connect to socket relay messages */
106 iphone_umux_client_t syslog_client = NULL;
107
108 ret = iphone_mux_new_client(phone, 514, port, &syslog_client);
109 if (ret == IPHONE_E_SUCCESS) {
110 while (!quit_flag) {
111 char *receive = NULL;
112 uint32_t datalen = 0, bytes = 0, recv_bytes = 0;
113
114 ret = iphone_mux_recv(syslog_client, (char *) &datalen, sizeof(datalen), &bytes);
115 datalen = ntohl(datalen);
116
117 if (datalen == 0)
118 continue;
119
120 recv_bytes += bytes;
121 receive = (char *) malloc(sizeof(char) * datalen);
122
123 while (!quit_flag && (recv_bytes <= datalen)) {
124 ret = iphone_mux_recv(syslog_client, receive, datalen, &bytes);
125
126 if (bytes == 0)
127 break;
128
129 recv_bytes += bytes;
130
131 fwrite(receive, sizeof(char), bytes, stdout);
132 }
133
134 free(receive);
135 }
136 } else {
137 printf("ERROR: Could not open usbmux connection.\n");
138 }
139 iphone_mux_free_client(syslog_client);
140 } else {
141 printf("ERROR: Could not start service com.apple.syslog_relay.\n");
142 }
143
144 iphone_lckd_free_client(control);
145 iphone_free_device(phone);
146
147 return 0;
148}
149
150void print_usage(int argc, char **argv)
151{
152 printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1));
153 printf("Relay syslog of a connected iPhone/iPod Touch.\n\n");
154 printf(" -d, --debug\t\tenable communication debugging\n");
155 printf(" -u, --usb=BUS,DEV\ttarget specific device by usb bus/dev number\n");
156 printf(" -h, --help\t\tprints usage information\n");
157 printf("\n");
158}
159