Autor |
Beitrag |
CodexX
      
Beiträge: 118
WinXP
Delphi XE
|
Verfasst: So 17.05.09 18:16
Ich möchte gerne prüfen, ob das Ipv6 Protokoll installiert ist. Das sollte mit der Funktion WSAEnumProtocols aus Winsock2 möglich sein. Leider erhalte ich bei genau diesem Aufruf [LCount := WSAEnumProtocols(nil,LPInfo,LLen);] den Fehler "Access violation at address 00000000. Read of address 00000000." Warum? Muss noch irgendetwas initialisiert werden? Oder ganz anders?
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32:
| function IPv6Installiert : Boolean; var LLen : LongWord; LPInfo, LPCurPtr : LPWSAProtocol_Info; LCount : Integer; i : Integer; begin Result := False; LLen := 0; WSAEnumProtocols(nil,nil,LLen); GetMem(LPInfo,LLen);
try LCount := WSAEnumProtocols(nil,LPInfo,LLen); if LCount <> SOCKET_ERROR then begin LPCurPtr := LPInfo; for i := 0 to LCount-1 do begin Memo1.Lines.Add(IntToStr(LPCurPtr^.iAddressFamily)); Result := (LPCurPtr^.iAddressFamily=PF_INET6); if Result then begin Break; end; Inc(LPCurPtr); end; end; finally FreeMem(LPInfo); end; end; |
WSAEnumProtocols kommt aus IdWinsock2 (Indy10).
|
|
BenBE
      
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: So 17.05.09 20:02
Crossposts bitte angeben:
www.delphipraxis.net...saenumprotocols.html
Zu deinem Problem: Alternativ auch einfach abfragen, ob er einen Hostname für "::1" kennt  Antwort ist dann entweder "Invalid Address" (kein IPv6) oder "No Host" (IPv6 installiert, aber keine brauchbare Hosts-File\kein DNSv6) oder ein Name (IPv6 installiert UND DNSv6 funzt).
_________________ Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: So 17.05.09 23:22
Moin!
CodexX hat folgendes geschrieben : | Muss noch irgendetwas initialisiert werden? |
Hab mir das jetzt nicht im Detail angesehen, aber du rufst nirgendwo WSAStartup() auf.
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
CodexX 
      
Beiträge: 118
WinXP
Delphi XE
|
Verfasst: Mo 18.05.09 03:50
Also ich glaub, ich habs jetzt...
WSAStartup hatte ich ursprünglich in der Funktion drin, habe es aber testweise ausgelagert. (deshalb fehlt das in meinem Beispiel)
Nach dem Posting von BenBE habe ich erstmal nach seinem Vorschlag gesucht und dabei ist mir aufgefallen, dass WSAStartup sowohl in Winsock als auch IdWinsock2 enthalten ist. Da ich beide über uses eingebunden hatte (IdWinsock2 reicht mir leider nicht), wurde aufgrund der Reihenfolge WSAStartup leider aus Winsock genommen und hat dann leider nicht mit WSAEnumProtocols funktioniert. Ich habe jetzt bei der Einbindung deren Plätze getauscht und damit funktioniert das jetzt.
Dein Hinweis ging also genau in die richtige Richtung, Narses.
Insofern danke Euch beiden!
|
|
CodexX 
      
Beiträge: 118
WinXP
Delphi XE
|
Verfasst: Mo 01.06.09 07:41
Doch noch nicht erledigt. Wie ich nun merke, funktioniert die Funktion nur beim ersten Aufruf. Ab dem zweiten leider nicht mehr... Wird das Programm neu gestartet, tut sie wieder genau ein Mal.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38:
| var LLen : LongWord; LPInfo, LPCurPtr : LPWSAProtocol_Info; LCount : Integer; i : Integer; Data: TWSAData; begin Result := False; LLen := 0;
if WSAStartup( MakeWord(2,2), Data) = SOCKET_ERROR then HandleWSAError else begin try WSAEnumProtocols(nil,nil,LLen); GetMem(LPInfo,LLen);
LCount := WSAEnumProtocols(nil,LPInfo,LLen); if LCount <> SOCKET_ERROR then begin LPCurPtr := LPInfo; for i := 0 to LCount-1 do begin Result := (LPCurPtr^.iAddressFamily=PF_INET6); if Result then begin Break; end; Inc(LPCurPtr); end; end; finally WSACleanup; end; end; end; |
Bin es mal durchgegangen und sehe, dass beim zweiten Aufruf der Funktion nach "WSAEnumProtocols(nil,nil,LLen);" LLen = 0 ist.
Warum?? Muss noch irgendwas resetet werden? WSACleanup wird korrekt aufgerufen. Sonst noch was? 
|
|
CodexX 
      
Beiträge: 118
WinXP
Delphi XE
|
Verfasst: Di 02.06.09 17:50
Kennt sich damit keiner aus? 
|
|
BenBE
      
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: Di 02.06.09 19:01
Du hast nicht angegeben, welche Fehlermeldung GetLastError liefert. Und Kristallkugeln sind immer so unglaublich teuer 
_________________ Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
|
|
CodexX 
      
Beiträge: 118
WinXP
Delphi XE
|
Verfasst: Di 02.06.09 19:14
Beim ersten Aufruf wie zu erwarten: 0
Beim zweiten Aufruf: 10093 = Either the application has not called WSAStartup, or WSAStartup failed.
Allerdings ist WSAStartup( MakeWord(2,2), Data) = SOCKET_ERROR sowohl beim ersten als auch beim zweiten Aufruf false (der else-Block wird verarbeitet), sodass eigentlich kein Fehler vorhanden sein sollte. :/
|
|
BenBE
      
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: Di 02.06.09 19:36
Wenn ich das richtig im Überblick hatte, so durfte WSAStartup insgesamt im Prozessverlauf nur einmal aufgerufen werden. Genau kann Dir das aber wahrscheinlich Narses am Besten sagen.
_________________ Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Do 04.06.09 17:54
Moin!
BenBE hat folgendes geschrieben : | Wenn ich das richtig im Überblick hatte, so durfte WSAStartup insgesamt im Prozessverlauf nur einmal aufgerufen werden. |
In der Regel macht es keinen Sinn, mehrfach WSAStartup() aufzurufen, aber verboten scheint es nicht zu sein:
WinSock2.hlp hat folgendes geschrieben: | An application or DLL may call WSAStartup more than once if it needs to obtain the WSAData structure information more than once. On each such call the application may specify any version number supported by the DLL.
There must be one WSACleanup call corresponding to every successful WSAStartup call to allow third-party DLLs to make use of a Windows Sockets DLL on behalf of an application. This means, for example, that if an application calls WSAStartup three times, it must call WSACleanup three times. The first two calls to WSACleanup do nothing except decrement an internal counter; the final WSACleanup call for the task does all necessary resource deallocation for the task. |
Genaueres sagt dir aber bestimmt das MSDN. WSASTARTUP
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
CodexX 
      
Beiträge: 118
WinXP
Delphi XE
|
Verfasst: So 07.06.09 16:11
Der Fehler liegt scheinbar bei Indy10. Ich habe testweise stattdessen die Jedi Winsock2-Übersetzung (JwaWinsock2) genommen und damit tritt der Fehler nicht auf. Ich werde es aber noch etwas genauer testen.
Das also mal als Hinweis an alle, die in dem Bereich was machen und ähnliche Probleme haben sollten.
|
|
|