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