sctp_rs/
lib.rs

1//! SCTP Implementation for Rust 'async' runtimes.
2//!
3//! The Goal of this implementation is being able to use SCTP within Rust's async ecosystem. Also,
4//! this implementation is a Pure Rust implementation leveraging the kernel SCTP stack in the Linux
5//! kernel without requiring `libsctp` or similar libraries to be present and makes use of the
6//! `libc` crate for system calls. This crate implements [Socket API
7//! Extensions](https://datatracker.ietf.org/doc/html/rfc6458), that are expected in a modern
8//! implementation of SCTP stack. As a result, APIs that are marked as `DEPRECATED` in the RFC will
9//! not will not be implemented initially.
10//!
11//! Also, the APIs are designed such that they are idiomatic Rust APIs and making use of
12//! appropriate types thus making use of the [`std::net::SocketAddr`] structures wherever
13//! appropriate rather than using the [`libc::sockaddr`] structures for example.
14//!
15//! # Example
16//!
17//! The examples below will help you to get started using the APIs in your application.
18//!
19//! ```rust,no_run
20//!
21//! # #[tokio::main(flavor="current_thread")]
22//! # async fn main() -> std::io::Result<()> {
23//!
24//! // Create a TCP Style (Socket-to-association is 1-1) socket.
25//! let client = sctp_rs::Socket::new_v4(sctp_rs::SocketToAssociation::OneToOne)?;
26//!
27//! let bind_addr: std::net::SocketAddr = "127.0.0.1:8080".parse().unwrap();
28//! client.bind(bind_addr)?;
29//!
30//! // Listen on the socket listen queue size of 10. Normally this number should be considerably
31//! // higher like 100 or so.
32//! let listener = client.listen(10)?;
33//!
34//! // Accept on the socket and process data.
35//! let (accepted, _client_addr) = listener.accept().await?;
36//!
37//! loop {
38//!     let notification_or_data = accepted.sctp_recv().await?;
39//!     match notification_or_data {
40//!         sctp_rs::NotificationOrData::Notification(notification) => {
41//!             // Process Notification
42//!         },
43//!         sctp_rs::NotificationOrData::Data(data) => {
44//!             // Process Data
45//!         }
46//!     }
47//! }
48//!
49//! # Ok(())
50//! # }
51//! ```
52
53mod connected_socket;
54mod listener;
55mod socket;
56
57#[doc(inline)]
58pub use socket::Socket;
59
60#[doc(inline)]
61pub use listener::Listener;
62
63#[doc(inline)]
64pub use connected_socket::ConnectedSocket;
65
66mod internal;
67
68mod consts;
69
70mod types;
71
72#[doc(inline)]
73pub use types::{
74    AssocChangeState, AssociationChange, AssociationId, BindxFlags, CmsgType, ConnStatus, Event,
75    Notification, NotificationOrData, NxtInfo, RcvInfo, ReceivedData, SendData, SendInfo, Shutdown,
76    SocketToAssociation, SubscribeEventAssocId,
77};