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