Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Problem with PIP_ADAPTER_INFO (https://www.delphipraxis.net/181239-problem-pip_adapter_info.html)

WojTec 28. Jul 2014 17:36

Delphi-Version: XE5

Problem with PIP_ADAPTER_INFO
 
So, I want to get network adapters and info about it.
Class worked fine till W$7 SP1 - it won't detect network card name as normal W$7 did, but uses some locale string, like 'Połączenie sieciowe Intel(R) 82566DC Gigabit' (previosly was 'Intel(R) 82566DC Gigabit Ethernet' or something similar). My code returns 'Po' in description filed, so problem is in reading PIP_ADAPTER_INFO.Description (I think):

Delphi-Quellcode:
AdapterName: array [0 .. MAX_ADAPTER_NAME_LENGTH + 3] of AnsiChar;
Description: array [0 .. MAX_ADAPTER_DESCRIPTION_LENGTH + 3] of AnsiChar;

PAdapter = ^TAdapter;
TAdapter = record
  Name: string;
  Description: string;
A: PAdapter;

A^.Name := Trim(string(AdapterInfo^.AdapterName));
A^.Description := Trim(string(AdapterInfo^.Description));
How to get valid values :?: :wall:

Der schöne Günther 28. Jul 2014 18:03

AW: Problem with PIP_ADAPTER_INFO
 
Liste der Anhänge anzeigen (Anzahl: 1)
Well, are you looking for an "adapter name" or a "device name"? As far as I know, the adapter names have always been localized. You can name them whatever you want.

himitsu 28. Jul 2014 18:03

AW: Problem with PIP_ADAPTER_INFO
 
ł and ą may be in ANSI not be represented
and then it comes down to how the corresponding code responds to these "invalid" characters => replace or cancel.


Does it work if you use the current API for this?
Zitat:

The MSDN-Library durchsuchenGetAdaptersInfo function retrieves adapter information for the local computer.

On Windows XP and later: Use the MSDN-Library durchsuchenGetAdaptersAddresses function instead of GetAdaptersInfo.

WojTec 28. Jul 2014 19:20

Re: AW: Problem with PIP_ADAPTER_INFO
 
Device description form device manager (should be real device name), not name from network connections (like on your screen) ;)

My connection name is 'Połączenie lokalne', network device name is 'Połączenie sieciowe Intel(R) 82566DC Gigabit' and I want to this name. On previous W$ installation was correct name.

So, 'ł' = 179 and 'ą' = 185, both included in basic ANSI characters set. :(

Result from DXE6 units is the same :(

BTW1: I don't uderstand what you mean with GetAdaptersAddresses?
BTW2: Is TMIB_IFROW available in DXE6, because I don't found?

Der schöne Günther 29. Jul 2014 09:12

AW: Problem with PIP_ADAPTER_INFO
 
Just getting that is rather easy. I just used Spring4D for the IP_ADAPTER_INFO struct and the GetAdaptersInfo method: Spring.Utils.WinApi.pas.
Delphi-Quellcode:
program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses System.SysUtils, Winapi.Windows, Spring.Utils.WinApi;

var
   adapterInfo: PIP_ADAPTER_INFO;
   bufferLength: Cardinal;
begin

   adapterInfo := New(PIP_ADAPTER_INFO);
   bufferLength := SizeOf(IP_ADAPTER_INFO);

   // SizeOf(IP_ADAPTER_INFO) is about 600-700 Byte. However, we might have
   // several adapters and so the buffer being too small for several adapters
   // is totally valid.
   if GetAdaptersInfo(adapterInfo, bufferLength) = ERROR_BUFFER_OVERFLOW then
      // When ERROR_BUFFER_OVERFLOW is returned, bufferLength was set to the needed size
      if not GetAdaptersInfo(adapterInfo, bufferLength) = ERROR_SUCCESS then
         raise Exception.Create('derp');

   While( Assigned(adapterInfo) ) do begin
      WriteLn('Description: '+adapterInfo.Description);
      adapterInfo := adapterInfo.Next;
   end;

  readln;
end.
For me, that returns
Code:
Description: Realtek PCIe GBE Family Controller
Description: VMware Virtual Ethernet Adapter for VMnet1
Description: VMware Virtual Ethernet Adapter for VMnet8

DeddyH 29. Jul 2014 09:36

AW: Problem with PIP_ADAPTER_INFO
 
Zitat:

Delphi-Quellcode:
if not GetAdaptersInfo(adapterInfo, bufferLength) = ERROR_SUCCESS then

Fehlen da nicht Klammern?
Delphi-Quellcode:
if not (GetAdaptersInfo(adapterInfo, bufferLength) = ERROR_SUCCESS) then

Der schöne Günther 29. Jul 2014 09:51

AW: Problem with PIP_ADAPTER_INFO
 
Ja :oops:

WojTec 30. Jul 2014 18:04

Re: Problem with PIP_ADAPTER_INFO
 
With Spring4D I got 'Po' too :cry:
Is this bug in API or in iphlpapi.dll?

Der schöne Günther 30. Jul 2014 18:39

AW: Problem with PIP_ADAPTER_INFO
 
To be honest, I'm really surprised to see some locale string as a device Name. Never seen anything like this. Can you reproduce this on other Computers that also have those names?

In the meantime, let's try
Delphi-Quellcode:
GetAdaptersAddresses(..)
instead:

Delphi-Quellcode:
program Project1;

{$APPTYPE CONSOLE}
{$R *.res}

uses
   System.SysUtils, // For RaiseLastOSError
   Winapi.IpTypes,
   Winapi.IpHlpApi,
   Winapi.Windows,
   WinApi.WinSock2 // For AF_xxx
;

const
   skipFriendlyName: Boolean = False;
var
   flags: DWORD;
   addresses: PIP_ADAPTER_ADDRESSES;
   buffSize: ULONG;
   returnValue: ULONG;
begin
   flags := 0;
   if skipFriendlyName then
      flags := flags or GAA_FLAG_SKIP_FRIENDLY_NAME;

   addresses := new(PIP_ADAPTER_ADDRESSES);
   buffSize := SizeOf(addresses^);

   returnValue := GetAdaptersAddresses(
      AF_UNSPEC, // Return both IPv4 and IPv6 addresses associated with adapters with IPv4 or IPv6 enabled.
      flags,
      nil,
      addresses,
      Addr(buffSize)
   );

   // Buffer to small? buffSize already got changed, just do it again
   if returnValue = ERROR_BUFFER_OVERFLOW then
      returnValue := GetAdaptersAddresses(
         AF_UNSPEC,
         flags,
         nil,
         addresses,
         Addr(buffSize)
      );

   if returnValue <> ERROR_SUCCESS then
      RaiseLastOSError();

   while Assigned(addresses) do begin
      WriteLn('Adapter Name: '+addresses.AdapterName);
      WriteLn('Friendly Name: '+addresses.FriendlyName);
      WriteLn('Description: '+addresses.Description);
      WriteLn(sLineBreak);
      addresses := addresses.Next;
   end;

   Readln;
end.

That gets me
Code:
Adapter Name: {5778C186-FC70-4E1B-91C2-55B230B54B0F}
Friendly Name: LAN-Verbindung
Description: Realtek PCIe GBE Family Controller


Adapter Name: {823AF0FA-25AF-4942-88C2-1048BCF6B989}
Friendly Name: VMware Network Adapter VMnet1
Description: VMware Virtual Ethernet Adapter for VMnet1


Adapter Name: {04B9E40E-82C6-41F7-B365-34C90086AED1}
Friendly Name: VMware Network Adapter VMnet8
Description: VMware Virtual Ethernet Adapter for VMnet8


Adapter Name: {846EE342-7039-11DE-9D20-806E6F6E6963}
Friendly Name: Loopback Pseudo-Interface 1
Description: Software Loopback Interface 1


Adapter Name: {57FBDD6B-EA00-4580-B520-7B5F254236CD}
Friendly Name: isatap.MyFancyCompany.local
Description: Microsoft-ISATAP-Adapter


Adapter Name: {AC3A8F85-921D-4F6A-A213-969C9AFD77BC}
Friendly Name: Teredo Tunneling Pseudo-Interface
Description: Teredo Tunneling Pseudo-Interface


Adapter Name: {16F898BB-DFC0-4C64-A298-55975DAFBCF8}
Friendly Name: isatap.{823AF0FA-25AF-4942-88C2-1048BCF6B989}
Description: Microsoft-ISATAP-Adapter #3


Adapter Name: {860710BE-74C2-4A45-9C0E-6BA4C0E6313C}
Friendly Name: isatap.{04B9E40E-82C6-41F7-B365-34C90086AED1}
Description: Microsoft-ISATAP-Adapter #2

hathor 30. Jul 2014 18:57

AW: Problem with PIP_ADAPTER_INFO
 
WINDOWS 8.0, XE2

With the code in #5 I get this output:

Description: Von Microsoft gehosteter, virtueller Netzwerkadapter
Description: Microsoft Wi-Fi Direct Virtual Adapter
Description: Qualcomm Atheros AR9485 Wireless Network Adapter
Description: Realtek PCIe GBE Family Controller


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:42 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz