diff options
Diffstat (limited to 'tcp.c')
-rw-r--r-- | tcp.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -14,6 +14,7 @@ #include <sys/time.h> #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; |