]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - lib/libc/net/sctp_sendmsg.3
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / lib / libc / net / sctp_sendmsg.3
1 .\" Copyright (c) 1983, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     From: @(#)send.2        8.2 (Berkeley) 2/21/94
29 .\" $FreeBSD$
30 .\"
31 .Dd December 15, 2006
32 .Dt SCTP_SENDMSG 3
33 .Os
34 .Sh NAME
35 .Nm sctp_sendmsg ,
36 .Nm sctp_sendmsgx
37 .Nd send a message from an SCTP socket
38 .Sh LIBRARY
39 .Lb libc
40 .Sh SYNOPSIS
41 .In sys/types.h
42 .In sys/socket.h
43 .In netinet/sctp.h
44 .Ft ssize_t
45 .Fo sctp_sendmsg
46 .Fa "int s" "const void *msg" "size_t len" "const struct sockaddr *to"
47 .Fa "socklen_t tolen" "uint32_t ppid" "uint32_t flags" "uint16_t stream_no"
48 .Fa "uint32_t timetolive" "uint32_t context"
49 .Fc
50 .Ft ssize_t
51 .Fo sctp_sendmsgx
52 .Fa "int s" "const void *msg" "size_t len" "const struct sockaddr *to"
53 .Fa "int addrcnt" "uint32_t ppid" "uint32_t flags" "uint16_t stream_no"
54 .Fa "uint32_t timetolive" "uint32_t context"
55 .Fc
56 .Sh DESCRIPTION
57 The
58 .Fn sctp_sendmsg
59 system call
60 is used to transmit a message to another SCTP endpoint.
61 The
62 .Fn sctp_sendmsg
63 may be used at any time.
64 If the socket is a one-to-many type (SOCK_SEQPACKET)
65 socket then an attempt to send to an address that no association exists to will
66 implicitly create a new association.
67 Data sent in such an instance will result in
68 the data being sent on the third leg of the SCTP four-way handshake.
69 Note that if
70 the socket is a one-to-one type (SOCK_STREAM) socket then an association must
71 be in existence (by use of the
72 .Xr connect 2
73 system call).
74 Calling
75 .Fn sctp_sendmsg
76 or
77 .Fn sctp_sendmsgx
78 on a non-connected one-to-one socket will result in
79 .Va errno
80 being set to
81 .Er ENOTCONN ,
82 -1 being returned, and the message not being transmitted.
83 .Pp
84 The address of the target is given by
85 .Fa to
86 with
87 .Fa tolen
88 specifying its size.
89 The length of the message
90 .Fa msg
91 is given by
92 .Fa len .
93 If the message is too long to pass atomically through the
94 underlying protocol,
95 .Va errno
96 is set to
97 .Er EMSGSIZE ,
98 -1 is returned, and
99 the message is not transmitted.
100 .Pp
101 No indication of failure to deliver is implicit in a
102 .Xr sctp_sendmsg 3
103 call.
104 Locally detected errors are indicated by a return value of -1.
105 .Pp
106 If no space is available at the socket to hold
107 the message to be transmitted, then
108 .Xr sctp_sendmsg 3
109 normally blocks, unless the socket has been placed in
110 non-blocking I/O mode.
111 The
112 .Xr select 2
113 system call may be used to determine when it is possible to
114 send more data on one-to-one type (SOCK_STREAM) sockets.
115 .Pp
116 The
117 .Fa ppid
118 argument is an opaque 32 bit value that is passed transparently
119 through the stack to the peer endpoint.
120 It will be available on
121 reception of a message (see
122 .Xr sctp_recvmsg 3 ) .
123 Note that the stack passes this value without regard to byte
124 order.
125 .Pp
126 The
127 .Fa flags
128 argument may include one or more of the following:
129 .Bd -literal
130 #define SCTP_EOF          0x0100        /* Start a shutdown procedures */
131 #define SCTP_ABORT        0x0200        /* Send an ABORT to peer */
132 #define SCTP_UNORDERED    0x0400        /* Message is un-ordered */
133 #define SCTP_ADDR_OVER    0x0800        /* Override the primary-address */
134 #define SCTP_SENDALL      0x1000        /* Send this on all associations */
135                                         /* for the endpoint */
136 /* The lower byte is an enumeration of PR-SCTP policies */
137 #define SCTP_PR_SCTP_TTL  0x0001        /* Time based PR-SCTP */
138 #define SCTP_PR_SCTP_BUF  0x0002        /* Buffer based PR-SCTP */
139 #define SCTP_PR_SCTP_RTX  0x0003        /* Number of retransmissions based PR-SCTP */
140 .Ed
141 .Pp
142 The flag
143 .Dv SCTP_EOF
144 is used to instruct the SCTP stack to queue this message
145 and then start a graceful shutdown of the association.
146 All
147 remaining data in queue will be sent after which the association
148 will be shut down.
149 .Pp
150 .Dv SCTP_ABORT
151 is used to immediately terminate an association.
152 An abort
153 is sent to the peer and the local TCB is destroyed.
154 .Pp
155 .Dv SCTP_UNORDERED
156 is used to specify that the message being sent has no
157 specific order and should be delivered to the peer application
158 as soon as possible.
159 When this flag is absent messages
160 are delivered in order within the stream they are sent, but without
161 respect to order to peer streams.
162 .Pp
163 The flag
164 .Dv SCTP_ADDR_OVER
165 is used to specify that an specific address should be used.
166 Normally
167 SCTP will use only one of a multi-homed peers addresses as the primary
168 address to send to.
169 By default, no matter what the
170 .Fa to
171 argument is, this primary address is used to send data.
172 By specifying
173 this flag, the user is asking the stack to ignore the primary address
174 and instead use the specified address not only as a lookup mechanism
175 to find the association but also as the actual address to send to.
176 .Pp
177 For a one-to-many type (SOCK_SEQPACKET) socket the flag
178 .Dv SCTP_SENDALL
179 can be used as a convenient way to make one send call and have
180 all associations that are under the socket get a copy of the message.
181 Note that this mechanism is quite efficient and makes only one actual
182 copy of the data which is shared by all the associations for sending.
183 .Pp
184 The remaining flags are used for the partial reliability extension (RFC3758)
185 and will only be effective if the peer endpoint supports this extension.
186 This option specifies what local policy the local endpoint should use
187 in skipping data.
188 If none of these options are set, then data is
189 never skipped over.
190 .Pp
191 .Dv SCTP_PR_SCTP_TTL
192 is used to indicate that a time based lifetime is being applied
193 to the data.
194 The
195 .Fa timetolive
196 argument is then a number of milliseconds for which the data is
197 attempted to be transmitted.
198 If that many milliseconds elapse
199 and the peer has not acknowledged the data, the data will be
200 skipped and no longer transmitted.
201 Note that this policy does
202 not even assure that the data will ever be sent.
203 In times of a congestion
204 with large amounts of data being queued, the
205 .Fa timetolive
206 may expire before the first transmission is ever made.
207 .Pp
208 The
209 .Dv SCTP_PR_SCTP_BUF
210 based policy transforms the
211 .Fa timetolive
212 field into a total number of bytes allowed on the outbound
213 send queue.
214 If that number or more bytes are in queue, then
215 other buffer based sends are looked to be removed and
216 skipped.
217 Note that this policy may also result in the data
218 never being sent if no buffer based sends are in queue and
219 the maximum specified by
220 .Fa timetolive
221 bytes is in queue.
222 .Pp
223 The
224 .Dv SCTP_PR_SCTP_RTX
225 policy transforms the
226 .Fa timetolive
227 into a number of retransmissions to allow.
228 This policy
229 always assures that at a minimum one send attempt is
230 made of the data.
231 After which no more than
232 .Fa timetolive
233 retransmissions will be made before the data is skipped.
234 .Pp
235 .Fa stream_no
236 is the SCTP stream that you wish to send the
237 message on.
238 Streams in SCTP are reliable (or partially reliable) flows of ordered
239 messages.
240 The
241 .Fa context
242 field is used only in the event the message cannot be sent.
243 This is an opaque
244 value that the stack retains and will give to the user when a failed send
245 is given if that notification is enabled (see
246 .Xr sctp 4 ) .
247 Normally a user process can use this value to index some application
248 specific data structure when a send cannot be fulfilled.
249 .Fn sctp_sendmsgx
250 is identical to
251 .Fn sctp_sendmsg
252 with the exception that it takes an array of sockaddr structures in the
253 argument
254 .Fa to
255 and adds the additional argument
256 .Fa addrcnt
257 which specifies how many addresses are in the array.
258 This allows a
259 caller to implicitly set up an association passing multiple addresses
260 as if
261 .Fn sctp_connectx
262 had been called to set up the association.
263 .Sh RETURN VALUES
264 The call returns the number of characters sent, or -1
265 if an error occurred.
266 .Sh ERRORS
267 The
268 .Fn sctp_sendmsg
269 system call
270 fails if:
271 .Bl -tag -width Er
272 .It Bq Er EBADF
273 An invalid descriptor was specified.
274 .It Bq Er ENOTSOCK
275 The argument
276 .Fa s
277 is not a socket.
278 .It Bq Er EFAULT
279 An invalid user space address was specified for an argument.
280 .It Bq Er EMSGSIZE
281 The socket requires that message be sent atomically,
282 and the size of the message to be sent made this impossible.
283 .It Bq Er EAGAIN
284 The socket is marked non-blocking and the requested operation
285 would block.
286 .It Bq Er ENOBUFS
287 The system was unable to allocate an internal buffer.
288 The operation may succeed when buffers become available.
289 .It Bq Er ENOBUFS
290 The output queue for a network interface was full.
291 This generally indicates that the interface has stopped sending,
292 but may be caused by transient congestion.
293 .It Bq Er EHOSTUNREACH
294 The remote host was unreachable.
295 .It Bq Er ENOTCONN
296 On a one-to-one style socket no association exists.
297 .It Bq Er ECONNRESET
298 An abort was received by the stack while the user was
299 attempting to send data to the peer.
300 .It Bq Er ENOENT
301 On a one-to-many style socket no address is specified
302 so that the association cannot be located or the
303 .Dv SCTP_ABORT
304 flag was specified on a non-existing association.
305 .It Bq Er EPIPE
306 The socket is unable to send anymore data
307 .Dv ( SBS_CANTSENDMORE
308 has been set on the socket).
309 This typically means that the socket
310 is not connected and is a one-to-one style socket.
311 .El
312 .Sh SEE ALSO
313 .Xr connect 2 ,
314 .Xr getsockopt 2 ,
315 .Xr recv 2 ,
316 .Xr select 2 ,
317 .Xr socket 2 ,
318 .Xr write 2 ,
319 .Xr sctp_connectx 3 ,
320 .Xr sendmsg 3 ,
321 .Xr sctp 4
322 .Sh BUGS
323 Because in the one-to-many style socket
324 .Fn sctp_sendmsg
325 or
326 .Fn sctp_sendmsgx
327 may have multiple associations under one endpoint, a
328 select on write will only work for a one-to-one style
329 socket.