-
-
Notifications
You must be signed in to change notification settings - Fork 491
/
repeater.c
101 lines (83 loc) · 2.96 KB
/
repeater.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
This example shows how to connect to an UltraVNC repeater.
To get you started, you will need the actual repeater.
Here's a non-exhaustive link list, some have install instructions,
some don't:
* The official UltraVNC repeater for Windows: https://uvnc.com/downloads/repeater/83-repeater-downloads.html
* The Linux port of the UltraVNC repeater, linked (but not made) by TurboVNC: https://turbovnc.org/Documentation/UltraVNCRepeater
* An enhanced versions of x11vnc's Perl implementation: https://github.com/tomka/ultravnc-repeater
After installing and running, you simply connect this server example via
`./repeater <id> <repeater-host> [<repeater-port>]`, where 'id' is a number.
For an UltraVNC repeater, the server will then show up in the
"Waiting servers" list of the repeater's web interface.
To connect with say the example SDLvncviewer, run
`./SDLvncviewer -repeaterdest ID:<id> <repeater-host>:[<repeater-port>]`
where 'id' is the same number you used with the server example above.
If the ids match, the repeater will then forward packets in between
the connected server and client. That's it!
*/
#include <rfb/rfb.h>
static void clientGone(rfbClientPtr cl)
{
rfbShutdownServer(cl->screen, TRUE);
}
int main(int argc,char** argv)
{
char *repeaterHost;
int repeaterPort, sock;
char id[250];
rfbClientPtr cl;
int i,j;
uint16_t* f;
/* Parse command-line arguments */
if (argc < 3) {
fprintf(stderr,
"Usage: %s <id> <repeater-host> [<repeater-port>]\n", argv[0]);
exit(1);
}
memset(id, 0, sizeof(id));
if(snprintf(id, sizeof(id), "ID:%s", argv[1]) >= (int)sizeof(id)) {
/* truncated! */
fprintf(stderr, "Error, given ID is too long.\n");
return 1;
}
repeaterHost = argv[2];
repeaterPort = argc < 4 ? 5500 : atoi(argv[3]);
/* The initialization is identical to simple15.c */
rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,5,3,2);
if(!server)
return 1;
server->frameBuffer=(char*)malloc(400*300*2);
if(!server->frameBuffer)
return 1;
f=(uint16_t*)server->frameBuffer;
for(j=0;j<300;j++)
for(i=0;i<400;i++)
f[j*400+i]=/* red */ ((j*32/300) << 10) |
/* green */ (((j+400-i)*32/700) << 5) |
/* blue */ (i*32/400);
/* Now for the repeater-specific part: */
server->port = -1; /* do not listen on any port */
server->ipv6port = -1; /* do not listen on any port */
/* Make sure to call this _before_ connecting out to the repeater */
rfbInitServer(server);
sock = rfbConnectToTcpAddr(repeaterHost, repeaterPort);
if (sock == RFB_INVALID_SOCKET) {
perror("connect to repeater");
return 1;
}
if (send(sock, id, sizeof(id),0) != sizeof(id)) {
perror("writing id");
return 1;
}
cl = rfbNewClient(server, sock);
if (!cl) {
perror("new client");
return 1;
}
cl->reverseConnection = 0;
cl->clientGoneHook = clientGone;
/* Run the server */
rfbRunEventLoop(server,-1,FALSE);
return 0;
}