diff options
Diffstat (limited to 'dev/syslog_relay.c')
| -rw-r--r-- | dev/syslog_relay.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c index 56cf56c..3407f2f 100644 --- a/dev/syslog_relay.c +++ b/dev/syslog_relay.c | |||
| @@ -24,9 +24,9 @@ | |||
| 24 | #include <errno.h> | 24 | #include <errno.h> |
| 25 | #include <netinet/in.h> | 25 | #include <netinet/in.h> |
| 26 | #include <signal.h> | 26 | #include <signal.h> |
| 27 | #include <usb.h> | ||
| 28 | 27 | ||
| 29 | #include <libiphone/libiphone.h> | 28 | #include <libiphone/libiphone.h> |
| 29 | #include <usbmuxd.h> | ||
| 30 | 30 | ||
| 31 | static int quit_flag = 0; | 31 | static int quit_flag = 0; |
| 32 | 32 | ||
| @@ -47,8 +47,9 @@ int main(int argc, char *argv[]) | |||
| 47 | iphone_device_t phone = NULL; | 47 | iphone_device_t phone = NULL; |
| 48 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 48 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 49 | int i; | 49 | int i; |
| 50 | int bus_n = -1, dev_n = -1; | 50 | char uuid[41]; |
| 51 | int port = 0; | 51 | int port = 0; |
| 52 | uuid[0] = 0; | ||
| 52 | 53 | ||
| 53 | signal(SIGINT, clean_exit); | 54 | signal(SIGINT, clean_exit); |
| 54 | signal(SIGQUIT, clean_exit); | 55 | signal(SIGQUIT, clean_exit); |
| @@ -61,11 +62,13 @@ int main(int argc, char *argv[]) | |||
| 61 | iphone_set_debug_mask(DBGMASK_ALL); | 62 | iphone_set_debug_mask(DBGMASK_ALL); |
| 62 | continue; | 63 | continue; |
| 63 | } | 64 | } |
| 64 | else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--usb")) { | 65 | else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { |
| 65 | if (sscanf(argv[++i], "%d,%d", &bus_n, &dev_n) < 2) { | 66 | i++; |
| 67 | if (!argv[i] || (strlen(argv[i]) != 40)) { | ||
| 66 | print_usage(argc, argv); | 68 | print_usage(argc, argv); |
| 67 | return 0; | 69 | return 0; |
| 68 | } | 70 | } |
| 71 | strcpy(uuid, argv[i]); | ||
| 69 | continue; | 72 | continue; |
| 70 | } | 73 | } |
| 71 | else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { | 74 | else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { |
| @@ -78,10 +81,10 @@ int main(int argc, char *argv[]) | |||
| 78 | } | 81 | } |
| 79 | } | 82 | } |
| 80 | 83 | ||
| 81 | if (bus_n != -1) { | 84 | if (uuid[0] != 0) { |
| 82 | ret = iphone_get_specific_device(bus_n, dev_n, &phone); | 85 | ret = iphone_get_device_by_uuid(&phone, uuid); |
| 83 | if (ret != IPHONE_E_SUCCESS) { | 86 | 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); | 87 | printf("No device found with uuid %s, is it plugged in?\n", uuid); |
| 85 | return -1; | 88 | return -1; |
| 86 | } | 89 | } |
| 87 | } | 90 | } |
| @@ -103,15 +106,16 @@ int main(int argc, char *argv[]) | |||
| 103 | ret = iphone_lckd_start_service(control, "com.apple.syslog_relay", &port); | 106 | ret = iphone_lckd_start_service(control, "com.apple.syslog_relay", &port); |
| 104 | if ((ret == IPHONE_E_SUCCESS) && port) { | 107 | if ((ret == IPHONE_E_SUCCESS) && port) { |
| 105 | /* connect to socket relay messages */ | 108 | /* connect to socket relay messages */ |
| 106 | iphone_umux_client_t syslog_client = NULL; | ||
| 107 | 109 | ||
| 108 | ret = iphone_mux_new_client(phone, 514, port, &syslog_client); | 110 | int sfd = usbmuxd_connect(iphone_get_device_handle(phone), port); |
| 109 | if (ret == IPHONE_E_SUCCESS) { | 111 | if (sfd < 0) { |
| 112 | printf("ERROR: Could not open usbmux connection.\n"); | ||
| 113 | } else { | ||
| 110 | while (!quit_flag) { | 114 | while (!quit_flag) { |
| 111 | char *receive = NULL; | 115 | char *receive = NULL; |
| 112 | uint32_t datalen = 0, bytes = 0, recv_bytes = 0; | 116 | uint32_t datalen = 0, bytes = 0, recv_bytes = 0; |
| 113 | 117 | ||
| 114 | ret = iphone_mux_recv(syslog_client, (char *) &datalen, sizeof(datalen), &bytes); | 118 | ret = usbmuxd_recv(sfd, (char *) &datalen, sizeof(datalen), &bytes); |
| 115 | datalen = ntohl(datalen); | 119 | datalen = ntohl(datalen); |
| 116 | 120 | ||
| 117 | if (datalen == 0) | 121 | if (datalen == 0) |
| @@ -121,7 +125,7 @@ int main(int argc, char *argv[]) | |||
| 121 | receive = (char *) malloc(sizeof(char) * datalen); | 125 | receive = (char *) malloc(sizeof(char) * datalen); |
| 122 | 126 | ||
| 123 | while (!quit_flag && (recv_bytes <= datalen)) { | 127 | while (!quit_flag && (recv_bytes <= datalen)) { |
| 124 | ret = iphone_mux_recv(syslog_client, receive, datalen, &bytes); | 128 | ret = usbmuxd_recv(sfd, receive, datalen, &bytes); |
| 125 | 129 | ||
| 126 | if (bytes == 0) | 130 | if (bytes == 0) |
| 127 | break; | 131 | break; |
| @@ -133,10 +137,8 @@ int main(int argc, char *argv[]) | |||
| 133 | 137 | ||
| 134 | free(receive); | 138 | free(receive); |
| 135 | } | 139 | } |
| 136 | } else { | ||
| 137 | printf("ERROR: Could not open usbmux connection.\n"); | ||
| 138 | } | 140 | } |
| 139 | iphone_mux_free_client(syslog_client); | 141 | usbmuxd_disconnect(sfd); |
| 140 | } else { | 142 | } else { |
| 141 | printf("ERROR: Could not start service com.apple.syslog_relay.\n"); | 143 | printf("ERROR: Could not start service com.apple.syslog_relay.\n"); |
| 142 | } | 144 | } |
| @@ -152,7 +154,7 @@ void print_usage(int argc, char **argv) | |||
| 152 | printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1)); | 154 | printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1)); |
| 153 | printf("Relay syslog of a connected iPhone/iPod Touch.\n\n"); | 155 | printf("Relay syslog of a connected iPhone/iPod Touch.\n\n"); |
| 154 | printf(" -d, --debug\t\tenable communication debugging\n"); | 156 | printf(" -d, --debug\t\tenable communication debugging\n"); |
| 155 | printf(" -u, --usb=BUS,DEV\ttarget specific device by usb bus/dev number\n"); | 157 | printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); |
| 156 | printf(" -h, --help\t\tprints usage information\n"); | 158 | printf(" -h, --help\t\tprints usage information\n"); |
| 157 | printf("\n"); | 159 | printf("\n"); |
| 158 | } | 160 | } |
