InetReadEx Function  
 
INT WINAPI InetReadEx(
  SOCKET hSocket,  
  LPVOID lpvBuffer,  
  INT cbBuffer,  
  DWORD dwReserved,  
  LPINTERNET_ADDRESS lpRemoteAddress,  
  UINT * lpnRemotePort  
);

The InetReadEx function reads the specified number of bytes from the socket and copies them into the buffer. The data may be of any type, and is not terminated with a null character.

Parameters

hSocket
The socket handle.
lpvBuffer
Pointer to the buffer in which the data will be copied.
cbBuffer
The maximum number of bytes to read and copy into the specified buffer. This value must be greater than zero.
dwReserved
Reserved parameter. This value must always be zero.
lpRemoteAddress
Pointer to an INTERNET_ADDRESS structure which will contain the IP address of the remote host that sent the data being read. If this information is not required, the parameter may be specified as NULL.
lpnRemotePort
Pointer to an unsigned integer which will contain the remote port number. If this information is not required, the parameter may be specified as NULL.

Return Value

If the function succeeds, the return value is the number of bytes actually read. A return value of zero indicates that the remote host has closed the connection and there is no more data available to be read. If the function fails, the return value is INET_ERROR. To get extended error information, call InetGetLastError.

Remarks

When InetReadEx is called and the socket is in non-blocking mode, it is possible that the function will fail because there is no available data to read at that time. This should not be considered a fatal error. Instead, the application should simply wait to receive the next asynchronous notification that data is available.

This function extends the InetRead function to return additional information about the peer who sent the data being received. For a client TCP socket, the IP address and remote port are the same values that were used to establish the connection. For a server TCP socket, it is the IP address and port number of the client which sent the data. When reading data from a UDP socket, this is the IP address and remote port of the peer that sent the datagram. This information can be used in conjunction with the InetWriteEx function to send a datagram back to that host.

Requirements

Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header: Include cswsock10.h
Import Library: cswskv10.lib

See Also

InetFlush, InetGetPeerAddress, InetPeek, InetRead, InetWrite, InetWriteEx, INTERNET_ADDRESS