From e7b75298fab79bec9380e7c5a81a5fd03dff63cc Mon Sep 17 00:00:00 2001 From: sijanec Date: Thu, 7 Jan 2021 23:05:06 +0100 Subject: =?UTF-8?q?0.0.6=20ne=20kriti=C4=8Dno,=2012-krat=20ponovno=20posku?= =?UTF-8?q?si=20resolvat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tcp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tcp.c b/tcp.c index df49c30..1265a58 100644 --- a/tcp.c +++ b/tcp.c @@ -14,6 +14,7 @@ #include #define ERR_INET_ADDR "0.9.9.0" #define TCPC_READ_BUF 1048576 /* en megabajt */ +#define TCPC_RESOLVE_RETRIES 12 union ip_conv { unsigned char c[4]; struct in_addr in; @@ -36,6 +37,7 @@ int spawn_conn (const char * address, const int port) { int ret; int conn_fd; struct sockaddr_in server_addr = { 0 }; + unsigned short int r /* etries */= TCPC_RESOLVE_RETRIES; server_addr.sin_family = AF_INET; server_addr.sin_port = htons(port); ret = inet_pton(AF_INET, address, &server_addr.sin_addr); @@ -43,11 +45,15 @@ int spawn_conn (const char * address, const int port) { if (ret == -1) perror("inet_pton"); fprintf(stderr, "%s is not an IPv4, trying to resolve ...\n", address); - struct in_addr ret = hostname_to_ip(address); + struct in_addr ret; /* zakaj sem tudi to poimenoval ret!? sicer dela. */ struct in_addr error_addr; +retry_resolve: + ret = hostname_to_ip(address); inet_aton(ERR_INET_ADDR, &error_addr); if (memcmp(&ret, &error_addr, 4) == 0) { - fprintf(stderr, "failed to resolve.\n"); + fprintf(stderr, "failed to resolve-%s.\n", r ? "retrying" : "failing"); + if (r--) + goto retry_resolve; return -1; } server_addr.sin_addr = ret; -- cgit v1.2.3