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