Skip to content

Commit 8e2c677

Browse files
committed
GUACAMOLE-1686: Update WOL for all protocols to use guac_wake_and_wait.
1 parent d4a2339 commit 8e2c677

File tree

4 files changed

+139
-39
lines changed

4 files changed

+139
-39
lines changed

src/protocols/rdp/rdp.c

+41-11
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include <guacamole/socket.h>
7777
#include <guacamole/string.h>
7878
#include <guacamole/timestamp.h>
79+
#include <guacamole/wol-constants.h>
7980
#include <guacamole/wol.h>
8081
#include <winpr/error.h>
8182
#include <winpr/synch.h>
@@ -681,19 +682,48 @@ void* guac_rdp_client_thread(void* data) {
681682
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
682683
guac_rdp_settings* settings = rdp_client->settings;
683684

684-
/* If Wake-on-LAN is enabled, try to wake. */
685+
/* If Wake-on-LAN is enabled, attempt to wake. */
685686
if (settings->wol_send_packet) {
686-
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
687-
"and pausing for %d seconds.", settings->wol_wait_time);
688-
689-
/* Send the Wake-on-LAN request. */
690-
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr,
691-
settings->wol_udp_port))
687+
688+
/**
689+
* If wait time is set, send the wake packet and try to connect to the
690+
* server, failing if the server does not respond.
691+
*/
692+
if (settings->wol_wait_time > 0) {
693+
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
694+
"and pausing for %d seconds.", settings->wol_wait_time);
695+
696+
char* str_port = NULL;
697+
if (guac_itoa(str_port, settings->port) < 1) {
698+
guac_client_log(client, GUAC_LOG_ERROR, "Failed to convert port to integer for WOL function.");
699+
guac_mem_free(str_port);
700+
return NULL;
701+
}
702+
703+
/* Send the Wake-on-LAN request and wait until the server is responsive. */
704+
if (guac_wol_wake_and_wait(settings->wol_mac_addr,
705+
settings->wol_broadcast_addr,
706+
settings->wol_udp_port,
707+
settings->wol_wait_time,
708+
GUAC_WOL_DEFAULT_CONNECT_RETRIES,
709+
settings->hostname,
710+
(const char *) str_port)) {
711+
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet, or server failed to wake up.");
712+
guac_mem_free(str_port);
713+
return NULL;
714+
}
715+
716+
guac_mem_free(str_port);
717+
718+
}
719+
720+
/* Just send the packet and continue the connection, or return if failed. */
721+
else if(guac_wol_wake(settings->wol_mac_addr,
722+
settings->wol_broadcast_addr,
723+
settings->wol_udp_port)) {
724+
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet.");
692725
return NULL;
693-
694-
/* If wait time is specified, sleep for that amount of time. */
695-
if (settings->wol_wait_time > 0)
696-
guac_timestamp_msleep(settings->wol_wait_time * 1000);
726+
}
697727
}
698728

699729
/* If audio enabled, choose an encoder */

src/protocols/ssh/ssh.c

+28-9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <guacamole/recording.h>
4040
#include <guacamole/socket.h>
4141
#include <guacamole/timestamp.h>
42+
#include <guacamole/wol-constants.h>
4243
#include <guacamole/wol.h>
4344
#include <openssl/err.h>
4445
#include <openssl/ssl.h>
@@ -233,17 +234,35 @@ void* ssh_client_thread(void* data) {
233234

234235
/* If Wake-on-LAN is enabled, attempt to wake. */
235236
if (settings->wol_send_packet) {
236-
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
237-
"and pausing for %d seconds.", settings->wol_wait_time);
238237

239-
/* Send the Wake-on-LAN request. */
240-
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr,
241-
settings->wol_udp_port))
242-
return NULL;
238+
/**
239+
* If wait time is set, send the wake packet and try to connect to the
240+
* server, failing if the server does not respond.
241+
*/
242+
if (settings->wol_wait_time > 0) {
243+
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
244+
"and pausing for %d seconds.", settings->wol_wait_time);
245+
246+
/* Send the Wake-on-LAN request and wait until the server is responsive. */
247+
if (guac_wol_wake_and_wait(settings->wol_mac_addr,
248+
settings->wol_broadcast_addr,
249+
settings->wol_udp_port,
250+
settings->wol_wait_time,
251+
GUAC_WOL_DEFAULT_CONNECT_RETRIES,
252+
settings->hostname,
253+
settings->port)) {
254+
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet or connect to remote server.");
255+
return NULL;
256+
}
257+
}
243258

244-
/* If wait time is specified, sleep for that amount of time. */
245-
if (settings->wol_wait_time > 0)
246-
guac_timestamp_msleep(settings->wol_wait_time * 1000);
259+
/* Just send the packet and continue the connection, or return if failed. */
260+
else if(guac_wol_wake(settings->wol_mac_addr,
261+
settings->wol_broadcast_addr,
262+
settings->wol_udp_port)) {
263+
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet.");
264+
return NULL;
265+
}
247266
}
248267

249268
/* Init SSH base libraries */

src/protocols/telnet/telnet.c

+28-9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <guacamole/recording.h>
3030
#include <guacamole/socket-tcp.h>
3131
#include <guacamole/timestamp.h>
32+
#include <guacamole/wol-constants.h>
3233
#include <guacamole/wol.h>
3334
#include <libtelnet.h>
3435

@@ -494,17 +495,35 @@ void* guac_telnet_client_thread(void* data) {
494495

495496
/* If Wake-on-LAN is enabled, attempt to wake. */
496497
if (settings->wol_send_packet) {
497-
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
498-
"and pausing for %d seconds.", settings->wol_wait_time);
499498

500-
/* Send the Wake-on-LAN request. */
501-
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr,
502-
settings->wol_udp_port))
503-
return NULL;
499+
/**
500+
* If wait time is set, send the wake packet and try to connect to the
501+
* server, failing if the server does not respond.
502+
*/
503+
if (settings->wol_wait_time > 0) {
504+
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
505+
"and pausing for %d seconds.", settings->wol_wait_time);
506+
507+
/* Send the Wake-on-LAN request and wait until the server is responsive. */
508+
if (guac_wol_wake_and_wait(settings->wol_mac_addr,
509+
settings->wol_broadcast_addr,
510+
settings->wol_udp_port,
511+
settings->wol_wait_time,
512+
GUAC_WOL_DEFAULT_CONNECT_RETRIES,
513+
settings->hostname,
514+
settings->port)) {
515+
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet or connect to remote server.");
516+
return NULL;
517+
}
518+
}
504519

505-
/* If wait time is specified, sleep for that amount of time. */
506-
if (settings->wol_wait_time > 0)
507-
guac_timestamp_msleep(settings->wol_wait_time * 1000);
520+
/* Just send the packet and continue the connection, or return if failed. */
521+
else if(guac_wol_wake(settings->wol_mac_addr,
522+
settings->wol_broadcast_addr,
523+
settings->wol_udp_port)) {
524+
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet.");
525+
return NULL;
526+
}
508527
}
509528

510529
/* Set up screen recording, if requested */

src/protocols/vnc/vnc.c

+42-10
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@
4242
#endif
4343

4444
#include <guacamole/client.h>
45+
#include <guacamole/mem.h>
4546
#include <guacamole/protocol.h>
4647
#include <guacamole/recording.h>
4748
#include <guacamole/socket.h>
49+
#include <guacamole/string.h>
4850
#include <guacamole/timestamp.h>
51+
#include <guacamole/wol-constants.h>
4952
#include <guacamole/wol.h>
5053
#include <rfb/rfbclient.h>
5154
#include <rfb/rfbconfig.h>
@@ -274,17 +277,46 @@ void* guac_vnc_client_thread(void* data) {
274277

275278
/* If Wake-on-LAN is enabled, attempt to wake. */
276279
if (settings->wol_send_packet) {
277-
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
278-
"and pausing for %d seconds.", settings->wol_wait_time);
279-
280-
/* Send the Wake-on-LAN request. */
281-
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr,
282-
settings->wol_udp_port))
280+
281+
/**
282+
* If wait time is set, send the wake packet and try to connect to the
283+
* server, failing if the server does not respond.
284+
*/
285+
if (settings->wol_wait_time > 0) {
286+
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
287+
"and pausing for %d seconds.", settings->wol_wait_time);
288+
289+
char* str_port = NULL;
290+
if (guac_itoa(str_port, settings->port) < 1) {
291+
guac_client_log(client, GUAC_LOG_ERROR, "Failed to convert port to integer for WOL function.");
292+
guac_mem_free(str_port);
293+
return NULL;
294+
}
295+
296+
/* Send the Wake-on-LAN request and wait until the server is responsive. */
297+
if (guac_wol_wake_and_wait(settings->wol_mac_addr,
298+
settings->wol_broadcast_addr,
299+
settings->wol_udp_port,
300+
settings->wol_wait_time,
301+
GUAC_WOL_DEFAULT_CONNECT_RETRIES,
302+
settings->hostname,
303+
(const char *) str_port)) {
304+
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet or connect to remote system.");
305+
guac_mem_free(str_port);
306+
return NULL;
307+
}
308+
309+
guac_mem_free(str_port);
310+
311+
}
312+
313+
/* Just send the packet and continue the connection, or return if failed. */
314+
else if(guac_wol_wake(settings->wol_mac_addr,
315+
settings->wol_broadcast_addr,
316+
settings->wol_udp_port)) {
317+
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet.");
283318
return NULL;
284-
285-
/* If wait time is specified, sleep for that amount of time. */
286-
if (settings->wol_wait_time > 0)
287-
guac_timestamp_msleep(settings->wol_wait_time * 1000);
319+
}
288320
}
289321

290322
/* Configure clipboard encoding */

0 commit comments

Comments
 (0)