summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2014-06-02 15:00:15 +0200
committerSimon Rettberg2014-06-02 15:00:15 +0200
commit841e3e35937d942f4456d73070de32a0247eca46 (patch)
tree5451b84197a7091faac267fa21c6d028f8aa56e9
parentFix getaddrinfo call (diff)
downloadldadp-841e3e35937d942f4456d73070de32a0247eca46.tar.gz
ldadp-841e3e35937d942f4456d73070de32a0247eca46.tar.xz
ldadp-841e3e35937d942f4456d73070de32a0247eca46.zip
Actually really fix helper_connect4 when passing a hostname
-rw-r--r--helper.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/helper.c b/helper.c
index 2589675..6aed251 100644
--- a/helper.c
+++ b/helper.c
@@ -65,10 +65,12 @@ int helper_connect4(char *address, int port, char *ip)
for (rp = result; rp != NULL; rp = rp->ai_next) {
const int sock = socket_tcp4b();
if (sock == -1) continue;
- memcpy(ip, rp->ai_addr->sa_data, 4);
- if (socket_connect4(sock, ip, port) == 0) {
- freeaddrinfo(result);
- return sock; // Success
+ if (rp->ai_addr != NULL) {
+ memcpy(ip, &((struct sockaddr_in*)rp->ai_addr)->sin_addr, 4);
+ if (socket_connect4(sock, ip, port) == 0) {
+ freeaddrinfo(result);
+ return sock; // Success
+ }
}
close(sock);
}