SCTP_SENDMSG(3)

πŸ“¦
version 1.0.21 Β· 4 versions
, in arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– SCTP_SENDMSG(3) πŸ’–

okay bestie, gather round, because this one is a library function from the Linux Programmer's Manual and it's literally the glow-up version of sendmsg(2) for SCTP girlies. no cap.


✨ NAME ✨

sctp_sendmsg β€” send a message from a SCTP socket. that's it. that's the whole job. sending. slay. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/sctp.h>

int sctp_sendmsg(int sd, const void * msg, size_t len,
                 struct sockaddr *to, socklen_t tolen,
                 uint32_t ppid, uint32_t flags,
                 uint16_t stream_no, uint32_t timetolive,
                 uint32_t context);

like, look at that parameter list. it's giving "i have options and i'm not afraid to use them." ✨


🌸 DESCRIPTION 🌸

so sctp_sendmsg is a wrapper library function, which is fancy-speak for "we made it easy for you." you use it to send a message from a socket while also unlocking the advanced features of SCTP, because regular sending is boring and we don't do boring here. πŸ’–

here's the breakdown, bestie:

  • sd β€” the socket descriptor, aka where the message is coming from. the origin story.
  • msg β€” a pointer to the message itself, and len is how long that message is.
  • to β€” the destination address of the message, with tolen being the length of that destination address.
  • stream_no β€” identifies the stream number the application wants to send this message to. pick your lane, queen. 🌈
  • flags β€” a parameter composed of a bitwise OR of the values listed below. yes, OR them together. stack those flags like accessories.

πŸ”₯ the flags (aka the whole personality) πŸ”₯

  • SCTP_UNORDERED β€” this flag requests un-ordered delivery of the message. no queue, no waiting, just vibes. πŸ’€
  • SCTP_ADDR_OVER β€” in the one-to-many style, this asks the SCTP stack to override the primary destination address with the address specified in to. main character address energy only. πŸ‘‘
  • SCTP_ABORT β€” setting this causes the specified association to abort by sending an ABORT message to the peer (one-to-many style only). the ABORT chunk will contain an error cause 'User Initiated Abort' with cause code 12, and the cause specific information of this error cause is provided in msg. dramatic? yes. necessary? also yes. 🫒
  • SCTP_EOF β€” setting this invokes the SCTP graceful shutdown procedure on the specific association (one-to-many style only). leaving the group chat politely, with a proper goodbye. πŸŽ€
  • SCTP_SENDALL β€” if set, this will cause a one-to-many style socket to send the message to all associations that are currently established on this socket. for the one-to-one style socket, this flag has no effect. group message, no notes. πŸ’Œ
  • SCTP_SACK_IMMEDIATELY β€” this flag lets the application set the I bit of the last DATA chunk when sending each user message, to make sure the corresponding SACK can be sent by the peer without delay. impatient? no, efficient. ⭐
  • SCTP_PR_SCTP_{TTL|RTX|PRIO} β€” one of these 3 pr_policies can be used through this flag, with its pr_value set in the timetolive parameter for this message. and note: sctp_sendv(3) with infotype SCTP_SENDV_PRINFO also works for PR-SCTP. options on options, iykyk. πŸ¦‹

🧚 the rest of the params, because they matter too 🧚

  • timetolive β€” specifies the time duration in milliseconds. the sending side will expire the message if the message has not been sent to the peer within this time period. a value of 0 indicates that no timeout should occur on this message. it also works as the pr_value if the flags parameter is set to pr_policy. so it's multitasking. iconic.
  • ppid β€” an opaque unsigned value that is passed to the remote end along with the message. it's a little gift, an opaque little gift. 🎁
  • context β€” a 32 bit opaque value that is passed back to the upper layer along with the undelivered message if an error occurs on the send of the message. so if things go wrong, at least you get your context back. closure, fr fr. 😭

πŸ’œ RETURN VALUE πŸ’œ

on success, sctp_sendmsg returns the number of bytes sent, or -1 if an error occurred. that's it. that's the whole mood. either you ate, or you got -1. πŸ”₯


🌈 SEE ALSO 🌈

the besties, the sisters, the whole crew:


lowkey reminder bestie: the SCTP_ABORT, SCTP_EOF and SCTP_ADDR_OVER flags are one-to-many style only, and SCTP_SENDALL literally does nothing on a one-to-one style socket. read the flags before you send, or you'll be sending into the void. πŸ’€

okay and that's the page!! this was the Linux 2.6 version, dated 2004-10-25, so yeah she's vintage but she still serves. mwah, go send some messages responsibly πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά