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.Fn sctp_sendmsg "int s" "const void *msg" "size_t len" "const struct sockaddr *to" "socklen_t tolen" "uint32_t ppid" "uint32_t flags" "uint16_t stream_no" "uint32_t timetolive" "uint32_t context" 50.Ft ssize_t 51.Fn sctp_sendmsgx "int s" "const void *msg" "size_t len" "const struct sockaddr *to" "int addrcnt" "uint32_t ppid" "uint32_t flags" "uint16_t stream_no" "uint32_t timetolive" "uint32_t context" 52 53.Sh DESCRIPTION 54The 55.Fn sctp_sendmsg 56system calls 57is used to transmit a message to another SCTP endpoint. 58The 59.Fn sctp_sendmsg 60may be used at any time. If the socket is a one-to-many type (SOCK_SEQPACKET) 61socket then an attempt to send to an address that no association exists to will 62implicitly create a new association. Data sent in such an instance will result in 63the data being sent on the third leg of the SCTP four-way handshake. Note that if 64the socket is a one-to-one type (SOCK_STREAM) socket then an association must 65be in existance (by use of the 66.Fn connect 2 67system call). Calling 68.Fn sctp_sendmsg 69or 70.Fn sctp_sendmsgx 71on a non-connected one-to-one socket will result in the errno being set to 72.Er ENOTCONN 73a -1 being returned, and the message is not transmitted. 74.Pp 75The address of the target is given by 76.Fa to 77with 78.Fa tolen 79specifying its size. 80The length of the message 81.Fa msg 82is given by 83.Fa len . 84If the message is too long to pass atomically through the 85underlying protocol, the errno is set to 86.Er EMSGSIZE 87a -1 is returned, and 88the message is not transmitted. 89.Pp 90No indication of failure to deliver is implicit in a 91.Fn sctp_sendmsg 2 92Locally detected errors are indicated by a return value of -1. 93.Pp 94If no messages space is available at the socket to hold 95the message to be transmitted, then 96.Fn sctp_sendmsg 2 97normally blocks, unless the socket has been placed in 98non-blocking I/O mode. 99The 100.Fn select 2 101system call may be used to determine when it is possible to 102send more data on one-to-one type (SOCK_STREAM) sockets. 103.Pp 104The 105.Fa ppid 106argument is an opaque 32 bit value that is passed transparently 107through the stack to the peer endpoint. It will be available on 108reception of a message (see 109.Fn sctp_recvmsg 2 110). Note that the stack passes this value without regard to byte 111order. 112.Pp 113The 114.Fa flags 115argument may include one or more of the following: 116.Bd -literal 117#define SCTP_EOF 0x0100 /* Start a shutdown procedures */ 118#define SCTP_ABORT 0x0200 /* Send an ABORT to peer */ 119#define SCTP_UNORDERED 0x0400 /* Message is un-ordered */ 120#define SCTP_ADDR_OVER 0x0800 /* Override the primary-address */ 121#define SCTP_SENDALL 0x1000 /* Send this on all associations */ 122 /* for the endpoint */ 123/* The lower byte is an enumeration of PR-SCTP policies */ 124#define SCTP_PR_SCTP_TTL 0x0001 /* Time based PR-SCTP */ 125#define SCTP_PR_SCTP_BUF 0x0002 /* Buffer based PR-SCTP */ 126#define SCTP_PR_SCTP_RTX 0x0003 /* Number of retransmissions based PR-SCTP */ 127.Ed 128.Pp 129The flag 130.Dv SCTP_EOF 131is used to instruct the SCTP stack to queue this message 132and then start a graceful shutdown of the association. All 133remaining data in queue will be sent after which the association 134will be shutdown. 135.Pp 136.Dv SCTP_ABORT 137is used to immediately terminate an association. An abort 138is sent to the peer and the local TCB is destroyed. 139.Pp 140.Dv SCTP_UNORDERED 141is used to specify that the message being sent has no 142specific order and should be delivered to the peer application 143as soon as possible. When this flag is absent messages 144are delivered in order within the stream they are sent, but without 145respect to order to peer streams. 146.Pp 147The flag 148.Dv SCTP_ADDR_OVER 149is used to specify that an specific address should be used. Normally 150SCTP will use only one of a multi-homed peers address as the primary 151address to send to. By default, no matter what the 152.Fa to 153argument is, this primary address is used to send data. By specifying 154this flag, the user is asking the stack to ignore the primary address 155and instead use the specified address not only has a lookup mechanism 156to find the association but also has the actual address to send to. 157.Pp 158For a one-to-many type (SOCK_SEQPACKET) socket the flag 159.Dv SCTP_SENDALL 160can be used as a convient way to make one send call and have 161all associations that are under the socket get a copy of the message. 162Note that this mechanism is quite efficent and makes only one actual 163copy of the data which is shared by all the associations for sending. 164.Pp 165The remaining flags are used for the partial reliabilty extension (RFC3758) 166and will only be effective if the peer endpoint supports this extension. 167This option specify's what local policy the local endpoint should use 168in skipping data. If none of these options are set, then data is 169never skipped over. 170.Pp 171.Dv SCTP_PR_SCTP_TTL 172Is used to indicate that a time based lifetime is being applied 173to the data. The 174.Fa timetolive 175argument is then a number of milliseconds for which the data is 176attempted to be transmitted. If that many milliseconds ellapses 177and the peer has not acknowledge the data, the data will be 178skipped and no longer transmitted. Note that this policy does 179not even assure that the data will ever be sent. In times of a congestion 180with large amounts of data being queued, the 181.Fa timetolive 182may expire before the first transmission is ever made. 183.Pp 184The 185.Dv SCTP_PR_SCTP_BUF 186based policy transforms the 187.Fa timetolive 188field into a total number of bytes allowed on the outbound 189send queue. If that number or more bytes are in queue, then 190other buffer based sends are looked to be removed and 191skipped. Note that this policy may also result in the data 192never being sent if no buffer based sends are in queue and 193the maximum specified by 194.Fa timetolive 195bytes is in queue. 196.Pp 197The 198.Dv SCTP_PR_SCTP_RTX 199policy transforms the 200.Fa timetolive 201into a number of retransmissions to allow. This policy 202always assures that at a minimum one send attempt is 203made of the data. After which no more than 204.Fa timetolive 205retransmissions will be made before the data is skipped. 206.Pp 207.Fa stream_no 208is the SCTP stream that you wish to send the 209message on. Streams in SCTP are reliable (or partially reliable) flows of ordered 210messages. The 211.Fa context 212field is used only in the event the message cannot be sent. This is an opaque 213value that the stack retains and will give to the user when a failed send 214is given if that notification is enabled (see 215.Tn sctp 216). Normally a user process can use this value to index some application 217specific data structure when a send cannot be fulfilled. 218.Fn sctp_sendmsgx 219is identical to 220.Fn sctp_sendmsg 221with the exception that it takes a array of sockaddr structures in the 222argument 223.Fa to 224and adds the additional argument 225.Fa addrcnt 226which specifies how many addresses are in the array. This allows a 227caller to implictly setup an association passing multiple addresses 228as if an 229.Fn sctp_connectx 230had been called to setup the association. 231.Sh RETURN VALUES 232The call returns the number of characters sent, or -1 233if an error occurred. 234.Sh ERRORS 235The 236.Fn sctp_sendmsg 2 237system call 238fail if: 239.Bl -tag -width Er 240.It Bq Er EBADF 241An invalid descriptor was specified. 242.It Bq Er ENOTSOCK 243The argument 244.Fa s 245is not a socket. 246.It Bq Er EFAULT 247An invalid user space address was specified for an argument. 248.It Bq Er EMSGSIZE 249The socket requires that message be sent atomically, 250and the size of the message to be sent made this impossible. 251.It Bq Er EAGAIN 252The socket is marked non-blocking and the requested operation 253would block. 254.It Bq Er ENOBUFS 255The system was unable to allocate an internal buffer. 256The operation may succeed when buffers become available. 257.It Bq Er ENOBUFS 258The output queue for a network interface was full. 259This generally indicates that the interface has stopped sending, 260but may be caused by transient congestion. 261.It Bq Er EHOSTUNREACH 262The remote host was unreachable. 263.It Bq Er ENOTCON 264On a one to one style socket no association exists. 265.It Bq Er ECONNRESET 266An abort was received by the stack while the user was 267attempting to send data to the peer. 268.It Bq Er ENOENT 269On a one to many style socket no address is specified 270so that the association cannot be located or the 271SCTP_ABORT flag was specified on a non-existing association. 272.It Bq Er EPIPE 273The socket is unable to send anymore data 274.Dv ( SBS_CANTSENDMORE 275has been set on the socket). 276This typically means that the socket 277is not connected and is a one-to-one style socket. 278.El 279.Sh SEE ALSO 280.Xr sctp 4 , 281.Xr sendmsg 3 , 282.Xr connect 2 , 283.Xr sctp_connectx 3 , 284.Xr getsockopt 2 , 285.Xr recv 2 , 286.Xr select 2 , 287.Xr socket 2 , 288.Xr write 2 289.Sh BUGS 290Because in the one-to-many style socket the 291.Fn sctp_sendmsg 292or 293.Fn sctp_sendmsgx 294may have multiple associations under one endpoint, a 295select on write will only work for a one-to-one style 296socket. 297 298