@@ -32,6 +32,26 @@ pub use self::datalink::LinkAddr;
32
32
#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
33
33
pub use self :: vsock:: VsockAddr ;
34
34
35
+ /// Convert a std::net::Ipv4Addr into the libc form.
36
+ #[ cfg( feature = "net" ) ]
37
+ pub ( crate ) fn ipv4addr_to_libc ( addr : net:: Ipv4Addr ) -> libc:: in_addr {
38
+ let octets = addr. octets ( ) ;
39
+ libc:: in_addr {
40
+ s_addr : u32:: to_be ( ( ( octets[ 0 ] as u32 ) << 24 ) |
41
+ ( ( octets[ 1 ] as u32 ) << 16 ) |
42
+ ( ( octets[ 2 ] as u32 ) << 8 ) |
43
+ ( octets[ 3 ] as u32 ) )
44
+ }
45
+ }
46
+
47
+ /// Convert a std::net::Ipv6Addr into the libc form.
48
+ #[ cfg( feature = "net" ) ]
49
+ pub ( crate ) const fn ipv6addr_to_libc ( addr : & net:: Ipv6Addr ) -> libc:: in6_addr {
50
+ libc:: in6_addr {
51
+ s6_addr : addr. octets ( )
52
+ }
53
+ }
54
+
35
55
/// These constants specify the protocol family to be used
36
56
/// in [`socket`](fn.socket.html) and [`socketpair`](fn.socketpair.html)
37
57
///
@@ -497,14 +517,20 @@ impl fmt::Display for InetAddr {
497
517
* ===== IpAddr =====
498
518
*
499
519
*/
500
- #[ allow( missing_docs) ] // https://github.com/nix-rust/nix/issues/1681
520
+ #[ allow( missing_docs) ] // Since they're all deprecated anyway
521
+ #[ allow( deprecated) ]
501
522
#[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
523
+ #[ deprecated(
524
+ since = "0.24.0" ,
525
+ note = "Use std::net::IpAddr instead"
526
+ ) ]
502
527
pub enum IpAddr {
503
528
V4 ( Ipv4Addr ) ,
504
529
V6 ( Ipv6Addr ) ,
505
530
}
506
531
507
- #[ allow( missing_docs) ] // https://github.com/nix-rust/nix/issues/1681
532
+ #[ allow( deprecated) ]
533
+ #[ allow( missing_docs) ] // Since they're all deprecated anyway
508
534
impl IpAddr {
509
535
/// Create a new IpAddr that contains an IPv4 address.
510
536
///
@@ -537,6 +563,7 @@ impl IpAddr {
537
563
}
538
564
}
539
565
566
+ #[ allow( deprecated) ]
540
567
impl fmt:: Display for IpAddr {
541
568
fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
542
569
match * self {
@@ -552,12 +579,17 @@ impl fmt::Display for IpAddr {
552
579
*
553
580
*/
554
581
555
- #[ allow( missing_docs) ] // https://github.com/nix-rust/nix/issues/1681
582
+ #[ deprecated(
583
+ since = "0.24.0" ,
584
+ note = "Use std::net::Ipv4Addr instead"
585
+ ) ]
586
+ #[ allow( missing_docs) ] // Since they're all deprecated anyway
556
587
#[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
557
588
#[ repr( transparent) ]
558
589
pub struct Ipv4Addr ( pub libc:: in_addr) ;
559
590
560
- #[ allow( missing_docs) ] // https://github.com/nix-rust/nix/issues/1681
591
+ #[ allow( deprecated) ]
592
+ #[ allow( missing_docs) ] // Since they're all deprecated anyway
561
593
impl Ipv4Addr {
562
594
#[ allow( clippy:: identity_op) ] // More readable this way
563
595
pub const fn new( a: u8 , b: u8 , c: u8 , d: u8 ) -> Ipv4Addr {
@@ -591,6 +623,7 @@ impl Ipv4Addr {
591
623
}
592
624
}
593
625
626
+ #[ allow( deprecated) ]
594
627
impl fmt:: Display for Ipv4Addr {
595
628
fn fmt( & self , fmt: & mut fmt:: Formatter ) -> fmt:: Result {
596
629
let octets = self . octets( ) ;
@@ -604,7 +637,11 @@ impl fmt::Display for Ipv4Addr {
604
637
*
605
638
*/
606
639
607
- #[ allow( missing_docs) ] // https://github.com/nix-rust/nix/issues/1681
640
+ #[ deprecated(
641
+ since = "0.24.0" ,
642
+ note = "Use std::net::Ipv6Addr instead"
643
+ ) ]
644
+ #[ allow( missing_docs) ] // Since they're all deprecated anyway
608
645
#[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
609
646
#[ repr( transparent) ]
610
647
pub struct Ipv6Addr ( pub libc:: in6_addr) ;
@@ -625,7 +662,8 @@ macro_rules! to_u16_array {
625
662
}
626
663
}
627
664
628
- #[ allow( missing_docs) ] // https://github.com/nix-rust/nix/issues/1681
665
+ #[ allow( deprecated) ]
666
+ #[ allow( missing_docs) ] // Since they're all deprecated anyway
629
667
impl Ipv6Addr {
630
668
#[ allow( clippy:: many_single_char_names) ]
631
669
#[ allow( clippy:: too_many_arguments) ]
@@ -649,6 +687,7 @@ impl Ipv6Addr {
649
687
}
650
688
}
651
689
690
+ #[ allow( deprecated) ]
652
691
impl fmt:: Display for Ipv6Addr {
653
692
fn fmt( & self , fmt: & mut fmt:: Formatter ) -> fmt:: Result {
654
693
self . to_std( ) . fmt( fmt)
@@ -1172,7 +1211,7 @@ impl From<net::SocketAddrV4> for SockaddrIn {
1172
1211
sin_len : mem:: size_of :: < libc:: sockaddr_in > ( ) as u8 ,
1173
1212
sin_family : AddressFamily :: Inet as sa_family_t ,
1174
1213
sin_port : addr. port ( ) . to_be ( ) , // network byte order
1175
- sin_addr : Ipv4Addr :: from_std ( addr. ip ( ) ) . 0 ,
1214
+ sin_addr : ipv4addr_to_libc ( * addr. ip ( ) ) ,
1176
1215
.. unsafe { mem:: zeroed ( ) }
1177
1216
} )
1178
1217
}
@@ -1266,7 +1305,7 @@ impl From<net::SocketAddrV6> for SockaddrIn6 {
1266
1305
sin6_len : mem:: size_of :: < libc:: sockaddr_in6 > ( ) as u8 ,
1267
1306
sin6_family : AddressFamily :: Inet6 as sa_family_t ,
1268
1307
sin6_port : addr. port ( ) . to_be ( ) , // network byte order
1269
- sin6_addr : Ipv6Addr :: from_std ( addr. ip ( ) ) . 0 ,
1308
+ sin6_addr : ipv6addr_to_libc ( addr. ip ( ) ) ,
1270
1309
sin6_flowinfo : addr. flowinfo ( ) , // host byte order
1271
1310
sin6_scope_id : addr. scope_id ( ) , // host byte order
1272
1311
.. unsafe { mem:: zeroed ( ) }
@@ -2545,6 +2584,24 @@ pub mod vsock {
2545
2584
mod tests {
2546
2585
use super :: * ;
2547
2586
2587
+ mod types {
2588
+ use super :: * ;
2589
+
2590
+ #[ test]
2591
+ fn test_ipv4addr_to_libc ( ) {
2592
+ let s = std:: net:: Ipv4Addr :: new ( 1 , 2 , 3 , 4 ) ;
2593
+ let l = ipv4addr_to_libc ( s) ;
2594
+ assert_eq ! ( l. s_addr, u32 :: to_be( 0x01020304 ) ) ;
2595
+ }
2596
+
2597
+ #[ test]
2598
+ fn test_ipv6addr_to_libc ( ) {
2599
+ let s = std:: net:: Ipv6Addr :: new ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ) ;
2600
+ let l = ipv6addr_to_libc ( & s) ;
2601
+ assert_eq ! ( l. s6_addr, [ 0 , 1 , 0 , 2 , 0 , 3 , 0 , 4 , 0 , 5 , 0 , 6 , 0 , 7 , 0 , 8 ] ) ;
2602
+ }
2603
+ }
2604
+
2548
2605
mod link {
2549
2606
#[ cfg( any( target_os = "ios" ,
2550
2607
target_os = "macos" ,
0 commit comments