erecv, erecvmsg, erecvfrom, enrecvmsg, or enrecvfrom Subroutine

Purpose

Allows applications to receive messages from sockets along with the Sensitivity Level (SL).

Library

The libraries that are available in the erecv subroutines are:
  1. Standard C Library (libc.a)
  2. Trusted AIX® Sensitivity Label Library (libmls.a)

Syntax

#include <sys/socket.h>
#include <sys/mac.h>
int erecv (Socket, Buffer, Length, Flags, Label)
int  Socket;
void * Buffer;
size_t  Length;
int  Flags;
sec_labels_t *Label;

int erecvmsg ( Socket,  Message,  Flags, Label)
int Socket;
struct msghdr Message [ ];
int Flags;
sec_labels_t *Label;

ssize_t erecvfrom (Socket, Buffer, Length, Flags, From, FromLength, Label)
int  Socket;
void * Buffer;
size_t  Length, 
int  Flags;
struct sockaddr * From;
socklen_t * FromLength;
sec_labels_t *Label;

int enrecvmsg (Socket, Message, Flags, Label)
int Socket;
struct msghdr Message [ ];
int Flags;
sec_labels_t *Label;

ssize_t enrecvfrom (Socket, Buffer, Length, Flags, From, FromLength, Label)
int Socket;
void *Buffer;
size_t Length;
int Flags;
struct sockaddr *From;
socklen_t *FromLength;
sec_labels_t *Label;

Description

The erecv, erecvmsg, erecvfrom, enrecvmsg, and enrecvfrom subroutines work exactly like the recv, recvmsg, recvfrom, nrecvmsg, and nrecvfrom subroutines respectively, except that the erecv, erecvmsg, erecvfrom, enrecvmsg, and enrecvfrom subroutines allow the application to retrieve the SL from the received data by providing a valid Label parameter.

If no messages are available at the socket, the erecv, erecvmsg, erecvfrom, enrecvmsg, and enrecvfrom subroutines wait for a message to arrive, unless the socket is nonblocking. If a socket is nonblocking, the system returns an error.

Parameters

Item Description
Socket Specifies the socket descriptor.
Buffer Specifies the address where the message is placed.
Length Specifies the size of the Buffer parameter.
Flags Points to a value controlling the message reception. The /usr/include/sys/socket.h file defines the Flags parameter. The argument to receive a call is formed by the logical OR operation with one or more of the following values:
MSG_OOB
Processes out-of-band data. The significance of out-of-band data is protocol dependent.
MSG_PEEK
Peeks at incoming data. The data continues to be treated as unread and will be read by the next call to the erecv, erecvmsg, erecvfrom, enrecvmsg, or enrecvfrom subroutine or a similar subroutine.
MSG_WAITALL
Requests that the subroutine does not return until the requested number of bytes are read. The subroutine can return fewer bytes than the requested number if a signal is caught, the connection is terminated, or an error is pending for the socket. The subroutine can also return fewer bytes when the SL information across the data stream is different. Only those bytes that have the same SL information are returned to the user.
Message Points to the address of the msghdr structure, which contains both the address for the incoming message and the space for the sender address.
From Points to a socket structure, containing the address of the source.
FromLength Specifies the length of the address of the sender or of the source.
Label Specifies a result parameter that contains the SL from the received data.

Return Values

Upon successful completion, the subroutines return the length of the message in bytes.

When an error occurs, the subroutine handler performs the following functions:
  • Returns a value of -1 to the calling program.
  • Returns a value of 0 if the connection disconnects (in case of connected sockets).
  • Moves an error code, indicating the specific error, into the errno global variable.

Error Codes

The erecv, erecvmsg, erecvfrom,enrecvmsg, or enrecvfrom subroutine is unsuccessful if any of the following errors occurs:
Item Description
EBADF The Socket parameter is not valid.
ECONNRESET The remote peer forced the connection to be closed.
EFAULT The data was directed into a nonexistent or protected part of the process address space. (The Buffer parameter is not valid.)
EINTR A signal interrupted the erecv, erecvmsg, erecvfrom, enrecvmsg, or enrecvfrom subroutine before any data is available.
EINVAL The MSG_OOB value was set and no out-of-band data was available.
ENOBUF Insufficient resources are available in the system to perform the operation.
ENOTCONN A receiving operation was attempted on a SOCK_STREAM socket that was not connected.
ENOTSOCK The Socket parameter refers to a file, not a socket.
EOPNOTSUPP The MSG_OOB value is set for a SOCK_DGRAM socket or any AF_UNIX socket.
ETIMEDOUT The connection timed out during connection establishment, or there was a transmission timeout on an active connection.
EWOULDBLOCK The socket is marked nonblocking, and no connections are present to be accepted.
EACCES The MLS MAC check failed.