diff --git a/lib/krb5/net_read.c b/lib/krb5/net_read.c index 5a8045988..512a3ccef 100644 --- a/lib/krb5/net_read.c +++ b/lib/krb5/net_read.c @@ -41,5 +41,19 @@ krb5_net_read (krb5_context context, { SOCKET fd = *((SOCKET *)p_fd); +#ifdef SOCKET_IS_NOT_AN_FD +#ifdef _MSC_VER + { + HANDLE h = _get_osfhandle(fd); + + if (h != INVALID_HANDLE_VALUE) { + return net_read (fd, buf, len); + } + } +#else +#error Don't know how to handle socket that may be an fd +#endif +#endif + return net_read_s (fd, buf, len); } diff --git a/lib/krb5/net_write.c b/lib/krb5/net_write.c index 6377957ac..1561a4440 100644 --- a/lib/krb5/net_write.c +++ b/lib/krb5/net_write.c @@ -41,6 +41,20 @@ krb5_net_write (krb5_context context, { SOCKET fd = *((SOCKET *)p_fd); +#ifdef SOCKET_IS_NOT_AN_FD +#ifdef _MSC_VER + { + HANDLE h = _get_osfhandle(fd); + + if (h != INVALID_HANDLE_VALUE) { + return net_write (fd, buf, len); + } + } +#else +#error Don't know how to handle SOCKET that may be an fd +#endif +#endif + return net_write_s (fd, buf, len); } diff --git a/lib/krb5/store_fd.c b/lib/krb5/store_fd.c index 2a3fdaf60..a8974b649 100644 --- a/lib/krb5/store_fd.c +++ b/lib/krb5/store_fd.c @@ -86,11 +86,25 @@ fd_free(krb5_storage * sp) */ KRB5_LIB_FUNCTION krb5_storage * KRB5_LIB_CALL -krb5_storage_from_fd(int fd) +krb5_storage_from_fd(SOCKET fd_in) { krb5_storage *sp; + int fd; + +#ifdef SOCKET_IS_NOT_AN_FD +#ifdef _MSC_VER + if (_get_osfhandle(fd_in) != -1) { + fd = dup(fd_in); + } else { + fd = _open_osfhandle(fd_in, 0); + } +#else +#error Don't know how to deal with fd that may or may not be a socket. +#endif +#else /* SOCKET_IS_NOT_AN_FD */ + fd = dup(fd_in); +#endif - fd = dup(fd); if (fd < 0) return NULL;