gio/auto/ip_tos_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 type of service (ToS) byte of an IPv4 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_IPV4` family with
18 /// `G_SOCKET_TYPE_DATAGRAM` type). The message is not meant for sending. To set
19 /// ToS 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_IP, IP_TOS, <ToS value>, &error);
24 /// ```
25 ///
26 /// # Implements
27 ///
28 /// [`SocketControlMessageExt`][trait@crate::prelude::SocketControlMessageExt], [`trait@glib::ObjectExt`], [`SocketControlMessageExtManual`][trait@crate::prelude::SocketControlMessageExtManual]
29 #[doc(alias = "GIPTosMessage")]
30 pub struct IPTosMessage(Object<ffi::GIPTosMessage, ffi::GIPTosMessageClass>) @extends SocketControlMessage;
31
32 match fn {
33 type_ => || ffi::g_ip_tos_message_get_type(),
34 }
35}
36
37impl IPTosMessage {
38 /// Creates a new type-of-service 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 type-of-service message
47 #[doc(alias = "g_ip_tos_message_new")]
48 pub fn new(dscp: u8, ecn: EcnCodePoint) -> IPTosMessage {
49 unsafe {
50 SocketControlMessage::from_glib_full(ffi::g_ip_tos_message_new(dscp, ecn.into_glib()))
51 .unsafe_cast()
52 }
53 }
54
55 /// Gets the differentiated services code point stored in @self.
56 ///
57 /// # Returns
58 ///
59 /// A DSCP value as described in [RFC 2474](https://www.rfc-editor.org/rfc/rfc2474.html#section-3).
60 #[doc(alias = "g_ip_tos_message_get_dscp")]
61 #[doc(alias = "get_dscp")]
62 pub fn dscp(&self) -> u8 {
63 unsafe { ffi::g_ip_tos_message_get_dscp(self.to_glib_none().0) }
64 }
65
66 /// Gets the Explicit Congestion Notification code point stored in @self.
67 ///
68 /// # Returns
69 ///
70 /// An ECN value as described in [RFC 3168](https://www.rfc-editor.org/rfc/rfc3168#section-5).
71 #[doc(alias = "g_ip_tos_message_get_ecn")]
72 #[doc(alias = "get_ecn")]
73 pub fn ecn(&self) -> EcnCodePoint {
74 unsafe { from_glib(ffi::g_ip_tos_message_get_ecn(self.to_glib_none().0)) }
75 }
76}