@@ -5,14 +5,13 @@ use {Error, Result};
5
5
use errno:: Errno ;
6
6
use features;
7
7
use libc:: { self , c_void, c_int, socklen_t, size_t} ;
8
- use std:: { mem, ptr, slice} ;
8
+ use std:: { fmt , mem, ptr, slice} ;
9
9
use std:: os:: unix:: io:: RawFd ;
10
10
use sys:: time:: TimeVal ;
11
11
use sys:: uio:: IoVec ;
12
12
13
13
mod addr;
14
14
mod ffi;
15
- mod multicast;
16
15
pub mod sockopt;
17
16
18
17
/*
@@ -34,22 +33,14 @@ pub use self::addr::{
34
33
pub use :: sys:: socket:: addr:: netlink:: NetlinkAddr ;
35
34
36
35
pub use libc:: {
37
- in_addr,
38
- in6_addr,
36
+ sa_family_t,
39
37
sockaddr,
40
38
sockaddr_in,
41
39
sockaddr_in6,
40
+ sockaddr_storage,
42
41
sockaddr_un,
43
- sa_family_t,
44
- } ;
45
-
46
- pub use self :: multicast:: {
47
- ip_mreq,
48
- ipv6_mreq,
49
42
} ;
50
43
51
- pub use libc:: sockaddr_storage;
52
-
53
44
/// These constants are used to specify the communication semantics
54
45
/// when creating a socket with [`socket()`](fn.socket.html)
55
46
#[ derive( Clone , Copy , PartialEq , Eq , Debug ) ]
@@ -177,8 +168,6 @@ libc_bitflags!{
177
168
178
169
cfg_if ! {
179
170
if #[ cfg( all( target_os = "linux" , not( target_arch = "arm" ) ) ) ] {
180
- use std:: fmt;
181
-
182
171
/// Unix credentials of the sending process.
183
172
///
184
173
/// This struct is used with the `SO_PEERCRED` ancillary message for UNIX sockets.
@@ -222,6 +211,76 @@ cfg_if! {
222
211
}
223
212
}
224
213
214
+ /// Request for multicast socket operations
215
+ ///
216
+ /// This is a wrapper type around `ip_mreq`.
217
+ #[ repr( C ) ]
218
+ #[ derive( Clone , Copy ) ]
219
+ pub struct IpMembershipRequest ( libc:: ip_mreq ) ;
220
+
221
+ impl IpMembershipRequest {
222
+ /// Instantiate a new `IpMembershipRequest`
223
+ ///
224
+ /// If `interface` is `None`, then `Ipv4Addr::any()` will be used for the interface.
225
+ pub fn new ( group : Ipv4Addr , interface : Option < Ipv4Addr > ) -> Self {
226
+ IpMembershipRequest ( libc:: ip_mreq {
227
+ imr_multiaddr : group. 0 ,
228
+ imr_interface : interface. unwrap_or ( Ipv4Addr :: any ( ) ) . 0 ,
229
+ } )
230
+ }
231
+ }
232
+
233
+ impl PartialEq for IpMembershipRequest {
234
+ fn eq ( & self , other : & Self ) -> bool {
235
+ self . 0 . imr_multiaddr . s_addr == other. 0 . imr_multiaddr . s_addr
236
+ && self . 0 . imr_interface . s_addr == other. 0 . imr_interface . s_addr
237
+ }
238
+ }
239
+ impl Eq for IpMembershipRequest { }
240
+
241
+ impl fmt:: Debug for IpMembershipRequest {
242
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
243
+ f. debug_struct ( "IpMembershipRequest" )
244
+ . field ( "imr_multiaddr" , & self . 0 . imr_multiaddr . s_addr )
245
+ . field ( "imr_interface" , & self . 0 . imr_interface . s_addr )
246
+ . finish ( )
247
+ }
248
+ }
249
+
250
+ /// Request for ipv6 multicast socket operations
251
+ ///
252
+ /// This is a wrapper type around `ipv6_mreq`.
253
+ #[ repr( C ) ]
254
+ #[ derive( Clone , Copy ) ]
255
+ pub struct Ipv6MembershipRequest ( libc:: ipv6_mreq ) ;
256
+
257
+ impl Ipv6MembershipRequest {
258
+ /// Instantiate a new `Ipv6MembershipRequest`
259
+ pub fn new ( group : Ipv6Addr ) -> Self {
260
+ Ipv6MembershipRequest ( libc:: ipv6_mreq {
261
+ ipv6mr_multiaddr : group. 0 ,
262
+ ipv6mr_interface : 0 ,
263
+ } )
264
+ }
265
+ }
266
+
267
+ impl PartialEq for Ipv6MembershipRequest {
268
+ fn eq ( & self , other : & Self ) -> bool {
269
+ self . 0 . ipv6mr_multiaddr . s6_addr == other. 0 . ipv6mr_multiaddr . s6_addr &&
270
+ self . 0 . ipv6mr_interface == other. 0 . ipv6mr_interface
271
+ }
272
+ }
273
+ impl Eq for Ipv6MembershipRequest { }
274
+
275
+ impl fmt:: Debug for Ipv6MembershipRequest {
276
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
277
+ f. debug_struct ( "Ipv6MembershipRequest" )
278
+ . field ( "ipv6mr_multiaddr" , & self . 0 . ipv6mr_multiaddr . s6_addr )
279
+ . field ( "ipv6mr_interface" , & self . 0 . ipv6mr_interface )
280
+ . finish ( )
281
+ }
282
+ }
283
+
225
284
/// Copy the in-memory representation of src into the byte slice dst,
226
285
/// updating the slice to point to the remainder of dst only. Unsafe
227
286
/// because it exposes all bytes in src, which may be UB if some of them
0 commit comments