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