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