I want to be able to call networking functions in my Fortran application. My boss wants me to do everything in Fortran instead of using C and Fortran. We have already done a version of the application using PGI's Fortran compiler on Windows. We are moving it to Linux where we will probably use their compiler. Right now, I'm using gfortran.
I have created an interface for these networking calls, and everything compiles and links. The code below is something similar to what I'm doing except the interfaces and constants are in a module.
PROGRAM MAIN
INTEGER,PARAMETER ::AF_INET = 2
INTEGER,PARAMETER ::SOCK_STREAM = 1
INTEGER,PARAMETER ::IPPROTO_TCP = 6
INTERFACE
FUNCTION socket(domain,type,protocol)
INTEGER ::socket,domain,type,protocol
END FUNCTION
END INTERFACE
sock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)
WRTIE(*,*)"Socket returned: ",sock
END PROGRAM
When I run the program, the socket function fails returning -1. I don't really know what's going on. I don't add any libraries on the command line so I'm guess it is linking with the default libraries correctly. I compile using
gfortran -o MAIN_PROGRAM MAIN_PROGRAM.f90 -fno-underscoring