function GetINetTime(p: Pointer): Integer;
var
szBuffer:
array[0..255]
of Char;
dwResult: DWORD;
hostent: PHostEnt;
sckt: TSocket;
saddr: TSockAddr;
res: integer;
i: Cardinal;
s:
string;
sStatus:
string;
bOnline: Boolean;
begin
result := 0;
SetDlgItemText(hApp, IDC_STCSRVRDATE,
nil);
SetDlgItemText(hApp, IDC_SRVRTIME,
nil);
bOnline := InternetGetConnectedState(@dwResult, 0);
while bOnline
do
begin
EnableWindow(GetDlgItem(hApp, IDC_BTNCORRECT), bOnline);
if bOnline = FALSE
then
begin
sStatus := '
nicht verbunden';
SendDlgItemMessage(hApp, IDC_STATBAR, SB_SETTEXT, 0, Integer(@sStatus[1]));
break;
end;
sStatus := '
verbunden';
SendDlgItemMessage(hApp, IDC_STATBAR, SB_SETTEXT, 0, Integer(@sStatus[1]));
SendDlgItemMessage(hApp, IDC_CBSERVER, CB_GETLBTEXT, 0, Integer(@szBuffer));
hostent := gethostbyname(szBuffer);
if hostent =
nil then exit;
sckt := socket(PF_INET, SOCK_STREAM, 0);
if (sckt <> INVALID_SOCKET)
and (hostent <>
nil)
then
begin
ZeroMemory(@saddr, sizeof(TSockAddr));
saddr.sin_addr.S_addr := integer(pointer(hostent^.h_addr_list^)^);
saddr.sin_family := PF_INET;
saddr.sin_port := htons(37);
res := connect(sckt, saddr, sizeof(TSockAddr));
if (res <> SOCKET_ERROR)
then
res := recv(sckt, i, sizeof(i), 0);
if (res <> SOCKET_ERROR)
then
// Cardinal-Wert "drehen" (host byte order -> TCP/IP network byte order)
i := htonl(i)
else
i := 0;
EnterCriticalSection(cs);
ServerTime := i;
LeaveCriticalSection(cs);
s := FormatTimeFromInternet(@i);
SetDlgItemText(hApp, IDC_SRVRTIME, pointer(s));
s := FormatdateFromInternet(@i);
SetDlgItemText(hApp, IDC_STCSRVRDATE, pointer(s));
CloseSocket(sckt);
end;
sleep(500);
bOnline := InternetGetConnectedState(@dwResult, 0);
end;
end;