bind (BPX1BND, BPX4BND) — Bind a unique local name to a socket descriptor

Function

The bind callable service binds a unique local name to a socket descriptor.

Requirements

Operation Environment
Authorization: Supervisor state or problem state, any PSW key
Dispatchable unit mode: Task or SRB
Cross memory mode: PASN = HASN
AMODE (BPX1BND): 31-bit task or SRB mode
AMODE (BPX4BND): 64-bit task mode only
ASC mode: Primary mode
Interrupt status: Enabled for interrupts
Locks: Unlocked
Control parameters: All parameters must be addressable by the caller and in the primary address space.

Format

The syntax format is as follows:
CALL BPX1BND,(Socket_descriptor,
              Sockaddr_length,
              Sockaddr,
              Return_value,
              Return_code,
              Reason_code)

AMODE 64 callers use BPX4BND with the same parameters.

Parameters

Socket_descriptor
Supplied parameter
Type:
Integer
Length:
Fullword

The name of a fullword that contains the socket file descriptor for which the bind is to be done.

Sockaddr_length
Supplied parameter
Type:
Integer
Length:
Fullword

The name of a field that contains the length of Sockaddr.

Sockaddr
Supplied parameter
Type:
Character
Length:
Length specified by Sockaddr_length.

The name of a field that contains the name to be bound to the socket descriptor. The format of Sockaddr is determined by the domain in which the socket descriptor was created. See BPXYSOCK — Map SOCKADDR structure and constants for additional information on the format of Sockaddr.

Return_value
Returned parameter
Type:
Integer
Length:
Fullword
The name of a fullword in which the bind service returns one of the following:
  • 0, if the request is successful.
  • -1, if the request is not successful.
Return_code
Returned parameter
Type:
Integer
Length:
Fullword
The name of a fullword in which the bind service stores the return code. The bind service returns Return_code only if Return_value is -1. For a list of return code values, see Return codes (errnos) in z/OS UNIX System Services Messages and Codes. The bind service can return one of the following values in the Return_code parameter:
Return_code Explanation
EADDRINUSE The specified address is already in use. The following reason code can accompany the return code: JRNameExists.
EAFNOSUPPORT The address family specified in the address structure is not supported.
EBADF The socket descriptor is incorrect. The following reason codes can accompany the return code: JRFileDesNotInUse, JRFileNotOpen.
EINVAL One of the input parameters was not valid. The following reason codes can accompany the return code: JRSocketCallParmError, JRSockNoname.
EIO There has been a network or transport failure. The following reason code can accompany the return code: JRPrevSockError.
ENOBUFS A buffer could not be obtained. The following reason code can accompany the return code: JROutofSocketCells.
ENOTSOCK Socket_descriptor does not refer to a valid socket descriptor. The following reason code can accompany the return code: JRMustBeSocket.
EPERM The user is not permitted to bind to the specified port. The following reason code can accompany the return code: JRUserNotPrivileged.
Reason_code
Returned parameter
Type:
Integer
Length:
Fullword

The name of a fullword in which the bind service stores the reason code. The bind service returns Reason_code only if Return_value is -1. Reason_code further qualifies the Return_code value. For a list of reason codes, see Reason codes in z/OS UNIX System Services Messages and Codes.

Usage notes

  1. An application can retrieve the assigned socket name with the getsockname service.
  2. Sockets in the AF_UNIX domain create a name in the file system that must be deleted by the application (using unlink) when it is no longer needed.
  3. For Sockaddr to be returned on an accept request for an AF_UNIX domain socket, the client application doing the connect must bind a unique local Sockaddr to the socket with the bind request before issuing the connect request.
  4. Server applications issue the bind request to register their addresses with the system. Both connection and connectionless servers must do this before accepting requests from clients.
  5. For network sockets, the user must have appropriate privileges (see Authorization) to bind to a port in the range from 1 to 1023.
  6. See Callable services for SRB mode routines for more information about programming considerations for SRB mode.

Related services

Characteristics and restrictions

None.