SEND(3SOCKET) | Sockets Library Functions | SEND(3SOCKET) |
send, sendto, sendmsg - send a message from a socket
cc [ flag... ] file... -lsocket -lnsl [ library... ] #include <sys/types.h> #include <sys/socket.h> ssize_t send(int s, const void *msg, size_t len, int flags);
ssize_t sendto(int s, const void *msg, size_t len, int flags,
const struct sockaddr *to, int tolen);
ssize_t sendmsg(int s, const struct msghdr *msg, int flags);
The send(), sendto(), and sendmsg() functions are used to transmit a message to another transport end-point. The send() function can be used only when the socket is in a connected state. See connect(3SOCKET). The sendto() and sendmsg() functions can be used at any time. The s socket is created with socket(3SOCKET).
The address of the target is supplied by to with a tolen parameter used to specify the size. The length of the message is supplied by the len parameter. For socket types such as SOCK_DGRAM and SOCK_RAW that require atomic messages, the error EMSGSIZE is returned and the message is not transmitted when it is too long to pass atomically through the underlying protocol. The same restrictions do not apply to SOCK_STREAM sockets.
A return value −1 indicates locally detected errors. It does not imply a delivery failure.
If the socket does not have enough buffer space available to hold a message, the send() function blocks the message, unless the socket has been placed in non-blocking I/O mode (see fcntl(2)). The select(3C) or poll(2) call can be used to determine when it is possible to send more data.
The flags parameter is formed from the bitwise OR of zero or more of the following:
MSG_OOB
MSG_DONTROUTE
MSG_NOSIGNAL
The sendmsg() function call uses a msghdr structure defined in <sys/socket.h> to minimize the number of directly supplied parameters.
Upon successful completion, these functions return the number of bytes sent. Otherwise, they return -1 and set errno to indicate the error.
In addition to the errors documented below, an asynchronous error generated by the underlying socket protocol may be returned. For the full list of errors, please see the corresponding socket protocol manual page. For example, for a list of TCP errors, please see tcp(4P).
The send(), sendto(), and sendmsg() functions return errors under the following conditions:
EBADF
ECONNRESET
EINTR
EMSGSIZE
ENOMEM
ENOSR
ENOTSOCK
EWOULDBLOCK
ECONNREFUSED
The send() and sendto() functions return errors under the following conditions:
EINVAL
Inconsistent port attributes for system call.
The sendto() function returns errors under the following conditions:
EINVAL
EISCON
The sendmsg() function returns errors under the following conditions:
EINVAL
One of the iov_len values in the msg_iov array member of the msghdr structure pointed to by msg is negative, or the sum of the iov_len values in the msg_iov array overflows a ssize_t.
msg_iov contents are inconsistent with port attributes.
The send() function returns errors under the following conditions:
EPIPE
See attributes(7) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
Interface Stability | Committed |
MT-Level | Safe |
fcntl(2), poll(2), write(2), select(3C), socket.h(3HEAD), connect(3SOCKET), getsockopt(3SOCKET), recv(3SOCKET), sockaddr(3SOCKET), socket(3SOCKET), tcp(4P), attributes(7)
September 10, 2018 | OmniOS |