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