如何检测Delphi 7中的IPV6地址变化?

时间:2013-03-07 12:53:07

标签: delphi delphi-7 winsock

我一直在寻找一种在Windows XP及更高版本上使用delphi 7检测IPV6地址更改的方法。对于vista,我知道有一个Windows API。我遇到了声称在XP上也做同样的代码。以下是代码:

uses  WinSock2 ; //

procedure TForm1.Button1Click(Sender: TObject);
var
  s: TSocket;
  wsaD: TWSADATA;
  BytesReturned: u_long;
  PtrA: Pointer;
  Buffer: array[0..20] of INTERFACE_INFO;
  ret: Integer;
begin
  try
    FillChar(wsaD, SizeOf(wsaD), #0);
    FillChar(Buffer, SizeOf(Buffer), #0);
    WSAStartup($0101, wsaD);                      // Start WinSock,You should normally check for errors here

    {Create a WSA Socket}
    // s := WSASocketA(AF_INET6,SOCK_STREAM, IPPROTO_TCP, nil, 0, 0);

    s := Socket(AF_INET6, SOCK_STREAM, IPPROTO_IP);         // Open a socket
    if (s = INVALID_SOCKET) then
      Exit;

    PtrA := @bytesReturned;
    //   Ret :=  WSAIoCtl(s, SIO_ADDRESS_LIST_CHANGE, @Buffer,1024, @Buffer, 1024, PtrA, nil, nil);
    Ret :=  WSAIoCtl(s, SIO_ADDRESS_LIST_QUERY, nil,0, @Buffer, SizeOf(Buffer), PtrA, nil, nil);
    DebugLog('Ret Value = ' + SysErrorMessage(WSAGetLastError),0);
    if ret = 0 then
    begin
      // DebugLog('IP Address changed !',0);
      //Showmessage('Operation succeeded !')
    end
    else
    begin
      //DebugLog('No change found in IP Address',0);
      // showmessage(SysErrorMessage(WSAGetLastError));
    end;

    WSAcleanUp;
  except

  end;
end;

我将错误代码视为

  

“提供了无效参数。”

当我将控制代码更改为SIO_ADDRESS_LIST_QUERY时,代码工作正常。

有人可以指导我吗?

0 个答案:

没有答案