xref: /freebsd/lib/libc/net/sctp_recvmsg.3 (revision 3d36ac98772ff4b4ad29e7457cb6e14231e4d426)
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.
12d8b5fd91SRandall Stewart.\" 3. All advertising materials mentioning features or use of this software
13d8b5fd91SRandall Stewart.\"    must display the following acknowledgement:
14d8b5fd91SRandall Stewart.\"	This product includes software developed by the University of
15d8b5fd91SRandall Stewart.\"	California, Berkeley and its contributors.
16d8b5fd91SRandall Stewart.\" 4. Neither the name of the University nor the names of its contributors
17d8b5fd91SRandall Stewart.\"    may be used to endorse or promote products derived from this software
18d8b5fd91SRandall Stewart.\"    without specific prior written permission.
19d8b5fd91SRandall Stewart.\"
20d8b5fd91SRandall Stewart.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21d8b5fd91SRandall Stewart.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22d8b5fd91SRandall Stewart.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23d8b5fd91SRandall Stewart.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24d8b5fd91SRandall Stewart.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25d8b5fd91SRandall Stewart.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26d8b5fd91SRandall Stewart.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27d8b5fd91SRandall Stewart.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28d8b5fd91SRandall Stewart.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29d8b5fd91SRandall Stewart.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30d8b5fd91SRandall Stewart.\" SUCH DAMAGE.
31d8b5fd91SRandall Stewart.\"
32d8b5fd91SRandall Stewart.\" $FreeBSD$
33d8b5fd91SRandall Stewart.\"
34694b0a6bSGabor Kovesdan.Dd August 13, 2007
35d8b5fd91SRandall Stewart.Dt SCTP_RECVMSG 3
36d8b5fd91SRandall Stewart.Os
37d8b5fd91SRandall Stewart.Sh NAME
38d8b5fd91SRandall Stewart.Nm sctp_recvmsg
39694b0a6bSGabor Kovesdan.Nd receive a message from an SCTP socket
40d8b5fd91SRandall Stewart.Sh LIBRARY
41d8b5fd91SRandall Stewart.Lb libc
42d8b5fd91SRandall Stewart.Sh SYNOPSIS
43d8b5fd91SRandall Stewart.In sys/types.h
44d8b5fd91SRandall Stewart.In sys/socket.h
457c376800SRandall Stewart.In netinet/sctp.h
46d8b5fd91SRandall Stewart.Ft ssize_t
4716c90ceeSChristian Brueffer.Fo sctp_recvmsg
4816c90ceeSChristian Brueffer.Fa "int s" "void *msg" "size_t len" "struct sockaddr * restrict from"
4916c90ceeSChristian Brueffer.Fa "socklen_t * restrict fromlen" "struct sctp_sndrcvinfo *sinfo" "int *flags"
5016c90ceeSChristian Brueffer.Fc
51d8b5fd91SRandall Stewart.Sh DESCRIPTION
52d8b5fd91SRandall StewartThe
53d8b5fd91SRandall Stewart.Fn sctp_recvmsg
5416c90ceeSChristian Brueffersystem call
55d8b5fd91SRandall Stewartis used to receive a message from another SCTP endpoint.
56d8b5fd91SRandall StewartThe
57d8b5fd91SRandall Stewart.Fn sctp_recvmsg
58d8b5fd91SRandall Stewartcall is used by one-to-one (SOCK_STREAM) type sockets after a
5916c90ceeSChristian Brueffersuccessful
6016c90ceeSChristian Brueffer.Fn connect
61d8b5fd91SRandall Stewartcall or after the application has performed a
62d8b5fd91SRandall Stewart.Fn listen
6344d9c281SChristian Bruefferfollowed by a successful
6444d9c281SChristian Brueffer.Fn accept .
65d8b5fd91SRandall StewartFor a one-to-many (SOCK_SEQPACKET) type socket, an endpoint may call
66d8b5fd91SRandall Stewart.Fn sctp_recvmsg
67d8b5fd91SRandall Stewartafter having implicitly started an association via one
68d8b5fd91SRandall Stewartof the send calls including
6916c90ceeSChristian Brueffer.Fn sctp_sendmsg
7016c90ceeSChristian Brueffer.Fn sendto
71d8b5fd91SRandall Stewartand
7216c90ceeSChristian Brueffer.Fn sendmsg .
73d8b5fd91SRandall StewartOr, an application may also receive a message after having
74d8b5fd91SRandall Stewartcalled
7516c90ceeSChristian Brueffer.Fn listen
7644d9c281SChristian Bruefferwith a positive backlog to enable the reception of new associations.
77d8b5fd91SRandall Stewart.Pp
78d8b5fd91SRandall StewartThe address of the sender is held in the
79d8b5fd91SRandall Stewart.Fa from
80d8b5fd91SRandall Stewartargument with
81d8b5fd91SRandall Stewart.Fa fromlen
8216c90ceeSChristian Bruefferspecifying its size.
8316c90ceeSChristian BruefferAt the completion of a successful
84d8b5fd91SRandall Stewart.Fn sctp_recvmsg
85d8b5fd91SRandall Stewartcall
86d8b5fd91SRandall Stewart.Fa from
87d8b5fd91SRandall Stewartwill hold the address of the peer and
88d8b5fd91SRandall Stewart.Fa fromlen
8916c90ceeSChristian Bruefferwill hold the length of that address.
9016c90ceeSChristian BruefferNote that
91d8b5fd91SRandall Stewartthe address is bounded by the inital value of
92d8b5fd91SRandall Stewart.Fa fromlen
93d8b5fd91SRandall Stewartwhich is used as an in/out variable.
94d8b5fd91SRandall Stewart.Pp
95d8b5fd91SRandall StewartThe length of the message
96d8b5fd91SRandall Stewart.Fa msg
97d8b5fd91SRandall Stewartto be received is bounded by
98d8b5fd91SRandall Stewart.Fa len .
9916c90ceeSChristian BruefferIf the message is too long to fit in the users
100d8b5fd91SRandall Stewartreceive buffer, then the
101d8b5fd91SRandall Stewart.Fa flags
10244d9c281SChristian Bruefferargument will
10344d9c281SChristian Brueffer.Em not
10444d9c281SChristian Bruefferhave the
10516c90ceeSChristian Brueffer.Dv MSG_EOF
10616c90ceeSChristian Bruefferflag applied.
10716c90ceeSChristian BruefferIf the message is a complete message then
108d8b5fd91SRandall Stewartthe
109d8b5fd91SRandall Stewart.Fa flags
11016c90ceeSChristian Bruefferargument will have
11116c90ceeSChristian Brueffer.Dv MSG_EOF
11216c90ceeSChristian Bruefferset.
11316c90ceeSChristian BruefferLocally detected errors are
11416c90ceeSChristian Bruefferindicated by a return value of -1 with
11516c90ceeSChristian Brueffer.Va errno
11616c90ceeSChristian Bruefferset accordingly.
117d8b5fd91SRandall StewartThe
118d8b5fd91SRandall Stewart.Fa flags
11916c90ceeSChristian Bruefferargument may also hold the value
12016c90ceeSChristian Brueffer.Dv MSG_NOTIFICATION .
12116c90ceeSChristian BruefferWhen this
12244d9c281SChristian Bruefferoccurs it indicates that the message received is
12344d9c281SChristian Brueffer.Em not
12444d9c281SChristian Bruefferfrom
125d8b5fd91SRandall Stewartthe peer endpoint, but instead is a notification from the
126d8b5fd91SRandall StewartSCTP stack (see
12716c90ceeSChristian Brueffer.Xr sctp 4
12816c90ceeSChristian Bruefferfor more details).
12916c90ceeSChristian BruefferNote that no notifications are ever
130d8b5fd91SRandall Stewartgiven unless the user subscribes to such notifications using
13116c90ceeSChristian Bruefferthe
13216c90ceeSChristian Brueffer.Dv SCTP_EVENTS
13316c90ceeSChristian Brueffersocket option.
134d8b5fd91SRandall Stewart.Pp
13516c90ceeSChristian BruefferIf no messages are available at the socket then
136d8b5fd91SRandall Stewart.Fn sctp_recvmsg
13716c90ceeSChristian Brueffernormally blocks on the reception of a message or NOTIFICATION, unless the
13816c90ceeSChristian Brueffersocket has been placed in non-blocking I/O mode.
139d8b5fd91SRandall StewartThe
140d8b5fd91SRandall Stewart.Xr select 2
141d8b5fd91SRandall Stewartsystem call may be used to determine when it is possible to
142d8b5fd91SRandall Stewartreceive a message.
143d8b5fd91SRandall Stewart.Pp
144d8b5fd91SRandall StewartThe
145d8b5fd91SRandall Stewart.Fa sinfo
146d8b5fd91SRandall Stewartargument is defined as follows.
147d8b5fd91SRandall Stewart.Bd -literal
148d8b5fd91SRandall Stewartstruct sctp_sndrcvinfo {
149*3d36ac98SRebecca Cran	uint16_t sinfo_stream;  /* Stream arriving on */
150*3d36ac98SRebecca Cran	uint16_t sinfo_ssn;     /* Stream Sequence Number */
151*3d36ac98SRebecca Cran	uint16_t sinfo_flags;   /* Flags on the incoming message */
152*3d36ac98SRebecca Cran	uint32_t sinfo_ppid;    /* The ppid field */
153*3d36ac98SRebecca Cran	uint32_t sinfo_context; /* context field */
154*3d36ac98SRebecca Cran	uint32_t sinfo_timetolive; /* not used by sctp_recvmsg */
155*3d36ac98SRebecca Cran	uint32_t sinfo_tsn;        /* The transport sequence number */
156*3d36ac98SRebecca Cran	uint32_t sinfo_cumtsn;     /* The cumulative acknowledgment point  */
157d8b5fd91SRandall Stewart	sctp_assoc_t sinfo_assoc_id; /* The association id of the peer */
158d8b5fd91SRandall Stewart};
159d8b5fd91SRandall Stewart.Ed
16016c90ceeSChristian Brueffer.Pp
161d8b5fd91SRandall StewartThe
162d8b5fd91SRandall Stewart.Fa sinfo->sinfo_ppid
163a47698f8SChristian Bruefferfield is an opaque 32 bit value that is passed transparently
164d8b5fd91SRandall Stewartthrough the stack from the peer endpoint.
165d8b5fd91SRandall StewartNote that the stack passes this value without regard to byte
166d8b5fd91SRandall Stewartorder.
167d8b5fd91SRandall Stewart.Pp
168d8b5fd91SRandall StewartThe
169d8b5fd91SRandall Stewart.Fa sinfo->sinfo_flags
170d8b5fd91SRandall Stewartfield may include the following:
171d8b5fd91SRandall Stewart.Bd -literal
172d8b5fd91SRandall Stewart#define SCTP_UNORDERED 	  0x0400	/* Message is un-ordered */
173d8b5fd91SRandall Stewart.Ed
174d8b5fd91SRandall Stewart.Pp
175d8b5fd91SRandall StewartThe
176d8b5fd91SRandall Stewart.Dv SCTP_UNORDERED
177d8b5fd91SRandall Stewartflag is used to specify that the message arrived with no
178d8b5fd91SRandall Stewartspecific order and was delivered to the peer application
17916c90ceeSChristian Bruefferas soon as possible.
18016c90ceeSChristian BruefferWhen this flag is absent the message
181d8b5fd91SRandall Stewartwas delivered in order within the stream it was received.
182d8b5fd91SRandall Stewart.Pp
183a47698f8SChristian BruefferThe
184d8b5fd91SRandall Stewart.Fa sinfo->sinfo_stream
185a47698f8SChristian Bruefferfield is the SCTP stream that the message was received on.
186d8b5fd91SRandall StewartStreams in SCTP are reliable (or partially reliable) flows of ordered
187d8b5fd91SRandall Stewartmessages.
188d8b5fd91SRandall Stewart.Pp
189d8b5fd91SRandall StewartThe
190d8b5fd91SRandall Stewart.Fa sinfo->sinfo_context
19116c90ceeSChristian Bruefferfield is used only if the local application set an association level
19216c90ceeSChristian Brueffercontext with the
19316c90ceeSChristian Brueffer.Dv SCTP_CONTEXT
19416c90ceeSChristian Brueffersocket option.
195d8b5fd91SRandall StewartOptionally a user process can use this value to index some application
196d8b5fd91SRandall Stewartspecific data structure for all data coming from a specific
197d8b5fd91SRandall Stewartassociation.
198d8b5fd91SRandall Stewart.Pp
199d8b5fd91SRandall StewartThe
200d8b5fd91SRandall Stewart.Fa sinfo->sinfo_ssn
201a47698f8SChristian Bruefferfield will hold the stream sequence number assigned
20244d9c281SChristian Bruefferby the peer endpoint if the message is
20344d9c281SChristian Brueffer.Em not
20444d9c281SChristian Bruefferunordered.
205d8b5fd91SRandall StewartFor unordered messages this field holds an undefined value.
206d8b5fd91SRandall Stewart.Pp
207d8b5fd91SRandall StewartThe
208d8b5fd91SRandall Stewart.Fa sinfo->sinfo_tsn
209a47698f8SChristian Bruefferfield holds a transport sequence number (TSN) that was assigned
21016c90ceeSChristian Bruefferto this message by the peer endpoint.
21116c90ceeSChristian BruefferFor messages that fit in or less
212d8b5fd91SRandall Stewartthan the path MTU this will be the only TSN assigned.
21344d9c281SChristian BruefferNote that for messages that span multiple TSNs this
21444d9c281SChristian Brueffervalue will be one of the TSNs that was used on the
215d8b5fd91SRandall Stewartmessage.
216d8b5fd91SRandall Stewart.Pp
217d8b5fd91SRandall StewartThe
218d8b5fd91SRandall Stewart.Fa sinfo->sinfo_cumtsn
219a47698f8SChristian Bruefferfield holds the current cumulative acknowledgment point of
22016c90ceeSChristian Bruefferthe transport association.
22116c90ceeSChristian BruefferNote that this may be larger
222d8b5fd91SRandall Stewartor smaller than the TSN assigned to the message itself.
223d8b5fd91SRandall Stewart.Pp
224d8b5fd91SRandall StewartThe
22516c90ceeSChristian Brueffer.Fa sinfo->sinfo_assoc_id
226d8b5fd91SRandall Stewartis the unique association identification that was assigned
22716c90ceeSChristian Bruefferto the association.
22816c90ceeSChristian BruefferFor one-to-many (SOCK_SEQPACKET) type
229d8b5fd91SRandall Stewartsockets this value can be used to send data to the peer without
23016c90ceeSChristian Bruefferthe use of an address field.
23116c90ceeSChristian BruefferIt is also quite useful in
232d8b5fd91SRandall Stewartsetting various socket options on the specific association
233d8b5fd91SRandall Stewart(see
23444d9c281SChristian Brueffer.Xr sctp 4 ) .
235d8b5fd91SRandall Stewart.Pp
236d8b5fd91SRandall StewartThe
23716c90ceeSChristian Brueffer.Fa sinfo->info_timetolive
238d8b5fd91SRandall Stewartfield is not used by
239a47698f8SChristian Brueffer.Fn sctp_recvmsg .
240d8b5fd91SRandall Stewart.Sh RETURN VALUES
241cefac273SRebecca CranThe call returns the number of bytes received, or -1
242d8b5fd91SRandall Stewartif an error occurred.
243d8b5fd91SRandall Stewart.Sh ERRORS
244d8b5fd91SRandall StewartThe
245d8b5fd91SRandall Stewart.Fn sctp_recvmsg
246d8b5fd91SRandall Stewartsystem call
24716c90ceeSChristian Bruefferfails if:
248d8b5fd91SRandall Stewart.Bl -tag -width Er
249d8b5fd91SRandall Stewart.It Bq Er EBADF
250d8b5fd91SRandall StewartAn invalid descriptor was specified.
251d8b5fd91SRandall Stewart.It Bq Er ENOTSOCK
252d8b5fd91SRandall StewartThe argument
253d8b5fd91SRandall Stewart.Fa s
254d8b5fd91SRandall Stewartis not a socket.
255d8b5fd91SRandall Stewart.It Bq Er EFAULT
256d8b5fd91SRandall StewartAn invalid user space address was specified for an argument.
257d8b5fd91SRandall Stewart.It Bq Er EMSGSIZE
258d8b5fd91SRandall StewartThe socket requires that message be sent atomically,
259d8b5fd91SRandall Stewartand the size of the message to be sent made this impossible.
260d8b5fd91SRandall Stewart.It Bq Er EAGAIN
261d8b5fd91SRandall StewartThe socket is marked non-blocking and the requested operation
262d8b5fd91SRandall Stewartwould block.
263d8b5fd91SRandall Stewart.It Bq Er ENOBUFS
264d8b5fd91SRandall StewartThe system was unable to allocate an internal buffer.
265d8b5fd91SRandall StewartThe operation may succeed when buffers become available.
266d8b5fd91SRandall Stewart.It Bq Er ENOBUFS
267d8b5fd91SRandall StewartThe output queue for a network interface was full.
268d8b5fd91SRandall StewartThis generally indicates that the interface has stopped sending,
269d8b5fd91SRandall Stewartbut may be caused by transient congestion.
270d8b5fd91SRandall Stewart.It Bq Er EHOSTUNREACH
271d8b5fd91SRandall StewartThe remote host was unreachable.
2720add3200SRebecca Cran.It Bq Er ENOTCONN
27316c90ceeSChristian BruefferOn a one-to-one style socket no association exists.
274d8b5fd91SRandall Stewart.It Bq Er ECONNRESET
275d8b5fd91SRandall StewartAn abort was received by the stack while the user was
276d8b5fd91SRandall Stewartattempting to send data to the peer.
277d8b5fd91SRandall Stewart.It Bq Er ENOENT
278d8b5fd91SRandall StewartOn a one to many style socket no address is specified
279d8b5fd91SRandall Stewartso that the association cannot be located or the
280d8b5fd91SRandall StewartSCTP_ABORT flag was specified on a non-existing association.
281d8b5fd91SRandall Stewart.It Bq Er EPIPE
282d8b5fd91SRandall StewartThe socket is unable to send anymore data
283d8b5fd91SRandall Stewart.Dv ( SBS_CANTSENDMORE
284d8b5fd91SRandall Stewarthas been set on the socket).
285d8b5fd91SRandall StewartThis typically means that the socket
286d8b5fd91SRandall Stewartis not connected and is a one-to-one style socket.
287d8b5fd91SRandall Stewart.El
288d8b5fd91SRandall Stewart.Sh SEE ALSO
289d8b5fd91SRandall Stewart.Xr recv 2 ,
290d8b5fd91SRandall Stewart.Xr select 2 ,
291d8b5fd91SRandall Stewart.Xr socket 2 ,
29216c90ceeSChristian Brueffer.Xr write 2 ,
29316c90ceeSChristian Brueffer.Xr getsockopt 2 ,
29416c90ceeSChristian Brueffer.Xr setsockopt 2 ,
29516c90ceeSChristian Brueffer.Xr sctp_send 3 ,
29616c90ceeSChristian Brueffer.Xr sctp_sendmsg 3 ,
29716c90ceeSChristian Brueffer.Xr sendmsg 3 ,
29816c90ceeSChristian Brueffer.Xr sctp 4
299