summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorGDR! <gdr@go2.pl>2014-12-11 23:27:26 +0100
committerGDR! <gdr@go2.pl>2014-12-11 23:27:26 +0100
commit99a66836911b804dce1455580cbf75dc99f23538 (patch)
tree2eee635f310b1dd9e39dbc45e74c60168a1fdce3 /main.c
parentc9f51df320380a537843145ebbf4ceff7ef1c561 (diff)
Pipe mode working, yay!
Diffstat (limited to 'main.c')
-rw-r--r--main.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/main.c b/main.c
index 8cef6ce..9d3d495 100644
--- a/main.c
+++ b/main.c
@@ -94,7 +94,7 @@ tunnel *tunnel_create(int sockfd, int connid, uint32_t friendnumber)
94 94
95void tunnel_delete(tunnel *t) 95void tunnel_delete(tunnel *t)
96{ 96{
97 printf("Deleting tunnel #%d\n", t->connid); 97 fprintf(stderr, "Deleting tunnel #%d\n", t->connid);
98 if(t->sockfd) 98 if(t->sockfd)
99 { 99 {
100 close(t->sockfd); 100 close(t->sockfd);
@@ -331,10 +331,10 @@ int handle_request_tunnel_frame(protocol_frame *rcvd_frame)
331 strncpy(hostname, rcvd_frame->data, rcvd_frame->data_length); 331 strncpy(hostname, rcvd_frame->data, rcvd_frame->data_length);
332 hostname[rcvd_frame->data_length] = '\0'; 332 hostname[rcvd_frame->data_length] = '\0';
333 333
334 printf("Got a request to forward data from %s:%d\n", hostname, port); 334 fprintf(stderr, "Got a request to forward data from %s:%d\n", hostname, port);
335 335
336 tunnel_id = get_random_tunnel_id(); 336 tunnel_id = get_random_tunnel_id();
337 printf("Tunnel ID: %d\n", tunnel_id); 337 fprintf(stderr, "Tunnel ID: %d\n", tunnel_id);
338 /* TODO make connection */ 338 /* TODO make connection */
339 sockfd = get_client_socket(hostname, port); 339 sockfd = get_client_socket(hostname, port);
340 if(sockfd > 0) 340 if(sockfd > 0)
@@ -509,7 +509,7 @@ int parse_lossless_packet(void *sender_uc, const uint8_t *data, uint32_t len)
509 frame->data_length = INT16_AT(data, 6); 509 frame->data_length = INT16_AT(data, 6);
510 frame->data = (uint8_t *)(data + PROTOCOL_BUFFER_OFFSET); 510 frame->data = (uint8_t *)(data + PROTOCOL_BUFFER_OFFSET);
511 frame->friendnumber = *((uint32_t*)sender_uc); 511 frame->friendnumber = *((uint32_t*)sender_uc);
512 printf("Got protocol frame magic 0x%x type 0x%x from friend %d\n", frame->magic, frame->packet_type, frame->friendnumber); 512 fprintf(stderr, "Got protocol frame magic 0x%x type 0x%x from friend %d\n", frame->magic, frame->packet_type, frame->friendnumber);
513 513
514 if(len < frame->data_length + PROTOCOL_BUFFER_OFFSET) 514 if(len < frame->data_length + PROTOCOL_BUFFER_OFFSET)
515 { 515 {
@@ -639,13 +639,13 @@ void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *d
639 int32_t friendnumber; 639 int32_t friendnumber;
640 int32_t *friendnumber_ptr = NULL; 640 int32_t *friendnumber_ptr = NULL;
641 641
642 printf("Got friend request\n"); 642 fprintf(stderr, "Got friend request\n");
643 643
644 friendnumber = tox_add_friend_norequest(tox, public_key); 644 friendnumber = tox_add_friend_norequest(tox, public_key);
645 645
646 memset(tox_printable_id, '\0', sizeof(tox_printable_id)); 646 memset(tox_printable_id, '\0', sizeof(tox_printable_id));
647 id_to_string(tox_printable_id, public_key); 647 id_to_string(tox_printable_id, public_key);
648 printf("Accepted friend request from %s as %d\n", tox_printable_id, friendnumber); 648 fprintf(stderr, "Accepted friend request from %s as %d\n", tox_printable_id, friendnumber);
649 649
650 /* TODO: this is not freed right now, we're leaking 4 bytes per contact (OMG!) */ 650 /* TODO: this is not freed right now, we're leaking 4 bytes per contact (OMG!) */
651 friendnumber_ptr = malloc(sizeof(int32_t)); 651 friendnumber_ptr = malloc(sizeof(int32_t));
@@ -662,7 +662,7 @@ void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *d
662 662
663void cleanup(int status, void *tmp) 663void cleanup(int status, void *tmp)
664{ 664{
665 printf("kthxbye\n"); 665 fprintf(stderr, "kthxbye\n");
666 fflush(stdout); 666 fflush(stdout);
667 tox_kill(tox); 667 tox_kill(tox);
668 if(client_socket) 668 if(client_socket)
@@ -726,7 +726,7 @@ int do_server_loop()
726 char data[PROTOCOL_BUFFER_OFFSET]; 726 char data[PROTOCOL_BUFFER_OFFSET];
727 protocol_frame frame_st, *frame; 727 protocol_frame frame_st, *frame;
728 728
729 printf("conn closed!\n"); 729 fprintf(stderr, "conn closed!\n");
730 730
731 frame = &frame_st; 731 frame = &frame_st;
732 memset(frame, 0, sizeof(protocol_frame)); 732 memset(frame, 0, sizeof(protocol_frame));
@@ -738,7 +738,6 @@ int do_server_loop()
738 738
739 tunnel_delete(tun); 739 tunnel_delete(tun);
740 740
741 /* TODO remove tunnel? resume connection? */
742 continue; 741 continue;
743 } 742 }
744 else 743 else
@@ -775,7 +774,7 @@ int main(int argc, char *argv[])
775 unsigned char tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1]; 774 unsigned char tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1];
776 int oc; 775 int oc;
777 776
778 while ((oc = getopt(argc, argv, "L:pi:C:")) != -1) 777 while ((oc = getopt(argc, argv, "L:pi:C:P:")) != -1)
779 { 778 {
780 switch(oc) 779 switch(oc)
781 { 780 {
@@ -794,8 +793,12 @@ int main(int argc, char *argv[])
794 /* Pipe forwarding */ 793 /* Pipe forwarding */
795 client_mode = 1; 794 client_mode = 1;
796 client_pipe_mode = 1; 795 client_pipe_mode = 1;
797 remote_port = atoi(optarg); 796 if(parse_pipe_port_forward(optarg, &remote_host, &remote_port) < 0)
798 fprintf(stderr, "Forwarding remote port %d\n", remote_port); 797 {
798 fprintf(stderr, "Invalid value for -P option - use something like -P 127.0.0.1:22\n");
799 exit(1);
800 }
801 fprintf(stderr, "Forwarding remote port %d to stdin/out\n", remote_port);
799 break; 802 break;
800 case 'p': 803 case 'p':
801 /* Ping */ 804 /* Ping */
@@ -843,7 +846,7 @@ int main(int argc, char *argv[])
843 tox_get_address(tox, tox_id); 846 tox_get_address(tox, tox_id);
844 id_to_string(tox_printable_id, tox_id); 847 id_to_string(tox_printable_id, tox_id);
845 tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2] = '\0'; 848 tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2] = '\0';
846 printf("Generated Tox ID: %s\n", tox_printable_id); 849 fprintf(stderr, "Generated Tox ID: %s\n", tox_printable_id);
847 850
848 if(!remote_tox_id) 851 if(!remote_tox_id)
849 { 852 {
@@ -866,7 +869,7 @@ int main(int argc, char *argv[])
866 memset(tox_printable_id, '\0', sizeof(tox_printable_id)); 869 memset(tox_printable_id, '\0', sizeof(tox_printable_id));
867 id_to_string(tox_printable_id, tox_id); 870 id_to_string(tox_printable_id, tox_id);
868 tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2] = '\0'; 871 tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2] = '\0';
869 printf("Using Tox ID: %s\n", tox_printable_id); 872 fprintf(stderr, "Using Tox ID: %s\n", tox_printable_id);
870 873
871 tox_callback_friend_request(tox, accept_friend_request, NULL); 874 tox_callback_friend_request(tox, accept_friend_request, NULL);
872 do_server_loop(); 875 do_server_loop();