File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 1010#include < sys/socket.h>
1111#include < arpa/inet.h>
1212#include < errno.h>
13+ #include < netdb.h>
1314#include < unistd.h> // for close()
1415#endif
1516
@@ -80,7 +81,16 @@ ConnectionResult TcpConnection::setup_port()
8081 struct sockaddr_in remote_addr {};
8182 remote_addr.sin_family = AF_INET;
8283 remote_addr.sin_port = htons (_remote_port_number);
83- remote_addr.sin_addr .s_addr = inet_addr (_remote_ip.c_str ());
84+
85+ struct hostent *hp;
86+ hp = gethostbyname (_remote_ip.c_str ());
87+ if (hp == nullptr ) {
88+ LogErr () << " Could not get host by name" ;
89+ _is_ok = false ;
90+ return ConnectionResult::SocketConnectionError;
91+ }
92+
93+ memcpy (&remote_addr.sin_addr , hp->h_addr , hp->h_length );
8494
8595 if (connect (_socket_fd, reinterpret_cast <sockaddr*>(&remote_addr), sizeof (struct sockaddr_in )) <
8696 0 ) {
You can’t perform that action at this time.
0 commit comments