From c7a908cc5adede6ca34519059f2e324dc6737ff6 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Fri, 1 May 2020 11:21:05 -0400 Subject: SSL network connections now seem to work, including on windows --- network.F90 | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'network.F90') diff --git a/network.F90 b/network.F90 index 2130841..2ad520b 100644 --- a/network.F90 +++ b/network.F90 @@ -56,6 +56,12 @@ implicit none integer(c_int32_t)::inet_addr_c end function inet_addr_c + function inet_ntoa_c(ip) bind(c, name="inet_ntoa") + use iso_c_binding + type(c_ptr)::inet_ntoa_c + integer(c_int32_t), value::ip + end function inet_ntoa_c + function htons(i) bind(c) use iso_c_binding integer(kind=c_int32_t), value::i @@ -77,6 +83,12 @@ implicit none type(c_ptr)::gethostbyname_c end function gethostbyname_c + function close_c(s) bind(c, name="close") + use iso_c_binding + integer(kind=c_int), value::s + integer(kind=c_int)::close_c + end function close_c + end interface contains @@ -92,6 +104,17 @@ implicit none end function socket + subroutine close_socket(s) + use iso_c_binding + implicit none + + integer::s + integer::ignored + + ignored = close_c(int(s, kind=c_int)) + + end subroutine close_socket + function inet_addr(str) use iso_c_binding implicit none @@ -115,6 +138,31 @@ implicit none end function inet_addr + function inet_ntoa(ip) result(res) + use iso_c_binding + implicit none + + integer(kind=c_int32_t), intent(in)::ip + character(15)::res + + type(c_ptr)::cptr + character(kind=c_char), dimension(:), pointer::cres + integer::i + + res = " " + cptr = inet_ntoa_c(ip) + if(c_associated(cptr)) then + call c_f_pointer(cptr, cres, [1]) + + i = 1 + do while(cres(i) /= c_null_char) + res(i:i) = cres(i) + i = i + 1 + end do + end if + + end function inet_ntoa + function connect(sockfd, sock_addr) use iso_c_binding implicit none -- cgit v1.2.3