xref: /freebsd/lib/libc/net/sctp_recvmsg.3 (revision 16c90ceeb35fa6183bb1348c38c30d5f13a5be17)
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.\"
34d8b5fd91SRandall Stewart.Dd December 15, 2006
35d8b5fd91SRandall Stewart.Dt SCTP_RECVMSG 3
36d8b5fd91SRandall Stewart.Os
37d8b5fd91SRandall Stewart.Sh NAME
38d8b5fd91SRandall Stewart.Nm sctp_recvmsg
39d8b5fd91SRandall Stewart.Nd send 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
63d8b5fd91SRandall Stewartfollowed by a sucessful
6416c90ceeSChristian 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
76d8b5fd91SRandall Stewartwith a postive 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
10216c90ceeSChristian Bruefferargument will NOT have the
10316c90ceeSChristian Brueffer.Dv MSG_EOF
10416c90ceeSChristian Bruefferflag applied.
10516c90ceeSChristian BruefferIf the message is a complete message then
106d8b5fd91SRandall Stewartthe
107d8b5fd91SRandall Stewart.Fa flags
10816c90ceeSChristian Bruefferargument will have
10916c90ceeSChristian Brueffer.Dv MSG_EOF
11016c90ceeSChristian Bruefferset.
11116c90ceeSChristian BruefferLocally detected errors are
11216c90ceeSChristian Bruefferindicated by a return value of -1 with
11316c90ceeSChristian Brueffer.Va errno
11416c90ceeSChristian Bruefferset accordingly.
115d8b5fd91SRandall StewartThe
116d8b5fd91SRandall Stewart.Fa flags
11716c90ceeSChristian Bruefferargument may also hold the value
11816c90ceeSChristian Brueffer.Dv MSG_NOTIFICATION .
11916c90ceeSChristian BruefferWhen this
120d8b5fd91SRandall Stewartoccurs this indicates that the message received is NOT from
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 {
145d8b5fd91SRandall Stewart	u_int16_t sinfo_stream;  /* Stream arriving on */
146d8b5fd91SRandall Stewart	u_int16_t sinfo_ssn;     /* Stream Sequence Number */
147d8b5fd91SRandall Stewart	u_int16_t sinfo_flags;   /* Flags on the incoming message */
148d8b5fd91SRandall Stewart	u_int32_t sinfo_ppid;    /* The ppid field */
149d8b5fd91SRandall Stewart	u_int32_t sinfo_context; /* context field */
150d8b5fd91SRandall Stewart	u_int32_t sinfo_timetolive; /* not used by sctp_recvmsg */
151d8b5fd91SRandall Stewart	u_int32_t sinfo_tsn;        /* The transport sequence number */
152d8b5fd91SRandall Stewart	u_int32_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
159d8b5fd91SRandall Stewartis 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
179d8b5fd91SRandall Stewart.Fa sinfo->sinfo_stream
180d8b5fd91SRandall Stewartis the SCTP stream that the message was received on.
181d8b5fd91SRandall StewartStreams in SCTP are reliable (or partially reliable) flows of ordered
182d8b5fd91SRandall Stewartmessages.
183d8b5fd91SRandall Stewart.Pp
184d8b5fd91SRandall StewartThe
185d8b5fd91SRandall Stewart.Fa sinfo->sinfo_context
18616c90ceeSChristian Bruefferfield is used only if the local application set an association level
18716c90ceeSChristian Brueffercontext with the
18816c90ceeSChristian Brueffer.Dv SCTP_CONTEXT
18916c90ceeSChristian Brueffersocket option.
190d8b5fd91SRandall StewartOptionally a user process can use this value to index some application
191d8b5fd91SRandall Stewartspecific data structure for all data coming from a specific
192d8b5fd91SRandall Stewartassociation.
193d8b5fd91SRandall Stewart.Pp
194d8b5fd91SRandall StewartThe
195d8b5fd91SRandall Stewart.Fa sinfo->sinfo_ssn
196d8b5fd91SRandall Stewartwill hold the stream sequence number assigned
197d8b5fd91SRandall Stewartby the peer endpoint if the message is NOT unordered.
198d8b5fd91SRandall StewartFor unordered messages this field holds an undefined value.
199d8b5fd91SRandall Stewart.Pp
200d8b5fd91SRandall StewartThe
201d8b5fd91SRandall Stewart.Fa sinfo->sinfo_tsn
202d8b5fd91SRandall Stewartholds a transport sequence number (TSN) that was assigned
20316c90ceeSChristian Bruefferto this message by the peer endpoint.
20416c90ceeSChristian BruefferFor messages that fit in or less
205d8b5fd91SRandall Stewartthan the path MTU this will be the only TSN assigned.
206d8b5fd91SRandall StewartNote that for messages that span multiple TSN's this
207d8b5fd91SRandall Stewartvalue will be one of the TSN's that was used on the
208d8b5fd91SRandall Stewartmessage.
209d8b5fd91SRandall Stewart.Pp
210d8b5fd91SRandall StewartThe
211d8b5fd91SRandall Stewart.Fa sinfo->sinfo_cumtsn
212d8b5fd91SRandall Stewartholds the current cumulative acknowledgment point of
21316c90ceeSChristian Bruefferthe transport association.
21416c90ceeSChristian BruefferNote that this may be larger
215d8b5fd91SRandall Stewartor smaller than the TSN assigned to the message itself.
216d8b5fd91SRandall Stewart.Pp
217d8b5fd91SRandall StewartThe
21816c90ceeSChristian Brueffer.Fa sinfo->sinfo_assoc_id
219d8b5fd91SRandall Stewartis the unique association identification that was assigned
22016c90ceeSChristian Bruefferto the association.
22116c90ceeSChristian BruefferFor one-to-many (SOCK_SEQPACKET) type
222d8b5fd91SRandall Stewartsockets this value can be used to send data to the peer without
22316c90ceeSChristian Bruefferthe use of an address field.
22416c90ceeSChristian BruefferIt is also quite useful in
225d8b5fd91SRandall Stewartsetting various socket options on the specific association
226d8b5fd91SRandall Stewart(see
22716c90ceeSChristian Brueffer.Xr sctp 4
228d8b5fd91SRandall Stewart).
229d8b5fd91SRandall Stewart.Pp
230d8b5fd91SRandall StewartThe
23116c90ceeSChristian Brueffer.Fa sinfo->info_timetolive
232d8b5fd91SRandall Stewartfield is not used by
233d8b5fd91SRandall Stewart.Fa sctp_recvmsg .
234d8b5fd91SRandall Stewart.Sh RETURN VALUES
235d8b5fd91SRandall StewartThe call returns the number of characters sent, or -1
236d8b5fd91SRandall Stewartif an error occurred.
237d8b5fd91SRandall Stewart.Sh ERRORS
238d8b5fd91SRandall StewartThe
239d8b5fd91SRandall Stewart.Fn sctp_recvmsg
240d8b5fd91SRandall Stewartsystem call
24116c90ceeSChristian Bruefferfails if:
242d8b5fd91SRandall Stewart.Bl -tag -width Er
243d8b5fd91SRandall Stewart.It Bq Er EBADF
244d8b5fd91SRandall StewartAn invalid descriptor was specified.
245d8b5fd91SRandall Stewart.It Bq Er ENOTSOCK
246d8b5fd91SRandall StewartThe argument
247d8b5fd91SRandall Stewart.Fa s
248d8b5fd91SRandall Stewartis not a socket.
249d8b5fd91SRandall Stewart.It Bq Er EFAULT
250d8b5fd91SRandall StewartAn invalid user space address was specified for an argument.
251d8b5fd91SRandall Stewart.It Bq Er EMSGSIZE
252d8b5fd91SRandall StewartThe socket requires that message be sent atomically,
253d8b5fd91SRandall Stewartand the size of the message to be sent made this impossible.
254d8b5fd91SRandall Stewart.It Bq Er EAGAIN
255d8b5fd91SRandall StewartThe socket is marked non-blocking and the requested operation
256d8b5fd91SRandall Stewartwould block.
257d8b5fd91SRandall Stewart.It Bq Er ENOBUFS
258d8b5fd91SRandall StewartThe system was unable to allocate an internal buffer.
259d8b5fd91SRandall StewartThe operation may succeed when buffers become available.
260d8b5fd91SRandall Stewart.It Bq Er ENOBUFS
261d8b5fd91SRandall StewartThe output queue for a network interface was full.
262d8b5fd91SRandall StewartThis generally indicates that the interface has stopped sending,
263d8b5fd91SRandall Stewartbut may be caused by transient congestion.
264d8b5fd91SRandall Stewart.It Bq Er EHOSTUNREACH
265d8b5fd91SRandall StewartThe remote host was unreachable.
266d8b5fd91SRandall Stewart.It Bq Er ENOTCON
26716c90ceeSChristian BruefferOn a one-to-one style socket no association exists.
268d8b5fd91SRandall Stewart.It Bq Er ECONNRESET
269d8b5fd91SRandall StewartAn abort was received by the stack while the user was
270d8b5fd91SRandall Stewartattempting to send data to the peer.
271d8b5fd91SRandall Stewart.It Bq Er ENOENT
272d8b5fd91SRandall StewartOn a one to many style socket no address is specified
273d8b5fd91SRandall Stewartso that the association cannot be located or the
274d8b5fd91SRandall StewartSCTP_ABORT flag was specified on a non-existing association.
275d8b5fd91SRandall Stewart.It Bq Er EPIPE
276d8b5fd91SRandall StewartThe socket is unable to send anymore data
277d8b5fd91SRandall Stewart.Dv ( SBS_CANTSENDMORE
278d8b5fd91SRandall Stewarthas been set on the socket).
279d8b5fd91SRandall StewartThis typically means that the socket
280d8b5fd91SRandall Stewartis not connected and is a one-to-one style socket.
281d8b5fd91SRandall Stewart.El
282d8b5fd91SRandall Stewart.Sh SEE ALSO
283d8b5fd91SRandall Stewart.Xr recv 2 ,
284d8b5fd91SRandall Stewart.Xr select 2 ,
285d8b5fd91SRandall Stewart.Xr socket 2 ,
28616c90ceeSChristian Brueffer.Xr write 2 ,
28716c90ceeSChristian Brueffer.Xr getsockopt 2 ,
28816c90ceeSChristian Brueffer.Xr setsockopt 2 ,
28916c90ceeSChristian Brueffer.Xr sctp_send 3 ,
29016c90ceeSChristian Brueffer.Xr sctp_sendmsg 3 ,
29116c90ceeSChristian Brueffer.Xr sendmsg 3 ,
29216c90ceeSChristian Brueffer.Xr sctp 4
293