1 '\" te
   2 .\" Copyright (C) 2009, Sun Microsystems, Inc. All Rights Reserved
   3 .\" Copyright 1989 AT&T
   4 .\" 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.
   5 .\"  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
   6 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
   7 .TH SEND 3SOCKET "Jun 18, 2017"
   8 .SH NAME
   9 send, sendto, sendmsg \- send a message from a socket
  10 .SH SYNOPSIS
  11 .LP
  12 .nf
  13 \fBcc\fR [ \fIflag\fR... ] \fIfile\fR... \fB-lsocket\fR \fB -lnsl \fR [ \fIlibrary\fR... ]
  14 #include <sys/types.h>
  15 #include <sys/socket.h>
  16 
  17 \fBssize_t\fR \fBsend\fR(\fBint\fR \fIs\fR, \fBconst void *\fR\fImsg\fR, \fBsize_t\fR \fIlen\fR, \fBint\fR \fIflags\fR);
  18 .fi
  19 
  20 .LP
  21 .nf
  22 \fBssize_t\fR \fBsendto\fR(\fBint\fR \fIs\fR, \fBconst void *\fR\fImsg\fR, \fBsize_t\fR \fIlen\fR, \fBint\fR \fIflags\fR,
  23      \fBconst struct sockaddr *\fR\fIto\fR, \fBint\fR  \fItolen\fR);
  24 .fi
  25 
  26 .LP
  27 .nf
  28 \fBssize_t\fR \fBsendmsg\fR(\fBint\fR \fIs\fR, \fBconst struct msghdr *\fR\fImsg\fR, \fBint\fR \fIflags\fR);
  29 .fi
  30 
  31 .SH DESCRIPTION
  32 .LP
  33 The \fBsend()\fR, \fBsendto()\fR, and \fBsendmsg()\fR functions are used to
  34 transmit a message to another transport end-point. The \fBsend()\fR function
  35 can be used only when the socket is in a connected state. See
  36 \fBconnect\fR(3SOCKET). The \fBsendto()\fR and \fBsendmsg()\fR functions can be
  37 used at any time. The \fIs\fR socket is created with \fBsocket\fR(3SOCKET).
  38 .sp
  39 .LP
  40 The address of the target is supplied by \fIto\fR with a \fItolen\fR parameter
  41 used to specify the size. The length of the message is supplied by the
  42 \fIlen\fR parameter. For socket types such as \fBSOCK_DGRAM\fR and
  43 \fBSOCK_RAW\fR that require atomic messages, the error \fBEMSGSIZE\fR is
  44 returned and the message is not transmitted when it is too long to pass
  45 atomically through the underlying protocol. The same restrictions do not apply
  46 to \fBSOCK_STREAM\fR sockets.
  47 .sp
  48 .LP
  49 A return value \fB\(mi1\fR indicates locally detected errors. It does not imply
  50 a delivery failure.
  51 .sp
  52 .LP
  53 If the socket does not have enough buffer space available to hold a message,
  54 the \fBsend()\fR function blocks the message, unless the socket has been placed
  55 in non-blocking I/O mode (see \fBfcntl\fR(2)). The \fBselect\fR(3C) or
  56 \fBpoll\fR(2) call can be used to determine when it is possible to send more
  57 data.
  58 .sp
  59 .LP
  60 The \fIflags\fR parameter is formed from the bitwise OR of zero or more of the
  61 following:
  62 .sp
  63 .ne 2
  64 .na
  65 \fB\fBMSG_OOB\fR\fR
  66 .ad
  67 .RS 17n
  68 Send \fBout-of-band\fR data on sockets that support this notion. The underlying
  69 protocol must also support \fBout-of-band\fR data. Only \fBSOCK_STREAM\fR
  70 sockets created in the \fBAF_INET\fR or the \fBAF_INET6\fR address family
  71 support out-of-band data.
  72 .RE
  73 
  74 .sp
  75 .ne 2
  76 .na
  77 \fB\fBMSG_DONTROUTE\fR\fR
  78 .ad
  79 .RS 17n
  80 The \fBSO_DONTROUTE\fR option is turned on for the duration of the operation.
  81 It is used only by diagnostic or routing programs.
  82 .RE
  83 
  84 .sp
  85 .ne 2
  86 .na
  87 \fB\fBMSG_NOSIGNAL\fR\fR
  88 .ad
  89 .RS 17n
  90 Don't generate the \fBSIGPIPE\fR signal when a stream-oriented socket is no
  91 longer connected.
  92 .RE
  93 
  94 .sp
  95 .LP
  96 See \fBrecv\fR(3SOCKET) for a description of the \fBmsghdr\fR structure.
  97 .SH RETURN VALUES
  98 .LP
  99 Upon successful completion, these functions return the number of bytes sent.
 100 Otherwise, they return \fB-1\fR and set \fBerrno\fR to indicate the error.
 101 .SH ERRORS
 102 .LP
 103 The \fBsend()\fR, \fBsendto()\fR, and \fBsendmsg()\fR functions return errors
 104 under the following conditions:
 105 .sp
 106 .ne 2
 107 .na
 108 \fB\fBEBADF\fR\fR
 109 .ad
 110 .RS 16n
 111 \fIs\fR is not a valid file descriptor.
 112 .RE
 113 
 114 .sp
 115 .ne 2
 116 .na
 117 \fB\fBECONNRESET\fR\fR
 118 .ad
 119 .RS 16n
 120 The \fIs\fR argument refers to a connection oriented socket and the connection
 121 was forcibly closed by the peer and is no longer valid. I/O can no longer be
 122 performed to \fIfiledes\fR.
 123 .RE
 124 
 125 .sp
 126 .ne 2
 127 .na
 128 \fB\fBEINTR\fR\fR
 129 .ad
 130 .RS 16n
 131 The operation was interrupted by delivery of a signal before any data could be
 132 buffered to be sent.
 133 .RE
 134 
 135 .sp
 136 .ne 2
 137 .na
 138 \fB\fBEMSGSIZE\fR\fR
 139 .ad
 140 .RS 16n
 141 The message is too large to be sent all at once (as the socket requires), or
 142 the \fImsg_iovlen\fR member of the \fBmsghdr\fR structure pointed to by message
 143 is less than or equal to 0 or is greater than {\fBIOV_MAX\fR}.
 144 .RE
 145 
 146 .sp
 147 .ne 2
 148 .na
 149 \fB\fBENOMEM\fR\fR
 150 .ad
 151 .RS 16n
 152 Insufficient memory is available to complete the operation.
 153 .RE
 154 
 155 .sp
 156 .ne 2
 157 .na
 158 \fB\fBENOSR\fR\fR
 159 .ad
 160 .RS 16n
 161 Insufficient STREAMS resources are available for the operation to complete.
 162 .RE
 163 
 164 .sp
 165 .ne 2
 166 .na
 167 \fB\fBENOTSOCK\fR\fR
 168 .ad
 169 .RS 16n
 170 \fIs\fR is not a socket.
 171 .RE
 172 
 173 .sp
 174 .ne 2
 175 .na
 176 \fB\fBEWOULDBLOCK\fR\fR
 177 .ad
 178 .RS 16n
 179 The socket is marked non-blocking and the requested operation would block.
 180 \fBEWOULDBLOCK\fR is also returned when sufficient memory is not immediately
 181 available to allocate a suitable buffer. In such a case, the operation can be
 182 retried later.
 183 .RE
 184 
 185 .sp
 186 .ne 2
 187 .na
 188 \fB\fBECONNREFUSED\fR\fR
 189 .ad
 190 .RS 16n
 191 The requested connection was refused by the peer. For connected IPv4 and IPv6
 192 datagram sockets, this indicates that the system received an \fBICMP
 193 Destination Port Unreachable\fR message from the peer in response to some prior
 194 transmission.
 195 .RE
 196 
 197 .sp
 198 .LP
 199 The \fBsend()\fR and \fBsendto()\fR functions return errors under the following
 200 conditions:
 201 .sp
 202 .ne 2
 203 .na
 204 \fB\fBEINVAL\fR\fR
 205 .ad
 206 .RS 10n
 207 The \fIlen\fR argument overflows a \fBssize_t\fR.
 208 .sp
 209 Inconsistent port attributes for system call.
 210 .RE
 211 
 212 .sp
 213 .LP
 214 The \fBsendto()\fR function returns errors under the following conditions:
 215 .sp
 216 .ne 2
 217 .na
 218 \fB\fBEINVAL\fR\fR
 219 .ad
 220 .RS 10n
 221 The value specified for the \fItolen\fR parameter is not the size of a valid
 222 address for the specified address family.
 223 .RE
 224 
 225 .sp
 226 .ne 2
 227 .na
 228 \fB\fBEISCON\fR\fR
 229 .ad
 230 .RS 10n
 231 A destination address was specified and the socket is already connected.
 232 .RE
 233 
 234 .sp
 235 .LP
 236 The \fBsendmsg()\fR function returns errors under the following conditions:
 237 .sp
 238 .ne 2
 239 .na
 240 \fB\fBEINVAL\fR\fR
 241 .ad
 242 .RS 10n
 243 The \fBmsg_iovlen\fR member of the \fBmsghdr\fR structure pointed to by
 244 \fImsg\fR is less than or equal to \fB0\fR, or the sum of the \fIiov_len\fR
 245 values in the \fBmsg_iov\fR array overflows a \fBssize_t\fR.
 246 .sp
 247 One of the \fIiov_len\fR values in the \fBmsg_iov\fR array member of the
 248 \fBmsghdr\fR structure pointed to by \fImsg\fR is negative, or the sum of the
 249 \fIiov_len\fR values in the \fBmsg_iov\fR array overflows a \fBssize_t\fR.
 250 .sp
 251 \fBmsg_iov\fR contents are inconsistent with port attributes.
 252 .RE
 253 
 254 .sp
 255 .LP
 256 The \fBsend()\fR function returns errors under the following conditions:
 257 .sp
 258 .ne 2
 259 .na
 260 \fB\fBEPIPE\fR\fR
 261 .ad
 262 .RS 9n
 263 The socket is shut down for writing, or the socket is connection-mode and is no
 264 longer connected. In the latter case, if the socket is of type
 265 \fBSOCK_STREAM\fR, the \fBSIGPIPE\fR signal is generated to the calling thread
 266 unless the \fBMSG_NOSIGNAL\fR flag is set.
 267 .RE
 268 
 269 .SH ATTRIBUTES
 270 .LP
 271 See \fBattributes\fR(5) for descriptions of the following attributes:
 272 .sp
 273 
 274 .sp
 275 .TS
 276 box;
 277 c | c
 278 l | l .
 279 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 280 _
 281 Interface Stability     Committed
 282 _
 283 MT-Level        Safe
 284 .TE
 285 
 286 .SH SEE ALSO
 287 .LP
 288 \fBfcntl\fR(2), \fBpoll\fR(2), \fBwrite\fR(2), \fBconnect\fR(3SOCKET),
 289 \fBgetsockopt\fR(3SOCKET), \fBrecv\fR(3SOCKET), \fBselect\fR(3C),
 290 \fBsockaddr\fR(3SOCKET), \fBsocket\fR(3SOCKET), \fBsocket.h\fR(3HEAD),
 291 \fBattributes\fR(5)