Cygwin doesn't support IPv6 or getaddrinfo()
hpa committed
Sep 28, 2005 at 16:37 UTC
4c505f71e60b9d152a3a9d7a59b8b5146991a288
1 file changed
+73
connect.c
+73
@@ -290,6 +290,8 @@ static enum protocol get_protocol(const char *name)
290
#define STR_(s) # s
291
#define STR(s) STR_(s)
292
293
+#ifndef __CYGWIN__
294
+
295
static int git_tcp_connect(int fd[2], const char *prog, char *host, char *path)
296
{
297
int sockfd = -1;
@@ -346,6 +348,77 @@ static int git_tcp_connect(int fd[2], const char *prog, char *host, char *path)
348
return 0;
349
}
350
351
+#else /* __CYGWIN__ */
352
+
353
+static int git_tcp_connect(int fd[2], const char *prog, char *host, char *path)
354
+{
355
+ int sockfd = -1;
356
+ char *colon, *end;
357
+ char *port = STR(DEFAULT_GIT_PORT), *ep;
358
+ struct hostent *he;
359
+ struct sockaddr_in sa;
360
+ char **ap;
361
+ unsigned int nport;
362
+
363
+ if (host[0] == '[') {
364
+ end = strchr(host + 1, ']');
365
+ if (end) {
366
+ *end = 0;
367
+ end++;
368
+ host++;
369
+ } else
370
+ end = host;
371
+ } else
372
+ end = host;
373
+ colon = strchr(end, ':');
374
+
375
+ if (colon) {
376
+ *colon = 0;
377
+ port = colon + 1;
378
+ }
379
+
380
+
381
+ he = gethostbyname(host);
382
+ if (!he)
383
+ die("Unable to look up %s (%s)", host, hstrerror(h_errno));
384
+ nport = strtoul(port, &ep, 10);
385
+ if ( ep == port || *ep ) {
386
+ /* Not numeric */
387
+ struct servent *se = getservbyname(port,"tcp");
388
+ if ( !se )
389
+ die("Unknown port %s\n", port);
390
+ nport = se->s_port;
391
+ }
392
+
393
+ for (ap = he->h_addr_list; *ap; ap++) {
394
+ sockfd = socket(he->h_addrtype, SOCK_STREAM, 0);
395
+ if (sockfd < 0)
396
+ continue;
397
+
398
+ memset(&sa, 0, sizeof sa);
399
+ sa.sin_family = he->h_addrtype;
400
+ sa.sin_port = nport;
401
+ memcpy(&sa.sin_addr, ap, he->h_length);
402
+
403
+ if (connect(sockfd, (struct sockaddr *)&sa, sizeof sa) < 0) {
404
+ close(sockfd);
405
+ sockfd = -1;
406
+ continue;
407
+ }
408
+ break;
409
+ }
410
+
411
+ if (sockfd < 0)
412
+ die("unable to connect a socket (%s)", strerror(errno));
413
+
414
+ fd[0] = sockfd;
415
+ fd[1] = sockfd;
416
+ packet_write(sockfd, "%s %s\n", prog, path);
417
+ return 0;
418
+}
419
+
420
+#endif /* __CYGWIN__ */
421
+
422
/*
423
* Yeah, yeah, fixme. Need to pass in the heads etc.
424
*/