AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Problem with PIP_ADAPTER_INFO

Ein Thema von WojTec · begonnen am 28. Jul 2014 · letzter Beitrag vom 31. Jul 2014
Antwort Antwort
Seite 1 von 2  1 2      
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

Problem with PIP_ADAPTER_INFO

  Alt 28. Jul 2014, 17:36
Delphi-Version: XE5
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
  Mit Zitat antworten Zitat
Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: Problem with PIP_ADAPTER_INFO

  Alt 28. Jul 2014, 18:03
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.
Miniaturansicht angehängter Grafiken
adapter-device.png  
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.114 Beiträge
 
Delphi 12 Athens
 
#3

AW: Problem with PIP_ADAPTER_INFO

  Alt 28. Jul 2014, 18:03
ł 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.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (28. Jul 2014 um 18:08 Uhr)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#4

Re: AW: Problem with PIP_ADAPTER_INFO

  Alt 28. Jul 2014, 19:20
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?

Geändert von WojTec (28. Jul 2014 um 19:36 Uhr)
  Mit Zitat antworten Zitat
Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#5

AW: Problem with PIP_ADAPTER_INFO

  Alt 29. Jul 2014, 09:12
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
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.537 Beiträge
 
Delphi 11 Alexandria
 
#6

AW: Problem with PIP_ADAPTER_INFO

  Alt 29. Jul 2014, 09:36
Zitat:
if not GetAdaptersInfo(adapterInfo, bufferLength) = ERROR_SUCCESS then
Fehlen da nicht Klammern?
if not (GetAdaptersInfo(adapterInfo, bufferLength) = ERROR_SUCCESS) then
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#7

AW: Problem with PIP_ADAPTER_INFO

  Alt 29. Jul 2014, 09:51
Ja
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#8

Re: Problem with PIP_ADAPTER_INFO

  Alt 30. Jul 2014, 18:04
With Spring4D I got 'Po' too
Is this bug in API or in iphlpapi.dll?
  Mit Zitat antworten Zitat
Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#9

AW: Problem with PIP_ADAPTER_INFO

  Alt 30. Jul 2014, 18:39
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 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

Geändert von Der schöne Günther (30. Jul 2014 um 18:44 Uhr) Grund: Added addresses.Description
  Mit Zitat antworten Zitat
hathor
(Gast)

n/a Beiträge
 
#10

AW: Problem with PIP_ADAPTER_INFO

  Alt 30. Jul 2014, 18:57
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
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:32 Uhr.
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