Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Sockets under Windows 7

CRodrig
Beginner
923 Views

I have question(s) on creating/configuring sockets under Windows 7 Professional.

System Configuration:
- Windows 7 Professional SP1  [ 32-bit OS ]
- Intel Composer XE 2013 SP1 Update 3 for Windows
- Microsoft Visual Studio Ultimate 2013 Update 3
- Microsoft Windows SDK for Windows 7 (7.1)

Question #1:
-----------------

I would like to create a socket (UDP) under Windows 7 Professional.

  sockfd = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0, 0, 0)
         or
  consock = socket(AF_INET, SOCK_DRAM, IPPROTO_UDP)

Upon creation, I would like to poll the newly created socket:

  status = WSAIoctl(sockfd,SIO_GET_INTERFACE_LIST,0,0,ifconf,sizeof(ifconf),BytesReturned,0,0)
         or
  { Use the GETADDRINFO function for response information about the host }

The socket information I would like to extract is as follows:
  - The network interface UP or DOWN.
  - Broadcast feature supported.
  - Multicast feature supported.
  - Loopback Interface.
  - Point-to-Point Interface.

I have included Winsock2 API by including the Winsock 2 header file.
  - USE WS2_32

If the Winsock2 API does provide access to the WSASocket | WSAIoctl functions from Fortran:
  - How would I get access to the INTERFACE_INFO structure used in conjunction with the SIO_GET_INTERFACE_LIST ioctl command
    used to obtain information about an interface IP address?

Question #2:
-----------

The Intel Fortran Compiler states ... This name does not have a type, and must have an explicit type.  [SIO_GET_INTERFACE_LIST]
  - Where would I find the SIO_GET_INTERFACE_LIST ioctl code defined?

The MSDN website states "the INTERFACE_INFO structure is defined in the Ws2ipdef.h header file which is automatically included
in the Ws2tcpip.h header file. The Ws2ipdef.h header files should never be used directly."

Since Ws2ipdef.h is a C/C++ header file, I need access to the interface flag parameters from Fortran.

Therefore, I have included the following snippet in the socket program:

      INTEGER(LONG) :: IFF_UP
      INTEGER(LONG) :: IFF_BROADCAST
      INTEGER(LONG) :: IFF_LOOPBACK
      INTEGER(LONG) :: IFF_POINTTOPOINT
c
      PARAMETER(IFF_UP = X'00000001')                       ! Interface is up
      PARAMETER(IFF_BROADCAST = X'00000002')        ! Broadcast address valid
      PARAMETER(IFF_LOOPBACK = X'00000008')          ! Is a loopback net
      PARAMETER(IFF_POINTTOPOINT = X'00000010')    ! Interface is point-to-point link                                                                          

Do I need to define the socket snippet above in my program, or am I missing something?

I am attempting to utilize the Winsock2 API and implement socket(s) in the Fortran world without having to write the socket program
in C .

Appreciate the help in advance.

0 Kudos
2 Replies
andrew_4619
Honored Contributor III
923 Views

Many questions and I am not familiar with the API's you discuss. Have you looked in ws2_32.f90 and ifwinty.f90? Some the the structures are defined e.g TYPE T_struct_sockaddr, andy missing ones you will need to define yourself I'm afraid .

integer(LONG), PARAMETER :: IFF_UP = int(z'00000001')     ! Interface is up

Is more compact/readable and is standard Fortran 2003 i.e. it uses no language extensions 

0 Kudos
Paul_Curtis
Valued Contributor I
923 Views

Take a look at the attached file, Winsock.f90.  This module is a tiny part of a large program, and it illustrates how to do socket-based communications from Fortran.

0 Kudos
Reply