diff options
Diffstat (limited to 'iproxy.c')
-rw-r--r-- | iproxy.c | 54 |
1 files changed, 26 insertions, 28 deletions
@@ -34,8 +34,6 @@ #include "usbmuxd.h" #include "sock_stuff.h" -#define SOCKET_FILE "/var/run/usbmuxd" - static uint16_t listen_port = 0; static uint16_t device_port = 0; @@ -50,7 +48,7 @@ struct client_data { int usbmuxd_get_result(int sfd, uint32_t tag, uint32_t *result) { - struct usbmux_result res; + struct usbmuxd_result res; int recv_len; int i; uint32_t rrr[5]; @@ -71,7 +69,7 @@ int usbmuxd_get_result(int sfd, uint32_t tag, uint32_t *result) if ((recv_len == sizeof(res)) && (res.header.length == recv_len) && (res.header.reserved == 0) - && (res.header.type == usbmux_result) + && (res.header.type == USBMUXD_RESULT) ) { *result = res.result; if (res.header.tag == tag) { @@ -185,8 +183,8 @@ void *acceptor_thread(void *arg) int connected; uint32_t pktlen; unsigned char *buf; - struct usbmux_header hello; - struct usbmux_dev_info device_info; + struct usbmuxd_hello hello; + struct usbmuxd_device_info device_info; pthread_t ctos; if (!arg) { @@ -196,26 +194,26 @@ void *acceptor_thread(void *arg) cdata = (struct client_data*)arg; - cdata->sfd = connect_unix_socket(SOCKET_FILE); + cdata->sfd = connect_unix_socket(USBMUXD_SOCKET_FILE); if (cdata->sfd < 0) { printf("error opening socket, terminating.\n"); return NULL; } // send hello - hello.length = sizeof(struct usbmux_header); - hello.reserved = 0; - hello.type = usbmux_hello; - hello.tag = 2; + hello.header.length = sizeof(struct usbmuxd_hello); + hello.header.reserved = 0; + hello.header.type = USBMUXD_HELLO; + hello.header.tag = 2; hello_done = 0; connected = 0; fprintf(stdout, "sending Hello packet\n"); - if (send(cdata->sfd, &hello, hello.length, 0) == hello.length) { + if (send(cdata->sfd, &hello, hello.header.length, 0) == hello.header.length) { uint32_t res = -1; // get response - if (usbmuxd_get_result(cdata->sfd, hello.tag, &res) && (res==0)) { + if (usbmuxd_get_result(cdata->sfd, hello.header.tag, &res) && (res==0)) { fprintf(stdout, "Got Hello Response!\n"); hello_done = 1; } else { @@ -241,7 +239,7 @@ void *acceptor_thread(void *arg) } fprintf(stdout, "Received device data\n"); //log_debug_buffer(stdout, (char*)buf, pktlen); - memcpy(&device_info, buf + sizeof(struct usbmux_header), sizeof(device_info)); + memcpy(&device_info, buf + sizeof(struct usbmuxd_header), sizeof(device_info)); free(buf); } else { // we _should_ have all of them now. @@ -252,17 +250,17 @@ void *acceptor_thread(void *arg) } if (device_info.device_id > 0) { - struct usbmux_connect_request c_req; + struct usbmuxd_connect_request c_req; fprintf(stdout, "Requesting connecion to device %d port %d\n", device_info.device_id, device_port); // try to connect to last device found c_req.header.length = sizeof(c_req); c_req.header.reserved = 0; - c_req.header.type = usbmux_connect; + c_req.header.type = USBMUXD_CONNECT; c_req.header.tag = 3; c_req.device_id = device_info.device_id; - c_req.port = htons(device_port); + c_req.tcp_dport = htons(device_port); c_req.reserved = 0; if (send_buf(cdata->sfd, &c_req, sizeof(c_req)) < 0) { @@ -346,26 +344,26 @@ int main(int argc, char **argv) } /* - sfd = connect_unix_socket(SOCKET_FILE); + sfd = connect_unix_socket(USBMUXD_SOCKET_FILE); if (sfd < 0) { printf("error opening socket, terminating.\n"); return -1; } // send hello - hello.length = sizeof(struct usbmux_header); - hello.reserved = 0; - hello.type = usbmux_hello; - hello.tag = 2; + hello.header.length = sizeof(hello); + hello.header.reserved = 0; + hello.header.type = USBMUXD_HELLO; + hello.header.tag = 2; hello_done = 0; connected = 0; fprintf(stdout, "sending Hello packet\n"); - if (send(sfd, &hello, hello.length, 0) == hello.length) { + if (send(sfd, &hello, hello.header.length, 0) == hello.header.length) { uint32_t res = -1; // get response - if (usbmuxd_get_result(sfd, hello.tag, &res) && (res==0)) { + if (usbmuxd_get_result(sfd, hello.header.tag, &res) && (res==0)) { fprintf(stdout, "Got Hello Response!\n"); hello_done = 1; } else { @@ -390,7 +388,7 @@ int main(int argc, char **argv) } fprintf(stdout, "Received device data\n"); //log_debug_buffer(stdout, (char*)buf, pktlen); - memcpy(&device_info, buf + sizeof(struct usbmux_header), sizeof(device_info)); + memcpy(&device_info, buf + sizeof(struct usbmuxd_header), sizeof(device_info)); free(buf); } else { // we _should_ have all of them now. @@ -401,17 +399,17 @@ int main(int argc, char **argv) } if (device_info.device_id > 0) { - struct usbmux_connect_request c_req; + struct usbmuxd_connect_request c_req; fprintf(stdout, "Requesting connecion to device %d port %d\n", device_info.device_id, device_port); // try to connect to last device found c_req.header.length = sizeof(c_req); c_req.header.reserved = 0; - c_req.header.type = usbmux_connect; + c_req.header.type = USBMUXD_CONNECT; c_req.header.tag = 3; c_req.device_id = device_info.device_id; - c_req.port = htons(device_port); + c_req.tcp_dport = htons(device_port); c_req.reserved = 0; if (send_buf(sfd, &c_req, sizeof(c_req)) < 0) { |