AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi WTSQuerySessionInformation IPv6 address

WTSQuerySessionInformation IPv6 address

Ein Thema von Remko · begonnen am 14. Nov 2007 · letzter Beitrag vom 21. Nov 2007
Antwort Antwort
Seite 1 von 2  1 2   
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#1

WTSQuerySessionInformation IPv6 address

  Alt 14. Nov 2007, 13:39
With the MSDN-Library durchsuchenWTSQuerySessionInformation API you can get the Client IP address of a Terminal Server client. On Vista and Windows Server 2008 this returns an IPv6 address in a pointer to a WtsClientAddress structure:
Code:
  _WTS_CLIENT_ADDRESS = record
    AddressFamily: DWORD;          // AF_INET, AF_IPX, AF_NETBIOS, AF_UNSPEC
    Address: array [0..19] of BYTE; // client network address
  end;
I want to convert the Address to a string but don't know how. I tried to use MSDN-Library durchsuchenRtlIpv6AddressToString API this succeeds but returns bogus.

My IPConfig:
IPv6 Address. . . . . . . . . . . : 1111:2222:1111:2222:1111:2222:1111:2222
Link-local IPv6 Address . . . . . : fe80::fd16:38fb:af7a:66c4%10

Dump of the Address byte array:
182530000010000000000710
Hex Dump: 7C F4 12 00 8B 1D 49 00 38 F4 12 00 AF 1E 49 00 7C F4 12 00

Anyone?
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#2

Re: WTSQuerySessionInformation IPv6 address

  Alt 16. Nov 2007, 09:00
push
  Mit Zitat antworten Zitat
Muetze1
(Gast)

n/a Beiträge
 
#3

Re: WTSQuerySessionInformation IPv6 address

  Alt 16. Nov 2007, 16:21
And what IPv6 address do you expect? Can you write the expected IPv6 address for the given hex dump please?
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#4

Re: WTSQuerySessionInformation IPv6 address

  Alt 16. Nov 2007, 16:23
That would be the ones from the listed ipconfig:
My IPConfig:
IPv6 Address. . . . . . . . . . . : 1111:2222:1111:2222:1111:2222:1111:2222
Link-local IPv6 Address . . . . . : fe80::fd16:38fb:af7a:66c4%10
  Mit Zitat antworten Zitat
Muetze1
(Gast)

n/a Beiträge
 
#5

Re: WTSQuerySessionInformation IPv6 address

  Alt 16. Nov 2007, 16:29
So, the returned structure contains crap. The call to WTSQuerySessionInformation seems to fail - did you checked the result value and even (if it say no error) check it deeply? Checking deeply meaning to call SetLastError(0); directly before calling the WTSQuerySessionInformation() and checking GetLastError() directly after the call. Are there any errors?
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#6

Re: WTSQuerySessionInformation IPv6 address

  Alt 16. Nov 2007, 16:31
I'm don't think the function failed, but just to be sure I will try again and make a new dump.
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#7

Re: WTSQuerySessionInformation IPv6 address

  Alt 16. Nov 2007, 21:51
This is odd, I tried the function 3 times and 3 times successfull. But I get 3 different values

1st four bytes is the addressfamily which always returns 0, then follows the clientaddress:
Code:
17 00 00 00 D8 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 49 00
17 00 00 00 04 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 49 00
17 00 00 00 A1 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 49 00
  Mit Zitat antworten Zitat
Muetze1
(Gast)

n/a Beiträge
 
#8

Re: WTSQuerySessionInformation IPv6 address

  Alt 17. Nov 2007, 01:00
Ok, can you show the code around the call to WTSQuerySessionInformation()? So memory & pointer preparation, etc?
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#9

Re: WTSQuerySessionInformation IPv6 address

  Alt 19. Nov 2007, 12:47
This is a helper function:
Delphi-Quellcode:
procedure TJwWTSSession.GetSessionInfoPtr(const WTSInfoClass: _WTS_INFO_CLASS;
  var ABuffer: Pointer);
var dwBytesReturned: DWORD;
  Res: Bool;
begin
  Res :=
{$IFDEF UNICODE}
    WTSQuerySessionInformationW(GetServerHandle, FSessionId, WTSInfoClass,
      ABuffer, dwBytesReturned);
{$ELSE}
    WTSQuerySessionInformationA(GetServerHandle, FSessionId, WTSInfoClass,
      ABuffer, dwBytesReturned);
{$ENDIF}
  // function always returns an error 997: overlapped IO on session 0
  if (not Res) and (FSessionId <> 0) then
  begin
    raise EJwsclWinCallFailedException.CreateFmtWinCall(RsWinCallFailed,
      'WTSQuerySessionInformation', ClassName, RSUNTerminalServer, 0, True,
      'WTSQuerySessionInformation', ['WTSQuerySessionInformation']);
  end;
end;
And this is where the ClientAddress is retrieved, as you can see I'm dumping this to a .bin file now (which is what I pasted above)
Delphi-Quellcode:
function TJwWTSSession.GetClientAddress: TJwString;
var ClientAddressPtr: PWtsClientAddress;
begin
  ZeroMemory(ClientAddressPtr, SizeOf(TWtsClientAddress));
  GetSessionInfoPtr(WTSClientAddress, Pointer(ClientAddressPtr));
  {Note that the first byte of the IP address returned in the ppBuffer
  parameter will be located at an offset of 2 bytes from the start of
   the Address member of the returned WTS_CLIENT_ADDRESS structure.}

  case ClientAddressPtr^.AddressFamily of
    AF_INET:
      Result := Format('%d.%d.%d.%d', [ClientAddressPtr^.Address[2],
        ClientAddressPtr^.Address[3], ClientAddressPtr^.Address[4],
        ClientAddressPtr^.Address[5]]);
    AF_INET6:
// Result := 'IPv6 address not yet supported';
      begin
        with TFileStream.Create('C:\temp\AF_INET6.bin', fmCreate) do
        try
          Write(ClientAddressPtr^, SizeOf(TWtsClientAddress));
        finally
          Free;
        end;
      end;
    AF_IPX:
      Result := 'IPX is not supported';
    AF_NETBIOS:
      Result := 'NETBIOS is not supported';
    AF_UNSPEC:
      Result := '';
  end;
  WTSFreeMemory(ClientAddressPtr);
end;
  Mit Zitat antworten Zitat
Muetze1
(Gast)

n/a Beiträge
 
#10

Re: WTSQuerySessionInformation IPv6 address

  Alt 19. Nov 2007, 18:58
1. You pass the local variable ClientAddressPtr to the call, but as far as I can read from the documentation, you have to pass the pointer to this variable. So call it with @ClientAddressPtr.

2. What about this comment
Zitat:
// function always returns an error 997: overlapped IO on session 0
and what does dwBytesReturned contain after the call?
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2   

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

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 15:51 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