Skip to main content
Open topic with navigation CAPL Functions » TCP/IP API » IpGetLastSocketErrorAsString

IpGetLastSocketErrorAsString

Valid for: CANoe DE • CANoe4SW DE

Function Syntax

long IpGetLastSocketErrorAsString( dword socket, char text[], dword count);

Method Syntax

socket.GetLastSocketErrorAsString( char text[], dword count);

Description

The function retrieves the error message of the last operation that failed on the specified socket (see Winsock 2 error code).

Parameters

  • socket: The socket handle.
  • text: The buffer used to store the error message.
  • count: The size of the text buffer.

Return Values

  • 0: The error message was written into the text buffer. In case of an invalid error code, the error message has the format “Unknown error: x” assuming the last error code x for the specified socket.
  • WSA_INVALID_PARAMETER (87): The specified socket was invalid.

Example

on start
{
  const dword INVALID_SOCKET = ~0; // invalid socket constant
  dword socket = INVALID_SOCKET;   // a socket
  char errMsg[255];                // error message buffer.

  // just create an unspecified socket.
  socket = UdpOpen( 0, 1 );

  // produce an error e.g. using invalid parameters to UdpSendTo
  if (UdpSendTo(socket, 0, 0, "a", 1) == -1)
  {
    IpGetLastSocketErrorAsString( socket, errMsg, elcount(errMsg) );
    writeLineEx(1, 3, "IpGetLastSocketErrorAsString: %s", errMsg);
  }

  // close the socket.
  UdpClose(socket);
}
IpGetLastSocketErrorIpGetLastError