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