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