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. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" From: @(#)send.2 8.2 (Berkeley) 2/21/94 33.\" $FreeBSD$ 34.\" 35.Dd December 15, 2006 36.Dt SCTP_SENDMSG 3 37.Os 38.Sh NAME 39.Nm sctp_sendmsg , 40.Nm sctp_sendmsgx 41.Nd send a message from an SCTP socket 42.Sh LIBRARY 43.Lb libc 44.Sh SYNOPSIS 45.In sys/types.h 46.In sys/socket.h 47.In netinet/sctp.h 48.Ft ssize_t 49.Fo sctp_sendmsg 50.Fa "int s" "const void *msg" "size_t len" "const struct sockaddr *to" 51.Fa "socklen_t tolen" "uint32_t ppid" "uint32_t flags" "uint16_t stream_no" 52.Fa "uint32_t timetolive" "uint32_t context" 53.Fc 54.Ft ssize_t 55.Fo sctp_sendmsgx 56.Fa "int s" "const void *msg" "size_t len" "const struct sockaddr *to" 57.Fa "int addrcnt" "uint32_t ppid" "uint32_t flags" "uint16_t stream_no" 58.Fa "uint32_t timetolive" "uint32_t context" 59.Fc 60.Sh DESCRIPTION 61The 62.Fn sctp_sendmsg 63system call 64is used to transmit a message to another SCTP endpoint. 65The 66.Fn sctp_sendmsg 67may be used at any time. 68If the socket is a one-to-many type (SOCK_SEQPACKET) 69socket then an attempt to send to an address that no association exists to will 70implicitly create a new association. 71Data sent in such an instance will result in 72the data being sent on the third leg of the SCTP four-way handshake. 73Note that if 74the socket is a one-to-one type (SOCK_STREAM) socket then an association must 75be in existance (by use of the 76.Xr connect 2 77system call). 78Calling 79.Fn sctp_sendmsg 80or 81.Fn sctp_sendmsgx 82on a non-connected one-to-one socket will result in 83.Va errno 84being set to 85.Er ENOTCONN , 86-1 being returned, and the message not being transmitted. 87.Pp 88The address of the target is given by 89.Fa to 90with 91.Fa tolen 92specifying its size. 93The length of the message 94.Fa msg 95is given by 96.Fa len . 97If the message is too long to pass atomically through the 98underlying protocol, 99.Va errno 100is set to 101.Er EMSGSIZE , 102-1 is returned, and 103the message is not transmitted. 104.Pp 105No indication of failure to deliver is implicit in a 106.Xr sctp_sendmsg 2 107call. 108Locally detected errors are indicated by a return value of -1. 109.Pp 110If no space is available at the socket to hold 111the message to be transmitted, then 112.Xr sctp_sendmsg 2 113normally blocks, unless the socket has been placed in 114non-blocking I/O mode. 115The 116.Xr select 2 117system call may be used to determine when it is possible to 118send more data on one-to-one type (SOCK_STREAM) sockets. 119.Pp 120The 121.Fa ppid 122argument is an opaque 32 bit value that is passed transparently 123through the stack to the peer endpoint. 124It will be available on 125reception of a message (see 126.Xr sctp_recvmsg 2 127). 128Note that the stack passes this value without regard to byte 129order. 130.Pp 131The 132.Fa flags 133argument may include one or more of the following: 134.Bd -literal 135#define SCTP_EOF 0x0100 /* Start a shutdown procedures */ 136#define SCTP_ABORT 0x0200 /* Send an ABORT to peer */ 137#define SCTP_UNORDERED 0x0400 /* Message is un-ordered */ 138#define SCTP_ADDR_OVER 0x0800 /* Override the primary-address */ 139#define SCTP_SENDALL 0x1000 /* Send this on all associations */ 140 /* for the endpoint */ 141/* The lower byte is an enumeration of PR-SCTP policies */ 142#define SCTP_PR_SCTP_TTL 0x0001 /* Time based PR-SCTP */ 143#define SCTP_PR_SCTP_BUF 0x0002 /* Buffer based PR-SCTP */ 144#define SCTP_PR_SCTP_RTX 0x0003 /* Number of retransmissions based PR-SCTP */ 145.Ed 146.Pp 147The flag 148.Dv SCTP_EOF 149is used to instruct the SCTP stack to queue this message 150and then start a graceful shutdown of the association. 151All 152remaining data in queue will be sent after which the association 153will be shut down. 154.Pp 155.Dv SCTP_ABORT 156is used to immediately terminate an association. 157An abort 158is sent to the peer and the local TCB is destroyed. 159.Pp 160.Dv SCTP_UNORDERED 161is used to specify that the message being sent has no 162specific order and should be delivered to the peer application 163as soon as possible. 164When this flag is absent messages 165are delivered in order within the stream they are sent, but without 166respect to order to peer streams. 167.Pp 168The flag 169.Dv SCTP_ADDR_OVER 170is used to specify that an specific address should be used. 171Normally 172SCTP will use only one of a multi-homed peers addresses as the primary 173address to send to. 174By default, no matter what the 175.Fa to 176argument is, this primary address is used to send data. 177By specifying 178this flag, the user is asking the stack to ignore the primary address 179and instead use the specified address not only as a lookup mechanism 180to find the association but also as the actual address to send to. 181.Pp 182For a one-to-many type (SOCK_SEQPACKET) socket the flag 183.Dv SCTP_SENDALL 184can be used as a convient way to make one send call and have 185all associations that are under the socket get a copy of the message. 186Note that this mechanism is quite efficent and makes only one actual 187copy of the data which is shared by all the associations for sending. 188.Pp 189The remaining flags are used for the partial reliabilty extension (RFC3758) 190and will only be effective if the peer endpoint supports this extension. 191This option specify's what local policy the local endpoint should use 192in skipping data. 193If none of these options are set, then data is 194never skipped over. 195.Pp 196.Dv SCTP_PR_SCTP_TTL 197Is used to indicate that a time based lifetime is being applied 198to the data. 199The 200.Fa timetolive 201argument is then a number of milliseconds for which the data is 202attempted to be transmitted. 203If that many milliseconds ellapse 204and the peer has not acknowledged the data, the data will be 205skipped and no longer transmitted. 206Note that this policy does 207not even assure that the data will ever be sent. 208In times of a congestion 209with large amounts of data being queued, the 210.Fa timetolive 211may expire before the first transmission is ever made. 212.Pp 213The 214.Dv SCTP_PR_SCTP_BUF 215based policy transforms the 216.Fa timetolive 217field into a total number of bytes allowed on the outbound 218send queue. 219If that number or more bytes are in queue, then 220other buffer based sends are looked to be removed and 221skipped. 222Note that this policy may also result in the data 223never being sent if no buffer based sends are in queue and 224the maximum specified by 225.Fa timetolive 226bytes is in queue. 227.Pp 228The 229.Dv SCTP_PR_SCTP_RTX 230policy transforms the 231.Fa timetolive 232into a number of retransmissions to allow. 233This policy 234always assures that at a minimum one send attempt is 235made of the data. 236After which no more than 237.Fa timetolive 238retransmissions will be made before the data is skipped. 239.Pp 240.Fa stream_no 241is the SCTP stream that you wish to send the 242message on. 243Streams in SCTP are reliable (or partially reliable) flows of ordered 244messages. 245The 246.Fa context 247field is used only in the event the message cannot be sent. 248This is an opaque 249value that the stack retains and will give to the user when a failed send 250is given if that notification is enabled (see 251.Xr sctp 4 252). 253Normally a user process can use this value to index some application 254specific data structure when a send cannot be fulfilled. 255.Fn sctp_sendmsgx 256is identical to 257.Fn sctp_sendmsg 258with the exception that it takes a array of sockaddr structures in the 259argument 260.Fa to 261and adds the additional argument 262.Fa addrcnt 263which specifies how many addresses are in the array. 264This allows a 265caller to implictly setup an association passing multiple addresses 266as if an 267.Fn sctp_connectx 268had been called to setup the association. 269.Sh RETURN VALUES 270The call returns the number of characters sent, or -1 271if an error occurred. 272.Sh ERRORS 273The 274.Fn sctp_sendmsg 2 275system call 276fail if: 277.Bl -tag -width Er 278.It Bq Er EBADF 279An invalid descriptor was specified. 280.It Bq Er ENOTSOCK 281The argument 282.Fa s 283is not a socket. 284.It Bq Er EFAULT 285An invalid user space address was specified for an argument. 286.It Bq Er EMSGSIZE 287The socket requires that message be sent atomically, 288and the size of the message to be sent made this impossible. 289.It Bq Er EAGAIN 290The socket is marked non-blocking and the requested operation 291would block. 292.It Bq Er ENOBUFS 293The system was unable to allocate an internal buffer. 294The operation may succeed when buffers become available. 295.It Bq Er ENOBUFS 296The output queue for a network interface was full. 297This generally indicates that the interface has stopped sending, 298but may be caused by transient congestion. 299.It Bq Er EHOSTUNREACH 300The remote host was unreachable. 301.It Bq Er ENOTCON 302On a one-to-one style socket no association exists. 303.It Bq Er ECONNRESET 304An abort was received by the stack while the user was 305attempting to send data to the peer. 306.It Bq Er ENOENT 307On a one-to-many style socket no address is specified 308so that the association cannot be located or the 309.Dv SCTP_ABORT 310flag was specified on a non-existing association. 311.It Bq Er EPIPE 312The socket is unable to send anymore data 313.Dv ( SBS_CANTSENDMORE 314has been set on the socket). 315This typically means that the socket 316is not connected and is a one-to-one style socket. 317.El 318.Sh SEE ALSO 319.Xr connect 2 , 320.Xr getsockopt 2 , 321.Xr recv 2 , 322.Xr select 2 , 323.Xr socket 2 , 324.Xr write 2 , 325.Xr sendmsg 3 , 326.Xr sctp_connectx 3 , 327.Xr sctp 4 328.Sh BUGS 329Because in the one-to-many style socket the 330.Fn sctp_sendmsg 331or 332.Fn sctp_sendmsgx 333may have multiple associations under one endpoint, a 334select on write will only work for a one-to-one style 335socket. 336