Здравствуйте. Нужна помощь по синхронизация времени с сервером (NetRemoteTOD). У кого есть примеры для masm?
Так понял нужен список серверов времени поддерживающих протокол SNTP? И потом с их помощью обновить лок. время?
Ну во первых нужно определить - какой сервер тебе подойдет, то есть сам ты откуда )) ... далее Европа ... ... потом Украина )) Найден твой сервер для синхр. времени. Теперь задача тебе достучаться к нему. Пишешь клиент Код (Text): ;Get SNTP Time .386 .model flat,stdcall option casemap:none include \masm32\include\windows.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\wsock32.inc include \masm32\include\masm32.inc includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\wsock32.lib includelib \masm32\lib\masm32.lib ; Microsoft Visual C++ Lib includelib \masm32\lib\msvcrt.lib ; .const WindowWidth equ 500 ; WindowHight equ 100 ; ; Button0ID equ 1 ; Button0‚МID Edit0ID equ 2 ; EditBox0‚МID ; Button0XPos equ 20 Button0YPos equ 20 Button0Hight equ 25 Button0Width equ 120 Edit0XPos equ ( Button0XPos + Button0Width + 20 ) Edit0YPos equ Button0YPos Edit0Hight equ 25 Edit0Width equ 300 TIMEOUT equ 3 ; ; WinMain proto :DWORD,:DWORD,:DWORD,:DWORD FD_ZERO proto :DWORD FD_SET proto :SOCKET,:DWORD FD_ISSET proto :SOCKET,:DWORD localtime proto c:DWORD DDWORD STRUCT Low_DD DWORD ? High_DD DWORD ? DDWORD ENDS NTP_Packet STRUCT Control_Word DWORD ? root_delay DWORD ? root_dispersion DWORD ? reference_identifier DWORD ? reference_timestamp DDWORD <> originate_timestamp DDWORD <> receive_timestamp DDWORD <> transmit_timestamp_seconds DWORD ? transmit_timestamp_fractions DWORD ? NTP_Packet ENDS tm STRUCT tm_sec DWORD ? ; seconds after the minute - [0,59] tm_min DWORD ? ; minutes after the hour - [0,59] tm_hour DWORD ? ; hours since midnight - [0,23] tm_mday DWORD ? ; day of the month - [1,31] tm_mon DWORD ? ; months since January - [0,11] tm_year DWORD ? ; years since 1900 tm_wday DWORD ? ; days since Sunday - [0,6] tm_yday DWORD ? ; days since January 1 - [0,365] tm_isdst DWORD ? ; daylight savings time flag tm ENDS .data AppName db "SendMsg",NULL ClassName db "SendMsgClass",NULL ButtonClassName db "button",NULL EditClassName db "edit",NULL Button0Caption db "Get SNTP Time!",NULL SNTPAddress db "0.ua.pool.ntp.org",NULL ; template1 db "NTP Server Time : %d/%d/%d %d:%d:%d",NULL ; ErrMsg0 db "Error[0]: WSACleanup s",NULL ErrMsg1 db "Error[1]: WinSock‚",NULL ErrMsg2 db "Error[2]: Socket",NULL ErrMsg3 db "Error[3]: ",NULL ErrMsg4 db "Error[4]: ",NULL ErrMsg5 db "Error[5]: ",NULL ErrMsg6 db "Error[6]: ",NULL ErrMsg7 db "Error[7]: ",NULL ErrMsg8 db "Error[8]: ",NULL ErrMsg9 db "Error[9]: ",NULL ErrMsg10 db "Error[10]:",NULL ErrMsg11 db "Error[11]:",NULL ; NullData db NULL ; port DWORD 123 ; unsigned short local_port DWORD 1024 ; unsigned short .data? hInstance HINSTANCE ? CommandLine LPSTR ? ; wsaData WSADATA <> ; STRUCT WSADATA(windows.inc) soc DWORD ? ; int sockname sockaddr_in <> ; STRUCT sockaddr_in() serversockaddr sockaddr_in <> ; STRUCT sockaddr_in() serveraddr DWORD ? ; unsigned long serverhostent DWORD ? ; struct hostent * NTP_Send NTP_Packet <> ; NTP_Recv NTP_Packet <> ; waittime timeval <> ; rdps fd_set <> ; sockaddr_Size DWORD ? ; int selret DWORD ? ; int ntp_time LONG ? ; long(4 Byte) NewNTP_Time tm <> lpNewNTP_Time DWORD ? ; tmЌ\'ў'М‚Ц‚Мѓ|ѓCѓ"ѓ^ ; hwndButton0 HWND ? ; Button‚МѓEѓBѓ"ѓhѓEѓnѓ"ѓhѓ‹ hwndEdit0 HWND ? ; EditBox‚МѓEѓBѓ"ѓhѓEѓnѓ"ѓhѓ‹ TextBuff0 db 64 dup( ? ) .code start: invoke GetModuleHandle, NULL ; ѓ‚ѓWѓ...Ѓ[ѓ‹‚МЋж"ѕ mov hInstance,eax invoke GetCommandLine ; ѓRѓ}ѓ"ѓhѓ‰ѓCѓ"‚МЋж"ѕ mov CommandLine,eax invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT ; WinMain‚МЋАЌs invoke ExitProcess,eax ; ЏI-№ѓvѓЌѓZѓX WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD LOCAL wc:WNDCLASSEX LOCAL msg:MSG LOCAL hwnd:HWND mov wc.cbSize,SIZEOF WNDCLASSEX mov wc.style, CS_HREDRAW or CS_VREDRAW mov wc.lpfnWndProc, OFFSET WndProc mov wc.cbClsExtra,NULL mov wc.cbWndExtra,NULL push hInstance pop wc.hInstance mov wc.hbrBackground,COLOR_BTNFACE+1 mov wc.lpszMenuName,NULL mov wc.lpszClassName,OFFSET ClassName invoke LoadIcon,NULL,IDI_APPLICATION mov wc.hIcon,eax mov wc.hIconSm,eax invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor,eax invoke RegisterClassEx, addr wc invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\ WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\ CW_USEDEFAULT,WindowWidth,WindowHight,NULL,NULL,\ hInst,NULL mov hwnd,eax invoke ShowWindow, hwnd,SW_SHOWNORMAL invoke UpdateWindow, hwnd .WHILE TRUE ; ѓЃѓbѓZЃ[ѓWѓ‹Ѓ[ѓv invoke GetMessage, ADDR msg,NULL,0,0 ; ѓЃѓbѓZЃ[ѓW‚МЋж"ѕ .BREAK .IF (!eax) invoke TranslateMessage, ADDR msg invoke DispatchMessage, ADDR msg .ENDW mov eax,msg.wParam ret WinMain endp ; API‚ WndProc proc uses ebx ecx edx hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM mov eax,uMsg .IF eax == WM_DESTROY invoke PostQuitMessage,NULL .ELSEIF eax == WM_CREATE ; invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR Button0Caption,\ WS_CHILD or WS_VISIBLE or ES_CENTER,\ Button0XPos,Button0YPos,Button0Width,Button0Hight,\ hWnd,Button0ID,hInstance,NULL mov hwndButton0,eax ; ; invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,NULL,\ WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or \ ES_AUTOHSCROLL,\ Edit0XPos,Edit0YPos,Edit0Width,Edit0Hight,\ hWnd,Edit0ID,hInstance,NULL mov hwndEdit0,eax ; .ELSEIF eax == WM_COMMAND mov eax,wParam .IF eax == 0 ; ; .ELSE ; .IF ax == Button0ID shr eax,16 .IF ax == BN_CLICKED ; call GetSNTPTime .ENDIF .ENDIF .ENDIF .ELSE invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret .ENDIF xor eax,eax ret WndProc endp GetSNTPTime proc uses ebx ecx edx ; invoke WSAStartup,101h,ADDR wsaData .IF eax != 0 invoke SetWindowText,hwndEdit0,ADDR ErrMsg1 mov eax,-1 ret .ENDIF ; UDP invoke socket,PF_INET,SOCK_DGRAM,0 mov soc,eax .IF soc == INVALID_SOCKET invoke WSACleanup invoke SetWindowText,hwndEdit0,ADDR ErrMsg2 mov eax,-1 ret .ENDIF ; mov sockname.sin_family,AF_INET mov sockname.sin_addr.S_un.S_addr,INADDR_ANY invoke htons,local_port mov sockname.sin_port,ax invoke MemCopy,ADDR NullData,ADDR sockname.sin_zero,sizeof sockname.sin_zero ; invoke bind,soc,ADDR sockname,sizeof sockname .IF eax == SOCKET_ERROR invoke WSAGetLastError invoke SetWindowText,hwndEdit0,ADDR ErrMsg3 invoke closesocket,soc invoke WSACleanup mov eax,-1 ret .ENDIF invoke inet_addr,ADDR SNTPAddress mov serveraddr,eax .IF serveraddr == -1 invoke gethostbyname ,ADDR SNTPAddress ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; gethostbyname mov serverhostent,eax .IF serverhostent == NULL invoke SetWindowText,hwndEdit0,ADDR ErrMsg4 invoke closesocket,soc invoke WSACleanup mov eax,-1 ret .ELSE mov eax,[eax + 12] ; h_list mov eax,[eax] mov eax,[eax] ; ip address mov serveraddr,eax .ENDIF .ENDIF ; mov serversockaddr.sin_family,AF_INET mov eax,serveraddr mov serversockaddr.sin_addr.S_un.S_addr,eax invoke htons,port ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;htons mov serversockaddr.sin_port,ax invoke MemCopy,ADDR NullData,ADDR serversockaddr.sin_zero,sizeof serversockaddr.sin_zero ; invoke htonl,0B000000h mov NTP_Send.Control_Word,eax mov NTP_Send.root_delay,0 mov NTP_Send.root_dispersion,0 mov NTP_Send.reference_identifier,0 mov NTP_Send.reference_timestamp.Low_DD,0 mov NTP_Send.reference_timestamp.High_DD,0 mov NTP_Send.originate_timestamp.Low_DD,0 mov NTP_Send.originate_timestamp.High_DD,0 mov NTP_Send.receive_timestamp.Low_DD,0 mov NTP_Send.receive_timestamp.High_DD,0 mov NTP_Send.transmit_timestamp_seconds,0 mov NTP_Send.transmit_timestamp_fractions,0 ; invoke sendto ,soc,ADDR NTP_Send,sizeof NTP_Send ,0,\ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sendto ADDR serversockaddr,sizeof serversockaddr .IF eax == SOCKET_ERROR invoke SetWindowText,hwndEdit0,ADDR ErrMsg5 invoke closesocket,soc invoke WSACleanup mov eax,-1 ret .ENDIF mov waittime.tv_sec,TIMEOUT mov waittime.tv_usec,0 invoke FD_ZERO,ADDR rdps invoke FD_SET,soc,ADDR rdps invoke select,FD_SETSIZE,ADDR rdps,NULL,NULL,ADDR waittime ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;select .IF eax == SOCKET_ERROR invoke SetWindowText,hwndEdit0,ADDR ErrMsg6 invoke closesocket,soc invoke WSACleanup mov eax,-1 ret .ENDIF .IF eax == 0 invoke SetWindowText,hwndEdit0,ADDR ErrMsg7 invoke closesocket,soc invoke WSACleanup mov eax,-1 ret .ENDIF invoke FD_ISSET,soc,ADDR rdps .IF eax == FALSE invoke SetWindowText,hwndEdit0,ADDR ErrMsg8 invoke closesocket,soc invoke WSACleanup mov eax,-1 ret .ENDIF mov sockaddr_Size,sizeof serversockaddr invoke recvfrom,soc,ADDR NTP_Recv,sizeof NTP_Recv,0,ADDR serversockaddr,ADDR sockaddr_Size;;;;;;;recvfrom .IF eax == SOCKET_ERROR invoke SetWindowText,hwndEdit0,ADDR ErrMsg8 invoke closesocket,soc invoke WSACleanup mov eax,-1 ret .ENDIF invoke closesocket,soc .IF eax == SOCKET_ERROR invoke SetWindowText,hwndEdit0,ADDR ErrMsg11 invoke WSACleanup mov eax,-1 ret .ENDIF invoke ntohl,NTP_Recv.transmit_timestamp_seconds sub eax,2208988800 ; 1970/01/01‚(c)‚з‚М•bђ"‚Й•ПЉ· mov ntp_time,eax invoke localtime,ADDR ntp_time .IF eax == NULL invoke SetWindowText,hwndEdit0,ADDR ErrMsg9 invoke WSACleanup mov eax,-1 ret .ENDIF mov lpNewNTP_Time,eax invoke MemCopy,lpNewNTP_Time,ADDR NewNTP_Time,sizeof NewNTP_Time ; tmЌ\'ў'М‚рѓRѓsЃ[ ; add NewNTP_Time.tm_year,1900 add NewNTP_Time.tm_mon,1 ; EditBox‚ invoke wsprintf,ADDR TextBuff0,ADDR template1,\ NewNTP_Time.tm_year,NewNTP_Time.tm_mon,NewNTP_Time.tm_mday,\ NewNTP_Time.tm_hour,NewNTP_Time.tm_min,NewNTP_Time.tm_sec mov ebx,eax mov TextBuff0[ ebx ],NULL ; invoke SetWindowText,hwndEdit0,ADDR TextBuff0 ; invoke WSACleanup .IF eax == SOCKET_ERROR invoke SetWindowText,hwndEdit0,ADDR ErrMsg0 mov eax,-1 ret .ENDIF xor eax,eax ret GetSNTPTime endp ; FD_ZERO proc uses ebx set:DWORD mov ebx,set mov DWORD PTR [ebx],NULL ; fd_count = 0 xor eax,eax ret FD_ZERO endp ; FD_SET proc uses ebx ecx edx fd:SOCKET,set:DWORD mov ebx,set mov eax,DWORD PTR [ebx] ; Load fd_count .IF eax < FD_SETSIZE ; fd_count < FD_SETSIZE push ebx mov ecx,eax inc ecx @loop1: add ebx,sizeof SOCKET loop @loop1 add ebx,eax mov edx,fd mov DWORD PTR [ebx],edx pop ebx inc DWORD PTR [ebx] .ENDIF xor eax,eax ret FD_SET endp ; FD_ISSET proc uses ebx ecx edx fd:SOCKET,set:DWORD mov ebx,set mov eax,DWORD PTR [ebx] ; Load fd_count mov edx,fd ; xor ecx,ecx @loop1: cmp ecx,eax jge @no_find1 add ebx,sizeof SOCKET cmp DWORD PTR [ebx],edx je @next1 inc ecx jmp @loop1 ; @no_find1: mov eax,FALSE ret @next1: mov eax,TRUE ret FD_ISSET endp end start Ну запускаем и результат Фсио )))