Skip to content

Commit

Permalink
dw_node: hostname resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
deRemo committed Oct 5, 2023
1 parent c2588a7 commit ee8a73e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/dw_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
Expand Down Expand Up @@ -1386,8 +1387,17 @@ int main(int argc, char *argv[]) {
serverAddr.sin_family = AF_INET;
/* Set port number, using htons function to use proper byte order */
serverAddr.sin_port = htons(bind_port);
/* Set IP address to localhost */
serverAddr.sin_addr.s_addr = inet_addr(bind_name);

// Resolve hostname
cw_log("Resolving %s...\n", bind_name);
struct hostent *e = gethostbyname(bind_name);
check(e != NULL);
cw_log("Host %s resolved to %d bytes: %s\n", bind_name, e->h_length,
inet_ntoa(*(struct in_addr *)e->h_addr));

/* Set IP address */
memmove((char *)e->h_addr, (char *) &serverAddr.sin_addr.s_addr, e->h_length);

/* Set all bits of the padding field to 0 */
memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);

Expand All @@ -1405,7 +1415,7 @@ int main(int argc, char *argv[]) {
sys_check(bind(thread_infos[i].listen_sock, (struct sockaddr *)&serverAddr,
sizeof(serverAddr)));

cw_log("Node binded to %s:%d\n", bind_name, bind_port);
cw_log("Node binded to %s:%d\n", inet_ntoa(serverAddr.sin_addr), bind_port);

/*---- Listen on the socket, with 5 max connection requests queued ----*/
sys_check(listen(thread_infos[i].listen_sock, 5));
Expand Down

0 comments on commit ee8a73e

Please sign in to comment.