Skip to main content

gio/auto/
ipv6_tclass_message.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{EcnCodePoint, SocketControlMessage, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// Contains the Traffic Class byte of an IPv6 header.
10    ///
11    /// This consists of the DSCP field as per
12    /// [RFC 2474](https://www.rfc-editor.org/rfc/rfc2474#section-3),
13    /// and the ECN field as per
14    /// [RFC 3168](https://www.rfc-editor.org/rfc/rfc3168#section-5).
15    ///
16    /// It may be received using [`SocketExtManual::receive_message()`][crate::prelude::SocketExtManual::receive_message()] over UDP sockets
17    /// (i.e. sockets in the `G_SOCKET_FAMILY_IPV6` family with
18    /// `G_SOCKET_TYPE_DATAGRAM` type). The message is not meant for sending. To set
19    /// Traffic Class field to be used in datagrams sent on a [`Socket`][crate::Socket] use:
20    /// **⚠️ The following code is in c ⚠️**
21    ///
22    /// ```c
23    /// g_socket_set_option (socket, IPPROTO_IPV6, IPV6_TCLASS, <TC value>, &error);
24    /// ```
25    ///
26    /// # Implements
27    ///
28    /// [`SocketControlMessageExt`][trait@crate::prelude::SocketControlMessageExt], [`trait@glib::ObjectExt`], [`SocketControlMessageExtManual`][trait@crate::prelude::SocketControlMessageExtManual]
29    #[doc(alias = "GIPv6TclassMessage")]
30    pub struct IPv6TclassMessage(Object<ffi::GIPv6TclassMessage, ffi::GIPv6TclassMessageClass>) @extends SocketControlMessage;
31
32    match fn {
33        type_ => || ffi::g_ipv6_tclass_message_get_type(),
34    }
35}
36
37impl IPv6TclassMessage {
38    /// Creates a new traffic class message with given DSCP and ECN values.
39    /// ## `dscp`
40    /// the DSCP value of the message
41    /// ## `ecn`
42    /// the ECN value of the message
43    ///
44    /// # Returns
45    ///
46    /// a new traffic class message
47    #[doc(alias = "g_ipv6_tclass_message_new")]
48    pub fn new(dscp: u8, ecn: EcnCodePoint) -> IPv6TclassMessage {
49        unsafe {
50            SocketControlMessage::from_glib_full(ffi::g_ipv6_tclass_message_new(
51                dscp,
52                ecn.into_glib(),
53            ))
54            .unsafe_cast()
55        }
56    }
57
58    /// Gets the differentiated services code point stored in @self.
59    ///
60    /// # Returns
61    ///
62    /// A DSCP value as described in [RFC 2474](https://www.rfc-editor.org/rfc/rfc2474.html#section-3).
63    #[doc(alias = "g_ipv6_tclass_message_get_dscp")]
64    #[doc(alias = "get_dscp")]
65    pub fn dscp(&self) -> u8 {
66        unsafe { ffi::g_ipv6_tclass_message_get_dscp(self.to_glib_none().0) }
67    }
68
69    /// Gets the Explicit Congestion Notification code point stored in @self.
70    ///
71    /// # Returns
72    ///
73    /// An ECN value as described in [RFC 3168](https://www.rfc-editor.org/rfc/rfc3168#section-5).
74    #[doc(alias = "g_ipv6_tclass_message_get_ecn")]
75    #[doc(alias = "get_ecn")]
76    pub fn ecn(&self) -> EcnCodePoint {
77        unsafe { from_glib(ffi::g_ipv6_tclass_message_get_ecn(self.to_glib_none().0)) }
78    }
79}