Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iphlpapi support #572

Closed
wants to merge 16 commits into from
Closed

Add iphlpapi support #572

wants to merge 16 commits into from

Conversation

LuoZijun
Copy link
Contributor

@LuoZijun LuoZijun commented Feb 13, 2018

@LuoZijun
Copy link
Contributor Author

@retep998 I know this PR have many code style problem, i hope we can put it in the final stage to solve it.

Copy link

@brooss brooss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time_t is 32bits on x86

@retep998
Copy link
Owner

@brooss time_t is 64bit on x86.

@brooss
Copy link

brooss commented Feb 27, 2018

Ok, possibly I'm wrong, but from my testing of GetAdapterAddresses() IP_ADAPTER_INFO.LeaseObtained and IP_ADAPTER_INFO.LeaseExpires are 32bit on x86 and 64bit on x86_64.

@retep998
Copy link
Owner

retep998 commented Feb 27, 2018

How exactly were you testing that? VC++ by default uses a 64bit time_t on 32bit. It is possible to get a 32-bit time_t by defining a certain macro, but that's a non-default configuration which I don't support. I don't know what MinGW does.

@brooss
Copy link

brooss commented Feb 27, 2018

I'm testing from Rust. Call GetAdaptersInfo() with a zero sized buffer and:

GetAdaptersInfo fills in this variable with the required size, and returns an error code of ERROR_BUFFER_OVERFLOW.

let mut buflen: ULONG = unsafe{mem::zeroed()};
let _ = unsafe{GetAdaptersInfo(null_mut(), &mut buflen)};

buflen should then be a multiple of mem::sizeof::<IP_ADAPTER_INFO>().

I get multiples of 640bytes returned by GetAdaptersInfo on x86.

If time_t is 32bit then sizeof::<IP_ADAPTER_INFO>() is 640bytes and the Lease times look correct to me. If time_t is 64bit then the sizeof::<IP_ADAPTER_INFO>() is 8bytes too long, LeaseObtained has a nonsense time and LeaseExpires is zero.

Just checked on mingw32 and sizeof (IP_ADAPTER_INFO); also shows 640 bytes.

What does sizeof (IP_ADAPTER_INFO); give on vc++?

@retep998
Copy link
Owner

retep998 commented Feb 27, 2018

sizeof(IP_ADAPTER_INFO) in VC++ is 648, but GetAdaptersInfo specifies a value that is a multiple of 640 for me as well. If I call the function with a large enough buffer, then the Next field points to an address that is 640 bytes after the base address.

Also MSDN has this to say:

When using Visual Studio 2005 and later, the time_t datatype defaults to an 8-byte datatype, not the 4-byte datatype used for the LeaseObtained and LeaseExpires members on a 32-bit platform. To properly use the IP_ADAPTER_INFO structure on a 32-bit platform, define _USE_32BIT_TIME_T (use -D _USE_32BIT_TIME_T as an option, for example) when compiling the application to force the time_t datatype to a 4-byte datatype.

So while time_t itself should remain 64bit, IP_ADAPTER_INFO should probably use __time32_t.

@brooss
Copy link

brooss commented Feb 27, 2018

So while time_t itself should remain 64bit, IP_ADAPTER_INFO should probably use __time32_t.

👍

@crmaxx
Copy link

crmaxx commented Mar 12, 2018

@LuoZijun on current nightly I have next issue

$ cargo build
   Compiling winapi v0.3.4 (https://github.com/LuoZijun/winapi-rs?branch=iphlpapi#9dddf9d6)
error: no rules expected the token `Value`
  --> C:\Users\mzhukov\.cargo\git\checkouts\winapi-rs-3464f7d97049bddf\9dddf9d\src\shared\ifdef.rs:79:5
   |
79 |     Value: ULONG64,
   |     ^^^^^

error: no rules expected the token `ullAlign`
   --> C:\Users\mzhukov\.cargo\git\checkouts\winapi-rs-3464f7d97049bddf\9dddf9d\src\shared\iprtrmib.rs:152:5
    |
152 |     ullAlign: ULONGLONG,
    |     ^^^^^^^^

error: no rules expected the token `s`
  --> C:\Users\mzhukov\.cargo\git\checkouts\winapi-rs-3464f7d97049bddf\9dddf9d\src\shared\udpmib.rs:52:5
   |
52 |     s: c_int,
   |     ^

error: no rules expected the token `s`
   --> C:\Users\mzhukov\.cargo\git\checkouts\winapi-rs-3464f7d97049bddf\9dddf9d\src\shared\udpmib.rs:103:5
    |
103 |     s: c_int,
    |     ^

error: aborting due to 4 previous errors

error: Could not compile `winapi`.

@LuoZijun
Copy link
Contributor Author

LuoZijun commented Mar 12, 2018

@crmaxx

Yeah, I guess this is an anonymous macro problem.
It seems that anonymous structure members should use BITFIELD!( not BITFIELD!{.
@retep998 Am i right ?

I developed it on macOS, so fixing the problem took me some time.
I will try to fix that on this weekend.

@retep998
Copy link
Owner

@LuoZijun According to CONTRIBUTING.md

Macro invocations at the item level should use {}. Macro invocations at the expression level should use ().

Since BITFIELD! is invoked at the item level...

@LuoZijun
Copy link
Contributor Author

@retep998 Thank you, got it.

@awakecoding
Copy link

Any update on this? We would need the same API

@devnought
Copy link

devnought commented May 30, 2018

Like @awakecoding, also looking to use this. Any updates? @LuoZijun ?

@glebpom
Copy link

glebpom commented Aug 13, 2018

Hi! Is it going to be merged? Is any help needed?

@retep998
Copy link
Owner

There is still some work done that needs to be done with this PR before it can be merged, but it appears the original author of this PR has abandoned it, so anyone is free to resume work on this PR.

@mattlknight
Copy link

@retep998 I would like to take ownership of this, or at least, help complete this PR. That being said, I am very noob when it comes to FFI stuff. I'm working on gettting this completed in my local fork now, contuining where @LuoZijun left off. Trying to figure out the output of "cargo test" now.

@mattlknight
Copy link

@awakecoding @devnought @glebpom I have opened a new PR #675 for this and continued where @LuoZijun left off. Any comments/critiques welcome. I'm now checking to see what is missing, if anything, otherwise the PR is done.

@retep998
Copy link
Owner

This PR has been superseded by #802

@retep998 retep998 closed this Aug 28, 2019
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.

9 participants