mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-24 05:09:27 +00:00
Fix compilation for mingw32 and cygwin
inet_pton is available only in windows vista or later, fixed the issue by reimplementing it using WSAStringToAddress
This commit is contained in:
parent
8a85378829
commit
d1a69d0fff
52
src/netops.c
52
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 */
|
/* Try to parse the host as an IP address to see if it is */
|
||||||
if (inet_pton(AF_INET, host, &addr4)) {
|
if (gitno_inet_pton(AF_INET, host, &addr4)) {
|
||||||
type = GEN_IPADD;
|
type = GEN_IPADD;
|
||||||
addr = &addr4;
|
addr = &addr4;
|
||||||
} else {
|
} else {
|
||||||
if(inet_pton(AF_INET6, host, &addr6)) {
|
if(gitno_inet_pton(AF_INET6, host, &addr6)) {
|
||||||
type = GEN_IPADD;
|
type = GEN_IPADD;
|
||||||
addr = &addr6;
|
addr = &addr6;
|
||||||
}
|
}
|
||||||
@ -597,3 +597,51 @@ int gitno_extract_host_and_port(char **host, char **port, const char *url, const
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int gitno_inet_pton(int af, const char* src, void* dst)
|
||||||
|
{
|
||||||
|
/* inet_pton is only available in Windows Vista or later
|
||||||
|
* mingw32 and cygwin give compile errors */
|
||||||
|
#ifndef GIT_WIN32
|
||||||
|
return inet_pton(af, src, dst);
|
||||||
|
#else
|
||||||
|
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;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
@ -67,5 +67,6 @@ int gitno_close(gitno_socket *s);
|
|||||||
int gitno_select_in(gitno_buffer *buf, long int sec, long int usec);
|
int gitno_select_in(gitno_buffer *buf, long int sec, long int usec);
|
||||||
|
|
||||||
int gitno_extract_host_and_port(char **host, char **port, const char *url, const char *default_port);
|
int gitno_extract_host_and_port(char **host, char **port, const char *url, const char *default_port);
|
||||||
|
int gitno_inet_pton(int af, const char *src, void *dst);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user