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. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.Dd February 2, 2024 29.Dt SCTP_SEND 3 30.Os 31.Sh NAME 32.Nm sctp_send , 33.Nm sctp_sendx , 34.Nm sctp_sendv 35.Nd send a message from an SCTP socket 36.Sh LIBRARY 37.Lb libc 38.Sh SYNOPSIS 39.In sys/types.h 40.In sys/socket.h 41.In netinet/sctp.h 42.Ft ssize_t 43.Fo sctp_send 44.Fa "int sd" "const void *msg" "size_t len" 45.Fa "const struct sctp_sndrcvinfo *sinfo" "int flags" 46.Fc 47.Ft ssize_t 48.Fo sctp_sendx 49.Fa "int sd" "const void *msg" "size_t len" "struct sockaddr *addrs" 50.Fa "int addrcnt" "const struct sctp_sndrcvinfo *sinfo" "int flags" 51.Fc 52.Ft ssize_t 53.Fo sctp_sendv 54.Fa "int sd" "const struct iovec *iov" "int iocnt" "struct sockaddr *addrs" 55.Fa "int addrcnt" "void *info" "socklen_t infolen" "unsigned int infotype" 56.Fa "int flags" 57.Fc 58.Sh DESCRIPTION 59The 60.Fn sctp_send 61system call 62is used to transmit a message to another SCTP endpoint. 63The 64.Fn sctp_sendx 65function is used to specify multiple peer addresses when creating an implicit 66association, as in 67.Xr sctp_connectx 3 . 68The 69.Fn sctp_sendv 70function is used to transmit a message whose data is gathered from the 71provided I/O buffers. 72.Pp 73.Fn sctp_send 74may be used to send data to an existing association for both 75one-to-many (SOCK_SEQPACKET) and one-to-one (SOCK_STREAM) socket types. 76The length of the message 77.Fa msg 78is given by 79.Fa len . 80If the message is too long to pass atomically through the 81underlying protocol, 82.Va errno 83is set to 84.Er EMSGSIZE , 85-1 is returned, and 86the message is not transmitted. 87.Pp 88No indication of failure to deliver is implicit in a 89.Fn sctp_send . 90Locally detected errors are indicated by a return value of -1. 91.Pp 92If no space is available at the socket to hold 93the message to be transmitted, then 94.Fn sctp_send 95normally blocks, unless the socket has been placed in 96non-blocking I/O mode. 97The 98.Xr select 2 99system call may be used to determine when it is possible to 100send more data on one-to-one type (SOCK_STREAM) sockets. 101.Pp 102The 103.Fa sinfo 104structure is used to control various SCTP features 105and has the following format: 106.Bd -literal 107struct sctp_sndrcvinfo { 108 uint16_t sinfo_stream; /* Stream sending to */ 109 uint16_t sinfo_ssn; /* valid for recv only */ 110 uint16_t sinfo_flags; /* flags to control sending */ 111 uint32_t sinfo_ppid; /* ppid field */ 112 uint32_t sinfo_context; /* context field */ 113 uint32_t sinfo_timetolive; /* timetolive for PR-SCTP */ 114 uint32_t sinfo_tsn; /* valid for recv only */ 115 uint32_t sinfo_cumtsn; /* valid for recv only */ 116 sctp_assoc_t sinfo_assoc_id; /* The association id */ 117}; 118.Ed 119.Pp 120The 121.Fa sinfo->sinfo_ppid 122argument is an opaque 32 bit value that is passed transparently 123through the stack to the peer endpoint. 124It will be available on reception of a message (see 125.Xr sctp_recvmsg 3 ) . 126Note that the stack passes this value without regard to byte 127order. 128.Pp 129The 130.Fa sinfo->sinfo_flags 131argument may include one or more of the following: 132.Bd -literal 133#define SCTP_EOF 0x0100 /* Start a shutdown procedures */ 134#define SCTP_ABORT 0x0200 /* Send an ABORT to peer */ 135#define SCTP_UNORDERED 0x0400 /* Message is un-ordered */ 136#define SCTP_ADDR_OVER 0x0800 /* Override the primary-address */ 137#define SCTP_SENDALL 0x1000 /* Send this on all associations */ 138 /* for the endpoint */ 139/* The lower byte is an enumeration of PR-SCTP policies */ 140#define SCTP_PR_SCTP_TTL 0x0001 /* Time based PR-SCTP */ 141#define SCTP_PR_SCTP_BUF 0x0002 /* Buffer based PR-SCTP */ 142#define SCTP_PR_SCTP_RTX 0x0003 /* Number of retransmissions based PR-SCTP */ 143.Ed 144.Pp 145The flag 146.Dv SCTP_EOF 147is used to instruct the SCTP stack to queue this message 148and then start a graceful shutdown of the association. 149All 150remaining data in queue will be sent after which the association 151will be shut down. 152.Pp 153.Dv SCTP_ABORT 154is used to immediately terminate an association. 155An abort 156is sent to the peer and the local TCB is destroyed. 157.Pp 158.Dv SCTP_UNORDERED 159is used to specify that the message being sent has no 160specific order and should be delivered to the peer application 161as soon as possible. 162When this flag is absent messages 163are delivered in order within the stream they are sent, but without 164respect to order to peer streams. 165.Pp 166The flag 167.Dv SCTP_ADDR_OVER 168is used to specify that a specific address should be used. 169Normally 170SCTP will use only one of a multi-homed peers addresses as the primary 171address to send to. 172By default, no matter what the 173.Fa to 174argument is, this primary address is used to send data. 175By specifying 176this flag, the user is asking the stack to ignore the primary address 177and instead use the specified address not only as a lookup mechanism 178to find the association but also as the actual address to send to. 179.Pp 180For a one-to-many type (SOCK_SEQPACKET) socket the flag 181.Dv SCTP_SENDALL 182can be used as a convenient way to make one send call and have 183all associations that are under the socket get a copy of the message. 184Note that this mechanism is quite efficient and makes only one actual 185copy of the data which is shared by all the associations for sending. 186.Pp 187The remaining flags are used for the partial reliability extension (RFC3758) 188and will only be effective if the peer endpoint supports this extension. 189This option specifies what local policy the local endpoint should use 190in skipping data. 191If none of these options are set, then data is 192never skipped over. 193.Pp 194.Dv SCTP_PR_SCTP_TTL 195is used to indicate that a time based lifetime is being applied 196to the data. 197The 198.Fa sinfo->sinfo_timetolive 199argument is then a number of milliseconds for which the data is 200attempted to be transmitted. 201If that many milliseconds elapse 202and the peer has not acknowledged the data, the data will be 203skipped and no longer transmitted. 204Note that this policy does 205not even assure that the data will ever be sent. 206In times of a congestion 207with large amounts of data being queued, the 208.Fa sinfo->sinfo_timetolive 209may expire before the first transmission is ever made. 210.Pp 211The 212.Dv SCTP_PR_SCTP_BUF 213based policy transforms the 214.Fa sinfo->sinfo_timetolive 215field into a total number of bytes allowed on the outbound 216send queue. 217If that number or more bytes are in queue, then 218other buffer-based sends are looked to be removed and 219skipped. 220Note that this policy may also result in the data 221never being sent if no buffer based sends are in queue and 222the maximum specified by 223.Fa timetolive 224bytes is in queue. 225.Pp 226The 227.Dv SCTP_PR_SCTP_RTX 228policy transforms the 229.Fa sinfo->sinfo_timetolive 230into a number of retransmissions to allow. 231This policy 232always assures that at a minimum one send attempt is 233made of the data. 234After which no more than 235.Fa sinfo->sinfo_timetolive 236retransmissions will be made before the data is skipped. 237.Pp 238.Fa sinfo->sinfo_stream 239is the SCTP stream that you wish to send the 240message on. 241Streams in SCTP are reliable (or partially reliable) flows of ordered 242messages. 243.Pp 244The 245.Fa sinfo->sinfo_assoc_id 246field is used to 247select the association to send to on a one-to-many socket. 248For a one-to-one socket, this field is ignored. 249.Pp 250The 251.Fa sinfo->sinfo_context 252field is used only in the event the message cannot be sent. 253This is an opaque 254value that the stack retains and will give to the user when a failed send 255is given if that notification is enabled (see 256.Xr sctp 4 ) . 257Normally a user process can use this value to index some application 258specific data structure when a send cannot be fulfilled. 259.Pp 260The 261.Fa flags 262argument holds the same meaning and values as those found in 263.Xr sendmsg 2 264but is generally ignored by SCTP. 265.Pp 266The fields 267.Fa sinfo->sinfo_ssn , 268.Fa sinfo->sinfo_tsn , 269and 270.Fa sinfo->sinfo_cumtsn 271are used only when receiving messages and are thus ignored by 272.Fn sctp_send . 273.Pp 274The function 275.Fn sctp_sendx 276has the same properties as 277.Fn sctp_send 278with the additional arguments of an array of sockaddr structures 279passed in. 280With the 281.Fa addrs 282argument being given as an array of addresses to be sent to and 283the 284.Fa addrcnt 285argument indicating how many socket addresses are in the passed 286in array. 287Note that all of the addresses will only be used 288when an implicit association is being set up. 289This allows the 290user the equivalent behavior as doing a 291.Fn sctp_connectx 292followed by a 293.Fn sctp_send 294to the association. 295Note that if the 296.Fa sinfo->sinfo_assoc_id 297field is 0, then the first address will be used to look up 298the association in place of the association id. 299If both 300an address and an association id are specified, the association 301id has priority. 302.Pp 303The function 304.Fn sctp_sendv 305works as 306.Fn sctp_sendx , 307with two differences. 308Firstly, the data to be written is passed as an array containing 309.Vt iocnt 310objects of type 311.Vt struct iovec , 312which will be gathered for sending in the same manner as 313.Xr writev 2 . 314Secondly, the 315.Fa info 316argument is replaced by the tuple 317.Fa sinfo , 318.Fa infolen , 319.Fa infotype , 320where 321.Fa sinfo 322is a pointer to a struct of size 323.Fa infolen 324whose type is indicated by the 325.Fa infotype 326argument. 327.Pp 328If no information is passed, set 329.Fa infotype 330to 331.Va SCTP_SENDV_NOINFO . 332.Fa sinfo 333may be a null pointer. 334.Pp 335If 336.Fa sinfo 337points to a 338.Vt struct sctp_sndinfo , 339set 340.Fa infotype 341to 342.Va SCTP_SENDV_SNDINFO . 343The 344.Vt sctp_sndinfo 345structure has the following format: 346.Bd -literal 347struct sctp_sndinfo { 348 uint16_t snd_sid; /* stream identifier */ 349 uint16_t snd_flags; /* Flags */ 350 uint32_t snd_ppid; /* ppid field */ 351 uint32_t snd_context; /* context field */ 352 sctp_assoc_t snd_assoc_id; /* association id */ 353}; 354.Ed 355.Pp 356The meaning of these fields is the same as in 357.Vt struct sctp_sndrcvinfo , 358described above. 359.Pp 360If 361.Fa sinfo 362points to a 363.Vt struct sctp_authinfo , 364set 365.Fa infotype 366to 367.Va SCTP_SENDV_AUTHINFO . 368The 369.Vt sctp_authinfo 370struct has the following format: 371.Bd -literal 372struct sctp_authinfo { 373 uint16_t auth_keynumber; /* Shared key identifier */ 374}; 375.Ed 376.Pp 377The 378.Va auth_keynumber 379field specifies the shared key identifier that will be used for sending the 380message. 381.Pp 382If 383.Fa sinfo 384points to a 385.Vt struct sctp_prinfo , 386set 387.Fa infotype 388to 389.Va SCTP_SENDV_PRINFO . 390The 391.Vt sctp_prinfo 392structure has the following format: 393.Bd -literal 394struct sctp_prinfo { 395 uint16_t pr_policy; /* PR-SCTP policy */ 396 uint32_t pr_value; /* PR-SCTP Policy option */ 397}; 398.Ed 399.Pp 400The 401.Va pr_policy 402field should be set to either 403.Va SCTP_PR_SCTP_NONE 404to use reliable transmission (in which case the field 405.Va pr_value 406is ignored), or 407.Va SCTP_PR_SCTP_TTL 408to use RFC 3758 timed reliability, in which case the field 409.Va pr_value 410contains the lifetime in milliseconds. 411.Pp 412To pass two or more types in 413.Fa sinfo , 414set 415.Fa infotype 416to 417.Va SCTP_SENDV_SPA 418and pass a pointer to a 419.Vt struct sctp_sendv_spa 420in 421.Fa sinfo . 422The 423.Ft sctp_sendv_spa 424structure has the following format: 425.Bd -literal 426struct sctp_sendv_spa { 427 uint32_t sendv_flags; 428 struct sctp_sndinfo sendv_sndinfo; 429 struct sctp_prinfo sendv_prinfo; 430 struct sctp_authinfo sendv_authinfo; 431}; 432.Ed 433.Pp 434The 435.Va sendv_flags 436member should be set to the bitwise OR of the flags 437.Va SCTP_SEND_SNDINFO_VALID , 438.Va SCTP_SEND_PRINFO_VALID , 439and 440.Va SCTP_SEND_AUTHINFO_VALID 441to indicate which fields of the struct contain valid data. 442.Pp 443If 444.Fa infotype 445is set to SCTP_SENDV_NOINFO, the 446.Fa infolen 447argument should be set to zero. 448Otherwise, 449.Fa infolen 450should be set to the length of the data structure pointed to by 451.Fa info . 452.Sh RETURN VALUES 453The call returns the number of characters sent, or -1 454if an error occurred. 455.Sh ERRORS 456The 457.Fn sctp_send 458system call 459fails if: 460.Bl -tag -width Er 461.It Bq Er EBADF 462An invalid descriptor was specified. 463.It Bq Er ENOTSOCK 464The argument 465.Fa s 466is not a socket. 467.It Bq Er EFAULT 468An invalid user space address was specified for an argument. 469.It Bq Er EMSGSIZE 470The socket requires that message be sent atomically, 471and the size of the message to be sent made this impossible. 472.It Bq Er EAGAIN 473The socket is marked non-blocking and the requested operation 474would block. 475.It Bq Er ENOBUFS 476The system was unable to allocate an internal buffer. 477The operation may succeed when buffers become available. 478.It Bq Er ENOBUFS 479The output queue for a network interface was full. 480This generally indicates that the interface has stopped sending, 481but may be caused by transient congestion. 482.It Bq Er EHOSTUNREACH 483The remote host was unreachable. 484.It Bq Er ENOTCONN 485On a one-to-one style socket no association exists. 486.It Bq Er ECONNRESET 487An abort was received by the stack while the user was 488attempting to send data to the peer. 489.It Bq Er ENOENT 490On a one-to-many style socket no address is specified 491so that the association cannot be located or the 492SCTP_ABORT flag was specified on a non-existing association. 493.It Bq Er EPIPE 494The socket is unable to send anymore data 495.Dv ( SBS_CANTSENDMORE 496has been set on the socket). 497This typically means that the socket 498is not connected and is a one-to-one style socket. 499.El 500.Sh NOTES 501The functions 502.Fn sctp_send 503and 504.Fn sctp_sendx 505are deprecated. 506New applications should use 507.Fn sctp_sendv . 508.Sh SEE ALSO 509.Xr getsockopt 2 , 510.Xr recv 2 , 511.Xr select 2 , 512.Xr sendmsg 2 , 513.Xr socket 2 , 514.Xr write 2 , 515.Xr sctp_connectx 3 , 516.Xr sctp_recvmsg 3 , 517.Xr sctp_sendmsg 3 , 518.Xr sctp 4 519.Rs 520.%A R. Stewart 521.%A M. Tuexen 522.%A K. Poon 523.%A P. Lei 524.%A V. Yasevich 525.%T Sockets API Extensions for the Stream Control Transmission Protocol (SCTP) 526.%R RFC 6458 527.%D December 2011 528.Re 529.Sh STANDARDS 530The functions described in this document conform to RFC 6458. 531.Sh BUGS 532Because 533.Fn sctp_send 534may have multiple associations under one endpoint, a 535select on write will only work for a one-to-one style 536socket. 537