diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2013-03-11 19:00:28 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2013-03-11 19:00:28 +0100 |
commit | f0e79c0c5946e113edc346220bb1906681ab82ac (patch) | |
tree | 7ccc2926c5d0af8ea3bd3dc252826a331dac9ac9 | |
parent | 908d1e8437404c34a267f3a8084d14434f1734d9 (diff) | |
download | econ-f0e79c0c5946e113edc346220bb1906681ab82ac.tar.gz econ-f0e79c0c5946e113edc346220bb1906681ab82ac.tar.bz2 econ-f0e79c0c5946e113edc346220bb1906681ab82ac.zip |
econproxy: Support connecting to a vnc server
So that we do not require that the server supports reverse connection.
-rw-r--r-- | econproxy.c | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/econproxy.c b/econproxy.c index d0012b0..eedbc82 100644 --- a/econproxy.c +++ b/econproxy.c @@ -614,7 +614,7 @@ err: } static int -rfb_init(struct ep *ep) +rfb_init(struct ep *ep, const char *vnc_server_ip, const char *vnc_server_port) { char client_protocol[12]; const char *rfb_protocol = "RFB 003.008\n"; @@ -635,13 +635,21 @@ rfb_init(struct ep *ep) } init; ssize_t len; - ep->vnc_mfd = bind_socket(SOCK_STREAM, "localhost", "5500"); - if (ep->vnc_mfd < 0) - return -1; + if (vnc_server_ip) { + ep->vnc_mfd = -1; + ep->vnc_fd = connect_to_host(SOCK_STREAM, + vnc_server_ip, vnc_server_port); + if (ep->vnc_fd < 0) + return -1; + } else { + ep->vnc_mfd = bind_socket(SOCK_STREAM, "localhost", "5500"); + if (ep->vnc_mfd < 0) + return -1; - ep->vnc_fd = accept(ep->vnc_mfd, NULL, NULL); - if (ep->vnc_fd < 0) - return -1; + ep->vnc_fd = accept(ep->vnc_mfd, NULL, NULL); + if (ep->vnc_fd < 0) + return -1; + } read(ep->vnc_fd, client_protocol, sizeof client_protocol); @@ -748,16 +756,34 @@ main(int argc, char *argv[]) { struct ep ep; const char *beamer; + const char *vnc_server_ip = NULL, *vnc_server_port = "5900"; int incremental = 0; + int ch; memset(&ep, 0, sizeof ep); - if (argc < 2) - exit(EXIT_FAILURE); + opterr = 0; + while ((ch = getopt(argc, argv, "v:p:")) != -1) { + switch (ch) { + case 'v': + vnc_server_ip = optarg; + break; + case 'p': + vnc_server_port = optarg; + break; + default: + exit(EXIT_FAILURE); + } + } + argc -= optind; + argv += optind; - beamer = argv[1]; + if (argc < 1) + exit(EXIT_FAILURE); - if (rfb_init(&ep) < 0) + beamer = argv[0]; + + if (rfb_init(&ep, vnc_server_ip, vnc_server_port) < 0) exit(EXIT_FAILURE); if (econ_init(&ep, beamer) < 0) |