summaryrefslogtreecommitdiffstats
path: root/dev/syslog_relay.c
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2009-07-28 10:58:50 +0200
committerGravatar Matt Colyer2009-07-28 21:32:13 -0700
commitd089bc54e88d7fa70be9f0c228403c6d02248b52 (patch)
tree2e8b1c8103727ae8a83d39dd59d4217430211de4 /dev/syslog_relay.c
parentc57ebf917e30afd78dac8042552966811531c632 (diff)
downloadlibimobiledevice-d089bc54e88d7fa70be9f0c228403c6d02248b52.tar.gz
libimobiledevice-d089bc54e88d7fa70be9f0c228403c6d02248b52.tar.bz2
Move production ready tools into tools/ and do not install the dev/ ones
Diffstat (limited to 'dev/syslog_relay.c')
-rw-r--r--dev/syslog_relay.c169
1 files changed, 0 insertions, 169 deletions
diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c
deleted file mode 100644
index a096101..0000000
--- a/dev/syslog_relay.c
+++ /dev/null
@@ -1,169 +0,0 @@
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 <stdlib.h>
28
29#include <libiphone/libiphone.h>
30#include <libiphone/lockdown.h>
31#include <usbmuxd.h>
32
33static int quit_flag = 0;
34
35void print_usage(int argc, char **argv);
36
37/**
38 * signal handler function for cleaning up properly
39 */
40static void clean_exit(int sig)
41{
42 fprintf(stderr, "Exiting...\n");
43 quit_flag++;
44}
45
46int main(int argc, char *argv[])
47{
48 lockdownd_client_t client = NULL;
49 iphone_device_t phone = NULL;
50 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
51 int i;
52 char uuid[41];
53 int port = 0;
54 uuid[0] = 0;
55 uint32_t handle = 0;
56
57 signal(SIGINT, clean_exit);
58 signal(SIGQUIT, clean_exit);
59 signal(SIGTERM, clean_exit);
60 signal(SIGPIPE, SIG_IGN);
61
62 /* parse cmdline args */
63 for (i = 1; i < argc; i++) {
64 if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) {
65 iphone_set_debug_mask(DBGMASK_ALL);
66 iphone_set_debug_level(1);
67 continue;
68 }
69 else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) {
70 i++;
71 if (!argv[i] || (strlen(argv[i]) != 40)) {
72 print_usage(argc, argv);
73 return 0;
74 }
75 strcpy(uuid, argv[i]);
76 continue;
77 }
78 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
79 print_usage(argc, argv);
80 return 0;
81 }
82 else {
83 print_usage(argc, argv);
84 return 0;
85 }
86 }
87
88 if (uuid[0] != 0) {
89 ret = iphone_get_device_by_uuid(&phone, uuid);
90 if (ret != IPHONE_E_SUCCESS) {
91 printf("No device found with uuid %s, is it plugged in?\n", uuid);
92 return -1;
93 }
94 }
95 else
96 {
97 ret = iphone_get_device(&phone);
98 if (ret != IPHONE_E_SUCCESS) {
99 printf("No device found, is it plugged in?\n");
100 return -1;
101 }
102 }
103
104 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) {
105 iphone_device_free(phone);
106 return -1;
107 }
108
109 /* start syslog_relay service and retrieve port */
110 ret = lockdownd_start_service(client, "com.apple.syslog_relay", &port);
111 if ((ret == LOCKDOWN_E_SUCCESS) && port) {
112 lockdownd_client_free(client);
113
114 /* connect to socket relay messages */
115 iphone_device_get_handle(phone, &handle);
116 int sfd = usbmuxd_connect(handle, port);
117 if (sfd < 0) {
118 printf("ERROR: Could not open usbmux connection.\n");
119 } else {
120 while (!quit_flag) {
121 char *receive = NULL;
122 uint32_t datalen = 0, bytes = 0, recv_bytes = 0;
123
124 ret = usbmuxd_recv(sfd, (char *) &datalen, sizeof(datalen), &bytes);
125 datalen = ntohl(datalen);
126
127 if (datalen == 0)
128 continue;
129
130 recv_bytes += bytes;
131 receive = (char *) malloc(sizeof(char) * datalen);
132
133 while (!quit_flag && (recv_bytes <= datalen)) {
134 ret = usbmuxd_recv(sfd, receive, datalen, &bytes);
135
136 if (bytes == 0)
137 break;
138
139 recv_bytes += bytes;
140
141 fwrite(receive, sizeof(char), bytes, stdout);
142 }
143
144 free(receive);
145 }
146 }
147 usbmuxd_disconnect(sfd);
148 } else {
149 printf("ERROR: Could not start service com.apple.syslog_relay.\n");
150 }
151
152 iphone_device_free(phone);
153
154 return 0;
155}
156
157void print_usage(int argc, char **argv)
158{
159 char *name = NULL;
160
161 name = strrchr(argv[0], '/');
162 printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
163 printf("Relay syslog of a connected iPhone/iPod Touch.\n\n");
164 printf(" -d, --debug\t\tenable communication debugging\n");
165 printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n");
166 printf(" -h, --help\t\tprints usage information\n");
167 printf("\n");
168}
169