File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ rustdoc-args = ["--cfg", "docsrs"]
3333features = [" all" ]
3434
3535[target ."cfg(unix)" .dependencies ]
36- libc = " 0.2.96 "
36+ libc = " 0.2.107 "
3737
3838[target ."cfg(windows)" .dependencies ]
3939winapi = { version = " 0.3.9" , features = [" handleapi" , " ws2ipdef" , " ws2tcpip" ] }
Original file line number Diff line number Diff line change @@ -1773,6 +1773,37 @@ impl crate::Socket {
17731773 } )
17741774 }
17751775 }
1776+
1777+ /// Attach Berkeley Packet Filter(BPF) on this socket.
1778+ ///
1779+ /// BPF allows a user-space program to attach a filter onto any socket
1780+ /// and allow or disallow certain types of data to come through the socket.
1781+ ///
1782+ /// For more information about this option, see [filter](https://www.kernel.org/doc/html/v5.12/networking/filter.html)
1783+ #[ cfg( all( feature = "all" , any( target_os = "linux" , target_os = "android" ) ) ) ]
1784+ pub fn attach_filter ( & self , filters : & [ libc:: sock_filter ] ) -> io:: Result < ( ) > {
1785+ let prog = libc:: sock_fprog {
1786+ len : filters. len ( ) as u16 ,
1787+ filter : filters. as_ptr ( ) as * mut _ ,
1788+ } ;
1789+
1790+ unsafe {
1791+ setsockopt (
1792+ self . as_raw ( ) ,
1793+ libc:: SOL_SOCKET ,
1794+ libc:: SO_ATTACH_FILTER ,
1795+ prog,
1796+ )
1797+ }
1798+ }
1799+
1800+ /// Detach Berkeley Packet Filter(BPF) from this socket.
1801+ ///
1802+ /// For more information about this option, see [`attach_filter`]
1803+ #[ cfg( all( feature = "all" , any( target_os = "linux" , target_os = "android" ) ) ) ]
1804+ pub fn detach_filter ( & self ) -> io:: Result < ( ) > {
1805+ unsafe { setsockopt ( self . as_raw ( ) , libc:: SOL_SOCKET , libc:: SO_DETACH_FILTER , 0 ) }
1806+ }
17761807}
17771808
17781809#[ cfg_attr( docsrs, doc( cfg( unix) ) ) ]
You can’t perform that action at this time.
0 commit comments