takesocket() — Acquire a socket from another program

Standards

Standards / Extensions C or C++ Dependencies
z/OS® UNIX both  

Format

#define _OPEN_SYS_SOCK_EXT
#include <sys/types.h>
#include <socket.h>

int takesocket(struct clientid *clientid, int sdesc);

General description

The takesocket() function acquires a socket from another program. Typically, the other program passes its client ID and socket descriptor, and/or process id (PID), to your program through your program's startup parameter list.
Parameter
Description
clientid
A pointer to the clientid of the application from which you are taking a socket.
sdesc
The descriptor of the socket to be taken.

If your program is using the PID to ensure integrity between givesocket() and takesocket(), before issuing the takesocket() call, your program should set the c_pid.pid field of the clientid structure to the PID of the giving program (that is, program that issued the givesocket() call). This identifies the process from which the socket is to be taken. If the c_reserved.type field of the clientid structure was set to SO_CLOSE on the givesocket() call, c_close.SockToken of clientid structure should be used as input to takesocket() instead of the normal socket descriptor. See givesocket() — Make the specified socket available for a description of the clientid structure.

Returned value

If successful, takesocket() returns the new socket descriptor.

If unsuccessful, takesocket() returns -1 and sets errno to one of the following values:
Error Code
Description
EACCES
The other application did not give the socket to your application.
EBADF
The sdesc parameter does not specify a valid socket descriptor owned by the other application, or the socket has already been taken.
EFAULT
Using the clientid parameter as specified would result in an attempt to access storage outside the caller's address space.
EINVAL
The clientid parameter does not specify a valid client identifier. Either the client process cannot be found, or the client exists, but has no outstanding givesockets.
EMFILE
The socket descriptor table is already full.

Related information