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_SEND 3 36d8b5fd91SRandall Stewart.Os 37d8b5fd91SRandall Stewart.Sh NAME 38d8b5fd91SRandall Stewart.Nm sctp_send 39d8b5fd91SRandall Stewart.Nm sctp_sendx 40d8b5fd91SRandall Stewart.Nd send a message from an SCTP socket 41d8b5fd91SRandall Stewart.Sh LIBRARY 42d8b5fd91SRandall Stewart.Lb libc 43d8b5fd91SRandall Stewart.Sh SYNOPSIS 44d8b5fd91SRandall Stewart.In sys/types.h 45d8b5fd91SRandall Stewart.In sys/socket.h 467c376800SRandall Stewart.In netinet/sctp.h 47d8b5fd91SRandall Stewart.Ft ssize_t 48d8b5fd91SRandall Stewart.Fn sctp_send "int sd" "const void *msg" "size_t len" "const struct sctp_sndrcvinfo *sinfo" "int flags" 49d8b5fd91SRandall Stewart.Ft ssize_t 50d8b5fd91SRandall Stewart.Fn sctp_sendx "int sd" "const void *msg" "size_t len" "struct sockaddr *addrs" "int addrcnt" "const struct sctp_sndrcvinfo *sinfo" "int flags" 51d8b5fd91SRandall Stewart.Sh DESCRIPTION 52d8b5fd91SRandall StewartThe 53d8b5fd91SRandall Stewart.Fn sctp_send 54d8b5fd91SRandall Stewartsystem calls 55d8b5fd91SRandall Stewartis used to transmit a message to another SCTP endpoint. 56d8b5fd91SRandall StewartThe 57d8b5fd91SRandall Stewart.Fn sctp_send 58d8b5fd91SRandall Stewartmay be used to send data to an existing association for both 59d8b5fd91SRandall Stewartone-to-many (SOCK_SEQPACKET) and one-to-one (SOCK_STREAM) socket types. 60d8b5fd91SRandall StewartThe length of the message 61d8b5fd91SRandall Stewart.Fa msg 62d8b5fd91SRandall Stewartis given by 63d8b5fd91SRandall Stewart.Fa len . 64d8b5fd91SRandall StewartIf the message is too long to pass atomically through the 65d8b5fd91SRandall Stewartunderlying protocol, the errno is set to 66d8b5fd91SRandall Stewart.Er EMSGSIZE 67d8b5fd91SRandall Stewarta -1 is returned, and 68d8b5fd91SRandall Stewartthe message is not transmitted. 69d8b5fd91SRandall Stewart.Pp 70d8b5fd91SRandall StewartNo indication of failure to deliver is implicit in a 71d8b5fd91SRandall Stewart.Fn sctp_send 72d8b5fd91SRandall StewartLocally detected errors are indicated by a return value of -1. 73d8b5fd91SRandall Stewart.Pp 74d8b5fd91SRandall StewartIf no messages space is available at the socket to hold 75d8b5fd91SRandall Stewartthe message to be transmitted, then 76d8b5fd91SRandall Stewart.Fn sctp_send 77d8b5fd91SRandall Stewartnormally blocks, unless the socket has been placed in 78d8b5fd91SRandall Stewartnon-blocking I/O mode. 79d8b5fd91SRandall StewartThe 80d8b5fd91SRandall Stewart.Fn select 2 81d8b5fd91SRandall Stewartsystem call may be used to determine when it is possible to 82d8b5fd91SRandall Stewartsend more data on one-to-one type (SOCK_STREAM) sockets. 83d8b5fd91SRandall Stewart.Pp 84d8b5fd91SRandall StewartThe 85d8b5fd91SRandall Stewart.Fa sinfo 86d8b5fd91SRandall Stewartstructure is used to control various SCTP features 87d8b5fd91SRandall Stewartand has the following format: 88d8b5fd91SRandall Stewart.Bd -literal 89d8b5fd91SRandall Stewartstruct sctp_sndrcvinfo { 90d8b5fd91SRandall Stewart u_int16_t sinfo_stream; /* Stream sending to */ 91d8b5fd91SRandall Stewart u_int16_t sinfo_ssn; /* valid for recv only */ 92d8b5fd91SRandall Stewart u_int16_t sinfo_flags; /* flags to control sending */ 93d8b5fd91SRandall Stewart u_int32_t sinfo_ppid; /* ppid field */ 94d8b5fd91SRandall Stewart u_int32_t sinfo_context; /* context field */ 95d8b5fd91SRandall Stewart u_int32_t sinfo_timetolive; /* timetolive for PR-SCTP */ 96d8b5fd91SRandall Stewart u_int32_t sinfo_tsn; /* valid for recv only */ 97d8b5fd91SRandall Stewart u_int32_t sinfo_cumtsn; /* valid for recv only */ 98d8b5fd91SRandall Stewart sctp_assoc_t sinfo_assoc_id; /* The association id */ 99d8b5fd91SRandall Stewart}; 100d8b5fd91SRandall Stewart.Ed 101d8b5fd91SRandall StewartThe 102d8b5fd91SRandall Stewart.Fa sinfo->sinfo_ppid 103d8b5fd91SRandall Stewartargument is an opaque 32 bit value that is passed transparently 104d8b5fd91SRandall Stewartthrough the stack to the peer endpoint. It will be available on 105d8b5fd91SRandall Stewartreception of a message (see 106d8b5fd91SRandall Stewart.Fn sctp_recvmsg 2 107d8b5fd91SRandall Stewart). Note that the stack passes this value without regard to byte 108d8b5fd91SRandall Stewartorder. 109d8b5fd91SRandall Stewart.Pp 110d8b5fd91SRandall StewartThe 111d8b5fd91SRandall Stewart.Fa sinfo->sinfo_flags 112d8b5fd91SRandall Stewartargument may include one or more of the following: 113d8b5fd91SRandall Stewart.Bd -literal 114d8b5fd91SRandall Stewart#define SCTP_EOF 0x0100 /* Start a shutdown procedures */ 115d8b5fd91SRandall Stewart#define SCTP_ABORT 0x0200 /* Send an ABORT to peer */ 116d8b5fd91SRandall Stewart#define SCTP_UNORDERED 0x0400 /* Message is un-ordered */ 117d8b5fd91SRandall Stewart#define SCTP_ADDR_OVER 0x0800 /* Override the primary-address */ 118d8b5fd91SRandall Stewart#define SCTP_SENDALL 0x1000 /* Send this on all associations */ 119d8b5fd91SRandall Stewart /* for the endpoint */ 120d8b5fd91SRandall Stewart/* The lower byte is an enumeration of PR-SCTP policies */ 121d8b5fd91SRandall Stewart#define SCTP_PR_SCTP_TTL 0x0001 /* Time based PR-SCTP */ 122d8b5fd91SRandall Stewart#define SCTP_PR_SCTP_BUF 0x0002 /* Buffer based PR-SCTP */ 123d8b5fd91SRandall Stewart#define SCTP_PR_SCTP_RTX 0x0003 /* Number of retransmissions based PR-SCTP */ 124d8b5fd91SRandall Stewart.Ed 125d8b5fd91SRandall Stewart.Pp 126d8b5fd91SRandall StewartThe flag 127d8b5fd91SRandall Stewart.Dv SCTP_EOF 128d8b5fd91SRandall Stewartis used to instruct the SCTP stack to queue this message 129d8b5fd91SRandall Stewartand then start a graceful shutdown of the association. All 130d8b5fd91SRandall Stewartremaining data in queue will be sent after which the association 131d8b5fd91SRandall Stewartwill be shutdown. 132d8b5fd91SRandall Stewart.Pp 133d8b5fd91SRandall Stewart.Dv SCTP_ABORT 134d8b5fd91SRandall Stewartis used to immediately terminate an association. An abort 135d8b5fd91SRandall Stewartis sent to the peer and the local TCB is destroyed. 136d8b5fd91SRandall Stewart.Pp 137d8b5fd91SRandall Stewart.Dv SCTP_UNORDERED 138d8b5fd91SRandall Stewartis used to specify that the message being sent has no 139d8b5fd91SRandall Stewartspecific order and should be delivered to the peer application 140d8b5fd91SRandall Stewartas soon as possible. When this flag is absent messages 141d8b5fd91SRandall Stewartare delivered in order within the stream they are sent, but without 142d8b5fd91SRandall Stewartrespect to order to peer streams. 143d8b5fd91SRandall Stewart.Pp 144d8b5fd91SRandall StewartThe flag 145d8b5fd91SRandall Stewart.Dv SCTP_ADDR_OVER 146d8b5fd91SRandall Stewartis used to specify that an specific address should be used. Normally 147d8b5fd91SRandall StewartSCTP will use only one of a multi-homed peers address as the primary 148d8b5fd91SRandall Stewartaddress to send to. By default, no matter what the 149d8b5fd91SRandall Stewart.Fa to 150d8b5fd91SRandall Stewartargument is, this primary address is used to send data. By specifying 151d8b5fd91SRandall Stewartthis flag, the user is asking the stack to ignore the primary address 152d8b5fd91SRandall Stewartand instead use the specified address not only has a lookup mechanism 153d8b5fd91SRandall Stewartto find the association but also has the actual address to send to. 154d8b5fd91SRandall Stewart.Pp 155d8b5fd91SRandall StewartFor a one-to-many type (SOCK_SEQPACKET) socket the flag 156d8b5fd91SRandall Stewart.Dv SCTP_SENDALL 157d8b5fd91SRandall Stewartcan be used as a convient way to make one send call and have 158d8b5fd91SRandall Stewartall associations that are under the socket get a copy of the message. 159d8b5fd91SRandall StewartNote that this mechanism is quite efficent and makes only one actual 160d8b5fd91SRandall Stewartcopy of the data which is shared by all the associations for sending. 161d8b5fd91SRandall Stewart.Pp 162d8b5fd91SRandall StewartThe remaining flags are used for the partial reliabilty extension (RFC3758) 163d8b5fd91SRandall Stewartand will only be effective if the peer endpoint supports this extension. 164d8b5fd91SRandall StewartThis option specify's what local policy the local endpoint should use 165d8b5fd91SRandall Stewartin skipping data. If none of these options are set, then data is 166d8b5fd91SRandall Stewartnever skipped over. 167d8b5fd91SRandall Stewart.Pp 168d8b5fd91SRandall Stewart.Dv SCTP_PR_SCTP_TTL 169d8b5fd91SRandall StewartIs used to indicate that a time based lifetime is being applied 170d8b5fd91SRandall Stewartto the data. The 171d8b5fd91SRandall Stewart.Fa sinfo->sinfo_timetolive 172d8b5fd91SRandall Stewartargument is then a number of milliseconds for which the data is 173d8b5fd91SRandall Stewartattempted to be transmitted. If that many milliseconds ellapses 174d8b5fd91SRandall Stewartand the peer has not acknowledge the data, the data will be 175d8b5fd91SRandall Stewartskipped and no longer transmitted. Note that this policy does 176d8b5fd91SRandall Stewartnot even assure that the data will ever be sent. In times of a congestion 177d8b5fd91SRandall Stewartwith large amounts of data being queued, the 178d8b5fd91SRandall Stewart.Fa sinfo->sinfo_timetolive 179d8b5fd91SRandall Stewartmay expire before the first transmission is ever made. 180d8b5fd91SRandall Stewart.Pp 181d8b5fd91SRandall StewartThe 182d8b5fd91SRandall Stewart.Dv SCTP_PR_SCTP_BUF 183d8b5fd91SRandall Stewartbased policy transforms the 184d8b5fd91SRandall Stewart.Fa sinfo->sinfo_timetolive 185d8b5fd91SRandall Stewartfield into a total number of bytes allowed on the outbound 186d8b5fd91SRandall Stewartsend queue. If that number or more bytes are in queue, then 187d8b5fd91SRandall Stewartother buffer based sends are looked to be removed and 188d8b5fd91SRandall Stewartskipped. Note that this policy may also result in the data 189d8b5fd91SRandall Stewartnever being sent if no buffer based sends are in queue and 190d8b5fd91SRandall Stewartthe maximum specified by 191d8b5fd91SRandall Stewart.Fa timetolive 192d8b5fd91SRandall Stewartbytes is in queue. 193d8b5fd91SRandall Stewart.Pp 194d8b5fd91SRandall StewartThe 195d8b5fd91SRandall Stewart.Dv SCTP_PR_SCTP_RTX 196d8b5fd91SRandall Stewartpolicy transforms the 197d8b5fd91SRandall Stewart.Fa sinfo->sinfo_timetolive 198d8b5fd91SRandall Stewartinto a number of retransmissions to allow. This policy 199d8b5fd91SRandall Stewartalways assures that at a minimum one send attempt is 200d8b5fd91SRandall Stewartmade of the data. After which no more than 201d8b5fd91SRandall Stewart.Fa sinfo->sinfo_timetolive 202d8b5fd91SRandall Stewartretransmissions will be made before the data is skipped. 203d8b5fd91SRandall Stewart.Pp 204d8b5fd91SRandall Stewart.Fa sinfo->sinfo_stream 205d8b5fd91SRandall Stewartis the SCTP stream that you wish to send the 206d8b5fd91SRandall Stewartmessage on. Streams in SCTP are reliable (or partially reliable) flows of ordered 207d8b5fd91SRandall Stewartmessages. 208d8b5fd91SRandall Stewart.Pp 209d8b5fd91SRandall StewartThe 210d8b5fd91SRandall Stewart.Fa sinfo->sinfo_assoc_id 211d8b5fd91SRandall Stewartfield is used to 212d8b5fd91SRandall Stewartselect the association to send to on an one-to-many socket. For a 213d8b5fd91SRandall Stewartone-to-one socket, this field is ignored. 214d8b5fd91SRandall Stewart.Pp 215d8b5fd91SRandall Stewart.Fa sinfo->sinfo_context 216d8b5fd91SRandall Stewartfield is used only in the event the message cannot be sent. This is an opaque 217d8b5fd91SRandall Stewartvalue that the stack retains and will give to the user when a failed send 218d8b5fd91SRandall Stewartis given if that notification is enabled (see 219d8b5fd91SRandall Stewart.Tn sctp 220d8b5fd91SRandall Stewart). Normally a user process can use this value to index some application 221d8b5fd91SRandall Stewartspecific data structure when a send cannot be fulfilled. 222d8b5fd91SRandall Stewart.Pp 223d8b5fd91SRandall StewartThe 224d8b5fd91SRandall Stewart.Fa flags 225d8b5fd91SRandall Stewartargument holds the same meaning and values has those found in 226d8b5fd91SRandall Stewart.Fn sendmsg 2 227d8b5fd91SRandall Stewartbut is generally ignored by SCTP. 228d8b5fd91SRandall Stewart.Pp 229d8b5fd91SRandall StewartThe fields 230d8b5fd91SRandall Stewart.Fa sinfo->sinfo_ssn , 231d8b5fd91SRandall Stewart.Fa sinfo->sinfo_tsn , 232d8b5fd91SRandall Stewartand 233d8b5fd91SRandall Stewart.Fa sinfo->sinfo_cumtsn 234d8b5fd91SRandall Stewartare used only when receiving messages and are thus ignored by 235d8b5fd91SRandall Stewart.Fn sctp_send. 236d8b5fd91SRandall StewartThe function 237d8b5fd91SRandall Stewart.Fn sctp_sendx 238d8b5fd91SRandall Stewarthas the same properties as 239d8b5fd91SRandall Stewart.Fn sctp_send 240d8b5fd91SRandall Stewartwith the additional arguments of an array of sockaddr structures 241d8b5fd91SRandall Stewartpassed in. With the 242d8b5fd91SRandall Stewart.Fa addrs 243d8b5fd91SRandall Stewartargument being given as an array of addresses to be sent to and 244d8b5fd91SRandall Stewartthe 245d8b5fd91SRandall Stewart.Fa addrcnt 246d8b5fd91SRandall Stewartargument indicating how many socket addresses are in the passed 247d8b5fd91SRandall Stewartin array. Note that all of the addresses will only be used 248d8b5fd91SRandall Stewartwhen an implicit association is being setup. This allows the 249d8b5fd91SRandall Stewartuser the equivilant behavior as doing a 250d8b5fd91SRandall Stewart.Fn sctp_connectx 251d8b5fd91SRandall Stewartfollowed by a 252d8b5fd91SRandall Stewart.Fn sctp_send 253d8b5fd91SRandall Stewartto the association. Note that if the association id. 254d8b5fd91SRandall Stewart.Fa sinfo->sinfo_assoc_id 255d8b5fd91SRandall Stewartfield is 0, then the first address will be used to look up 256d8b5fd91SRandall Stewartthe association in place of the association id. If both 257d8b5fd91SRandall Stewartan address and and association id are specified, the association 258d8b5fd91SRandall Stewartid has priority. 259d8b5fd91SRandall Stewart.Sh RETURN VALUES 260d8b5fd91SRandall StewartThe call returns the number of characters sent, or -1 261d8b5fd91SRandall Stewartif an error occurred. 262d8b5fd91SRandall Stewart.Sh ERRORS 263d8b5fd91SRandall StewartThe 264d8b5fd91SRandall Stewart.Fn sctp_send 265d8b5fd91SRandall Stewartsystem call 266d8b5fd91SRandall Stewartfail if: 267d8b5fd91SRandall Stewart.Bl -tag -width Er 268d8b5fd91SRandall Stewart.It Bq Er EBADF 269d8b5fd91SRandall StewartAn invalid descriptor was specified. 270d8b5fd91SRandall Stewart.It Bq Er ENOTSOCK 271d8b5fd91SRandall StewartThe argument 272d8b5fd91SRandall Stewart.Fa s 273d8b5fd91SRandall Stewartis not a socket. 274d8b5fd91SRandall Stewart.It Bq Er EFAULT 275d8b5fd91SRandall StewartAn invalid user space address was specified for an argument. 276d8b5fd91SRandall Stewart.It Bq Er EMSGSIZE 277d8b5fd91SRandall StewartThe socket requires that message be sent atomically, 278d8b5fd91SRandall Stewartand the size of the message to be sent made this impossible. 279d8b5fd91SRandall Stewart.It Bq Er EAGAIN 280d8b5fd91SRandall StewartThe socket is marked non-blocking and the requested operation 281d8b5fd91SRandall Stewartwould block. 282d8b5fd91SRandall Stewart.It Bq Er ENOBUFS 283d8b5fd91SRandall StewartThe system was unable to allocate an internal buffer. 284d8b5fd91SRandall StewartThe operation may succeed when buffers become available. 285d8b5fd91SRandall Stewart.It Bq Er ENOBUFS 286d8b5fd91SRandall StewartThe output queue for a network interface was full. 287d8b5fd91SRandall StewartThis generally indicates that the interface has stopped sending, 288d8b5fd91SRandall Stewartbut may be caused by transient congestion. 289d8b5fd91SRandall Stewart.It Bq Er EHOSTUNREACH 290d8b5fd91SRandall StewartThe remote host was unreachable. 291d8b5fd91SRandall Stewart.It Bq Er ENOTCON 292d8b5fd91SRandall StewartOn a one to one style socket no association exists. 293d8b5fd91SRandall Stewart.It Bq Er ECONNRESET 294d8b5fd91SRandall StewartAn abort was received by the stack while the user was 295d8b5fd91SRandall Stewartattempting to send data to the peer. 296d8b5fd91SRandall Stewart.It Bq Er ENOENT 297d8b5fd91SRandall StewartOn a one to many style socket no address is specified 298d8b5fd91SRandall Stewartso that the association cannot be located or the 299d8b5fd91SRandall StewartSCTP_ABORT flag was specified on a non-existing association. 300d8b5fd91SRandall Stewart.It Bq Er EPIPE 301d8b5fd91SRandall StewartThe socket is unable to send anymore data 302d8b5fd91SRandall Stewart.Dv ( SBS_CANTSENDMORE 303d8b5fd91SRandall Stewarthas been set on the socket). 304d8b5fd91SRandall StewartThis typically means that the socket 305d8b5fd91SRandall Stewartis not connected and is a one-to-one style socket. 306d8b5fd91SRandall Stewart.El 307d8b5fd91SRandall Stewart.Sh SEE ALSO 308d8b5fd91SRandall Stewart.Xr sctp 4 , 309d8b5fd91SRandall Stewart.Xr sendmsg 2 , 310d8b5fd91SRandall Stewart.Xr sctp_sendmsg 3 , 311d8b5fd91SRandall Stewart.Xr sctp_recvmsg 3 , 312d8b5fd91SRandall Stewart.Xr sctp_connectx 3 , 313d8b5fd91SRandall Stewart.Xr getsockopt 2 , 314d8b5fd91SRandall Stewart.Xr recv 2 , 315d8b5fd91SRandall Stewart.Xr select 2 , 316d8b5fd91SRandall Stewart.Xr socket 2 , 317d8b5fd91SRandall Stewart.Xr write 2 318d8b5fd91SRandall Stewart.Sh BUGS 319d8b5fd91SRandall StewartBecause 320d8b5fd91SRandall Stewart.Fn sctp_send 321d8b5fd91SRandall Stewartmay have multiple associations under one endpoint, a 322d8b5fd91SRandall Stewartselect on write will only work for a one-to-one style 323d8b5fd91SRandall Stewartsocket. 324d8b5fd91SRandall Stewart 325