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