Skip to content

Fix platform-specific types#32

Open
chitoku-k wants to merge 1 commit into
pkts-rs:mainfrom
chitoku-k:fix-platform-specific-types
Open

Fix platform-specific types#32
chitoku-k wants to merge 1 commit into
pkts-rs:mainfrom
chitoku-k:fix-platform-specific-types

Conversation

@chitoku-k

Copy link
Copy Markdown

This PR fixes hard-coded platform-specific types in rscap to let Rust infer them instead because not all environments use the same underlying types for libc’s primitives:

$ cross check --target=aarch64-unknown-linux-musl
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu unchanged - rustc 1.93.0 (254b59607 2026-01-19)

info: self-update is disabled for this build of rustup
info: any updates to rustup will need to be fetched with your system package manager
    Checking rscap v0.3.1 (/project/rscap)
error[E0308]: mismatched types
    --> rscap/src/linux/l2.rs:621:69
     |
 621 |             let res = unsafe { libc::if_indextoname(iface.index()?, if_name_ptr) };
     |                                --------------------                 ^^^^^^^^^^^ expected `*mut u8`, found `*mut i8`
     |                                |
     |                                arguments to this function are incorrect
     |
     = note: expected raw pointer `*mut u8`
                found raw pointer `*mut i8`
note: function defined here
    --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libc-0.2.180/src/unix/mod.rs:1199:12
     |
1199 |     pub fn if_indextoname(ifindex: c_uint, ifname: *mut c_char) -> *mut c_char;
     |            ^^^^^^^^^^^^^^

error[E0308]: mismatched types
   --> rscap/src/linux/l2.rs:627:27
    |
627 |                 ifr_name: if_name,
    |                           ^^^^^^^ expected `[u8; 16]`, found `[i8; 16]`
    |
    = note: expected array `[u8; 16]`
               found array `[i8; 16]`

error[E0308]: mismatched types
    --> rscap/src/linux/l2.rs:634:47
     |
 634 |                 unsafe { libc::ioctl(self.fd, libc::SIOCSHWTSTAMP, ptr::addr_of_mut!(ifreq)) };
     |                          -----------          ^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u64`
     |                          |
     |                          arguments to this function are incorrect
     |
note: function defined here
    --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libc-0.2.180/src/unix/linux_like/mod.rs:1731:20
     |
1731 |             pub fn ioctl(fd: c_int, request: Ioctl, ...) -> c_int;
     |                    ^^^^^
help: you can convert a `u64` to an `i32` and panic if the converted value doesn't fit
     |
 634 |                 unsafe { libc::ioctl(self.fd, libc::SIOCSHWTSTAMP.try_into().unwrap(), ptr::addr_of_mut!(ifreq)) };
     |                                                                  ++++++++++++++++++++

error[E0308]: mismatched types
    --> rscap/src/linux/l3.rs:260:69
     |
 260 |             let res = unsafe { libc::if_indextoname(iface.index()?, if_name_ptr) };
     |                                --------------------                 ^^^^^^^^^^^ expected `*mut u8`, found `*mut i8`
     |                                |
     |                                arguments to this function are incorrect
     |
     = note: expected raw pointer `*mut u8`
                found raw pointer `*mut i8`
note: function defined here
    --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libc-0.2.180/src/unix/mod.rs:1199:12
     |
1199 |     pub fn if_indextoname(ifindex: c_uint, ifname: *mut c_char) -> *mut c_char;
     |            ^^^^^^^^^^^^^^

error[E0308]: mismatched types
   --> rscap/src/linux/l3.rs:266:27
    |
266 |                 ifr_name: if_name,
    |                           ^^^^^^^ expected `[u8; 16]`, found `[i8; 16]`
    |
    = note: expected array `[u8; 16]`
               found array `[i8; 16]`

error[E0308]: mismatched types
    --> rscap/src/linux/l3.rs:273:47
     |
 273 |                 unsafe { libc::ioctl(self.fd, libc::SIOCSHWTSTAMP, ptr::addr_of_mut!(ifreq)) };
     |                          -----------          ^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u64`
     |                          |
     |                          arguments to this function are incorrect
     |
note: function defined here
    --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libc-0.2.180/src/unix/linux_like/mod.rs:1731:20
     |
1731 |             pub fn ioctl(fd: c_int, request: Ioctl, ...) -> c_int;
     |                    ^^^^^
help: you can convert a `u64` to an `i32` and panic if the converted value doesn't fit
     |
 273 |                 unsafe { libc::ioctl(self.fd, libc::SIOCSHWTSTAMP.try_into().unwrap(), ptr::addr_of_mut!(ifreq)) };
     |                                                                  ++++++++++++++++++++

error[E0308]: mismatched types
    --> rscap/src/lib.rs:185:55
     |
 185 |         match unsafe { libc::if_indextoname(if_index, name.as_mut_ptr() as *mut i8) } {
     |                        --------------------           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `*mut u8`, found `*mut i8`
     |                        |
     |                        arguments to this function are incorrect
     |
     = note: expected raw pointer `*mut u8`
                found raw pointer `*mut i8`
note: function defined here
    --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libc-0.2.180/src/unix/mod.rs:1199:12
     |
1199 |     pub fn if_indextoname(ifindex: c_uint, ifname: *mut c_char) -> *mut c_char;
     |            ^^^^^^^^^^^^^^

error[E0308]: mismatched types
    --> rscap/src/lib.rs:195:45
     |
 195 |         match unsafe { libc::if_nametoindex(self.name.as_ptr() as *const i8) } {
     |                        -------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `*const u8`, found `*const i8`
     |                        |
     |                        arguments to this function are incorrect
     |
     = note: expected raw pointer `*const u8`
                found raw pointer `*const i8`
note: function defined here
    --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libc-0.2.180/src/unix/mod.rs:1198:12
     |
1198 |     pub fn if_nametoindex(ifname: *const c_char) -> c_uint;
     |            ^^^^^^^^^^^^^^

error[E0308]: mismatched types
   --> rscap/src/lib.rs:234:23
    |
234 |             ifr_name: array::from_fn(|i| self.name[i] as i8),
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[u8; 16]`, found `[i8; _]`
    |
    = note: expected array `[u8; 16]`
               found array `[i8; _]`

error[E0308]: mismatched types
    --> rscap/src/lib.rs:248:37
     |
 248 |         if unsafe { libc::ioctl(fd, libc::SIOCGIFHWADDR, ptr::addr_of_mut!(ifr)) } < 0 {
     |                     -----------     ^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u64`
     |                     |
     |                     arguments to this function are incorrect
     |
note: function defined here
    --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libc-0.2.180/src/unix/linux_like/mod.rs:1731:20
     |
1731 |             pub fn ioctl(fd: c_int, request: Ioctl, ...) -> c_int;
     |                    ^^^^^
help: you can convert a `u64` to an `i32` and panic if the converted value doesn't fit
     |
 248 |         if unsafe { libc::ioctl(fd, libc::SIOCGIFHWADDR.try_into().unwrap(), ptr::addr_of_mut!(ifr)) } < 0 {
     |                                                        ++++++++++++++++++++

error[E0308]: mismatched types
   --> rscap/src/linux/l2.rs:629:32
    |
629 |                     ifru_data: ptr::addr_of_mut!(hwtstamp_config) as *mut i8,
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `*mut u8`, found `*mut i8`
    |
    = note: expected raw pointer `*mut u8`
               found raw pointer `*mut i8`

error[E0308]: mismatched types
   --> rscap/src/linux/l3.rs:268:32
    |
268 |                     ifru_data: ptr::addr_of_mut!(hwtstamp_config) as *mut i8,
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `*mut u8`, found `*mut i8`
    |
    = note: expected raw pointer `*mut u8`
               found raw pointer `*mut i8`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `rscap` (lib) due to 12 previous errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant