send, sendto, sendmsg
Purpose
Sends a message from a socket.
Library
Sockets Library (libsock.a)
Syntax
#include <sys/types.h>
#include <sys/socket.h>
int send (s, msg, len, flags) int sendto (s, msg, len, flags, to, tolen)
int s; int s;
char *msg; char *msg;
int len, flags; int len, flags;
struct sockaddr *to;
int sendmsg (s, msg, flags) int tolen;
int s;
struct msghdr msg[ ];
int flags;
Description
The send subroutine sends a message only when the socket
is in a connected state. The sendto and sendmsg subrou-
tines can be used at any time.
Give the address of the target by to, with tolen speci-
fying its size. Specify the length of the message with
len. If the message is too long to pass through the
underlying protocol, the error EMSGSIZE is returned and
the message is not transmitted.
No indication of failure to deliver is implied in a send.
Return values of -1 indicate some locally detected
errors.
If no space for messages is available at the sending
socket to hold the message to be transmitted, the send
subroutine blocks unless the socket is in a non-blocking
I/O mode.
Use the select system call to determine when it is pos-
sible to send more data.
The flags argument to send a call is formed by logically
OR-ing one or both of the values shown in the following
list:
MSG_OOB Processes out-of-band data on sockets
that support SOCK_STREAM.
MSG_DONTROUTE Sends without using routing tables.
For a description of the msghdr structure, see "recv,
recvfrom, recvmsg."
Return Value
Upon successful completion, the number of characters sent
is returned. If the send, sendto, or sendmsg routine
fails, a value of -1 is returned, and errno is set to
indicate the error.
Diagnostics
The subroutine fails if one or more of the following are
true:
EBADF The s parameter is not valid.
ENOTSOCK The s parameter refers to a file, not a
socket.
EFAULT The addr parameter is not in a writable
part of the user address space.
EMSGSIZE The socket requires that the message be
sent all at once, and the message is
too large for that to happen.
EWOULDBLOCK The socket is marked non-blocking, and
no connections are present to be
accepted.
Related Information
In this book: "recv, recvfrom, recvmsg" and "socket."