Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit cb5d358

Browse files
authored
Support remote_host DNS resolution (#130)
1 parent cd3ef38 commit cb5d358

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/remote_debugger.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <iostream>
1818
#include <memory>
19+
#include <netdb.h>
1920

2021
#include "./php_yasd_cxx.h"
2122
#include "include/global.h"
@@ -46,6 +47,7 @@ void RemoteDebugger::init() {
4647
register_cmd_handler();
4748

4849
struct sockaddr_in ide_address;
50+
struct hostent *host_entry;
4951

5052
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == 0) {
5153
perror("create socket failed");
@@ -55,13 +57,17 @@ void RemoteDebugger::init() {
5557
ide_address.sin_family = AF_INET;
5658
ide_address.sin_port = htons(YASD_G(remote_port));
5759

58-
if (inet_pton(AF_INET, YASD_G(remote_host), &ide_address.sin_addr) <= 0) {
59-
perror("Invalid address/ Address not supported");
60-
exit(EXIT_FAILURE);
60+
if (!inet_pton(AF_INET, YASD_G(remote_host), &ide_address.sin_addr)) {
61+
host_entry = gethostbyname(YASD_G(remote_host));
62+
if (host_entry == nullptr) {
63+
yasd::util::printfln_info(yasd::Color::YASD_ECHO_YELLOW, "[yasd] DNS resolution failed (%s %s)", YASD_G(remote_host), hstrerror(h_errno));
64+
return;
65+
}
66+
memcpy(&(ide_address.sin_addr.s_addr), host_entry->h_addr_list[0], host_entry->h_length);
6167
}
6268

6369
if (connect(sock, (struct sockaddr *) &ide_address, sizeof(ide_address)) < 0) {
64-
yasd::util::printfln_info(yasd::Color::YASD_ECHO_YELLOW, "[yasd] %s", strerror(errno));
70+
yasd::util::printfln_info(yasd::Color::YASD_ECHO_YELLOW, "[yasd] Connect IDE failed (%s), please check that the IDE is in a listening state", strerror(errno));
6571
return;
6672
}
6773

0 commit comments

Comments
 (0)