@@ -859,6 +859,64 @@ pub(crate) fn to_mreqn(
859
859
}
860
860
}
861
861
862
+ /// Get the value for the `SO_ORIGINAL_DST` option on this socket.
863
+ /// Only valid for sockets in accepting mode.
864
+ ///
865
+ /// Note: if using this function in a proxy context, you must query the
866
+ /// redirect records for this socket and set them on the outbound socket
867
+ /// created by your proxy in order for any OS level firewall rules to be
868
+ /// applied. Read more in the Windows bind and connect redirection
869
+ /// [documentation](https://learn.microsoft.com/en-us/windows-hardware/drivers/network/using-bind-or-connect-redirection).
870
+ #[ cfg( feature = "all" ) ]
871
+ #[ cfg_attr( docsrs, doc( cfg( all( windows, feature = "all" ) ) ) ) ]
872
+ pub ( crate ) fn original_dst ( socket : Socket ) -> io:: Result < SockAddr > {
873
+ unsafe {
874
+ SockAddr :: try_init ( |storage, len| {
875
+ syscall ! (
876
+ getsockopt(
877
+ socket,
878
+ SOL_IP as i32 ,
879
+ SO_ORIGINAL_DST as i32 ,
880
+ storage. cast( ) ,
881
+ len,
882
+ ) ,
883
+ PartialEq :: eq,
884
+ SOCKET_ERROR
885
+ )
886
+ } )
887
+ }
888
+ . map ( |( _, addr) | addr)
889
+ }
890
+
891
+ /// Get the value for the `IP6T_SO_ORIGINAL_DST` option on this socket.
892
+ /// Only valid for sockets in accepting mode.
893
+ ///
894
+ /// Note: if using this function in a proxy context, you must query the
895
+ /// redirect records for this socket and set them on the outbound socket
896
+ /// created by your proxy in order for any OS level firewall rules to be
897
+ /// applied. Read more in the Windows bind and connect redirection
898
+ /// [documentation](https://learn.microsoft.com/en-us/windows-hardware/drivers/network/using-bind-or-connect-redirection).
899
+ #[ cfg( feature = "all" ) ]
900
+ #[ cfg_attr( docsrs, doc( cfg( all( windows, feature = "all" ) ) ) ) ]
901
+ pub ( crate ) fn original_dst_ipv6 ( socket : Socket ) -> io:: Result < SockAddr > {
902
+ unsafe {
903
+ SockAddr :: try_init ( |storage, len| {
904
+ syscall ! (
905
+ getsockopt(
906
+ socket,
907
+ SOL_IP as i32 ,
908
+ IP6T_SO_ORIGINAL_DST as i32 ,
909
+ storage. cast( ) ,
910
+ len,
911
+ ) ,
912
+ PartialEq :: eq,
913
+ SOCKET_ERROR
914
+ )
915
+ } )
916
+ }
917
+ . map ( |( _, addr) | addr)
918
+ }
919
+
862
920
#[ allow( unsafe_op_in_unsafe_fn) ]
863
921
pub ( crate ) fn unix_sockaddr ( path : & Path ) -> io:: Result < SockAddr > {
864
922
// SAFETY: a `sockaddr_storage` of all zeros is valid.
@@ -929,64 +987,6 @@ impl crate::Socket {
929
987
}
930
988
}
931
989
932
- /// Get the value for the `SO_ORIGINAL_DST` option on this socket.
933
- /// Only valid for sockets in accepting mode.
934
- ///
935
- /// Note: if using this function in a proxy context, you must query the
936
- /// redirect records for this socket and set them on the outbound socket
937
- /// created by your proxy in order for any OS level firewall rules to be
938
- /// applied. Read more in the Windows bind and connect redirection
939
- /// [documentation](https://learn.microsoft.com/en-us/windows-hardware/drivers/network/using-bind-or-connect-redirection).
940
- #[ cfg( feature = "all" ) ]
941
- #[ cfg_attr( docsrs, doc( cfg( all( windows, feature = "all" ) ) ) ) ]
942
- pub fn original_dst ( & self ) -> io:: Result < SockAddr > {
943
- unsafe {
944
- SockAddr :: try_init ( |storage, len| {
945
- syscall ! (
946
- getsockopt(
947
- self . as_raw( ) ,
948
- SOL_IP as i32 ,
949
- SO_ORIGINAL_DST as i32 ,
950
- storage. cast( ) ,
951
- len,
952
- ) ,
953
- PartialEq :: eq,
954
- SOCKET_ERROR
955
- )
956
- } )
957
- }
958
- . map ( |( _, addr) | addr)
959
- }
960
-
961
- /// Get the value for the `IP6T_SO_ORIGINAL_DST` option on this socket.
962
- /// Only valid for sockets in accepting mode.
963
- ///
964
- /// Note: if using this function in a proxy context, you must query the
965
- /// redirect records for this socket and set them on the outbound socket
966
- /// created by your proxy in order for any OS level firewall rules to be
967
- /// applied. Read more in the Windows bind and connect redirection
968
- /// [documentation](https://learn.microsoft.com/en-us/windows-hardware/drivers/network/using-bind-or-connect-redirection).
969
- #[ cfg( feature = "all" ) ]
970
- #[ cfg_attr( docsrs, doc( cfg( all( windows, feature = "all" ) ) ) ) ]
971
- pub fn original_dst_ipv6 ( & self ) -> io:: Result < SockAddr > {
972
- unsafe {
973
- SockAddr :: try_init ( |storage, len| {
974
- syscall ! (
975
- getsockopt(
976
- self . as_raw( ) ,
977
- SOL_IP as i32 ,
978
- IP6T_SO_ORIGINAL_DST as i32 ,
979
- storage. cast( ) ,
980
- len,
981
- ) ,
982
- PartialEq :: eq,
983
- SOCKET_ERROR
984
- )
985
- } )
986
- }
987
- . map ( |( _, addr) | addr)
988
- }
989
-
990
990
/// Returns the [`Protocol`] of this socket by checking the `SO_PROTOCOL_INFOW`
991
991
/// option on this socket.
992
992
///
0 commit comments