gio/auto/
inet_socket_address.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::{ffi, InetAddress, SocketAddress, SocketConnectable};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// An IPv4 or IPv6 socket address. That is, the combination of a
10    /// [`InetAddress`][crate::InetAddress] and a port number.
11    ///
12    /// In UNIX terms, `GInetSocketAddress` corresponds to a
13    /// [`struct sockaddr_in` or `struct sockaddr_in6`](man:sockaddr(3type)).
14    ///
15    /// ## Properties
16    ///
17    ///
18    /// #### `address`
19    ///  The address.
20    ///
21    /// Readable | Writeable | Construct Only
22    ///
23    ///
24    /// #### `flowinfo`
25    ///  The `sin6_flowinfo` field, for IPv6 addresses.
26    ///
27    /// Readable | Writeable | Construct Only
28    ///
29    ///
30    /// #### `port`
31    ///  The port.
32    ///
33    /// Readable | Writeable | Construct Only
34    ///
35    ///
36    /// #### `scope-id`
37    ///  The `sin6_scope_id` field, for IPv6 addresses.
38    ///
39    /// Readable | Writeable | Construct Only
40    /// <details><summary><h4>SocketAddress</h4></summary>
41    ///
42    ///
43    /// #### `family`
44    ///  The family of the socket address.
45    ///
46    /// Readable
47    /// </details>
48    ///
49    /// # Implements
50    ///
51    /// [`InetSocketAddressExt`][trait@crate::prelude::InetSocketAddressExt], [`SocketAddressExt`][trait@crate::prelude::SocketAddressExt], [`trait@glib::ObjectExt`], [`SocketConnectableExt`][trait@crate::prelude::SocketConnectableExt]
52    #[doc(alias = "GInetSocketAddress")]
53    pub struct InetSocketAddress(Object<ffi::GInetSocketAddress, ffi::GInetSocketAddressClass>) @extends SocketAddress, @implements SocketConnectable;
54
55    match fn {
56        type_ => || ffi::g_inet_socket_address_get_type(),
57    }
58}
59
60impl InetSocketAddress {
61    pub const NONE: Option<&'static InetSocketAddress> = None;
62
63    /// Creates a new #GInetSocketAddress for @address and @port.
64    /// ## `address`
65    /// a #GInetAddress
66    /// ## `port`
67    /// a port number
68    ///
69    /// # Returns
70    ///
71    /// a new #GInetSocketAddress
72    #[doc(alias = "g_inet_socket_address_new")]
73    pub fn new(address: &impl IsA<InetAddress>, port: u16) -> InetSocketAddress {
74        unsafe {
75            SocketAddress::from_glib_full(ffi::g_inet_socket_address_new(
76                address.as_ref().to_glib_none().0,
77                port,
78            ))
79            .unsafe_cast()
80        }
81    }
82
83    /// Creates a new #GInetSocketAddress for @address and @port.
84    ///
85    /// If @address is an IPv6 address, it can also contain a scope ID
86    /// (separated from the address by a `%`).
87    /// ## `address`
88    /// the string form of an IP address
89    /// ## `port`
90    /// a port number
91    ///
92    /// # Returns
93    ///
94    /// a new #GInetSocketAddress,
95    /// or [`None`] if @address cannot be parsed.
96    #[doc(alias = "g_inet_socket_address_new_from_string")]
97    #[doc(alias = "new_from_string")]
98    pub fn from_string(address: &str, port: u32) -> Option<InetSocketAddress> {
99        unsafe {
100            Option::<SocketAddress>::from_glib_full(ffi::g_inet_socket_address_new_from_string(
101                address.to_glib_none().0,
102                port,
103            ))
104            .map(|o| o.unsafe_cast())
105        }
106    }
107}
108
109unsafe impl Send for InetSocketAddress {}
110unsafe impl Sync for InetSocketAddress {}
111
112/// Trait containing all [`struct@InetSocketAddress`] methods.
113///
114/// # Implementors
115///
116/// [`InetSocketAddress`][struct@crate::InetSocketAddress], [`ProxyAddress`][struct@crate::ProxyAddress]
117pub trait InetSocketAddressExt: IsA<InetSocketAddress> + 'static {
118    /// Gets @self's #GInetAddress.
119    ///
120    /// # Returns
121    ///
122    /// the #GInetAddress for @self, which must be
123    /// g_object_ref()'d if it will be stored
124    #[doc(alias = "g_inet_socket_address_get_address")]
125    #[doc(alias = "get_address")]
126    fn address(&self) -> InetAddress {
127        unsafe {
128            from_glib_none(ffi::g_inet_socket_address_get_address(
129                self.as_ref().to_glib_none().0,
130            ))
131        }
132    }
133
134    /// Gets the `sin6_flowinfo` field from @self,
135    /// which must be an IPv6 address.
136    ///
137    /// # Returns
138    ///
139    /// the flowinfo field
140    #[doc(alias = "g_inet_socket_address_get_flowinfo")]
141    #[doc(alias = "get_flowinfo")]
142    fn flowinfo(&self) -> u32 {
143        unsafe { ffi::g_inet_socket_address_get_flowinfo(self.as_ref().to_glib_none().0) }
144    }
145
146    /// Gets @self's port.
147    ///
148    /// # Returns
149    ///
150    /// the port for @self
151    #[doc(alias = "g_inet_socket_address_get_port")]
152    #[doc(alias = "get_port")]
153    fn port(&self) -> u16 {
154        unsafe { ffi::g_inet_socket_address_get_port(self.as_ref().to_glib_none().0) }
155    }
156
157    /// Gets the `sin6_scope_id` field from @self,
158    /// which must be an IPv6 address.
159    ///
160    /// # Returns
161    ///
162    /// the scope id field
163    #[doc(alias = "g_inet_socket_address_get_scope_id")]
164    #[doc(alias = "get_scope_id")]
165    #[doc(alias = "scope-id")]
166    fn scope_id(&self) -> u32 {
167        unsafe { ffi::g_inet_socket_address_get_scope_id(self.as_ref().to_glib_none().0) }
168    }
169}
170
171impl<O: IsA<InetSocketAddress>> InetSocketAddressExt for O {}