@@ -1833,6 +1833,33 @@ impl crate::Socket {
1833
1833
. map ( |_| ( ) )
1834
1834
}
1835
1835
1836
+ /// This method is deprecated, use [`crate::Socket::bind_device_by_index_v4`].
1837
+ #[ cfg( all(
1838
+ feature = "all" ,
1839
+ any(
1840
+ target_os = "ios" ,
1841
+ target_os = "macos" ,
1842
+ target_os = "tvos" ,
1843
+ target_os = "watchos" ,
1844
+ )
1845
+ ) ) ]
1846
+ #[ cfg_attr(
1847
+ docsrs,
1848
+ doc( cfg( all(
1849
+ feature = "all" ,
1850
+ any(
1851
+ target_os = "ios" ,
1852
+ target_os = "macos" ,
1853
+ target_os = "tvos" ,
1854
+ target_os = "watchos" ,
1855
+ )
1856
+ ) ) )
1857
+ ) ]
1858
+ #[ deprecated = "Use `Socket::device_index_v4` instead" ]
1859
+ pub fn bind_device_by_index ( & self , interface : Option < NonZeroU32 > ) -> io:: Result < ( ) > {
1860
+ self . bind_device_by_index_v4 ( interface)
1861
+ }
1862
+
1836
1863
/// Sets the value for `IP_BOUND_IF` option on this socket.
1837
1864
///
1838
1865
/// If a socket is bound to an interface, only packets received from that
@@ -1864,11 +1891,47 @@ impl crate::Socket {
1864
1891
)
1865
1892
) ) )
1866
1893
) ]
1867
- pub fn bind_device_by_index ( & self , interface : Option < NonZeroU32 > ) -> io:: Result < ( ) > {
1894
+ pub fn bind_device_by_index_v4 ( & self , interface : Option < NonZeroU32 > ) -> io:: Result < ( ) > {
1868
1895
let index = interface. map_or ( 0 , NonZeroU32 :: get) ;
1869
1896
unsafe { setsockopt ( self . as_raw ( ) , IPPROTO_IP , libc:: IP_BOUND_IF , index) }
1870
1897
}
1871
1898
1899
+ /// Sets the value for `IPV6_BOUND_IF` option on this socket.
1900
+ ///
1901
+ /// If a socket is bound to an interface, only packets received from that
1902
+ /// particular interface are processed by the socket.
1903
+ ///
1904
+ /// If `interface` is `None`, the binding is removed. If the `interface`
1905
+ /// index is not valid, an error is returned.
1906
+ ///
1907
+ /// One can use [`libc::if_nametoindex`] to convert an interface alias to an
1908
+ /// index.
1909
+ #[ cfg( all(
1910
+ feature = "all" ,
1911
+ any(
1912
+ target_os = "ios" ,
1913
+ target_os = "macos" ,
1914
+ target_os = "tvos" ,
1915
+ target_os = "watchos" ,
1916
+ )
1917
+ ) ) ]
1918
+ #[ cfg_attr(
1919
+ docsrs,
1920
+ doc( cfg( all(
1921
+ feature = "all" ,
1922
+ any(
1923
+ target_os = "ios" ,
1924
+ target_os = "macos" ,
1925
+ target_os = "tvos" ,
1926
+ target_os = "watchos" ,
1927
+ )
1928
+ ) ) )
1929
+ ) ]
1930
+ pub fn bind_device_by_index_v6 ( & self , interface : Option < NonZeroU32 > ) -> io:: Result < ( ) > {
1931
+ let index = interface. map_or ( 0 , NonZeroU32 :: get) ;
1932
+ unsafe { setsockopt ( self . as_raw ( ) , IPPROTO_IPV6 , libc:: IPV6_BOUND_IF , index) }
1933
+ }
1934
+
1872
1935
/// Gets the value for `IP_BOUND_IF` option on this socket, i.e. the index
1873
1936
/// for the interface to which the socket is bound.
1874
1937
///
@@ -1895,12 +1958,72 @@ impl crate::Socket {
1895
1958
)
1896
1959
) ) )
1897
1960
) ]
1898
- pub fn device_index ( & self ) -> io:: Result < Option < NonZeroU32 > > {
1961
+ pub fn device_index_v4 ( & self ) -> io:: Result < Option < NonZeroU32 > > {
1899
1962
let index =
1900
1963
unsafe { getsockopt :: < libc:: c_uint > ( self . as_raw ( ) , IPPROTO_IP , libc:: IP_BOUND_IF ) ? } ;
1901
1964
Ok ( NonZeroU32 :: new ( index) )
1902
1965
}
1903
1966
1967
+ /// This method is deprecated, use [`crate::Socket::device_index_v4`].
1968
+ #[ cfg( all(
1969
+ feature = "all" ,
1970
+ any(
1971
+ target_os = "ios" ,
1972
+ target_os = "macos" ,
1973
+ target_os = "tvos" ,
1974
+ target_os = "watchos" ,
1975
+ )
1976
+ ) ) ]
1977
+ #[ cfg_attr(
1978
+ docsrs,
1979
+ doc( cfg( all(
1980
+ feature = "all" ,
1981
+ any(
1982
+ target_os = "ios" ,
1983
+ target_os = "macos" ,
1984
+ target_os = "tvos" ,
1985
+ target_os = "watchos" ,
1986
+ )
1987
+ ) ) )
1988
+ ) ]
1989
+ #[ deprecated = "Use `Socket::device_index_v4` instead" ]
1990
+ pub fn device_index ( & self ) -> io:: Result < Option < NonZeroU32 > > {
1991
+ self . device_index_v4 ( )
1992
+ }
1993
+
1994
+ /// Gets the value for `IPV6_BOUND_IF` option on this socket, i.e. the index
1995
+ /// for the interface to which the socket is bound.
1996
+ ///
1997
+ /// Returns `None` if the socket is not bound to any interface, otherwise
1998
+ /// returns an interface index.
1999
+ #[ cfg( all(
2000
+ feature = "all" ,
2001
+ any(
2002
+ target_os = "ios" ,
2003
+ target_os = "macos" ,
2004
+ target_os = "tvos" ,
2005
+ target_os = "watchos" ,
2006
+ )
2007
+ ) ) ]
2008
+ #[ cfg_attr(
2009
+ docsrs,
2010
+ doc( cfg( all(
2011
+ feature = "all" ,
2012
+ any(
2013
+ target_os = "ios" ,
2014
+ target_os = "macos" ,
2015
+ target_os = "tvos" ,
2016
+ target_os = "watchos" ,
2017
+ )
2018
+ ) ) )
2019
+ ) ]
2020
+ pub fn device_index_v6 ( & self ) -> io:: Result < Option < NonZeroU32 > > {
2021
+ let index = unsafe {
2022
+ getsockopt :: < libc:: c_uint > ( self . as_raw ( ) , IPPROTO_IPV6 , libc:: IPV6_BOUND_IF ) ?
2023
+ } ;
2024
+ Ok ( NonZeroU32 :: new ( index) )
2025
+ }
2026
+
1904
2027
/// Get the value of the `SO_INCOMING_CPU` option on this socket.
1905
2028
///
1906
2029
/// For more information about this option, see [`set_cpu_affinity`].
0 commit comments