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