aboutsummaryrefslogtreecommitdiff
path: root/network.F90
diff options
context:
space:
mode:
Diffstat (limited to 'network.F90')
-rw-r--r--network.F9022
1 files changed, 13 insertions, 9 deletions
diff --git a/network.F90 b/network.F90
index 637d092..8e77b9d 100644
--- a/network.F90
+++ b/network.F90
@@ -264,6 +264,15 @@ implicit none
! To process h_name
character(kind=c_char), dimension(:), pointer::h_name
+ integer::hnamelen
+ interface
+ function strlen_c(cstr) bind(c, name="strlen")
+ use iso_c_binding
+ type(c_ptr), value::cstr
+ integer(kind=c_size_t)::strlen_c
+ end function strlen_c
+ end interface
+
! To process h_addr
type(c_ptr), dimension(:), pointer::addrptr
@@ -282,16 +291,11 @@ implicit none
call c_f_pointer(callres, cres)
! Extract the name
- call c_f_pointer(cres%h_name, h_name, [1])
- i = 1
- do while(h_name(i) /= c_null_char)
- i = i + 1
- end do
- allocate(character(len=i-1) :: res%h_name)
- i = 1
- do while(h_name(i) /= c_null_char)
+ hnamelen = strlen_c(cres%h_name)
+ call c_f_pointer(cres%h_name, h_name, [hnamelen])
+ allocate(character(len=i) :: res%h_name)
+ do i = 1, hnamelen
res%h_name(i:i) = h_name(i)
- i = i + 1
end do
! And address