Merge pull request #1050 from edubart/development Fix compilation for mingw32 and cygwin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
diff --git a/src/netops.c b/src/netops.c
index 3e27434..fa4a729 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -274,11 +274,11 @@ static int verify_server_cert(gitno_ssl *ssl, const char *host)
}
/* Try to parse the host as an IP address to see if it is */
- if (inet_pton(AF_INET, host, &addr4)) {
+ if (p_inet_pton(AF_INET, host, &addr4)) {
type = GEN_IPADD;
addr = &addr4;
} else {
- if(inet_pton(AF_INET6, host, &addr6)) {
+ if(p_inet_pton(AF_INET6, host, &addr6)) {
type = GEN_IPADD;
addr = &addr6;
}
diff --git a/src/posix.c b/src/posix.c
index 985221d..d207ce1 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -205,3 +205,5 @@ int p_write(git_file fd, const void *buf, size_t cnt)
}
return 0;
}
+
+
diff --git a/src/unix/posix.h b/src/unix/posix.h
index bcd8003..f6f2e23 100644
--- a/src/unix/posix.h
+++ b/src/unix/posix.h
@@ -21,5 +21,6 @@
#define p_snprintf(b, c, f, ...) snprintf(b, c, f, __VA_ARGS__)
#define p_mkstemp(p) mkstemp(p)
#define p_setenv(n,v,o) setenv(n,v,o)
+#define p_inet_pton(a, b, c) inet_pton(a, b, c)
#endif
diff --git a/src/win32/posix.h b/src/win32/posix.h
index 80dcca5..d99864d 100644
--- a/src/win32/posix.h
+++ b/src/win32/posix.h
@@ -48,5 +48,6 @@ extern int p_getcwd(char *buffer_out, size_t size);
extern int p_rename(const char *from, const char *to);
extern int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags);
extern int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags);
+extern int p_inet_pton(int af, const char* src, void* dst);
#endif
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 649fe9b..557f4f3 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -11,7 +11,7 @@
#include <errno.h>
#include <io.h>
#include <fcntl.h>
-
+#include <ws2tcpip.h>
int p_unlink(const char *path)
{
@@ -504,3 +504,45 @@ int p_gettimeofday(struct timeval *tv, struct timezone *tz)
return 0;
}
+
+int p_inet_pton(int af, const char* src, void* dst)
+{
+ union {
+ struct sockaddr_in6 sin6;
+ struct sockaddr_in sin;
+ } sa;
+ size_t srcsize;
+
+ switch(af)
+ {
+ case AF_INET:
+ sa.sin.sin_family = AF_INET;
+ srcsize = sizeof (sa.sin);
+ break;
+ case AF_INET6:
+ sa.sin6.sin6_family = AF_INET6;
+ srcsize = sizeof (sa.sin6);
+ break;
+ default:
+ errno = WSAEPFNOSUPPORT;
+ return -1;
+ }
+
+ if (WSAStringToAddress(src, af, NULL, (struct sockaddr *) &sa, &srcsize) != 0)
+ {
+ errno = WSAGetLastError();
+ return -1;
+ }
+
+ switch(af)
+ {
+ case AF_INET:
+ memcpy(dst, &sa.sin.sin_addr, sizeof(sa.sin.sin_addr));
+ break;
+ case AF_INET6:
+ memcpy(dst, &sa.sin6.sin6_addr, sizeof(sa.sin6.sin6_addr));
+ break;
+ }
+
+ return 1;
+}