File tree 2 files changed +35
-31
lines changed
2 files changed +35
-31
lines changed Original file line number Diff line number Diff line change @@ -596,37 +596,6 @@ impl<I: Into<IpAddr>> From<(I, u16)> for SocketAddr {
596
596
}
597
597
}
598
598
599
- /// A type with the same memory layout as `c::sockaddr`. Used in converting Rust level
600
- /// SocketAddr* types into their system representation. The benefit of this specific
601
- /// type over using `c::sockaddr_storage` is that this type is exactly as large as it
602
- /// needs to be and not a lot larger. And it can be initialized more cleanly from Rust.
603
- #[ repr( C ) ]
604
- pub ( crate ) union SocketAddrCRepr {
605
- v4 : c:: sockaddr_in ,
606
- v6 : c:: sockaddr_in6 ,
607
- }
608
-
609
- impl SocketAddrCRepr {
610
- pub fn as_ptr ( & self ) -> * const c:: sockaddr {
611
- self as * const _ as * const c:: sockaddr
612
- }
613
- }
614
-
615
- impl < ' a > IntoInner < ( SocketAddrCRepr , c:: socklen_t ) > for & ' a SocketAddr {
616
- fn into_inner ( self ) -> ( SocketAddrCRepr , c:: socklen_t ) {
617
- match * self {
618
- SocketAddr :: V4 ( ref a) => {
619
- let sockaddr = SocketAddrCRepr { v4 : a. into_inner ( ) } ;
620
- ( sockaddr, mem:: size_of :: < c:: sockaddr_in > ( ) as c:: socklen_t )
621
- }
622
- SocketAddr :: V6 ( ref a) => {
623
- let sockaddr = SocketAddrCRepr { v6 : a. into_inner ( ) } ;
624
- ( sockaddr, mem:: size_of :: < c:: sockaddr_in6 > ( ) as c:: socklen_t )
625
- }
626
- }
627
- }
628
- }
629
-
630
599
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
631
600
impl fmt:: Display for SocketAddr {
632
601
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
Original file line number Diff line number Diff line change @@ -700,3 +700,38 @@ impl fmt::Debug for UdpSocket {
700
700
res. field ( name, & self . inner . as_raw ( ) ) . finish ( )
701
701
}
702
702
}
703
+
704
+ ////////////////////////////////////////////////////////////////////////////////
705
+ // Converting SocketAddr to libc representation
706
+ ////////////////////////////////////////////////////////////////////////////////
707
+
708
+ /// A type with the same memory layout as `c::sockaddr`. Used in converting Rust level
709
+ /// SocketAddr* types into their system representation. The benefit of this specific
710
+ /// type over using `c::sockaddr_storage` is that this type is exactly as large as it
711
+ /// needs to be and not a lot larger. And it can be initialized more cleanly from Rust.
712
+ #[ repr( C ) ]
713
+ pub ( crate ) union SocketAddrCRepr {
714
+ v4 : c:: sockaddr_in ,
715
+ v6 : c:: sockaddr_in6 ,
716
+ }
717
+
718
+ impl SocketAddrCRepr {
719
+ pub fn as_ptr ( & self ) -> * const c:: sockaddr {
720
+ self as * const _ as * const c:: sockaddr
721
+ }
722
+ }
723
+
724
+ impl < ' a > IntoInner < ( SocketAddrCRepr , c:: socklen_t ) > for & ' a SocketAddr {
725
+ fn into_inner ( self ) -> ( SocketAddrCRepr , c:: socklen_t ) {
726
+ match * self {
727
+ SocketAddr :: V4 ( ref a) => {
728
+ let sockaddr = SocketAddrCRepr { v4 : a. into_inner ( ) } ;
729
+ ( sockaddr, mem:: size_of :: < c:: sockaddr_in > ( ) as c:: socklen_t )
730
+ }
731
+ SocketAddr :: V6 ( ref a) => {
732
+ let sockaddr = SocketAddrCRepr { v6 : a. into_inner ( ) } ;
733
+ ( sockaddr, mem:: size_of :: < c:: sockaddr_in6 > ( ) as c:: socklen_t )
734
+ }
735
+ }
736
+ }
737
+ }
You can’t perform that action at this time.
0 commit comments