diff options
author | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2012-06-14 18:57:24 +0100 |
---|---|---|
committer | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2012-06-14 18:57:24 +0100 |
commit | a8df98c6fb07b8ddff18a01d7f2f607d9493dd7c (patch) | |
tree | 508aa2bdd6278e967ce4122c37a6a7d9a77bdad5 /src/netops.c | |
parent | a21bb1aa33e9887c06852db62526895df6091736 (diff) | |
download | libgit2-a8df98c6fb07b8ddff18a01d7f2f607d9493dd7c.tar.gz |
Updates from comments on OS4 compatibility pull request http://github.com/libgit2/libgit2/pull/766
Diffstat (limited to 'src/netops.c')
-rw-r--r-- | src/netops.c | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/src/netops.c b/src/netops.c index 11295c5cd..166c97162 100644 --- a/src/netops.c +++ b/src/netops.c @@ -33,6 +33,16 @@ #include "buffer.h" #include "transport.h" +#ifdef NO_ADDRINFO +struct addrinfo { + struct hostent *ai_hostent; + struct servent *ai_servent; + struct sockaddr_in ai_addr; + int ai_socktype; + long ai_port; +}; +#endif + #ifdef GIT_WIN32 static void net_set_error(const char *str) { @@ -378,41 +388,38 @@ int gitno_connect(git_transport *t, const char *host, const char *port) { #ifndef NO_ADDRINFO struct addrinfo *info = NULL, *p; - struct addrinfo hints; #else int p; - struct hostent *hent; - struct servent *sent; - struct sockaddr_in saddr; - long port_num = 0; #endif + struct addrinfo hints; int ret; GIT_SOCKET s = INVALID_SOCKET; -#ifndef NO_ADDRINFO + memset(&hints, 0x0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; +#ifndef NO_ADDRINFO + hints.ai_family = AF_UNSPEC; if ((ret = getaddrinfo(host, port, &hints, &info)) < 0) { giterr_set(GITERR_NET, "Failed to resolve address for %s: %s", host, gai_strerror(ret)); return -1; } #else - hent = gethostbyname(host); - sent = getservbyname(port, 0); + hints.ai_hostent = gethostbyname(host); + hints.ai_servent = getservbyname(port, 0); - if(sent) - port_num = sent->s_port; + if(hints.ai_servent) + hints.ai_port = hints.ai_servent->s_port; else - port_num = atol(port); + hints.ai_port = atol(port); #endif #ifndef NO_ADDRINFO for (p = info; p != NULL; p = p->ai_next) { s = socket(p->ai_family, p->ai_socktype, p->ai_protocol); #else - for (p = 0; hent->h_addr_list[p] != NULL; p++) { - s = socket(hent->h_addrtype, SOCK_STREAM, 0); + for (p = 0; hints.ai_hostent->h_addr_list[p] != NULL; p++) { + s = socket(hints.ai_hostent->h_addrtype, hints.ai_socktype, 0); #endif if (s == INVALID_SOCKET) { net_set_error("error creating socket"); @@ -421,10 +428,10 @@ int gitno_connect(git_transport *t, const char *host, const char *port) #ifndef NO_ADDRINFO if (connect(s, p->ai_addr, (socklen_t)p->ai_addrlen) == 0) #else - memcpy(&saddr.sin_addr, hent->h_addr_list[p], hent->h_length); - saddr.sin_family = hent->h_addrtype; - saddr.sin_port = port_num; - if (connect(s, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in)) == 0) + memcpy(&hints.ai_addr.sin_addr, hints.ai_hostent->h_addr_list[p], hints.ai_hostent->h_length); + hints.ai_addr.sin_family = hints.ai_hostent->h_addrtype; + hints.ai_addr.sin_port = honts.ai_port; + if (connect(s, (struct sockaddr *)&hints.ai_addr, sizeof(struct sockaddr_in)) == 0) #endif break; @@ -438,7 +445,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port) #ifndef NO_ADDRINFO p == NULL) { #else - hent->h_addr_list[p] == NULL) { + hints.ai_hostent->h_addr_list[p] == NULL) { #endif giterr_set(GITERR_OS, "Failed to connect to %s", host); return -1; |