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 45d8b5fd91SRandall Stewart.In sys/sctp.h 46d8b5fd91SRandall Stewart.Ft ssize_t 47d8b5fd91SRandall Stewart.Ft ssize_t 48d8b5fd91SRandall Stewart.Fn sctp_recvmsg "int s" "void *msg" "size_t len" "struct sockaddr * restrict from" "socklen_t * restrict fromlen" "struct sctp_sndrcvinfo *sinfo" "int *flags" 49d8b5fd91SRandall Stewart.Sh DESCRIPTION 50d8b5fd91SRandall StewartThe 51d8b5fd91SRandall Stewart.Fn sctp_recvmsg 52d8b5fd91SRandall Stewartsystem calls 53d8b5fd91SRandall Stewartis used to receive a message from another SCTP endpoint. 54d8b5fd91SRandall StewartThe 55d8b5fd91SRandall Stewart.Fn sctp_recvmsg 56d8b5fd91SRandall Stewartcall is used by one-to-one (SOCK_STREAM) type sockets after a 57d8b5fd91SRandall Stewartsucessful 58d8b5fd91SRandall Stewart.Fn connect 2 59d8b5fd91SRandall Stewartcall or after the application has performed a 60d8b5fd91SRandall Stewart.Fn listen 61d8b5fd91SRandall Stewartfollowed by a sucessful 62d8b5fd91SRandall Stewart.Fn accept 2 63d8b5fd91SRandall StewartFor a one-to-many (SOCK_SEQPACKET)type socket, an endpoint may call 64d8b5fd91SRandall Stewart.Fn sctp_recvmsg 65d8b5fd91SRandall Stewartafter having implicitly started an association via one 66d8b5fd91SRandall Stewartof the send calls including 67d8b5fd91SRandall Stewart.Fn sctp_sendmsg 2 68d8b5fd91SRandall Stewart.Fn sendto 2 69d8b5fd91SRandall Stewartand 70d8b5fd91SRandall Stewart.Fn sendmsg 2 71d8b5fd91SRandall StewartOr, an application may also receive a message after having 72d8b5fd91SRandall Stewartcalled 73d8b5fd91SRandall Stewart.Fn listen 2 74d8b5fd91SRandall Stewartwith a postive backlog to enable the reception of new associations. 75d8b5fd91SRandall Stewart.Pp 76d8b5fd91SRandall Stewart.Pp 77d8b5fd91SRandall StewartThe address of the sender is held in the 78d8b5fd91SRandall Stewart.Fa from 79d8b5fd91SRandall Stewartargument with 80d8b5fd91SRandall Stewart.Fa fromlen 81d8b5fd91SRandall Stewartspecifying its size. At the completion of a sucessful 82d8b5fd91SRandall Stewart.Fn sctp_recvmsg 83d8b5fd91SRandall Stewartcall 84d8b5fd91SRandall Stewart.Fa from 85d8b5fd91SRandall Stewartwill hold the address of the peer and 86d8b5fd91SRandall Stewart.Fa fromlen 87d8b5fd91SRandall Stewartwill hold the length of that address. Note that 88d8b5fd91SRandall Stewartthe address is bounded by the inital value of 89d8b5fd91SRandall Stewart.Fa fromlen 90d8b5fd91SRandall Stewartwhich is used as an in/out variable. 91d8b5fd91SRandall Stewart.Pp 92d8b5fd91SRandall StewartThe length of the message 93d8b5fd91SRandall Stewart.Fa msg 94d8b5fd91SRandall Stewartto be received is bounded by 95d8b5fd91SRandall Stewart.Fa len . 96d8b5fd91SRandall StewartIf the message is to long to fit in the users 97d8b5fd91SRandall Stewartreceive buffer, then the 98d8b5fd91SRandall Stewart.Fa flags 99d8b5fd91SRandall Stewartargument will NOT have the MSG_EOF flag 100d8b5fd91SRandall Stewartapplied. If the message is a complete message then 101d8b5fd91SRandall Stewartthe 102d8b5fd91SRandall Stewart.Fa flags 103d8b5fd91SRandall Stewartargument will have MSG_EOF set. Locally detected errors are 104d8b5fd91SRandall Stewartindicated by a return value of -1 with errno set accordingly. 105d8b5fd91SRandall StewartThe 106d8b5fd91SRandall Stewart.Fa flags 107d8b5fd91SRandall Stewartargument may also hold the value MSG_NOTIFICATION. When this 108d8b5fd91SRandall Stewartoccurs this indicates that the message received is NOT from 109d8b5fd91SRandall Stewartthe peer endpoint, but instead is a notification from the 110d8b5fd91SRandall StewartSCTP stack (see 111d8b5fd91SRandall Stewart.Fn sctp 4 112d8b5fd91SRandall Stewartfor more details). Note that no notifications are ever 113d8b5fd91SRandall Stewartgiven unless the user subscribes to such notifications using 114d8b5fd91SRandall Stewartthe SCTP_EVENTS socket option. 115d8b5fd91SRandall Stewart.Pp 116d8b5fd91SRandall StewartIf no messages is available at the socket then 117d8b5fd91SRandall Stewart.Fn sctp_recvmsg 118d8b5fd91SRandall Stewartnormally blocks on the reception of a message or NOTIFICATION, unless the socket has been placed in 119d8b5fd91SRandall Stewartnon-blocking I/O mode. 120d8b5fd91SRandall StewartThe 121d8b5fd91SRandall Stewart.Xr select 2 122d8b5fd91SRandall Stewartsystem call may be used to determine when it is possible to 123d8b5fd91SRandall Stewartreceive a message. 124d8b5fd91SRandall Stewart.Pp 125d8b5fd91SRandall Stewart 126d8b5fd91SRandall StewartThe 127d8b5fd91SRandall Stewart.Fa sinfo 128d8b5fd91SRandall Stewartargument is defined as follows. 129d8b5fd91SRandall Stewart.Bd -literal 130d8b5fd91SRandall Stewartstruct sctp_sndrcvinfo { 131d8b5fd91SRandall Stewart u_int16_t sinfo_stream; /* Stream arriving on */ 132d8b5fd91SRandall Stewart u_int16_t sinfo_ssn; /* Stream Sequence Number */ 133d8b5fd91SRandall Stewart u_int16_t sinfo_flags; /* Flags on the incoming message */ 134d8b5fd91SRandall Stewart u_int32_t sinfo_ppid; /* The ppid field */ 135d8b5fd91SRandall Stewart u_int32_t sinfo_context; /* context field */ 136d8b5fd91SRandall Stewart u_int32_t sinfo_timetolive; /* not used by sctp_recvmsg */ 137d8b5fd91SRandall Stewart u_int32_t sinfo_tsn; /* The transport sequence number */ 138d8b5fd91SRandall Stewart u_int32_t sinfo_cumtsn; /* The cumulative acknowledgment point */ 139d8b5fd91SRandall Stewart sctp_assoc_t sinfo_assoc_id; /* The association id of the peer */ 140d8b5fd91SRandall Stewart}; 141d8b5fd91SRandall Stewart.Ed 142d8b5fd91SRandall Stewart 143d8b5fd91SRandall StewartThe 144d8b5fd91SRandall Stewart.Fa sinfo->sinfo_ppid 145d8b5fd91SRandall Stewartis an opaque 32 bit value that is passed transparently 146d8b5fd91SRandall Stewartthrough the stack from the peer endpoint. 147d8b5fd91SRandall StewartNote that the stack passes this value without regard to byte 148d8b5fd91SRandall Stewartorder. 149d8b5fd91SRandall Stewart.Pp 150d8b5fd91SRandall StewartThe 151d8b5fd91SRandall Stewart.Fa sinfo->sinfo_flags 152d8b5fd91SRandall Stewartfield may include the following: 153d8b5fd91SRandall Stewart.Bd -literal 154d8b5fd91SRandall Stewart#define SCTP_UNORDERED 0x0400 /* Message is un-ordered */ 155d8b5fd91SRandall Stewart.Ed 156d8b5fd91SRandall Stewart.Pp 157d8b5fd91SRandall StewartThe 158d8b5fd91SRandall Stewart.Dv SCTP_UNORDERED 159d8b5fd91SRandall Stewartflag is used to specify that the message arrived with no 160d8b5fd91SRandall Stewartspecific order and was delivered to the peer application 161d8b5fd91SRandall Stewartas soon as possible. When this flag is absent the message 162d8b5fd91SRandall Stewartwas delivered in order within the stream it was received. 163d8b5fd91SRandall Stewart.Pp 164d8b5fd91SRandall Stewart.Fa sinfo->sinfo_stream 165d8b5fd91SRandall Stewartis the SCTP stream that the message was received on. 166d8b5fd91SRandall StewartStreams in SCTP are reliable (or partially reliable) flows of ordered 167d8b5fd91SRandall Stewartmessages. 168d8b5fd91SRandall Stewart.Pp 169d8b5fd91SRandall Stewart The 170d8b5fd91SRandall Stewart.Fa sinfo->sinfo_context 171d8b5fd91SRandall Stewartfield is used only if the local application set a association level 172d8b5fd91SRandall Stewartcontext with the SCTP_CONTEXT socket option. 173d8b5fd91SRandall StewartOptionally a user process can use this value to index some application 174d8b5fd91SRandall Stewartspecific data structure for all data coming from a specific 175d8b5fd91SRandall Stewartassociation. 176d8b5fd91SRandall Stewart.Pp 177d8b5fd91SRandall StewartThe 178d8b5fd91SRandall Stewart.Fa sinfo->sinfo_ssn 179d8b5fd91SRandall Stewartwill hold the stream sequence number assigned 180d8b5fd91SRandall Stewartby the peer endpoint if the message is NOT unordered. 181d8b5fd91SRandall StewartFor unordered messages this field holds an undefined value. 182d8b5fd91SRandall Stewart.Pp 183d8b5fd91SRandall StewartThe 184d8b5fd91SRandall Stewart.Fa sinfo->sinfo_tsn 185d8b5fd91SRandall Stewartholds a transport sequence number (TSN) that was assigned 186d8b5fd91SRandall Stewartto this message by the peer endpoint. For messages that fit in or less 187d8b5fd91SRandall Stewartthan the path MTU this will be the only TSN assigned. 188d8b5fd91SRandall StewartNote that for messages that span multiple TSN's this 189d8b5fd91SRandall Stewartvalue will be one of the TSN's that was used on the 190d8b5fd91SRandall Stewartmessage. 191d8b5fd91SRandall Stewart.Pp 192d8b5fd91SRandall StewartThe 193d8b5fd91SRandall Stewart.Fa sinfo->sinfo_cumtsn 194d8b5fd91SRandall Stewartholds the current cumulative acknowledgment point of 195d8b5fd91SRandall Stewartthe transport association. Note that this may be larger 196d8b5fd91SRandall Stewartor smaller than the TSN assigned to the message itself. 197d8b5fd91SRandall Stewart.Pp 198d8b5fd91SRandall StewartThe 199d8b5fd91SRandall Stewartsinfo->sinfo_assoc_id 200d8b5fd91SRandall Stewartis the unique association identification that was assigned 201d8b5fd91SRandall Stewartto the association. For one-to-many (SOCK_SEQPACKET) type 202d8b5fd91SRandall Stewartsockets this value can be used to send data to the peer without 203d8b5fd91SRandall Stewartthe use of an address field. It is also quite useful in 204d8b5fd91SRandall Stewartsetting various socket options on the specific association 205d8b5fd91SRandall Stewart(see 206d8b5fd91SRandall Stewart.Fn sctp 4 207d8b5fd91SRandall Stewart). 208d8b5fd91SRandall Stewart.Pp 209d8b5fd91SRandall StewartThe 210d8b5fd91SRandall Stewartsinfo->info_timetolive 211d8b5fd91SRandall Stewartfield is not used by 212d8b5fd91SRandall Stewart.Fa sctp_recvmsg . 213d8b5fd91SRandall Stewart.Sh RETURN VALUES 214d8b5fd91SRandall StewartThe call returns the number of characters sent, or -1 215d8b5fd91SRandall Stewartif an error occurred. 216d8b5fd91SRandall Stewart.Sh ERRORS 217d8b5fd91SRandall StewartThe 218d8b5fd91SRandall Stewart.Fn sctp_recvmsg 219d8b5fd91SRandall Stewartsystem call 220d8b5fd91SRandall Stewartfail if: 221d8b5fd91SRandall Stewart.Bl -tag -width Er 222d8b5fd91SRandall Stewart.It Bq Er EBADF 223d8b5fd91SRandall StewartAn invalid descriptor was specified. 224d8b5fd91SRandall Stewart.It Bq Er ENOTSOCK 225d8b5fd91SRandall StewartThe argument 226d8b5fd91SRandall Stewart.Fa s 227d8b5fd91SRandall Stewartis not a socket. 228d8b5fd91SRandall Stewart.It Bq Er EFAULT 229d8b5fd91SRandall StewartAn invalid user space address was specified for an argument. 230d8b5fd91SRandall Stewart.It Bq Er EMSGSIZE 231d8b5fd91SRandall StewartThe socket requires that message be sent atomically, 232d8b5fd91SRandall Stewartand the size of the message to be sent made this impossible. 233d8b5fd91SRandall Stewart.It Bq Er EAGAIN 234d8b5fd91SRandall StewartThe socket is marked non-blocking and the requested operation 235d8b5fd91SRandall Stewartwould block. 236d8b5fd91SRandall Stewart.It Bq Er ENOBUFS 237d8b5fd91SRandall StewartThe system was unable to allocate an internal buffer. 238d8b5fd91SRandall StewartThe operation may succeed when buffers become available. 239d8b5fd91SRandall Stewart.It Bq Er ENOBUFS 240d8b5fd91SRandall StewartThe output queue for a network interface was full. 241d8b5fd91SRandall StewartThis generally indicates that the interface has stopped sending, 242d8b5fd91SRandall Stewartbut may be caused by transient congestion. 243d8b5fd91SRandall Stewart.It Bq Er EHOSTUNREACH 244d8b5fd91SRandall StewartThe remote host was unreachable. 245d8b5fd91SRandall Stewart.It Bq Er ENOTCON 246d8b5fd91SRandall StewartOn a one to one style socket no association exists. 247d8b5fd91SRandall Stewart.It Bq Er ECONNRESET 248d8b5fd91SRandall StewartAn abort was received by the stack while the user was 249d8b5fd91SRandall Stewartattempting to send data to the peer. 250d8b5fd91SRandall Stewart.It Bq Er ENOENT 251d8b5fd91SRandall StewartOn a one to many style socket no address is specified 252d8b5fd91SRandall Stewartso that the association cannot be located or the 253d8b5fd91SRandall StewartSCTP_ABORT flag was specified on a non-existing association. 254d8b5fd91SRandall Stewart.It Bq Er EPIPE 255d8b5fd91SRandall StewartThe socket is unable to send anymore data 256d8b5fd91SRandall Stewart.Dv ( SBS_CANTSENDMORE 257d8b5fd91SRandall Stewarthas been set on the socket). 258d8b5fd91SRandall StewartThis typically means that the socket 259d8b5fd91SRandall Stewartis not connected and is a one-to-one style socket. 260d8b5fd91SRandall Stewart.El 261d8b5fd91SRandall Stewart.Sh SEE ALSO 262d8b5fd91SRandall Stewart.Xr sctp 4 , 263d8b5fd91SRandall Stewart.Xr sendmsg 3 , 264d8b5fd91SRandall Stewart.Xr sctp_sendmsg 3 , 265d8b5fd91SRandall Stewart.Xr sctp_send 3 , 266d8b5fd91SRandall Stewart.Xr getsockopt 2 , 267d8b5fd91SRandall Stewart.Xr setsockopt 2 , 268d8b5fd91SRandall Stewart.Xr recv 2 , 269d8b5fd91SRandall Stewart.Xr select 2 , 270d8b5fd91SRandall Stewart.Xr socket 2 , 271d8b5fd91SRandall Stewart.Xr write 2 272d8b5fd91SRandall Stewart 273