concept ipaddr_port in category fortran

appears as: ipaddr_port
Modern Fortran: Building efficient parallel applications

This is an excerpt from Manning's book Modern Fortran: Building efficient parallel applications.

Exercise 1: The Fortran interface to ipaddr_port

It’s your turn now! We need to check that the port number is stored correctly when we call the ipaddr_local function. We’ve already implemented the interface to ipaddr_str, which returns the character string representation of the IP address. libdill also provides the ipaddr_port function, which returns the integer value of the port number associated with the ipaddr data structure:

11.5.1 Exercise 1: The Fortran interface to ipaddr_port

The C function ipaddr_port takes the ipaddr struct as an input argument and returns the port number as a c_int. The key to implementing the Fortran interface is to match the argument and the function result data types, as shown in the following listing.

Listing 11.10. Fortran interface to ipaddr_port
language="fortran" linenumbering="unnumbered">module mod_dill
  ...
  public :: ipaddr, ipaddr_local, & #1
            ipaddr_port, ipaddr_str #1
  ...
  interface
    ...
    integer(c_int) function ipaddr_port(addr) & #2
                   bind(c, name='dill_ipaddr_port') #3
      import :: c_int, ipaddr #4
      type(ipaddr), intent(in) :: addr #5
    end function ipaddr_port
    ...
  end interface

end module