File tree Expand file tree Collapse file tree 2 files changed +13
-11
lines changed Expand file tree Collapse file tree 2 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -229,8 +229,16 @@ impl INodeInterface for InetSocket {
229229 fn ioctl ( & self , command : usize , arg : usize ) -> fs:: Result < usize > {
230230 match command {
231231 SIOCGIFHWADDR => {
232- let hwaddr =
233- unsafe { core:: slice:: from_raw_parts_mut ( arg as * mut u8 , MacAddr :: ADDR_SIZE ) } ;
232+ let ifreq = VirtAddr :: new ( arg as _ )
233+ . read_mut :: < IfReq > ( )
234+ . ok_or ( FileSystemError :: NotSupported ) ?;
235+
236+ let name = ifreq. name ( ) . ok_or ( FileSystemError :: InvalidPath ) ?;
237+ assert ! ( name == "eth0" ) ;
238+
239+ let hwaddr = unsafe {
240+ core:: slice:: from_raw_parts_mut ( ifreq. sa_data . as_mut_ptr ( ) , MacAddr :: ADDR_SIZE )
241+ } ;
234242
235243 let mac_addr = net:: default_device ( ) . mac ( ) ;
236244 hwaddr. copy_from_slice ( & mac_addr. 0 . as_slice ( ) ) ;
Original file line number Diff line number Diff line change 1717 * along with Aero. If not, see <https://www.gnu.org/licenses/>.
1818 */
1919
20- use core:: ffi:: CStr ;
21-
2220use crate :: OpenFlags ;
2321
2422// syscall number constants:
@@ -367,12 +365,8 @@ impl IfReq {
367365 /// Get the interface name, e.g. "en0". [`None`] is returned if UTF-8
368366 /// validation failed.
369367 pub fn name ( & self ) -> Option < & str > {
370- match CStr :: from_bytes_until_nul ( & self . name ) {
371- Ok ( s) => s. to_str ( ) ,
372- // The name does not have a null terminator, that means
373- // the whole buffer has the name.
374- Err ( _) => core:: str:: from_utf8 ( & self . name ) ,
375- }
376- . ok ( )
368+ let null_index = self . name . iter ( ) . position ( |& x| x == 0 ) . unwrap_or_default ( ) ;
369+ let name = & self . name [ ..null_index] ;
370+ core:: str:: from_utf8 ( name) . ok ( )
377371 }
378372}
You can’t perform that action at this time.
0 commit comments