1 diff --git a/connect.c b/connect.c
4 @@ -96,42 +96,57 @@ static enum protocol get_protocol(const
5 die("I don't handle protocol '%s'", name);
8 -static void lookup_host(const char *host, struct sockaddr *in)
10 - struct addrinfo *res;
13 - ret = getaddrinfo(host, NULL, NULL, &res);
15 - die("Unable to look up %s (%s)", host, gai_strerror(ret));
16 - *in = *res->ai_addr;
20 +#define STR(s) STR_(s)
22 static int git_tcp_connect(int fd[2], const char *prog, char *host, char *path)
24 - struct sockaddr addr;
25 - int port = DEFAULT_GIT_PORT, sockfd;
28 - colon = strchr(host, ':');
31 - unsigned long n = strtoul(colon+1, &end, 0);
32 - if (colon[1] && !*end) {
37 + char *port = STR(DEFAULT_GIT_PORT);
38 + struct addrinfo hints, *ai0, *ai;
41 + if (host[0] == '[') {
42 + end = strchr(host + 1, ']');
51 + colon = strchr(end, ':');
56 + memset(&hints, 0, sizeof(hints));
57 + hints.ai_socktype = SOCK_STREAM;
58 + hints.ai_protocol = IPPROTO_TCP;
60 + gai = getaddrinfo(host, port, &hints, &ai);
62 + die("Unable to look up %s (%s)", host, gai_strerror(gai));
64 + for (ai0 = ai; ai; ai = ai->ai_next) {
65 + sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
68 + if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
76 - lookup_host(host, &addr);
77 - ((struct sockaddr_in *)&addr)->sin_port = htons(port);
80 - sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
82 die("unable to create socket (%s)", strerror(errno));
83 - if (connect(sockfd, (void *)&addr, sizeof(addr)) < 0)
84 - die("unable to connect (%s)", strerror(errno));
88 packet_write(sockfd, "%s %s\n", prog, path);
91 YOSHIFUJI Hideaki @ USAGI Project <yoshfuji@linux-ipv6.org>
92 GPG-FP : 9022 65EB 1ECF 3AD1 0BDF 80D8 4807 F894 E062 0EEA