xref: /titanic_51/usr/src/man/man3socket/send.3socket (revision b0e753dd6a955fb2f10a0ce17d32bd33172e0400)
te
Copyright (C) 2009, Sun Microsystems, Inc. All Rights Reserved
Copyright 1989 AT&T
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with
the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
SEND 3SOCKET "Dec 03, 2014"
NAME
send, sendto, sendmsg - send a message from a socket
SYNOPSIS

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);
DESCRIPTION

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

Send out-of-band data on sockets that support this notion. The underlying protocol must also support out-of-band data. Only SOCK_STREAM sockets created in the AF_INET or the AF_INET6 address family support out-of-band data.

MSG_DONTROUTE

The SO_DONTROUTE option is turned on for the duration of the operation. It is used only by diagnostic or routing programs.

See recv(3SOCKET) for a description of the msghdr structure.

RETURN VALUES

Upon successful completion, these functions return the number of bytes sent. Otherwise, they return -1 and set errno to indicate the error.

ERRORS

The send(), sendto(), and sendmsg() functions return errors under the following conditions: EBADF

s is not a valid file descriptor.

ECONNRESET

The s argument refers to a connection oriented socket and the connection was forcibly closed by the peer and is no longer valid. I/O can no longer be performed to filedes.

EINTR

The operation was interrupted by delivery of a signal before any data could be buffered to be sent.

EMSGSIZE

The message is too large to be sent all at once (as the socket requires), or the msg_iovlen member of the msghdr structure pointed to by message is less than or equal to 0 or is greater than {IOV_MAX}.

ENOMEM

Insufficient memory is available to complete the operation.

ENOSR

Insufficient STREAMS resources are available for the operation to complete.

ENOTSOCK

s is not a socket.

EWOULDBLOCK

The socket is marked non-blocking and the requested operation would block. EWOULDBLOCK is also returned when sufficient memory is not immediately available to allocate a suitable buffer. In such a case, the operation can be retried later.

ECONNREFUSED

The requested connection was refused by the peer. For conected IPv4 and IPv6 datagram sockets, this indicates that the system received an ICMP Destination Port Unreachable message from the peer in response to some prior transmission.

The send() and sendto() functions return errors under the following conditions: EINVAL

The len argument overflows a ssize_t. Inconsistent port attributes for system call.

The sendto() function returns errors under the following conditions: EINVAL

The value specified for the tolen parameter is not the size of a valid address for the specified address family.

EISCON

A destination address was specified and the socket is already connected.

The sendmsg() function returns errors under the following conditions: EINVAL

The msg_iovlen member of the msghdr structure pointed to by msg is less than or equal to 0, or the sum of the iov_len values in the msg_iov array overflows a ssize_t. 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

The socket is shut down for writing, or the socket is connection-mode and is no longer connected. In the latter case, if the socket is of type SOCK_STREAM, the SIGPIPE signal is generated to the calling thread.

ATTRIBUTES

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE
Interface Stability Committed
MT-Level Safe
SEE ALSO

fcntl(2), poll(2), write(2), connect(3SOCKET), getsockopt(3SOCKET), recv(3SOCKET), select(3C), sockaddr(3SOCKET), socket(3SOCKET), socket.h(3HEAD), attributes(5)