diff options
author | Eduardo Bart <edub4rt@gmail.com> | 2012-11-07 16:10:57 -0200 |
---|---|---|
committer | Eduardo Bart <edub4rt@gmail.com> | 2012-11-07 16:15:09 -0200 |
commit | 345eef23741b98636ab7ac3b1a12fa5178d5912b (patch) | |
tree | 489bcfa38bf8d4365d5dc8c77ca8acecbe739a7b /src/win32 | |
parent | d1a69d0fff03dcd4326adb63aee6464be0cad83f (diff) | |
download | libgit2-345eef23741b98636ab7ac3b1a12fa5178d5912b.tar.gz |
Move inet_pton to posix platform-compatibility layer
Diffstat (limited to 'src/win32')
-rw-r--r-- | src/win32/posix.h | 1 | ||||
-rw-r--r-- | src/win32/posix_w32.c | 44 |
2 files changed, 44 insertions, 1 deletions
diff --git a/src/win32/posix.h b/src/win32/posix.h index 80dcca5c1..d99864d05 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 649fe9b95..557f4f3bf 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; +} |