# Include <iostream>
# Include <stdio. h>
# Include <windows. h>
# Include <string. h>
Using namespace STD;
# Pragma comment (Lib, "ws2_32.lib ")
Class cinitsock
{
Public:
Cinitsock (INT version01 = 2, int versiont02 = 2)
{
Word sockversion = makeword (2, 2 );
Wsadata = {0 };
If (wsastartup (sockversion, & wsadata )! = 0)
{
Cout <"initlization failed! "<Endl;
Exit (0 );
}
}
~ Cinitsock ()
{
Wsacleanup ();
}
};
Cinitsock mysock;
Void settimefromtp (ulong ultime)
{
Filetime ft;
Systemtime st;
St. wyear = 1900;
St. wmonth = 1;
St. wday = 1;
St. whour = 0;
St. wminute = 0;
St. wsecond = 0;
St. wmilliseconds = 0;
Systemtimetofiletime (& St, & ft );
Longlong * pllong = (Longlong *) & ft;
* Pllong + = (Longlong) 10000000 & ultime;
Filetimetosystemtime (& ft, & St );
Setsystemtime (& St );
}
Int main ()
{
Socket S = socket (af_inet, sock_stream, ipproto_tcp );
If (S = invalid_socket)
{
Cout <"faied socket" <Endl;
Return 0;
}
Sockaddr_in sin;
Sin. sin_addr.s_un.s_addr = inet_addr ("129.6.15.28 ");
Sin. sin_family = af_inet;
Sin. sin_port = htons (37 );
If (connect (S, (sockaddr *) & sin, sizeof (SIN) =-1)
{
Cout <"failed connect..." <Endl;
Return 0;
}
Ulong ultime = 0;
Int nrecv = Recv (S, (char *) & ultime, sizeof (ultime), 0 );
If (nrecv> 0)
{
Ultime = ntohl (ultime );
Settimefromtp (ultime );
Cout <"Update time successfully! "<Endl;
}
Else
{
Cout <"can't update time..." <Endl;
}
Closesocket (s );
Return 0;
}