xref: /freebsd/lib/libc/net/sctp_recvmsg.3 (revision 446734c25efb5b4270c7426f6fa793524ca0fd2d)
1d8b5fd91SRandall Stewart.\" Copyright (c) 1983, 1991, 1993
2d8b5fd91SRandall Stewart.\"	The Regents of the University of California.  All rights reserved.
3d8b5fd91SRandall Stewart.\"
4d8b5fd91SRandall Stewart.\" Redistribution and use in source and binary forms, with or without
5d8b5fd91SRandall Stewart.\" modification, are permitted provided that the following conditions
6d8b5fd91SRandall Stewart.\" are met:
7d8b5fd91SRandall Stewart.\" 1. Redistributions of source code must retain the above copyright
8d8b5fd91SRandall Stewart.\"    notice, this list of conditions and the following disclaimer.
9d8b5fd91SRandall Stewart.\" 2. Redistributions in binary form must reproduce the above copyright
10d8b5fd91SRandall Stewart.\"    notice, this list of conditions and the following disclaimer in the
11d8b5fd91SRandall Stewart.\"    documentation and/or other materials provided with the distribution.
12921ca2fdSEd Maste.\" 3. Neither the name of the University nor the names of its contributors
13d8b5fd91SRandall Stewart.\"    may be used to endorse or promote products derived from this software
14d8b5fd91SRandall Stewart.\"    without specific prior written permission.
15d8b5fd91SRandall Stewart.\"
16d8b5fd91SRandall Stewart.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17d8b5fd91SRandall Stewart.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18d8b5fd91SRandall Stewart.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19d8b5fd91SRandall Stewart.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20d8b5fd91SRandall Stewart.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21d8b5fd91SRandall Stewart.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22d8b5fd91SRandall Stewart.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23d8b5fd91SRandall Stewart.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24d8b5fd91SRandall Stewart.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25d8b5fd91SRandall Stewart.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26d8b5fd91SRandall Stewart.\" SUCH DAMAGE.
27d8b5fd91SRandall Stewart.\"
28d8b5fd91SRandall Stewart.\" $FreeBSD$
29d8b5fd91SRandall Stewart.\"
30*446734c2SMichael Tuexen.Dd April 23, 2015
31d8b5fd91SRandall Stewart.Dt SCTP_RECVMSG 3
32d8b5fd91SRandall Stewart.Os
33d8b5fd91SRandall Stewart.Sh NAME
34d8b5fd91SRandall Stewart.Nm sctp_recvmsg
35694b0a6bSGabor Kovesdan.Nd receive a message from an SCTP socket
36d8b5fd91SRandall Stewart.Sh LIBRARY
37d8b5fd91SRandall Stewart.Lb libc
38d8b5fd91SRandall Stewart.Sh SYNOPSIS
39d8b5fd91SRandall Stewart.In sys/types.h
40d8b5fd91SRandall Stewart.In sys/socket.h
417c376800SRandall Stewart.In netinet/sctp.h
42d8b5fd91SRandall Stewart.Ft ssize_t
4316c90ceeSChristian Brueffer.Fo sctp_recvmsg
4416c90ceeSChristian Brueffer.Fa "int s" "void *msg" "size_t len" "struct sockaddr * restrict from"
4516c90ceeSChristian Brueffer.Fa "socklen_t * restrict fromlen" "struct sctp_sndrcvinfo *sinfo" "int *flags"
4616c90ceeSChristian Brueffer.Fc
47d8b5fd91SRandall Stewart.Sh DESCRIPTION
48d8b5fd91SRandall StewartThe
49d8b5fd91SRandall Stewart.Fn sctp_recvmsg
5016c90ceeSChristian Brueffersystem call
51d8b5fd91SRandall Stewartis used to receive a message from another SCTP endpoint.
52d8b5fd91SRandall StewartThe
53d8b5fd91SRandall Stewart.Fn sctp_recvmsg
54d8b5fd91SRandall Stewartcall is used by one-to-one (SOCK_STREAM) type sockets after a
5516c90ceeSChristian Brueffersuccessful
5616c90ceeSChristian Brueffer.Fn connect
57d8b5fd91SRandall Stewartcall or after the application has performed a
58d8b5fd91SRandall Stewart.Fn listen
5944d9c281SChristian Bruefferfollowed by a successful
6044d9c281SChristian Brueffer.Fn accept .
61d8b5fd91SRandall StewartFor a one-to-many (SOCK_SEQPACKET) type socket, an endpoint may call
62d8b5fd91SRandall Stewart.Fn sctp_recvmsg
63d8b5fd91SRandall Stewartafter having implicitly started an association via one
64d8b5fd91SRandall Stewartof the send calls including
65a3fb6da9SGlen Barber.Fn sctp_sendmsg ,
6616c90ceeSChristian Brueffer.Fn sendto
67d8b5fd91SRandall Stewartand
6816c90ceeSChristian Brueffer.Fn sendmsg .
69d8b5fd91SRandall StewartOr, an application may also receive a message after having
70d8b5fd91SRandall Stewartcalled
7116c90ceeSChristian Brueffer.Fn listen
7244d9c281SChristian Bruefferwith a positive backlog to enable the reception of new associations.
73d8b5fd91SRandall Stewart.Pp
74d8b5fd91SRandall StewartThe address of the sender is held in the
75d8b5fd91SRandall Stewart.Fa from
76d8b5fd91SRandall Stewartargument with
77d8b5fd91SRandall Stewart.Fa fromlen
7816c90ceeSChristian Bruefferspecifying its size.
7916c90ceeSChristian BruefferAt the completion of a successful
80d8b5fd91SRandall Stewart.Fn sctp_recvmsg
81d8b5fd91SRandall Stewartcall
82d8b5fd91SRandall Stewart.Fa from
83d8b5fd91SRandall Stewartwill hold the address of the peer and
84d8b5fd91SRandall Stewart.Fa fromlen
8516c90ceeSChristian Bruefferwill hold the length of that address.
8616c90ceeSChristian BruefferNote that
87f6ac2391SJoel Dahlthe address is bounded by the initial value of
88d8b5fd91SRandall Stewart.Fa fromlen
89d8b5fd91SRandall Stewartwhich is used as an in/out variable.
90d8b5fd91SRandall Stewart.Pp
91d8b5fd91SRandall StewartThe length of the message
92d8b5fd91SRandall Stewart.Fa msg
93d8b5fd91SRandall Stewartto be received is bounded by
94d8b5fd91SRandall Stewart.Fa len .
9516c90ceeSChristian BruefferIf the message is too long to fit in the users
96d8b5fd91SRandall Stewartreceive buffer, then the
97d8b5fd91SRandall Stewart.Fa flags
9844d9c281SChristian Bruefferargument will
9944d9c281SChristian Brueffer.Em not
10044d9c281SChristian Bruefferhave the
101*446734c2SMichael Tuexen.Dv MSG_EOR
10216c90ceeSChristian Bruefferflag applied.
10316c90ceeSChristian BruefferIf the message is a complete message then
104d8b5fd91SRandall Stewartthe
105d8b5fd91SRandall Stewart.Fa flags
10616c90ceeSChristian Bruefferargument will have
107*446734c2SMichael Tuexen.Dv MSG_EOR
10816c90ceeSChristian Bruefferset.
10916c90ceeSChristian BruefferLocally detected errors are
11016c90ceeSChristian Bruefferindicated by a return value of -1 with
11116c90ceeSChristian Brueffer.Va errno
11216c90ceeSChristian Bruefferset accordingly.
113d8b5fd91SRandall StewartThe
114d8b5fd91SRandall Stewart.Fa flags
11516c90ceeSChristian Bruefferargument may also hold the value
11616c90ceeSChristian Brueffer.Dv MSG_NOTIFICATION .
11716c90ceeSChristian BruefferWhen this
11844d9c281SChristian Bruefferoccurs it indicates that the message received is
11944d9c281SChristian Brueffer.Em not
12044d9c281SChristian Bruefferfrom
121d8b5fd91SRandall Stewartthe peer endpoint, but instead is a notification from the
122d8b5fd91SRandall StewartSCTP stack (see
12316c90ceeSChristian Brueffer.Xr sctp 4
12416c90ceeSChristian Bruefferfor more details).
12516c90ceeSChristian BruefferNote that no notifications are ever
126d8b5fd91SRandall Stewartgiven unless the user subscribes to such notifications using
12716c90ceeSChristian Bruefferthe
12816c90ceeSChristian Brueffer.Dv SCTP_EVENTS
12916c90ceeSChristian Brueffersocket option.
130d8b5fd91SRandall Stewart.Pp
13116c90ceeSChristian BruefferIf no messages are available at the socket then
132d8b5fd91SRandall Stewart.Fn sctp_recvmsg
13316c90ceeSChristian Brueffernormally blocks on the reception of a message or NOTIFICATION, unless the
13416c90ceeSChristian Brueffersocket has been placed in non-blocking I/O mode.
135d8b5fd91SRandall StewartThe
136d8b5fd91SRandall Stewart.Xr select 2
137d8b5fd91SRandall Stewartsystem call may be used to determine when it is possible to
138d8b5fd91SRandall Stewartreceive a message.
139d8b5fd91SRandall Stewart.Pp
140d8b5fd91SRandall StewartThe
141d8b5fd91SRandall Stewart.Fa sinfo
142d8b5fd91SRandall Stewartargument is defined as follows.
143d8b5fd91SRandall Stewart.Bd -literal
144d8b5fd91SRandall Stewartstruct sctp_sndrcvinfo {
1453d36ac98SRebecca Cran	uint16_t sinfo_stream;  /* Stream arriving on */
1463d36ac98SRebecca Cran	uint16_t sinfo_ssn;     /* Stream Sequence Number */
1473d36ac98SRebecca Cran	uint16_t sinfo_flags;   /* Flags on the incoming message */
1483d36ac98SRebecca Cran	uint32_t sinfo_ppid;    /* The ppid field */
1493d36ac98SRebecca Cran	uint32_t sinfo_context; /* context field */
1503d36ac98SRebecca Cran	uint32_t sinfo_timetolive; /* not used by sctp_recvmsg */
1513d36ac98SRebecca Cran	uint32_t sinfo_tsn;        /* The transport sequence number */
1523d36ac98SRebecca Cran	uint32_t sinfo_cumtsn;     /* The cumulative acknowledgment point  */
153d8b5fd91SRandall Stewart	sctp_assoc_t sinfo_assoc_id; /* The association id of the peer */
154d8b5fd91SRandall Stewart};
155d8b5fd91SRandall Stewart.Ed
15616c90ceeSChristian Brueffer.Pp
157d8b5fd91SRandall StewartThe
158d8b5fd91SRandall Stewart.Fa sinfo->sinfo_ppid
159a47698f8SChristian Bruefferfield is an opaque 32 bit value that is passed transparently
160d8b5fd91SRandall Stewartthrough the stack from the peer endpoint.
161d8b5fd91SRandall StewartNote that the stack passes this value without regard to byte
162d8b5fd91SRandall Stewartorder.
163d8b5fd91SRandall Stewart.Pp
164d8b5fd91SRandall StewartThe
165d8b5fd91SRandall Stewart.Fa sinfo->sinfo_flags
166d8b5fd91SRandall Stewartfield may include the following:
167d8b5fd91SRandall Stewart.Bd -literal
168d8b5fd91SRandall Stewart#define SCTP_UNORDERED 	  0x0400	/* Message is un-ordered */
169d8b5fd91SRandall Stewart.Ed
170d8b5fd91SRandall Stewart.Pp
171d8b5fd91SRandall StewartThe
172d8b5fd91SRandall Stewart.Dv SCTP_UNORDERED
173d8b5fd91SRandall Stewartflag is used to specify that the message arrived with no
174d8b5fd91SRandall Stewartspecific order and was delivered to the peer application
17516c90ceeSChristian Bruefferas soon as possible.
17616c90ceeSChristian BruefferWhen this flag is absent the message
177d8b5fd91SRandall Stewartwas delivered in order within the stream it was received.
178d8b5fd91SRandall Stewart.Pp
179a47698f8SChristian BruefferThe
180d8b5fd91SRandall Stewart.Fa sinfo->sinfo_stream
181a47698f8SChristian Bruefferfield is the SCTP stream that the message was received on.
182d8b5fd91SRandall StewartStreams in SCTP are reliable (or partially reliable) flows of ordered
183d8b5fd91SRandall Stewartmessages.
184d8b5fd91SRandall Stewart.Pp
185d8b5fd91SRandall StewartThe
186d8b5fd91SRandall Stewart.Fa sinfo->sinfo_context
18716c90ceeSChristian Bruefferfield is used only if the local application set an association level
18816c90ceeSChristian Brueffercontext with the
18916c90ceeSChristian Brueffer.Dv SCTP_CONTEXT
19016c90ceeSChristian Brueffersocket option.
191d8b5fd91SRandall StewartOptionally a user process can use this value to index some application
192d8b5fd91SRandall Stewartspecific data structure for all data coming from a specific
193d8b5fd91SRandall Stewartassociation.
194d8b5fd91SRandall Stewart.Pp
195d8b5fd91SRandall StewartThe
196d8b5fd91SRandall Stewart.Fa sinfo->sinfo_ssn
197a47698f8SChristian Bruefferfield will hold the stream sequence number assigned
19844d9c281SChristian Bruefferby the peer endpoint if the message is
19944d9c281SChristian Brueffer.Em not
20044d9c281SChristian Bruefferunordered.
201d8b5fd91SRandall StewartFor unordered messages this field holds an undefined value.
202d8b5fd91SRandall Stewart.Pp
203d8b5fd91SRandall StewartThe
204d8b5fd91SRandall Stewart.Fa sinfo->sinfo_tsn
205a47698f8SChristian Bruefferfield holds a transport sequence number (TSN) that was assigned
20616c90ceeSChristian Bruefferto this message by the peer endpoint.
20716c90ceeSChristian BruefferFor messages that fit in or less
208d8b5fd91SRandall Stewartthan the path MTU this will be the only TSN assigned.
20944d9c281SChristian BruefferNote that for messages that span multiple TSNs this
21044d9c281SChristian Brueffervalue will be one of the TSNs that was used on the
211d8b5fd91SRandall Stewartmessage.
212d8b5fd91SRandall Stewart.Pp
213d8b5fd91SRandall StewartThe
214d8b5fd91SRandall Stewart.Fa sinfo->sinfo_cumtsn
215a47698f8SChristian Bruefferfield holds the current cumulative acknowledgment point of
21616c90ceeSChristian Bruefferthe transport association.
21716c90ceeSChristian BruefferNote that this may be larger
218d8b5fd91SRandall Stewartor smaller than the TSN assigned to the message itself.
219d8b5fd91SRandall Stewart.Pp
220d8b5fd91SRandall StewartThe
22116c90ceeSChristian Brueffer.Fa sinfo->sinfo_assoc_id
222d8b5fd91SRandall Stewartis the unique association identification that was assigned
22316c90ceeSChristian Bruefferto the association.
22416c90ceeSChristian BruefferFor one-to-many (SOCK_SEQPACKET) type
225d8b5fd91SRandall Stewartsockets this value can be used to send data to the peer without
22616c90ceeSChristian Bruefferthe use of an address field.
22716c90ceeSChristian BruefferIt is also quite useful in
228d8b5fd91SRandall Stewartsetting various socket options on the specific association
229d8b5fd91SRandall Stewart(see
23044d9c281SChristian Brueffer.Xr sctp 4 ) .
231d8b5fd91SRandall Stewart.Pp
232d8b5fd91SRandall StewartThe
23316c90ceeSChristian Brueffer.Fa sinfo->info_timetolive
234d8b5fd91SRandall Stewartfield is not used by
235a47698f8SChristian Brueffer.Fn sctp_recvmsg .
236d8b5fd91SRandall Stewart.Sh RETURN VALUES
237cefac273SRebecca CranThe call returns the number of bytes received, or -1
238d8b5fd91SRandall Stewartif an error occurred.
239d8b5fd91SRandall Stewart.Sh ERRORS
240d8b5fd91SRandall StewartThe
241d8b5fd91SRandall Stewart.Fn sctp_recvmsg
242d8b5fd91SRandall Stewartsystem call
24316c90ceeSChristian Bruefferfails if:
244d8b5fd91SRandall Stewart.Bl -tag -width Er
245d8b5fd91SRandall Stewart.It Bq Er EBADF
246d8b5fd91SRandall StewartAn invalid descriptor was specified.
247d8b5fd91SRandall Stewart.It Bq Er ENOTSOCK
248d8b5fd91SRandall StewartThe argument
249d8b5fd91SRandall Stewart.Fa s
250d8b5fd91SRandall Stewartis not a socket.
251d8b5fd91SRandall Stewart.It Bq Er EFAULT
252d8b5fd91SRandall StewartAn invalid user space address was specified for an argument.
253d8b5fd91SRandall Stewart.It Bq Er EMSGSIZE
254d8b5fd91SRandall StewartThe socket requires that message be sent atomically,
255d8b5fd91SRandall Stewartand the size of the message to be sent made this impossible.
256d8b5fd91SRandall Stewart.It Bq Er EAGAIN
257d8b5fd91SRandall StewartThe socket is marked non-blocking and the requested operation
258d8b5fd91SRandall Stewartwould block.
259d8b5fd91SRandall Stewart.It Bq Er ENOBUFS
260d8b5fd91SRandall StewartThe system was unable to allocate an internal buffer.
261d8b5fd91SRandall StewartThe operation may succeed when buffers become available.
262d8b5fd91SRandall Stewart.It Bq Er ENOBUFS
263d8b5fd91SRandall StewartThe output queue for a network interface was full.
264d8b5fd91SRandall StewartThis generally indicates that the interface has stopped sending,
265d8b5fd91SRandall Stewartbut may be caused by transient congestion.
266d8b5fd91SRandall Stewart.It Bq Er EHOSTUNREACH
267d8b5fd91SRandall StewartThe remote host was unreachable.
2680add3200SRebecca Cran.It Bq Er ENOTCONN
26916c90ceeSChristian BruefferOn a one-to-one style socket no association exists.
270d8b5fd91SRandall Stewart.It Bq Er ECONNRESET
271d8b5fd91SRandall StewartAn abort was received by the stack while the user was
272d8b5fd91SRandall Stewartattempting to send data to the peer.
273d8b5fd91SRandall Stewart.It Bq Er ENOENT
274d8b5fd91SRandall StewartOn a one to many style socket no address is specified
275d8b5fd91SRandall Stewartso that the association cannot be located or the
276d8b5fd91SRandall StewartSCTP_ABORT flag was specified on a non-existing association.
277d8b5fd91SRandall Stewart.It Bq Er EPIPE
278d8b5fd91SRandall StewartThe socket is unable to send anymore data
279d8b5fd91SRandall Stewart.Dv ( SBS_CANTSENDMORE
280d8b5fd91SRandall Stewarthas been set on the socket).
281d8b5fd91SRandall StewartThis typically means that the socket
282d8b5fd91SRandall Stewartis not connected and is a one-to-one style socket.
283d8b5fd91SRandall Stewart.El
284d8b5fd91SRandall Stewart.Sh SEE ALSO
2850aee91e1SChristian Brueffer.Xr getsockopt 2 ,
286d8b5fd91SRandall Stewart.Xr recv 2 ,
287d8b5fd91SRandall Stewart.Xr select 2 ,
2880aee91e1SChristian Brueffer.Xr setsockopt 2 ,
289d8b5fd91SRandall Stewart.Xr socket 2 ,
29016c90ceeSChristian Brueffer.Xr write 2 ,
29116c90ceeSChristian Brueffer.Xr sctp_send 3 ,
29216c90ceeSChristian Brueffer.Xr sctp_sendmsg 3 ,
29316c90ceeSChristian Brueffer.Xr sendmsg 3 ,
29416c90ceeSChristian Brueffer.Xr sctp 4
295