With SCTP, a one-to-many socket can also be used in conjunction with the sctp_peeloff function (see Section 9.12(See 8.7.12)) to allow the iterative and concurrent server models to be combined as follows:
1.The sctp_peeloff function can be used to peel off a particular association (for example, a long-running session) from a one-to-many socket into its own one-to-one socket.
2.The one-to-one socket of the extracted association can then be dispatched to its own thread or forked process (as in the concurrent model).
3.Meanwhile, the main thread continues to handle messages from any remaining associations in an iterative fashion on the original socket.
A one-to-many-style SCTP socket is an IP socket (family AF_INET or AF_INET6) with type SOCK_SEQPACKET and protocol IPPROTO_SCTP.
An SCTP server may wish to bind a subset of IP addresses associated with the host system. Traditionally, a TCP or UDP server can bind one or all addresses on a host, but they cannot bind a subset of addresses. The sctp_bindx function provides more flexibility by allowing an SCTP socket to bind a particular subset of addresses.
#include
int sctp_bindx(int sockfd, const struct sockaddr *addrs, int addrcnt, int flags);
#include
int sctp_connectx(int sockfd, const struct sockaddr *addrs, int addrcnt);
The getpeername function was not designed with the concept of a multihoming-aware transport protocol; when using SCTP, it only returns the primary address. When all the addresses are required, the sctp_getpaddrs function provides a mechanism for an application to retrieve all the addresses of a peer.
#include
int sctp_getpaddrs(int sockfd, sctp_assoc_t id, struct sockaddr **addrs);
The sctp_freepaddrs function frees resources allocated by the sctp_getpaddrs function. It is called as follows:
#include
void sctp_freepaddrs(struct sockaddr *addrs);
The sctp_getladdrs function can be used to retrieve the local addresses that are part of an association. This function is often necessary when a local endpoint wishes to know exactly which local addresses are in use (which may be a proper subset of the system’s addresses).
#include
int sctp_getladdrs(int sockfd, sctp_assoc_t id, struct sockaddr **addrs);
The sctp_freeladdrs function frees resources allocated by the sctp_getladdrs function. It is called as follows:
#include
void sctp_freeladdrs(struct sockaddr *addrs);
An application can control various features of SCTP by using the sendmsg function along with ancillary data (described in Chapter 14(See 9.3)). However, because the use of ancillary data may be inconvenient, many SCTP implementations provide an auxiliary library call (possibly implemented as a system call) that eases an application’s use of SCTP’s advanced features. The call takes the following form:
ssize_t sctp_sendmsg(int sockfd, const void *msg, size_t msgsz, const struct sockaddr *to, socklen_t tolen, uint32_t ppid, uint32_t flags, uint16_t stream, uint32_t timetolive, uint32_t context);
Just like sctp_sendmsg, the sctp_recvmsg function provides a more user-friendly interface to the advanced SCTP features. Using this function allows a user to retrieve not only its peer’s address, but also the msg_flags field that would normally accompany the recvmsg function call (e.g., MSG_NOTIFICATION, MSG_EOR, etc.). The function also allows the user to retrieve the sctp_sndrcvinfo structure that accompanies the message that was read into the message buffer. Note that if an application wishes to receive sctp_sndrcvinfo information, the sctp_data_io_event must be subscribed to with the SCTP_EVENTS socket option (ON by default). The sctp_recvmsg function takes the following form:
ssize_t sctp_recvmsg(int sockfd, void *msg, size_t msgsz, struct sockaddr *from, socklen_t *fromlen, struct sctp_sndrcvinfo *sinfo, int *msg_flags);