|
45 | 45 | #include <sys/ioctl.h> |
46 | 46 | #include <sys/types.h> |
47 | 47 | #include <unistd.h> |
| 48 | +#include <netdb.h> |
| 49 | +#include <sys/socket.h> |
48 | 50 |
|
49 | 51 | #if HAVE_PTY_H |
50 | 52 | #include <pty.h> |
@@ -193,7 +195,7 @@ void STMClient::init( void ) |
193 | 195 | tmp = std::string( escape_key_name_buf ); |
194 | 196 | std::wstring escape_key_name = std::wstring( tmp.begin(), tmp.end() ); |
195 | 197 | escape_key_help |
196 | | - = L"Commands: Ctrl-Z suspends, \".\" quits, " + escape_pass_name + L" gives literal " + escape_key_name; |
| 198 | + = L"Commands: Ctrl-Z suspends, \".\" quits, \"r\" forces a re-resolve, " + escape_pass_name + L" gives literal " + escape_key_name; |
197 | 199 | overlays.get_notification_engine().set_escape_key_string( tmp ); |
198 | 200 | } |
199 | 201 | wchar_t tmp[128]; |
@@ -367,6 +369,41 @@ bool STMClient::process_user_input( int fd ) |
367 | 369 | kill( 0, SIGSTOP ); |
368 | 370 |
|
369 | 371 | resume(); |
| 372 | + } else if ( the_byte == 'r' || the_byte == 'R' ) { |
| 373 | + if ( !hostname.empty() ) { |
| 374 | + overlays.get_notification_engine().set_notification_string( std::wstring( L"Re-resolving..." ), true ); |
| 375 | + output_new_frame(); |
| 376 | + struct addrinfo hints, *res; |
| 377 | + memset( &hints, 0, sizeof( hints ) ); |
| 378 | + hints.ai_family = AF_UNSPEC; |
| 379 | + hints.ai_socktype = SOCK_DGRAM; |
| 380 | + int err = getaddrinfo( hostname.c_str(), port.c_str(), &hints, &res ); |
| 381 | + if ( err == 0 ) { |
| 382 | + struct addrinfo *p; |
| 383 | + struct addrinfo *match = NULL; |
| 384 | + int current_family = net.get_remote_addr().sa.sa_family; |
| 385 | + |
| 386 | + for ( p = res; p != NULL; p = p->ai_next ) { |
| 387 | + if ( p->ai_family == current_family ) { |
| 388 | + match = p; |
| 389 | + break; |
| 390 | + } |
| 391 | + } |
| 392 | + |
| 393 | + if ( match ) { |
| 394 | + net.set_remote_addr( match->ai_addr, match->ai_addrlen ); |
| 395 | + } else { |
| 396 | + net.set_remote_addr( res->ai_addr, res->ai_addrlen ); |
| 397 | + } |
| 398 | + |
| 399 | + freeaddrinfo( res ); |
| 400 | + overlays.get_notification_engine().set_notification_string( std::wstring( L"Re-resolved hostname." ), false ); |
| 401 | + } else { |
| 402 | + std::string msg = "DNS failure: "; |
| 403 | + msg += gai_strerror( err ); |
| 404 | + overlays.get_notification_engine().set_notification_string( std::wstring( msg.begin(), msg.end() ), false ); |
| 405 | + } |
| 406 | + } |
370 | 407 | } else if ( ( the_byte == escape_pass_key ) || ( the_byte == escape_pass_key2 ) ) { |
371 | 408 | /* Emulation sequence to type escape_key is escape_key + |
372 | 409 | escape_pass_key (that is escape key without Ctrl) */ |
|
0 commit comments