]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - lib/libc/net/sctp_send.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_send.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 .\" $FreeBSD$
33 .\"
34 .Dd December 15, 2006
35 .Dt SCTP_SEND 3
36 .Os
37 .Sh NAME
38 .Nm sctp_send ,
39 .Nm sctp_sendx
40 .Nd send a message from an SCTP socket
41 .Sh LIBRARY
42 .Lb libc
43 .Sh SYNOPSIS
44 .In sys/types.h
45 .In sys/socket.h
46 .In netinet/sctp.h
47 .Ft ssize_t
48 .Fo sctp_send
49 .Fa "int sd" "const void *msg" "size_t len"
50 .Fa "const struct sctp_sndrcvinfo *sinfo" "int flags"
51 .Fc
52 .Ft ssize_t
53 .Fo sctp_sendx
54 .Fa "int sd" "const void *msg" "size_t len" "struct sockaddr *addrs"
55 .Fa "int addrcnt" "const struct sctp_sndrcvinfo *sinfo" "int flags"
56 .Fc
57 .Sh DESCRIPTION
58 The
59 .Fn sctp_send
60 system call
61 is used to transmit a message to another SCTP endpoint.
62 .Fn sctp_send
63 may be used to send data to an existing association for both
64 one-to-many (SOCK_SEQPACKET) and one-to-one (SOCK_STREAM) socket types.
65 The length of the message
66 .Fa msg
67 is given by
68 .Fa len .
69 If the message is too long to pass atomically through the
70 underlying protocol,
71 .Va errno
72 is set to
73 .Er EMSGSIZE ,
74 -1 is returned, and
75 the message is not transmitted.
76 .Pp
77 No indication of failure to deliver is implicit in a
78 .Fn sctp_send .
79 Locally detected errors are indicated by a return value of -1.
80 .Pp
81 If no space is available at the socket to hold
82 the message to be transmitted, then
83 .Fn sctp_send
84 normally blocks, unless the socket has been placed in
85 non-blocking I/O mode.
86 The
87 .Xr select 2
88 system call may be used to determine when it is possible to
89 send more data on one-to-one type (SOCK_STREAM) sockets.
90 .Pp
91 The
92 .Fa sinfo
93 structure is used to control various SCTP features
94 and has the following format:
95 .Bd -literal
96 struct sctp_sndrcvinfo {
97         uint16_t sinfo_stream;  /* Stream sending to */
98         uint16_t sinfo_ssn;     /* valid for recv only */
99         uint16_t sinfo_flags;   /* flags to control sending */
100         uint32_t sinfo_ppid;    /* ppid field */
101         uint32_t sinfo_context; /* context field */
102         uint32_t sinfo_timetolive; /* timetolive for PR-SCTP */
103         uint32_t sinfo_tsn;        /* valid for recv only */
104         uint32_t sinfo_cumtsn;     /* valid for recv only */
105         sctp_assoc_t sinfo_assoc_id; /* The association id */
106 };
107 .Ed
108 .Pp
109 The
110 .Fa sinfo->sinfo_ppid
111 argument is an opaque 32 bit value that is passed transparently
112 through the stack to the peer endpoint. It will be available on
113 reception of a message (see
114 .Xr sctp_recvmsg 3 ) .
115 Note that the stack passes this value without regard to byte
116 order.
117 .Pp
118 The
119 .Fa sinfo->sinfo_flags
120 argument may include one or more of the following:
121 .Bd -literal
122 #define SCTP_EOF          0x0100        /* Start a shutdown procedures */
123 #define SCTP_ABORT        0x0200        /* Send an ABORT to peer */
124 #define SCTP_UNORDERED    0x0400        /* Message is un-ordered */
125 #define SCTP_ADDR_OVER    0x0800        /* Override the primary-address */
126 #define SCTP_SENDALL      0x1000        /* Send this on all associations */
127                                         /* for the endpoint */
128 /* The lower byte is an enumeration of PR-SCTP policies */
129 #define SCTP_PR_SCTP_TTL  0x0001        /* Time based PR-SCTP */
130 #define SCTP_PR_SCTP_BUF  0x0002        /* Buffer based PR-SCTP */
131 #define SCTP_PR_SCTP_RTX  0x0003        /* Number of retransmissions based PR-SCTP */
132 .Ed
133 .Pp
134 The flag
135 .Dv SCTP_EOF
136 is used to instruct the SCTP stack to queue this message
137 and then start a graceful shutdown of the association.
138 All
139 remaining data in queue will be sent after which the association
140 will be shut down.
141 .Pp
142 .Dv SCTP_ABORT
143 is used to immediately terminate an association.
144 An abort
145 is sent to the peer and the local TCB is destroyed.
146 .Pp
147 .Dv SCTP_UNORDERED
148 is used to specify that the message being sent has no
149 specific order and should be delivered to the peer application
150 as soon as possible.
151 When this flag is absent messages
152 are delivered in order within the stream they are sent, but without
153 respect to order to peer streams.
154 .Pp
155 The flag
156 .Dv SCTP_ADDR_OVER
157 is used to specify that a specific address should be used.
158 Normally
159 SCTP will use only one of a multi-homed peers addresses as the primary
160 address to send to.
161 By default, no matter what the
162 .Fa to
163 argument is, this primary address is used to send data.
164 By specifying
165 this flag, the user is asking the stack to ignore the primary address
166 and instead use the specified address not only as a lookup mechanism
167 to find the association but also as the actual address to send to.
168 .Pp
169 For a one-to-many type (SOCK_SEQPACKET) socket the flag
170 .Dv SCTP_SENDALL
171 can be used as a convenient way to make one send call and have
172 all associations that are under the socket get a copy of the message.
173 Note that this mechanism is quite efficient and makes only one actual
174 copy of the data which is shared by all the associations for sending.
175 .Pp
176 The remaining flags are used for the partial reliability extension (RFC3758)
177 and will only be effective if the peer endpoint supports this extension.
178 This option specifies what local policy the local endpoint should use
179 in skipping data.
180 If none of these options are set, then data is
181 never skipped over.
182 .Pp
183 .Dv SCTP_PR_SCTP_TTL
184 is used to indicate that a time based lifetime is being applied
185 to the data.
186 The
187 .Fa sinfo->sinfo_timetolive
188 argument is then a number of milliseconds for which the data is
189 attempted to be transmitted.
190 If that many milliseconds elapse
191 and the peer has not acknowledged the data, the data will be
192 skipped and no longer transmitted.
193 Note that this policy does
194 not even assure that the data will ever be sent.
195 In times of a congestion
196 with large amounts of data being queued, the
197 .Fa sinfo->sinfo_timetolive
198 may expire before the first transmission is ever made.
199 .Pp
200 The
201 .Dv SCTP_PR_SCTP_BUF
202 based policy transforms the
203 .Fa sinfo->sinfo_timetolive
204 field into a total number of bytes allowed on the outbound
205 send queue.
206 If that number or more bytes are in queue, then
207 other buffer-based sends are looked to be removed and
208 skipped.
209 Note that this policy may also result in the data
210 never being sent if no buffer based sends are in queue and
211 the maximum specified by
212 .Fa timetolive
213 bytes is in queue.
214 .Pp
215 The
216 .Dv SCTP_PR_SCTP_RTX
217 policy transforms the
218 .Fa sinfo->sinfo_timetolive
219 into a number of retransmissions to allow.
220 This policy
221 always assures that at a minimum one send attempt is
222 made of the data.
223 After which no more than
224 .Fa sinfo->sinfo_timetolive
225 retransmissions will be made before the data is skipped.
226 .Pp
227 .Fa sinfo->sinfo_stream
228 is the SCTP stream that you wish to send the
229 message on.
230 Streams in SCTP are reliable (or partially reliable) flows of ordered
231 messages.
232 .Pp
233 The
234 .Fa sinfo->sinfo_assoc_id
235 field is used to
236 select the association to send to on a one-to-many socket.
237 For a one-to-one socket, this field is ignored.
238 .Pp
239 The
240 .Fa sinfo->sinfo_context
241 field is used only in the event the message cannot be sent.
242 This is an opaque
243 value that the stack retains and will give to the user when a failed send
244 is given if that notification is enabled (see
245 .Xr sctp 4 ) .
246 Normally a user process can use this value to index some application
247 specific data structure when a send cannot be fulfilled.
248 .Pp
249 The
250 .Fa flags
251 argument holds the same meaning and values as those found in
252 .Xr sendmsg 2
253 but is generally ignored by SCTP.
254 .Pp
255 The fields
256 .Fa sinfo->sinfo_ssn ,
257 .Fa sinfo->sinfo_tsn ,
258 and
259 .Fa sinfo->sinfo_cumtsn
260 are used only when receiving messages and are thus ignored by
261 .Fn sctp_send .
262 The function
263 .Fn sctp_sendx
264 has the same properties as
265 .Fn sctp_send
266 with the additional arguments of an array of sockaddr structures
267 passed in.
268 With the
269 .Fa addrs
270 argument being given as an array of addresses to be sent to and
271 the
272 .Fa addrcnt
273 argument indicating how many socket addresses are in the passed
274 in array.
275 Note that all of the addresses will only be used
276 when an implicit association is being set up.
277 This allows the
278 user the equivalent behavior as doing a
279 .Fn sctp_connectx
280 followed by a
281 .Fn sctp_send
282 to the association.
283 Note that if the
284 .Fa sinfo->sinfo_assoc_id
285 field is 0, then the first address will be used to look up
286 the association in place of the association id.
287 If both
288 an address and an association id are specified, the association
289 id has priority.
290 .Sh RETURN VALUES
291 The call returns the number of characters sent, or -1
292 if an error occurred.
293 .Sh ERRORS
294 The
295 .Fn sctp_send
296 system call
297 fails if:
298 .Bl -tag -width Er
299 .It Bq Er EBADF
300 An invalid descriptor was specified.
301 .It Bq Er ENOTSOCK
302 The argument
303 .Fa s
304 is not a socket.
305 .It Bq Er EFAULT
306 An invalid user space address was specified for an argument.
307 .It Bq Er EMSGSIZE
308 The socket requires that message be sent atomically,
309 and the size of the message to be sent made this impossible.
310 .It Bq Er EAGAIN
311 The socket is marked non-blocking and the requested operation
312 would block.
313 .It Bq Er ENOBUFS
314 The system was unable to allocate an internal buffer.
315 The operation may succeed when buffers become available.
316 .It Bq Er ENOBUFS
317 The output queue for a network interface was full.
318 This generally indicates that the interface has stopped sending,
319 but may be caused by transient congestion.
320 .It Bq Er EHOSTUNREACH
321 The remote host was unreachable.
322 .It Bq Er ENOTCONN
323 On a one-to-one style socket no association exists.
324 .It Bq Er ECONNRESET
325 An abort was received by the stack while the user was
326 attempting to send data to the peer.
327 .It Bq Er ENOENT
328 On a one-to-many style socket no address is specified
329 so that the association cannot be located or the
330 SCTP_ABORT flag was specified on a non-existing association.
331 .It Bq Er EPIPE
332 The socket is unable to send anymore data
333 .Dv ( SBS_CANTSENDMORE
334 has been set on the socket).
335 This typically means that the socket
336 is not connected and is a one-to-one style socket.
337 .El
338 .Sh SEE ALSO
339 .Xr getsockopt 2 ,
340 .Xr recv 2 ,
341 .Xr select 2 ,
342 .Xr sendmsg 2 ,
343 .Xr socket 2 ,
344 .Xr write 2
345 .Xr sctp_connectx 3 ,
346 .Xr sctp_recvmsg 3 ,
347 .Xr sctp_sendmsg 3 ,
348 .Xr sctp 4
349 .Sh BUGS
350 Because
351 .Fn sctp_send
352 may have multiple associations under one endpoint, a
353 select on write will only work for a one-to-one style
354 socket.