diff --git a/src/tds/tls.c b/src/tds/tls.c index 09e7fa0..1da18f6 100644 --- a/src/tds/tls.c +++ b/src/tds/tls.c @@ -101,6 +101,29 @@ #define SSL_PTR BIO_get_data(bio) #endif +/* + * Add a workaround for older Mingw versions without inet_pton(). + * This means RubyInstallers DevKit-4.7.2 in particular. + */ +#if defined(__MINGW32__) && !defined(InetPtonA) + #include + + static HMODULE ws2_32 = NULL; + typedef INT (WINAPI * __inet_pton)(INT Family, LPCWSTR pStringBuf, PVOID pAddr); + static __inet_pton _inet_pton = NULL; + + INT WINAPI inet_pton(INT Family, LPCWSTR pStringBuf, PVOID pAddr) + { + if (_inet_pton == NULL) { + ws2_32 = LoadLibraryEx("Ws2_32.dll", NULL, 0); + + _inet_pton = (__inet_pton)GetProcAddress(ws2_32, "inet_pton"); + } + + return (_inet_pton)(Family, pStringBuf, pAddr); + } +#endif + static SSL_RET tds_pull_func_login(SSL_PULL_ARGS) {