diff options
Diffstat (limited to 'testclient.c')
| -rw-r--r-- | testclient.c | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/testclient.c b/testclient.c index fafbf23..679b6d0 100644 --- a/testclient.c +++ b/testclient.c | |||
| @@ -10,11 +10,9 @@ | |||
| 10 | #include "usbmuxd.h" | 10 | #include "usbmuxd.h" |
| 11 | #include "sock_stuff.h" | 11 | #include "sock_stuff.h" |
| 12 | 12 | ||
| 13 | #define SOCKET_FILE "/var/run/usbmuxd" | ||
| 14 | |||
| 15 | int usbmuxd_get_result(int sfd, uint32_t tag, uint32_t *result) | 13 | int usbmuxd_get_result(int sfd, uint32_t tag, uint32_t *result) |
| 16 | { | 14 | { |
| 17 | struct usbmux_result res; | 15 | struct usbmuxd_result res; |
| 18 | int recv_len; | 16 | int recv_len; |
| 19 | 17 | ||
| 20 | if (!result) { | 18 | if (!result) { |
| @@ -28,7 +26,7 @@ int usbmuxd_get_result(int sfd, uint32_t tag, uint32_t *result) | |||
| 28 | if ((recv_len == sizeof(res)) | 26 | if ((recv_len == sizeof(res)) |
| 29 | && (res.header.length == recv_len) | 27 | && (res.header.length == recv_len) |
| 30 | && (res.header.reserved == 0) | 28 | && (res.header.reserved == 0) |
| 31 | && (res.header.type == usbmux_result) | 29 | && (res.header.type == USBMUXD_RESULT) |
| 32 | ) { | 30 | ) { |
| 33 | *result = res.result; | 31 | *result = res.result; |
| 34 | if (res.header.tag == tag) { | 32 | if (res.header.tag == tag) { |
| @@ -50,29 +48,29 @@ int main(int argc, char **argv) | |||
| 50 | int connected; | 48 | int connected; |
| 51 | uint32_t pktlen; | 49 | uint32_t pktlen; |
| 52 | unsigned char *buf; | 50 | unsigned char *buf; |
| 53 | struct usbmux_header hello; | 51 | struct usbmuxd_hello hello; |
| 54 | struct usbmux_dev_info device_info; | 52 | struct usbmuxd_device_info device_info; |
| 55 | 53 | ||
| 56 | sfd = connect_unix_socket(SOCKET_FILE); | 54 | sfd = connect_unix_socket(USBMUXD_SOCKET_FILE); |
| 57 | if (sfd < 0) { | 55 | if (sfd < 0) { |
| 58 | printf("error opening socket, terminating.\n"); | 56 | printf("error opening socket, terminating.\n"); |
| 59 | return -1; | 57 | return -1; |
| 60 | } | 58 | } |
| 61 | 59 | ||
| 62 | // send hello | 60 | // send hello |
| 63 | hello.length = sizeof(struct usbmux_header); | 61 | hello.header.length = sizeof(struct usbmuxd_hello); |
| 64 | hello.reserved = 0; | 62 | hello.header.reserved = 0; |
| 65 | hello.type = usbmux_hello; | 63 | hello.header.type = USBMUXD_HELLO; |
| 66 | hello.tag = 2; | 64 | hello.header.tag = 2; |
| 67 | 65 | ||
| 68 | hello_done = 0; | 66 | hello_done = 0; |
| 69 | connected = 0; | 67 | connected = 0; |
| 70 | 68 | ||
| 71 | fprintf(stdout, "sending Hello packet\n"); | 69 | fprintf(stdout, "sending Hello packet\n"); |
| 72 | if (send(sfd, &hello, hello.length, 0) == hello.length) { | 70 | if (send(sfd, &hello, hello.header.length, 0) == hello.header.length) { |
| 73 | uint32_t res = -1; | 71 | uint32_t res = -1; |
| 74 | // get response | 72 | // get response |
| 75 | if (usbmuxd_get_result(sfd, hello.tag, &res) && (res==0)) { | 73 | if (usbmuxd_get_result(sfd, hello.header.tag, &res) && (res==0)) { |
| 76 | fprintf(stdout, "Got Hello Response!\n"); | 74 | fprintf(stdout, "Got Hello Response!\n"); |
| 77 | hello_done = 1; | 75 | hello_done = 1; |
| 78 | } else { | 76 | } else { |
| @@ -97,7 +95,7 @@ int main(int argc, char **argv) | |||
| 97 | } | 95 | } |
| 98 | fprintf(stdout, "got device data:\n"); | 96 | fprintf(stdout, "got device data:\n"); |
| 99 | //log_debug_buffer(stdout, (char*)buf, pktlen); | 97 | //log_debug_buffer(stdout, (char*)buf, pktlen); |
| 100 | memcpy(&device_info, buf + sizeof(struct usbmux_header), sizeof(device_info)); | 98 | memcpy(&device_info, buf + sizeof(struct usbmuxd_header), sizeof(device_info)); |
| 101 | free(buf); | 99 | free(buf); |
| 102 | } else { | 100 | } else { |
| 103 | // we _should_ have all of them now. | 101 | // we _should_ have all of them now. |
| @@ -108,15 +106,15 @@ int main(int argc, char **argv) | |||
| 108 | } | 106 | } |
| 109 | 107 | ||
| 110 | if (device_info.device_id > 0) { | 108 | if (device_info.device_id > 0) { |
| 111 | struct usbmux_connect_request c_req; | 109 | struct usbmuxd_connect_request c_req; |
| 112 | 110 | ||
| 113 | // try to connect to last device found | 111 | // try to connect to last device found |
| 114 | c_req.header.length = sizeof(c_req); | 112 | c_req.header.length = sizeof(c_req); |
| 115 | c_req.header.reserved = 0; | 113 | c_req.header.reserved = 0; |
| 116 | c_req.header.type = usbmux_connect; | 114 | c_req.header.type = USBMUXD_CONNECT; |
| 117 | c_req.header.tag = 3; | 115 | c_req.header.tag = 3; |
| 118 | c_req.device_id = device_info.device_id; | 116 | c_req.device_id = device_info.device_id; |
| 119 | c_req.port = htons(22); | 117 | c_req.tcp_dport = htons(22); |
| 120 | c_req.reserved = 0; | 118 | c_req.reserved = 0; |
| 121 | 119 | ||
| 122 | if (send_buf(sfd, &c_req, sizeof(c_req)) < 0) { | 120 | if (send_buf(sfd, &c_req, sizeof(c_req)) < 0) { |
