xref: /netbsd-src/lib/libc/net/sctp_sendmsg.3 (revision c9911a308e544f9996ca8c1b3d55033e1670fc78)
1.\"	$NetBSD: sctp_sendmsg.3,v 1.2 2018/08/13 06:00:21 wiz Exp $
2.\"
3.\" Copyright (c) 1983, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     From: @(#)send.2	8.2 (Berkeley) 2/21/94
31.\"
32.Dd August 1, 2018
33.Dt SCTP_SENDMSG 3
34.Os
35.Sh NAME
36.Nm sctp_sendmsg ,
37.Nm sctp_sendmsgx
38.Nd send a message from an SCTP socket
39.Sh LIBRARY
40.Lb libc
41.Sh SYNOPSIS
42.In sys/types.h
43.In sys/socket.h
44.In netinet/sctp.h
45.Ft ssize_t
46.Fo sctp_sendmsg
47.Fa "int s" "const void *msg" "size_t len" "const struct sockaddr *to"
48.Fa "socklen_t tolen" "uint32_t ppid" "uint32_t flags" "uint16_t stream_no"
49.Fa "uint32_t timetolive" "uint32_t context"
50.Fc
51.Ft ssize_t
52.Fo sctp_sendmsgx
53.Fa "int s" "const void *msg" "size_t len" "const struct sockaddr *to"
54.Fa "int addrcnt" "uint32_t ppid" "uint32_t flags" "uint16_t stream_no"
55.Fa "uint32_t timetolive" "uint32_t context"
56.Fc
57.Sh DESCRIPTION
58The
59.Fn sctp_sendmsg
60system call
61is used to transmit a message to another SCTP endpoint.
62The
63.Fn sctp_sendmsg
64may be used at any time.
65If the socket is a one-to-many type
66.Dv ( SOCK_SEQPACKET )
67socket then an attempt to send to an address that no association exists to will
68implicitly create a new association.
69Data sent in such an instance will result in
70the data being sent on the third leg of the SCTP four-way handshake.
71Note that if
72the socket is a one-to-one type
73.Dv ( SOCK_STREAM )
74socket then an association must
75be in existence (by use of the
76.Xr connect 2
77system call).
78Calling
79.Fn sctp_sendmsg
80or
81.Fn sctp_sendmsgx
82on a non-connected one-to-one socket will result in
83.Va errno
84being set to
85.Er ENOTCONN ,
86\-1 being returned, and the message not being transmitted.
87.Pp
88The address of the target is given by
89.Fa to
90with
91.Fa tolen
92specifying its size.
93The length of the message
94.Fa msg
95is given by
96.Fa len .
97If the message is too long to pass atomically through the
98underlying protocol,
99.Va errno
100is set to
101.Er EMSGSIZE ,
102\-1 is returned, and
103the message is not transmitted.
104.Pp
105No indication of failure to deliver is implicit in a
106.Fn sctp_sendmsg
107call.
108Locally detected errors are indicated by a return value of -1.
109.Pp
110If no space is available at the socket to hold
111the message to be transmitted, then
112.Fn sctp_sendmsg
113normally blocks, unless the socket has been placed in
114non-blocking I/O mode.
115The
116.Xr select 2
117system call may be used to determine when it is possible to
118send more data on one-to-one type
119.Dv ( SOCK_STREAM )
120sockets.
121.Pp
122The
123.Fa ppid
124argument is an opaque 32 bit value that is passed transparently
125through the stack to the peer endpoint.
126It will be available on
127reception of a message (see
128.Xr sctp_recvmsg 3 ) .
129Note that the stack passes this value without regard to byte
130order.
131.Pp
132The
133.Fa flags
134argument may include one or more of the following:
135.Bd -literal
136#define SCTP_EOF 	  0x0100	/* Start a shutdown procedures */
137#define SCTP_ABORT	  0x0200	/* Send an ABORT to peer */
138#define SCTP_UNORDERED 	  0x0400	/* Message is un-ordered */
139#define SCTP_ADDR_OVER	  0x0800	/* Override the primary-address */
140#define SCTP_SENDALL      0x1000	/* Send this on all associations */
141					/* for the endpoint */
142/* The lower byte is an enumeration of PR-SCTP policies */
143#define SCTP_PR_SCTP_TTL  0x0001	/* Time based PR-SCTP */
144#define SCTP_PR_SCTP_BUF  0x0002	/* Buffer based PR-SCTP */
145#define SCTP_PR_SCTP_RTX  0x0003	/* Number of retransmissions based PR-SCTP */
146.Ed
147.Pp
148The flag
149.Dv SCTP_EOF
150is used to instruct the SCTP stack to queue this message
151and then start a graceful shutdown of the association.
152All
153remaining data in queue will be sent after which the association
154will be shut down.
155.Pp
156.Dv SCTP_ABORT
157is used to immediately terminate an association.
158An abort
159is sent to the peer and the local TCB is destroyed.
160.Pp
161.Dv SCTP_UNORDERED
162is used to specify that the message being sent has no
163specific order and should be delivered to the peer application
164as soon as possible.
165When this flag is absent messages
166are delivered in order within the stream they are sent, but without
167respect to order to peer streams.
168.Pp
169The flag
170.Dv SCTP_ADDR_OVER
171is used to specify that an specific address should be used.
172Normally
173SCTP will use only one of a multi-homed peers addresses as the primary
174address to send to.
175By default, no matter what the
176.Fa to
177argument is, this primary address is used to send data.
178By specifying
179this flag, the user is asking the stack to ignore the primary address
180and instead use the specified address not only as a lookup mechanism
181to find the association but also as the actual address to send to.
182.Pp
183For a one-to-many type
184.Dv ( SOCK_SEQPACKET )
185socket the flag
186.Dv SCTP_SENDALL
187can be used as a convenient way to make one send call and have
188all associations that are under the socket get a copy of the message.
189Note that this mechanism is quite efficient and makes only one actual
190copy of the data which is shared by all the associations for sending.
191.Pp
192The remaining flags are used for the partial reliability extension (RFC3758)
193and will only be effective if the peer endpoint supports this extension.
194This option specifies what local policy the local endpoint should use
195in skipping data.
196If none of these options are set, then data is
197never skipped over.
198.Pp
199.Dv SCTP_PR_SCTP_TTL
200is used to indicate that a time based lifetime is being applied
201to the data.
202The
203.Fa timetolive
204argument is then a number of milliseconds for which the data is
205attempted to be transmitted.
206If that many milliseconds elapse
207and the peer has not acknowledged the data, the data will be
208skipped and no longer transmitted.
209Note that this policy does
210not even assure that the data will ever be sent.
211In times of a congestion
212with large amounts of data being queued, the
213.Fa timetolive
214may expire before the first transmission is ever made.
215.Pp
216The
217.Dv SCTP_PR_SCTP_BUF
218based policy transforms the
219.Fa timetolive
220field into a total number of bytes allowed on the outbound
221send queue.
222If that number or more bytes are in queue, then
223other buffer based sends are looked to be removed and
224skipped.
225Note that this policy may also result in the data
226never being sent if no buffer based sends are in queue and
227the maximum specified by
228.Fa timetolive
229bytes is in queue.
230.Pp
231The
232.Dv SCTP_PR_SCTP_RTX
233policy transforms the
234.Fa timetolive
235into a number of retransmissions to allow.
236This policy
237always assures that at a minimum one send attempt is
238made of the data.
239After which no more than
240.Fa timetolive
241retransmissions will be made before the data is skipped.
242.Pp
243.Fa stream_no
244is the SCTP stream that you wish to send the
245message on.
246Streams in SCTP are reliable (or partially reliable) flows of ordered
247messages.
248The
249.Fa context
250field is used only in the event the message cannot be sent.
251This is an opaque
252value that the stack retains and will give to the user when a failed send
253is given if that notification is enabled (see
254.Xr sctp 4 ) .
255Normally a user process can use this value to index some application
256specific data structure when a send cannot be fulfilled.
257.Fn sctp_sendmsgx
258is identical to
259.Fn sctp_sendmsg
260with the exception that it takes an array of sockaddr structures in the
261argument
262.Fa to
263and adds the additional argument
264.Fa addrcnt
265which specifies how many addresses are in the array.
266This allows a
267caller to implicitly set up an association passing multiple addresses
268as if
269.Fn sctp_connectx
270had been called to set up the association.
271.Sh RETURN VALUES
272The call returns the number of characters sent, or \-1
273if an error occurred.
274.Sh ERRORS
275The
276.Fn sctp_sendmsg
277system call
278fails if:
279.Bl -tag -width Er
280.It Bq Er EAGAIN
281The socket is marked non-blocking and the requested operation
282would block.
283.It Bq Er EBADF
284An invalid descriptor was specified.
285.It Bq Er ECONNRESET
286An abort was received by the stack while the user was
287attempting to send data to the peer.
288.It Bq Er EFAULT
289An invalid user space address was specified for an argument.
290.It Bq Er EHOSTUNREACH
291The remote host was unreachable.
292.It Bq Er EMSGSIZE
293The socket requires that message be sent atomically,
294and the size of the message to be sent made this impossible.
295.It Bq Er ENOBUFS
296The system was unable to allocate an internal buffer.
297The operation may succeed when buffers become available.
298This error is also returned when
299the output queue for a network interface was full.
300This generally indicates that the interface has stopped sending,
301but may be caused by transient congestion.
302.It Bq Er ENOENT
303On a one-to-many style socket no address is specified
304so that the association cannot be located or the
305.Dv SCTP_ABORT
306flag was specified on a non-existing association.
307.It Bq Er ENOTCONN
308On a one-to-one style socket no association exists.
309.It Bq Er ENOTSOCK
310The argument
311.Fa s
312is not a socket.
313.It Bq Er EPIPE
314The socket is unable to send anymore data
315.Dv ( SBS_CANTSENDMORE
316has been set on the socket).
317This typically means that the socket
318is not connected and is a one-to-one style socket.
319.El
320.Sh SEE ALSO
321.Xr connect 2 ,
322.Xr getsockopt 2 ,
323.Xr recv 2 ,
324.Xr select 2 ,
325.Xr sendmsg 2 ,
326.Xr socket 2 ,
327.Xr write 2 ,
328.Xr sctp_connectx 3 ,
329.Xr sctp 4
330.Rs
331.%R RFC
332.%N 6458
333.%T "Sockets API Extensions for the Stream Control Transmission Protocol (SCTP)"
334.%D December 2011
335.Re
336.Sh HISTORY
337These functions first appeared in
338.Nx 9.0 .
339.Sh BUGS
340Because in the one-to-many style socket
341.Fn sctp_sendmsg
342or
343.Fn sctp_sendmsgx
344may have multiple associations under one endpoint, a
345select on write will only work for a one-to-one style
346socket.
347