diff options
| author | 2009-02-25 20:01:34 +0100 | |
|---|---|---|
| committer | 2009-02-25 20:01:34 +0100 | |
| commit | 523c44d0018c2e8480b37ac917aef7469b4b3a65 (patch) | |
| tree | 981015afabe6df3574bb7ee06c82bd438b7f29fe /iproxy.c | |
| parent | 6e2946da89ce8c44ac2b78e49c8fc934974d021d (diff) | |
| download | usbmuxd-523c44d0018c2e8480b37ac917aef7469b4b3a65.tar.gz usbmuxd-523c44d0018c2e8480b37ac917aef7469b4b3a65.tar.bz2 | |
A Readme, Makefile updates and cosmetic changes.
Diffstat (limited to 'iproxy.c')
| -rw-r--r-- | iproxy.c | 54 |
1 files changed, 26 insertions, 28 deletions
| @@ -34,8 +34,6 @@ | |||
| 34 | #include "usbmuxd.h" | 34 | #include "usbmuxd.h" |
| 35 | #include "sock_stuff.h" | 35 | #include "sock_stuff.h" |
| 36 | 36 | ||
| 37 | #define SOCKET_FILE "/var/run/usbmuxd" | ||
| 38 | |||
| 39 | static uint16_t listen_port = 0; | 37 | static uint16_t listen_port = 0; |
| 40 | static uint16_t device_port = 0; | 38 | static uint16_t device_port = 0; |
| 41 | 39 | ||
| @@ -50,7 +48,7 @@ struct client_data { | |||
| 50 | 48 | ||
| 51 | int usbmuxd_get_result(int sfd, uint32_t tag, uint32_t *result) | 49 | int usbmuxd_get_result(int sfd, uint32_t tag, uint32_t *result) |
| 52 | { | 50 | { |
| 53 | struct usbmux_result res; | 51 | struct usbmuxd_result res; |
| 54 | int recv_len; | 52 | int recv_len; |
| 55 | int i; | 53 | int i; |
| 56 | uint32_t rrr[5]; | 54 | uint32_t rrr[5]; |
| @@ -71,7 +69,7 @@ int usbmuxd_get_result(int sfd, uint32_t tag, uint32_t *result) | |||
| 71 | if ((recv_len == sizeof(res)) | 69 | if ((recv_len == sizeof(res)) |
| 72 | && (res.header.length == recv_len) | 70 | && (res.header.length == recv_len) |
| 73 | && (res.header.reserved == 0) | 71 | && (res.header.reserved == 0) |
| 74 | && (res.header.type == usbmux_result) | 72 | && (res.header.type == USBMUXD_RESULT) |
| 75 | ) { | 73 | ) { |
| 76 | *result = res.result; | 74 | *result = res.result; |
| 77 | if (res.header.tag == tag) { | 75 | if (res.header.tag == tag) { |
| @@ -185,8 +183,8 @@ void *acceptor_thread(void *arg) | |||
| 185 | int connected; | 183 | int connected; |
| 186 | uint32_t pktlen; | 184 | uint32_t pktlen; |
| 187 | unsigned char *buf; | 185 | unsigned char *buf; |
| 188 | struct usbmux_header hello; | 186 | struct usbmuxd_hello hello; |
| 189 | struct usbmux_dev_info device_info; | 187 | struct usbmuxd_device_info device_info; |
| 190 | pthread_t ctos; | 188 | pthread_t ctos; |
| 191 | 189 | ||
| 192 | if (!arg) { | 190 | if (!arg) { |
| @@ -196,26 +194,26 @@ void *acceptor_thread(void *arg) | |||
| 196 | 194 | ||
| 197 | cdata = (struct client_data*)arg; | 195 | cdata = (struct client_data*)arg; |
| 198 | 196 | ||
| 199 | cdata->sfd = connect_unix_socket(SOCKET_FILE); | 197 | cdata->sfd = connect_unix_socket(USBMUXD_SOCKET_FILE); |
| 200 | if (cdata->sfd < 0) { | 198 | if (cdata->sfd < 0) { |
| 201 | printf("error opening socket, terminating.\n"); | 199 | printf("error opening socket, terminating.\n"); |
| 202 | return NULL; | 200 | return NULL; |
| 203 | } | 201 | } |
| 204 | 202 | ||
| 205 | // send hello | 203 | // send hello |
| 206 | hello.length = sizeof(struct usbmux_header); | 204 | hello.header.length = sizeof(struct usbmuxd_hello); |
| 207 | hello.reserved = 0; | 205 | hello.header.reserved = 0; |
| 208 | hello.type = usbmux_hello; | 206 | hello.header.type = USBMUXD_HELLO; |
| 209 | hello.tag = 2; | 207 | hello.header.tag = 2; |
| 210 | 208 | ||
| 211 | hello_done = 0; | 209 | hello_done = 0; |
| 212 | connected = 0; | 210 | connected = 0; |
| 213 | 211 | ||
| 214 | fprintf(stdout, "sending Hello packet\n"); | 212 | fprintf(stdout, "sending Hello packet\n"); |
| 215 | if (send(cdata->sfd, &hello, hello.length, 0) == hello.length) { | 213 | if (send(cdata->sfd, &hello, hello.header.length, 0) == hello.header.length) { |
| 216 | uint32_t res = -1; | 214 | uint32_t res = -1; |
| 217 | // get response | 215 | // get response |
| 218 | if (usbmuxd_get_result(cdata->sfd, hello.tag, &res) && (res==0)) { | 216 | if (usbmuxd_get_result(cdata->sfd, hello.header.tag, &res) && (res==0)) { |
| 219 | fprintf(stdout, "Got Hello Response!\n"); | 217 | fprintf(stdout, "Got Hello Response!\n"); |
| 220 | hello_done = 1; | 218 | hello_done = 1; |
| 221 | } else { | 219 | } else { |
| @@ -241,7 +239,7 @@ void *acceptor_thread(void *arg) | |||
| 241 | } | 239 | } |
| 242 | fprintf(stdout, "Received device data\n"); | 240 | fprintf(stdout, "Received device data\n"); |
| 243 | //log_debug_buffer(stdout, (char*)buf, pktlen); | 241 | //log_debug_buffer(stdout, (char*)buf, pktlen); |
| 244 | memcpy(&device_info, buf + sizeof(struct usbmux_header), sizeof(device_info)); | 242 | memcpy(&device_info, buf + sizeof(struct usbmuxd_header), sizeof(device_info)); |
| 245 | free(buf); | 243 | free(buf); |
| 246 | } else { | 244 | } else { |
| 247 | // we _should_ have all of them now. | 245 | // we _should_ have all of them now. |
| @@ -252,17 +250,17 @@ void *acceptor_thread(void *arg) | |||
| 252 | } | 250 | } |
| 253 | 251 | ||
| 254 | if (device_info.device_id > 0) { | 252 | if (device_info.device_id > 0) { |
| 255 | struct usbmux_connect_request c_req; | 253 | struct usbmuxd_connect_request c_req; |
| 256 | 254 | ||
| 257 | fprintf(stdout, "Requesting connecion to device %d port %d\n", device_info.device_id, device_port); | 255 | fprintf(stdout, "Requesting connecion to device %d port %d\n", device_info.device_id, device_port); |
| 258 | 256 | ||
| 259 | // try to connect to last device found | 257 | // try to connect to last device found |
| 260 | c_req.header.length = sizeof(c_req); | 258 | c_req.header.length = sizeof(c_req); |
| 261 | c_req.header.reserved = 0; | 259 | c_req.header.reserved = 0; |
| 262 | c_req.header.type = usbmux_connect; | 260 | c_req.header.type = USBMUXD_CONNECT; |
| 263 | c_req.header.tag = 3; | 261 | c_req.header.tag = 3; |
| 264 | c_req.device_id = device_info.device_id; | 262 | c_req.device_id = device_info.device_id; |
| 265 | c_req.port = htons(device_port); | 263 | c_req.tcp_dport = htons(device_port); |
| 266 | c_req.reserved = 0; | 264 | c_req.reserved = 0; |
| 267 | 265 | ||
| 268 | if (send_buf(cdata->sfd, &c_req, sizeof(c_req)) < 0) { | 266 | if (send_buf(cdata->sfd, &c_req, sizeof(c_req)) < 0) { |
| @@ -346,26 +344,26 @@ int main(int argc, char **argv) | |||
| 346 | } | 344 | } |
| 347 | 345 | ||
| 348 | /* | 346 | /* |
| 349 | sfd = connect_unix_socket(SOCKET_FILE); | 347 | sfd = connect_unix_socket(USBMUXD_SOCKET_FILE); |
| 350 | if (sfd < 0) { | 348 | if (sfd < 0) { |
| 351 | printf("error opening socket, terminating.\n"); | 349 | printf("error opening socket, terminating.\n"); |
| 352 | return -1; | 350 | return -1; |
| 353 | } | 351 | } |
| 354 | 352 | ||
| 355 | // send hello | 353 | // send hello |
| 356 | hello.length = sizeof(struct usbmux_header); | 354 | hello.header.length = sizeof(hello); |
| 357 | hello.reserved = 0; | 355 | hello.header.reserved = 0; |
| 358 | hello.type = usbmux_hello; | 356 | hello.header.type = USBMUXD_HELLO; |
| 359 | hello.tag = 2; | 357 | hello.header.tag = 2; |
| 360 | 358 | ||
| 361 | hello_done = 0; | 359 | hello_done = 0; |
| 362 | connected = 0; | 360 | connected = 0; |
| 363 | 361 | ||
| 364 | fprintf(stdout, "sending Hello packet\n"); | 362 | fprintf(stdout, "sending Hello packet\n"); |
| 365 | if (send(sfd, &hello, hello.length, 0) == hello.length) { | 363 | if (send(sfd, &hello, hello.header.length, 0) == hello.header.length) { |
| 366 | uint32_t res = -1; | 364 | uint32_t res = -1; |
| 367 | // get response | 365 | // get response |
| 368 | if (usbmuxd_get_result(sfd, hello.tag, &res) && (res==0)) { | 366 | if (usbmuxd_get_result(sfd, hello.header.tag, &res) && (res==0)) { |
| 369 | fprintf(stdout, "Got Hello Response!\n"); | 367 | fprintf(stdout, "Got Hello Response!\n"); |
| 370 | hello_done = 1; | 368 | hello_done = 1; |
| 371 | } else { | 369 | } else { |
| @@ -390,7 +388,7 @@ int main(int argc, char **argv) | |||
| 390 | } | 388 | } |
| 391 | fprintf(stdout, "Received device data\n"); | 389 | fprintf(stdout, "Received device data\n"); |
| 392 | //log_debug_buffer(stdout, (char*)buf, pktlen); | 390 | //log_debug_buffer(stdout, (char*)buf, pktlen); |
| 393 | memcpy(&device_info, buf + sizeof(struct usbmux_header), sizeof(device_info)); | 391 | memcpy(&device_info, buf + sizeof(struct usbmuxd_header), sizeof(device_info)); |
| 394 | free(buf); | 392 | free(buf); |
| 395 | } else { | 393 | } else { |
| 396 | // we _should_ have all of them now. | 394 | // we _should_ have all of them now. |
| @@ -401,17 +399,17 @@ int main(int argc, char **argv) | |||
| 401 | } | 399 | } |
| 402 | 400 | ||
| 403 | if (device_info.device_id > 0) { | 401 | if (device_info.device_id > 0) { |
| 404 | struct usbmux_connect_request c_req; | 402 | struct usbmuxd_connect_request c_req; |
| 405 | 403 | ||
| 406 | fprintf(stdout, "Requesting connecion to device %d port %d\n", device_info.device_id, device_port); | 404 | fprintf(stdout, "Requesting connecion to device %d port %d\n", device_info.device_id, device_port); |
| 407 | 405 | ||
| 408 | // try to connect to last device found | 406 | // try to connect to last device found |
| 409 | c_req.header.length = sizeof(c_req); | 407 | c_req.header.length = sizeof(c_req); |
| 410 | c_req.header.reserved = 0; | 408 | c_req.header.reserved = 0; |
| 411 | c_req.header.type = usbmux_connect; | 409 | c_req.header.type = USBMUXD_CONNECT; |
| 412 | c_req.header.tag = 3; | 410 | c_req.header.tag = 3; |
| 413 | c_req.device_id = device_info.device_id; | 411 | c_req.device_id = device_info.device_id; |
| 414 | c_req.port = htons(device_port); | 412 | c_req.tcp_dport = htons(device_port); |
| 415 | c_req.reserved = 0; | 413 | c_req.reserved = 0; |
| 416 | 414 | ||
| 417 | if (send_buf(sfd, &c_req, sizeof(c_req)) < 0) { | 415 | if (send_buf(sfd, &c_req, sizeof(c_req)) < 0) { |
