diff -Naur httping-1.5.1beta/main.c httping-1.5.1beta2/main.c --- httping-1.5.1beta/main.c 2010-08-13 16:06:41.000000000 +0300 +++ httping-1.5.1beta2/main.c 2011-05-11 11:50:15.887375403 +0300 @@ -262,6 +262,7 @@ SSL *ssl_h = NULL; BIO *s_bio; struct sockaddr_in6 bind_to; + struct sockaddr_in bind_to4; char bind_to_valid = 0; char split = 0, use_ipv6 = 0; char persistent_connections = 0, persistent_did_reconnect = 0; @@ -342,19 +343,28 @@ { char *dummy = strchr(optarg, ':'); - bind_to_valid = 1; - memset(&bind_to, 0x00, sizeof(bind_to)); + memset(&bind_to4, 0x00, sizeof(bind_to4)); + bind_to4.sin_family = AF_INET; + bind_to.sin6_family = AF_INET6; if (dummy) { bind_to.sin6_port = htons(atoi(dummy + 1)); + bind_to4.sin_port = htons(atoi(dummy + 1)); *dummy = 0x00; } if (inet_pton(AF_INET6, optarg, &(bind_to.sin6_addr)) != 1) { - error_exit("cannot convert ip address '%s' (for -y)\n", optarg); + /* Try IPv4 fallback */ + if (inet_pton(AF_INET, optarg, &(bind_to4.sin_addr)) != 1) { + error_exit("cannot convert ip address '%s' (for -y)\n", optarg); + } else { + bind_to_valid = 4; + } + } else { + bind_to_valid = 6; } } break; @@ -724,8 +734,21 @@ have_resolved = 1; } - if ((persistent_connections && fd < 0) || (!persistent_connections)) - fd = connect_to(bind_to_valid?(struct sockaddr *)&bind_to:NULL, &ai, timeout); + if ((persistent_connections && fd < 0) || (!persistent_connections)) { + switch(bind_to_valid) { + case 0: + fd = connect_to(NULL, &ai, timeout); + break; + case 4: + fd = connect_to((struct sockaddr *)&bind_to4, &ai, timeout); + break; + case 6: + fd = connect_to((struct sockaddr *)&bind_to, &ai, timeout); + break; + default: + break; + } + } if (fd == -3) /* ^C pressed */ break;