Skip to content

Commit

Permalink
Remove every instance of i8 and replace with libc::c_char
Browse files Browse the repository at this point in the history
  • Loading branch information
nathaniel-bennett committed Nov 5, 2024
1 parent 6d88bcb commit a57a993
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ impl Interface {
}

let mut name = [0u8; Self::MAX_INTERFACE_NAME_LEN + 1];
match unsafe { libc::if_indextoname(if_index, name.as_mut_ptr() as *mut i8) } {
match unsafe { libc::if_indextoname(if_index, name.as_mut_ptr() as *mut libc::c_char) } {
ptr if ptr.is_null() => Err(io::Error::last_os_error()),
_ => Ok(Self {
name,
Expand Down
8 changes: 4 additions & 4 deletions src/linux/tap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Tap {
let flags = libc::IFF_TAP | libc::IFF_NO_PI | libc::IFF_TUN_EXCL;

let mut req = libc::ifreq {
ifr_name: [0i8; 16],
ifr_name: [0; 16],
ifr_ifru: libc::__c_anonymous_ifr_ifru {
ifru_flags: flags as i16,
},
Expand Down Expand Up @@ -137,7 +137,7 @@ impl Tap {
/// Retrieves the interface name associated with the TAP device.
pub fn name(&self) -> io::Result<Interface> {
let mut req = libc::ifreq {
ifr_name: [0i8; 16],
ifr_name: [0; 16],
ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_flags: 0 },
};

Expand Down Expand Up @@ -177,7 +177,7 @@ impl Tap {
/// Retrieves the current state of the TAP device (i.e. "up" or "down").
pub fn state(&self) -> io::Result<DeviceState> {
let mut req = libc::ifreq {
ifr_name: [0i8; 16],
ifr_name: [0; 16],
ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_flags: 0 },
};

Expand All @@ -198,7 +198,7 @@ impl Tap {
/// Sets the adapter state of the TAP device (e.g. "up" or "down").
pub fn set_state(&self, state: DeviceState) -> io::Result<()> {
let mut req = libc::ifreq {
ifr_name: [0i8; 16],
ifr_name: [0; 16],
ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_flags: 0 },
};

Expand Down
8 changes: 4 additions & 4 deletions src/linux/tun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Tun {
let flags = libc::IFF_TUN_EXCL | libc::IFF_TUN | libc::IFF_NO_PI;

let mut req = libc::ifreq {
ifr_name: [0i8; 16],
ifr_name: [0; 16],
ifr_ifru: libc::__c_anonymous_ifr_ifru {
ifru_flags: flags as i16,
},
Expand Down Expand Up @@ -134,7 +134,7 @@ impl Tun {
/// Retrieves the interface name associated with the TUN device.
pub fn name(&self) -> io::Result<Interface> {
let mut req = libc::ifreq {
ifr_name: [0i8; 16],
ifr_name: [0; 16],
ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_flags: 0 },
};

Expand Down Expand Up @@ -175,7 +175,7 @@ impl Tun {
/// Retrieves the current state of the TUN device (i.e. "up" or "down").
pub fn state(&self) -> io::Result<DeviceState> {
let mut req = libc::ifreq {
ifr_name: [0i8; 16],
ifr_name: [0; 16],
ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_flags: 0 },
};

Expand All @@ -196,7 +196,7 @@ impl Tun {
/// Sets the adapter state of the TUN device (e.g. "up" or "down").
pub fn set_state(&self, state: DeviceState) -> io::Result<()> {
let mut req = libc::ifreq {
ifr_name: [0i8; 16],
ifr_name: [0; 16],
ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_flags: 0 },
};

Expand Down
18 changes: 12 additions & 6 deletions src/macos/feth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ impl FethTap {
ifr_ifru: libc::__c_anonymous_ifr_ifru {
ifru_addr: libc::sockaddr {
sa_family: 0,
sa_data: [0i8; 14],
sa_data: [0; 14],
}
},
};
Expand Down Expand Up @@ -828,7 +828,13 @@ impl FethTap {
sdl_nlen: 0,
sdl_alen: 6, // This is what the XNU kernel wants, based on source inspection
sdl_slen: 0,
sdl_data: array::from_fn(|i| if i < 6 { addr.addr[i] as i8 } else { 0i8 }),
sdl_data: array::from_fn(|i| {
if i < 6 {
addr.addr[i] as libc::c_char
} else {
0
}
}),
};

let mut req = libc::ifreq {
Expand All @@ -837,7 +843,7 @@ impl FethTap {
ifru_addr: libc::sockaddr {
sa_family: 0,
sa_len: mem::size_of::<libc::sockaddr_in>() as u8,
sa_data: [0i8; 14],
sa_data: [0; 14],
},
},
};
Expand Down Expand Up @@ -874,9 +880,9 @@ impl FethTap {
sdl_slen: 0,
sdl_data: array::from_fn(|i| {
if i < 6 {
multicast_addr.addr[i] as i8
multicast_addr.addr[i] as libc::c_char
} else {
0i8
0
}
}),
};
Expand All @@ -887,7 +893,7 @@ impl FethTap {
ifru_addr: libc::sockaddr {
sa_family: 0,
sa_len: mem::size_of::<libc::sockaddr_in>() as u8,
sa_data: [0i8; 14],
sa_data: [0; 14],
},
},
};
Expand Down
7 changes: 6 additions & 1 deletion src/macos/utun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ impl Utun {
let mut utun_ctrl_iter = UTUN_CONTROL_NAME.iter();
let mut info = libc::ctl_info {
ctl_id: 0u32,
ctl_name: array::from_fn(|_| utun_ctrl_iter.next().map(|b| *b as i8).unwrap_or(0)),
ctl_name: array::from_fn(|_| {
utun_ctrl_iter
.next()
.map(|b| *b as libc::c_char)
.unwrap_or(0)
}),
};

if unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/tap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Tap {
let mut name = [0u8; Interface::MAX_INTERFACE_NAME_LEN + 1];
if fdevname_r(
tap_fd,
name.as_mut_ptr() as *mut i8,
name.as_mut_ptr() as *mut libc::c_char,
Interface::MAX_INTERFACE_NAME_LEN as i32,
)
.is_null()
Expand Down
4 changes: 2 additions & 2 deletions src/unix/tun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl Tun {
let mut name = [0u8; Interface::MAX_INTERFACE_NAME_LEN + 1];
if fdevname_r(
tun_fd,
name.as_mut_ptr() as *mut i8,
name.as_mut_ptr() as *mut libc::c_char,
Interface::MAX_INTERFACE_NAME_LEN as i32,
)
.is_null()
Expand All @@ -151,7 +151,7 @@ impl Tun {
let mut name = [0u8; Interface::MAX_INTERFACE_NAME_LEN + 1];
if fdevname_r(
tun_fd,
name.as_mut_ptr() as *mut i8,
name.as_mut_ptr() as *mut libc::c_char,
Interface::MAX_INTERFACE_NAME_LEN as i32,
) != 0
{
Expand Down

0 comments on commit a57a993

Please sign in to comment.