Advertisement
TLama

Untitled

Dec 5th, 2014
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.11 KB | None | 0 0
  1. [Code]
  2. const
  3.   WINSOCK_2_2 = 514;
  4.   INADDR_NONE = $FFFFFFFF;
  5.   WSASYS_STATUS_LEN = 128;
  6.   WSADESCRIPTION_LEN = 256;
  7.  
  8. type
  9.   u_long = DWORD;
  10.   #ifndef UNICODE
  11.   AnsiString = string;
  12.   #endif
  13.  
  14.   TWSAData = record
  15.     wVersion: Word;
  16.     wHighVersion: Word;
  17.     szDescription: array[0..WSADESCRIPTION_LEN] of AnsiChar;
  18.     szSystemStatus: array[0..WSASYS_STATUS_LEN] of AnsiChar;
  19.     iMaxSockets: Word;
  20.     iMaxUdpDg: Word;
  21.     lpVendorInfo: PAnsiChar;
  22.   end;
  23.  
  24. function WSAStartup(wVersionRequested: Word; var lpWSAData: TWSAData): Integer;
  25.   external 'WSAStartup@ws2_32.dll stdcall';
  26. function WSACleanup: Integer;
  27.   external 'WSACleanup@ws2_32.dll stdcall';
  28. function inet_addr(cp: AnsiString): DWORD;
  29.   external 'inet_addr@ws2_32.dll stdcall';
  30.  
  31. function IsValidIPv4(const Value: string): Boolean;
  32. var
  33.   Data: TWSAData;
  34. begin
  35.   Result := Value <> '';
  36.   if Result then
  37.   begin
  38.     if WSAStartup(WINSOCK_2_2, Data) = 0 then
  39.     begin
  40.       Result := inet_addr(AnsiString(Value)) <> INADDR_NONE;
  41.       WSACleanup;
  42.     end
  43.     else
  44.       RaiseException('Winsock initialization failed!');
  45.   end;
  46. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement