1 SEND(3C) Standard C Library Functions SEND(3C) 2 3 NAME 4 send, sendto, sendmsg - send a message from a socket 5 6 LIBRARY 7 Standard C Library (libc, -lc) 8 9 SYNOPSIS 10 #include <sys/types.h> 11 #include <sys/socket.h> 12 13 ssize_t 14 send(int s, const void *msg, size_t len, int flags); 15 16 ssize_t 17 sendto(int s, const void *msg, size_t len, int flags, 18 const struct sockaddr *to, socklen_t tolen); 19 20 ssize_t 21 sendmsg(int s, const struct msghdr *msg, int flags); 22 23 DESCRIPTION 24 The send(), sendto(), and sendmsg() functions are used to transmit a 25 message to another transport end-point. The send() function can be used 26 only when the socket is in a connected state. See connect(3C). The 27 sendto() and sendmsg() functions can be used at any time. The s socket 28 is created with socket(3C). 29 30 The address of the target is supplied by to with a tolen parameter used 31 to specify the size. The length of the message is supplied by the len 32 parameter. For socket types such as SOCK_DGRAM and SOCK_RAW that require 33 atomic messages, the error EMSGSIZE is returned and the message is not 34 transmitted when it is too long to pass atomically through the underlying 35 protocol. The same restrictions do not apply to SOCK_STREAM sockets. 36 37 A return value -1 indicates locally detected errors. It does not imply a 38 delivery failure. 39 40 If the socket does not have enough buffer space available to hold a 41 message, the send() function blocks the message, unless the socket has 42 been placed in non-blocking I/O mode (see fcntl(2)). The select(3C) or 43 poll(2) call can be used to determine when it is possible to send more 44 data. 45 46 The flags parameter is formed from the bitwise OR of zero or more of the 47 following: 48 49 MSG_OOB Send out-of-band data on sockets that support this notion. 50 The underlying protocol must also support out-of-band 51 data. Only SOCK_STREAM sockets created in the AF_INET or 52 the AF_INET6 address family support out-of-band data. 53 54 MSG_DONTROUTE The SO_DONTROUTE option is turned on for the duration of 55 the operation. It is used only by diagnostic or routing 56 programs. 57 58 MSG_NOSIGNAL Don't generate the SIGPIPE signal when a stream-oriented 59 socket is no longer connected. 60 61 See recv(3C) for a description of the msghdr structure. 62 63 RETURN VALUES 64 Upon successful completion, these functions return the number of bytes 65 sent. Otherwise, they return -1 and set errno to indicate the error. 66 67 ERRORS 68 The send(), sendto(), and sendmsg() functions return errors under the 69 following conditions: 70 71 [EBADF] s is not a valid file descriptor. 72 73 [ECONNRESET] The s argument refers to a connection oriented socket 74 and the connection was forcibly closed by the peer and 75 is no longer valid. I/O can no longer be performed to 76 filedes. 77 78 [EINTR] The operation was interrupted by delivery of a signal 79 before any data could be buffered to be sent. 80 81 [EMSGSIZE] The message is too large to be sent all at once (as 82 the socket requires), or the msg_iovlen member of the 83 msghdr structure pointed to by message is less than or 84 equal to 0 or is greater than {IOV_MAX}. 85 86 [ENOMEM] Insufficient memory is available to complete the 87 operation. 88 89 [ENOSR] Insufficient STREAMS resources are available for the 90 operation to complete. 91 92 [ENOTSOCK] s is not a socket. 93 94 [EWOULDBLOCK] The socket is marked non-blocking and the requested 95 operation would block. EWOULDBLOCK is also returned 96 when sufficient memory is not immediately available to 97 allocate a suitable buffer. In such a case, the 98 operation can be retried later. 99 100 [ECONNREFUSED] The requested connection was refused by the peer. For 101 connected IPv4 and IPv6 datagram sockets, this 102 indicates that the system received an ICMP 103 "Destination Port Unreachable" message from the peer 104 in response to some prior transmission. 105 106 The send() and sendto() functions return errors under the following 107 conditions: 108 109 [EINVAL] The len argument overflows a ssize_t. 110 111 Inconsistent port attributes for system call. 112 113 The sendto() function returns errors under the following conditions: 114 115 [EINVAL] The value specified for the tolen parameter is not the 116 size of a valid address for the specified address 117 family. 118 119 [EISCON] A destination address was specified and the socket is 120 already connected. 121 122 The sendmsg() function returns errors under the following conditions: 123 124 [EINVAL] The msg_iovlen member of the msghdr structure pointed 125 to by msg is less than or equal to 0, or the sum of 126 the iov_len values in the msg_iov array overflows a 127 ssize_t. 128 129 One of the iov_len values in the msg_iov array member 130 of the msghdr structure pointed to by msg is negative, 131 or the sum of the iov_len values in the msg_iov array 132 overflows a ssize_t. 133 134 msg_iov contents are inconsistent with port 135 attributes. 136 137 The send() function returns errors under the following conditions: 138 139 [EPIPE] The socket is shut down for writing, or the socket is 140 connection-mode and is no longer connected. In the 141 latter case, if the socket is of type SOCK_STREAM, the 142 SIGPIPE signal is generated to the calling thread 143 unless the MSG_NOSIGNAL flag is set. 144 145 MT-LEVEL 146 Safe 147 148 SEE ALSO 149 fcntl(2), poll(2), write(2), connect(3C), getsockopt(3C), recv(3C), 150 select(3C), sockaddr(3C), socket(3C), socket.h(3HEAD), attributes(5) 151 152 illumos August 2, 2018 illumos