diff options
author | sijanec <anton@sijanec.eu> | 2021-01-07 23:05:06 +0100 |
---|---|---|
committer | sijanec <anton@sijanec.eu> | 2021-01-07 23:05:06 +0100 |
commit | e7b75298fab79bec9380e7c5a81a5fd03dff63cc (patch) | |
tree | 360df28d611bd6a86bdaf9621f41581cef505c2f /tcp.c | |
parent | 0.0.6 stdout buffering fuc (diff) | |
download | rtv4d-dl-e7b75298fab79bec9380e7c5a81a5fd03dff63cc.tar rtv4d-dl-e7b75298fab79bec9380e7c5a81a5fd03dff63cc.tar.gz rtv4d-dl-e7b75298fab79bec9380e7c5a81a5fd03dff63cc.tar.bz2 rtv4d-dl-e7b75298fab79bec9380e7c5a81a5fd03dff63cc.tar.lz rtv4d-dl-e7b75298fab79bec9380e7c5a81a5fd03dff63cc.tar.xz rtv4d-dl-e7b75298fab79bec9380e7c5a81a5fd03dff63cc.tar.zst rtv4d-dl-e7b75298fab79bec9380e7c5a81a5fd03dff63cc.zip |
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; |