{"id":117,"date":"2009-07-24T00:57:05","date_gmt":"2009-07-23T16:57:05","guid":{"rendered":"http:\/\/115.29.108.60\/?p=117"},"modified":"2011-09-26T21:35:26","modified_gmt":"2011-09-26T13:35:26","slug":"%e5%9f%ba%e4%ba%8esocket%e7%9a%84%e6%8e%88%e6%97%b6%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"http:\/\/115.29.108.60\/?p=117","title":{"rendered":"\u57fa\u4e8eSocket\u7684\u6388\u65f6\u7a0b\u5e8f"},"content":{"rendered":"<p>#include &lt;windowsx.h&gt;<br \/>\n#include &lt;winsock2.h&gt;<\/p>\n<p>#define HIGHTIME 21968699 \/\/ 21968708 \/\/ Jan 1, 1900 FILETIME.highTime<br \/>\n#define LOWTIME 4259332096 \/\/ 1604626432 \/\/ Jan 1, 1900 FILETIME.lowtime<\/p>\n<p>void WinSocket()<br \/>\n{<br \/>\n\u00a0WSADATA wsaData;\u00a0<br \/>\n\u00a0WSAStartup(MAKEWORD(2, 0), &amp;wsaData);\/\/\u521d\u59cb\u5316Socket\u5e93\uff0c\u201c2,0\u201d\u4e3a\u7248\u672c\u53f7\u3002<br \/>\n\u00a0SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);\/\/\u5957\u63a5\u5b57\uff0c\u5373\u8fde\u63a5\u7ebf\u3002<br \/>\n\u00a0SOCKADDR_IN sa;<br \/>\n\u00a0sa.sin_family = AF_INET;\u00a0<br \/>\n\u00a0sa.sin_port = htons(IPPORT_TIMESERVER);\/\/\u8bbe\u7f6e\u8fde\u63a5\u670d\u52a1\u5668\u7aef\u7aef\u53e3<br \/>\n\u00a0sa.sin_addr.S_un.S_addr = inet_addr(&#8220;210.72.145.8&#8221;);\/\/ping www.time.ac.cn<br \/>\n\u00a0\/\/\u5ba2\u6237\u7aef\u7aef\u53e3\u52a8\u6001\u5206\u914d\u3001\u81ea\u52a8\u751f\u6210\u3002<br \/>\n\u00a0if(connect(sock, (SOCKADDR *)&amp;sa, sizeof(sa)) == SOCKET_ERROR)<br \/>\n\u00a0{<br \/>\n\u00a0\u00a0ShowError();<br \/>\n\u00a0\u00a0return;<br \/>\n\u00a0}<br \/>\n\u00a0\u00a0\u00a0 \/\/<br \/>\n\u00a0\u00a0\u00a0 \/\/ Add code here<br \/>\n\u00a0\u00a0\u00a0 \/\/<br \/>\n\u00a0unsigned long ulTime;<br \/>\n\u00a0\/\/\u63a5\u6536\u65f6\u95f4\u6d88\u606f<br \/>\n\u00a0recv(sock, (char*)&amp;ulTime, sizeof(unsigned long), 0);<br \/>\n\u00a0ulTime = ntohl(ulTime);\/\/\u4ece\u7f51\u7edc\u5b57\u8282\u987a\u5e8f\u8f6c\u6362\u4e3a\u4e3b\u673a\u5b57\u8282\u987a\u5e8f<br \/>\n\u00a0SYSTEMTIME st;<br \/>\n\u00a0UINT64 uiCurTime, uiBaseTime, uiResult;<br \/>\n\u00a0uiBaseTime = ((UINT64) HIGHTIME &lt;&lt; 32) + LOWTIME;<br \/>\n\u00a0uiCurTime = (UINT64)ulTime * (UINT64)10000000;<br \/>\n\u00a0uiResult = uiBaseTime + uiCurTime;<br \/>\n\u00a0FileTimeToSystemTime((LPFILETIME)&amp;uiResult, &amp;st);<br \/>\n\u00a0TCHAR cBuffer[256];<br \/>\n\u00a0ZeroMemory(cBuffer, sizeof(cBuffer));<br \/>\n\u00a0wsprintf(cBuffer, TEXT(&#8220;\u5f53\u524d\u51c6\u786e\u65f6\u95f4\u4e3a\uff1a%d\u5e74%d\u6708%d\u65e5 %d\u65f6:%d\u5206:%d\u79d2&#8221;), st.wYear, st.wMonth, st.wDay, st.wHour+8, st.wMinute, st.wSecond);<br \/>\n\u00a0\/\/\u7531\u4e8e\u6388\u65f6\u670d\u52a1\u5668\u8fd4\u56de\u7684\u662f\u683c\u6797\u5c3c\u6cbb\u65f6\u95f4\uff0c\u4e2d\u56fd\u5728\u4e1c\u516b\u533a\uff0c\u6545st.wHour+8\u3002<br \/>\n\u00a0MessageBox(NULL, cBuffer, &#8220;\u51c6\u786e\u65f6\u95f4&#8221;, MB_OK);<br \/>\n\u00a0SetSystemTime(&amp;st);<br \/>\n\u00a0MessageBox(NULL, TEXT(&#8220;\u6388\u65f6\u6210\u529f&#8221;), TEXT(&#8220;\u6388\u65f6\u6210\u529f&#8221;), MB_OK);<br \/>\n\u00a0closesocket(sock);<br \/>\n\u00a0WSACleanup();<br \/>\n}<\/p>\n<p>void ShowError()<br \/>\n{<br \/>\n\u00a0TCHAR* lpMsgBuf;<br \/>\n\u00a0FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |\/\/\u81ea\u52a8\u5206\u914d\u6d88\u606f\u7f13\u51b2\u533a<br \/>\n\u00a0FORMAT_MESSAGE_FROM_SYSTEM, \/\/\u4ece\u7cfb\u7edf\u83b7\u53d6\u4fe1\u606f<br \/>\n\u00a0NULL, GetLastError(), \/\/\u83b7\u53d6\u9519\u8bef\u4fe1\u606f\u6807\u8bc6<br \/>\n\u00a0MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \/\/\u4f7f\u7528\u7cfb\u7edf\u7f3a\u7701\u8bed\u8a00<br \/>\n\u00a0(LPTSTR)&amp;lpMsgBuf, \/\/\u6d88\u606f\u7f13\u51b2\u533a<br \/>\n\u00a00, NULL);<br \/>\n\u00a0MessageBox(NULL, lpMsgBuf, TEXT(&#8220;\u9519\u8bef\u4fe1\u606f&#8221;), MB_ICONERROR);<br \/>\n}<\/p>\n<p><a href=\"http:\/\/115.29.108.60\/wp-content\/uploads\/2009\/07\/Time.exe\">\u7535\u8111\u51c6\u786e\u5bf9\u65f6<\/a><\/p>\n<p>\u53ef\u80fd\u4f1a\u56e0\u7f3a\u5c11<a href=\"http:\/\/115.29.108.60\/wp-content\/uploads\/2009\/07\/MSVCIRTD.DLL\">MSVCIRTD.DLL<\/a>\u6587\u4ef6\u62a5\u9519\uff0c\u5c06\u8be5\u6587\u4ef6\u4e0b\u8f7d\u5e76\u653e\u5165WINDOWS\/system32\u6587\u4ef6\u5939\u4e0b\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#include &lt;windowsx.h&gt; #include &lt;winsock2.h&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-117","post","type-post","status-publish","format-standard","hentry","category-windows"],"_links":{"self":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=117"}],"version-history":[{"count":3,"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":853,"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts\/117\/revisions\/853"}],"wp:attachment":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}