z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


tcperror()

z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference
SC27-3660-00

When a socket call produces an error, the call returns a negative value and the variable errno is set to an error value found in TCPERRNO.H. The tcperror() call prints a short error message describing the last error that occurred. If s is non-NULL, tcperror() prints the string s followed by a colon, followed by a space, followed by the error message, and terminating with a new-line character. If s is NULL or points to a NULL string, only the error message and the new-line character are output.

The tcperror() function is equivalent to the UNIX perror() function.

#include <manifest.h>
#include <socket.h>
#include <tcperrno.h>
 
void tcperror(char *s)
Parameter
Description
s
A NULL or NULL-terminated character string

Example 1

if   ((s=socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
     tcperror(“socket()”);
     exit(2);
}
If the socket() call produces error ENOMEM, socket() returns a negative value and errno is set to ENOMEM. When tcperror() is called, it prints the string:
    socket():  Not enough storage (ENOMEM)

Example 2

if ((s=socket(AF_INET, SOCK_DGRAM, 0)) < 0)
   tcperror(NULL);
If the socket() call produces error ENOMEM, socket() returns a negative value and errno is set to ENOMEM. When tcperror() is called, it prints the string:
     Not enough storage (ENOMEM)

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014