]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - lib/libc/net/sctp_recvmsg.3
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / lib / libc / net / sctp_recvmsg.3
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. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\" $FreeBSD$
29 .\"
30 .Dd August 13, 2007
31 .Dt SCTP_RECVMSG 3
32 .Os
33 .Sh NAME
34 .Nm sctp_recvmsg
35 .Nd receive a message from an SCTP socket
36 .Sh LIBRARY
37 .Lb libc
38 .Sh SYNOPSIS
39 .In sys/types.h
40 .In sys/socket.h
41 .In netinet/sctp.h
42 .Ft ssize_t
43 .Fo sctp_recvmsg
44 .Fa "int s" "void *msg" "size_t len" "struct sockaddr * restrict from"
45 .Fa "socklen_t * restrict fromlen" "struct sctp_sndrcvinfo *sinfo" "int *flags"
46 .Fc
47 .Sh DESCRIPTION
48 The
49 .Fn sctp_recvmsg
50 system call
51 is used to receive a message from another SCTP endpoint.
52 The
53 .Fn sctp_recvmsg
54 call is used by one-to-one (SOCK_STREAM) type sockets after a
55 successful
56 .Fn connect
57 call or after the application has performed a
58 .Fn listen
59 followed by a successful
60 .Fn accept .
61 For a one-to-many (SOCK_SEQPACKET) type socket, an endpoint may call
62 .Fn sctp_recvmsg
63 after having implicitly started an association via one
64 of the send calls including
65 .Fn sctp_sendmsg ,
66 .Fn sendto
67 and
68 .Fn sendmsg .
69 Or, an application may also receive a message after having
70 called
71 .Fn listen
72 with a positive backlog to enable the reception of new associations.
73 .Pp
74 The address of the sender is held in the
75 .Fa from
76 argument with
77 .Fa fromlen
78 specifying its size.
79 At the completion of a successful
80 .Fn sctp_recvmsg
81 call
82 .Fa from
83 will hold the address of the peer and
84 .Fa fromlen
85 will hold the length of that address.
86 Note that
87 the address is bounded by the initial value of
88 .Fa fromlen
89 which is used as an in/out variable.
90 .Pp
91 The length of the message
92 .Fa msg
93 to be received is bounded by
94 .Fa len .
95 If the message is too long to fit in the users
96 receive buffer, then the
97 .Fa flags
98 argument will
99 .Em not
100 have the
101 .Dv MSG_EOF
102 flag applied.
103 If the message is a complete message then
104 the
105 .Fa flags
106 argument will have
107 .Dv MSG_EOF
108 set.
109 Locally detected errors are
110 indicated by a return value of -1 with
111 .Va errno
112 set accordingly.
113 The
114 .Fa flags
115 argument may also hold the value
116 .Dv MSG_NOTIFICATION .
117 When this
118 occurs it indicates that the message received is
119 .Em not
120 from
121 the peer endpoint, but instead is a notification from the
122 SCTP stack (see
123 .Xr sctp 4
124 for more details).
125 Note that no notifications are ever
126 given unless the user subscribes to such notifications using
127 the
128 .Dv SCTP_EVENTS
129 socket option.
130 .Pp
131 If no messages are available at the socket then
132 .Fn sctp_recvmsg
133 normally blocks on the reception of a message or NOTIFICATION, unless the
134 socket has been placed in non-blocking I/O mode.
135 The
136 .Xr select 2
137 system call may be used to determine when it is possible to
138 receive a message.
139 .Pp
140 The
141 .Fa sinfo
142 argument is defined as follows.
143 .Bd -literal
144 struct sctp_sndrcvinfo {
145         uint16_t sinfo_stream;  /* Stream arriving on */
146         uint16_t sinfo_ssn;     /* Stream Sequence Number */
147         uint16_t sinfo_flags;   /* Flags on the incoming message */
148         uint32_t sinfo_ppid;    /* The ppid field */
149         uint32_t sinfo_context; /* context field */
150         uint32_t sinfo_timetolive; /* not used by sctp_recvmsg */
151         uint32_t sinfo_tsn;        /* The transport sequence number */
152         uint32_t sinfo_cumtsn;     /* The cumulative acknowledgment point  */
153         sctp_assoc_t sinfo_assoc_id; /* The association id of the peer */
154 };
155 .Ed
156 .Pp
157 The
158 .Fa sinfo->sinfo_ppid
159 field is an opaque 32 bit value that is passed transparently
160 through the stack from the peer endpoint.
161 Note that the stack passes this value without regard to byte
162 order.
163 .Pp
164 The
165 .Fa sinfo->sinfo_flags
166 field may include the following:
167 .Bd -literal
168 #define SCTP_UNORDERED    0x0400        /* Message is un-ordered */
169 .Ed
170 .Pp
171 The
172 .Dv SCTP_UNORDERED
173 flag is used to specify that the message arrived with no
174 specific order and was delivered to the peer application
175 as soon as possible.
176 When this flag is absent the message
177 was delivered in order within the stream it was received.
178 .Pp
179 The
180 .Fa sinfo->sinfo_stream
181 field is the SCTP stream that the message was received on.
182 Streams in SCTP are reliable (or partially reliable) flows of ordered
183 messages.
184 .Pp
185 The
186 .Fa sinfo->sinfo_context
187 field is used only if the local application set an association level
188 context with the
189 .Dv SCTP_CONTEXT
190 socket option.
191 Optionally a user process can use this value to index some application
192 specific data structure for all data coming from a specific
193 association.
194 .Pp
195 The
196 .Fa sinfo->sinfo_ssn
197 field will hold the stream sequence number assigned
198 by the peer endpoint if the message is
199 .Em not
200 unordered.
201 For unordered messages this field holds an undefined value.
202 .Pp
203 The
204 .Fa sinfo->sinfo_tsn
205 field holds a transport sequence number (TSN) that was assigned
206 to this message by the peer endpoint.
207 For messages that fit in or less
208 than the path MTU this will be the only TSN assigned.
209 Note that for messages that span multiple TSNs this
210 value will be one of the TSNs that was used on the
211 message.
212 .Pp
213 The
214 .Fa sinfo->sinfo_cumtsn
215 field holds the current cumulative acknowledgment point of
216 the transport association.
217 Note that this may be larger
218 or smaller than the TSN assigned to the message itself.
219 .Pp
220 The
221 .Fa sinfo->sinfo_assoc_id
222 is the unique association identification that was assigned
223 to the association.
224 For one-to-many (SOCK_SEQPACKET) type
225 sockets this value can be used to send data to the peer without
226 the use of an address field.
227 It is also quite useful in
228 setting various socket options on the specific association
229 (see
230 .Xr sctp 4 ) .
231 .Pp
232 The
233 .Fa sinfo->info_timetolive
234 field is not used by
235 .Fn sctp_recvmsg .
236 .Sh RETURN VALUES
237 The call returns the number of bytes received, or -1
238 if an error occurred.
239 .Sh ERRORS
240 The
241 .Fn sctp_recvmsg
242 system call
243 fails if:
244 .Bl -tag -width Er
245 .It Bq Er EBADF
246 An invalid descriptor was specified.
247 .It Bq Er ENOTSOCK
248 The argument
249 .Fa s
250 is not a socket.
251 .It Bq Er EFAULT
252 An invalid user space address was specified for an argument.
253 .It Bq Er EMSGSIZE
254 The socket requires that message be sent atomically,
255 and the size of the message to be sent made this impossible.
256 .It Bq Er EAGAIN
257 The socket is marked non-blocking and the requested operation
258 would block.
259 .It Bq Er ENOBUFS
260 The system was unable to allocate an internal buffer.
261 The operation may succeed when buffers become available.
262 .It Bq Er ENOBUFS
263 The output queue for a network interface was full.
264 This generally indicates that the interface has stopped sending,
265 but may be caused by transient congestion.
266 .It Bq Er EHOSTUNREACH
267 The remote host was unreachable.
268 .It Bq Er ENOTCONN
269 On a one-to-one style socket no association exists.
270 .It Bq Er ECONNRESET
271 An abort was received by the stack while the user was
272 attempting to send data to the peer.
273 .It Bq Er ENOENT
274 On a one to many style socket no address is specified
275 so that the association cannot be located or the
276 SCTP_ABORT flag was specified on a non-existing association.
277 .It Bq Er EPIPE
278 The socket is unable to send anymore data
279 .Dv ( SBS_CANTSENDMORE
280 has been set on the socket).
281 This typically means that the socket
282 is not connected and is a one-to-one style socket.
283 .El
284 .Sh SEE ALSO
285 .Xr recv 2 ,
286 .Xr select 2 ,
287 .Xr socket 2 ,
288 .Xr write 2 ,
289 .Xr getsockopt 2 ,
290 .Xr setsockopt 2 ,
291 .Xr sctp_send 3 ,
292 .Xr sctp_sendmsg 3 ,
293 .Xr sendmsg 3 ,
294 .Xr sctp 4