getsockopt()

PROTOTYPE

#include <sockets.h>

int getsockopt(int socket, int level, int optname, void *optval, int *optlen);

DESCRIPTION

getsockopt() reads various options that control socket or protocol behavior. socket is a handle returned by socket(). level indicates the software layer controlled by the option. optname specifies the selected option. optval and optlen point to a parameter value and a parameter size, respectively, that are output by getsockopt(). The supported options are listed here.

If successful, getsockopt() returns 0. Otherwise, it sets errno and returns -1.

ERROR CODES

EFAULT optval is NULL or optlen is not correct for the specified option.
EINVAL optval has an invalid value.
ENETDOWN TargetTCP has not been initialized.
ENOPROTOOPT The combination of level and optname is unsupported.
ENOTSOCK socket is not a valid socket handle.
EOPNOTSUPP Operation not supported, socket type is not correct for specified option.

EXAMPLE

  int timeo;
  socklen_t olen = sizeof(timeo);

  /*-------------------------------------------------------------------*/
  /* Read and display the send timeout in milliseconds.                */
  /*-------------------------------------------------------------------*/
  rc = getsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &timeo, &olen);
  if (rc < 0) exit(errno);
  printf("Send timeout = %u ms\n", timeo);