Internet Date

User avatar
Ugo
Posts: 283
Joined: Sat Oct 15, 2005 6:40 am
Location: Turin, Italy

Re: Internet Date

Post by Ugo »

Hi James,
There are two links to the source code further up in this message thread.
yes, I download it. But, as Stefan wrote, the source code of the function GetSntp() is not present. :(

Stefan Haupt wrote on 26 Nov 2012 09:29
I found parts of the source here
http://www4.zzz.com.tw/phpbb2/viewtopic.php?t=29
But the function GetSntp() is missing, maybe you can contact the author
and Jeff Barnes wrote on 26 Nov 2012 20:23
I was able to get it working by linking the .lib file then adding an INCLUDE "TSNTP.PRG"
The sorce of Jeff with the sntp.lib, work with any ntp server, but over the 32 requests always returns "fail"

This is my last test with the change, every test, of the ntp server:
(is the same if the time between 2 requests is 1 sec. or 5 min. o also 30 min.)
(is the same if renew the object oSntp)

Code: Select all

Func    TestNTP()
Local   aNet      := {},;
        nPort     := 123,;
        cIp       := "ntp1.inrim.it",;   // "time.windows.com",;
        lSync     := .F.,;
        oSntp     := NIL,;
        cTimeTest := "",;
        nX,;
        lOk  := .F.,;
        cServer

        cIp := { "1.it.pool.ntp.org", ;
                 "ntp1.inrim.it" ,;
                 "time.windows.com",;
                 "ntp2.inrim.it" ,;
                 "1.europe.pool.ntp.org" }


        ? "test begin"

        // test-1
        // lSync = .T., ?????, ? LocalTime ? NTP Server ????
        // or oSntp := TSntp():New(); oSntp:cIp := '....'; oSntp:nPort = ....
        IF ValType( cIp ) == "A"
           cServer := cIp[1]
           FOR nX := 0 TO 200
              Millisec( 1000 * 1 )  // 60 *
              // is the same if the time between 2 requests is 1 sec. or 5 min. o also 30 min.
              cServer := cIp[ Val( cValToChar( nX % Len( cIp ) + 1 ) ) ]
              IF nX % 30 == 0
                // is the same if renew the object oSntp
                oSntp := Nil
                 SysRefresh()
                 oSntp := TSntp():New( cServer, nPort, lSync )
              ENDIF
              If oSntp:GetData( @cServer )
                 MyLogFile( "tst.log", { oSntp:DateTime2(), cServer } )
              Else
                 MyLogFile( "tst.log", { "FAIL", cServer, oSntp:nError } )
              ENDIF
           NEXT
        ELSE
           cServer := cIp
           oSntp := TSntp():New( cServer, nPort, lSync )
           FOR nX := 1 TO 200
              Millisec( 1000 * 5 )  // 60 *
              If oSntp:GetData( @cServer )
                 MyLogFile( "tst.log", { oSntp:DateTime2(), cServer } )
              Else
                 MyLogFile( "tst.log", { "FAIL", cServer, oSntp:nError } )
              ENDIF
           NEXT
        ENDIF

Return  NIL



// TSNTP.PRG
// Copyright by WenSheng come from TAIWAN
#include "hbclass.ch"
#include "common.ch"
CLASS   TSNTP

        DATA    cServer,;       // server name/ip
                nPort,;         // server port
                lSync,;         // Sync flag
                lError

        DATA    nYear,;
                nMonth,;
                nDay,;
                nWeek,;
                nDayOfYear

        DATA    nHours,;
                nMinute,;
                nSeconds,;
                nError

        METHOD  New( cServer, nPort, lSync)
        METHOD  GetData()
        MESSAGE DATE      METHOD  _Date()
        MESSAGE TIME      METHOD  _Time()
        MESSAGE DATETIME  METHOD _DateTime()
        MESSAGE DATETIME2 METHOD _DateTime2()

ENDCLASS

//
METHOD  New( cServer, nPort, lSync )    CLASS   TSNTP
DEFAULT cServer to "time.windows.com"   // ????
DEFAULT nPort   to 123                  // ?? port
DEFAULT lSync   to .F.                  // ????

        ::cServer   := cServer
        ::nPort     := nPort
        ::lSync     := lSync
        ::lError    := .F.
        ::nError    := 0

RETURN  Self

//
METHOD  GetData( cServer )   CLASS   TSNTP
   Local   xRet

   DEFAULT cServer := ::cServer

   xRet := GetSNTP( cServer, ::nPort, ::lSync )
        If ValType(xRet) == "N"
           ::lError   := .T.
           ::nError   := xRet
           ::nYear    := 0
           ::nMonth   := 0
           ::nDay     := 0
           ::nHours   := 0
           ::nMinute  := 0
           ::nSeconds := 0
           ::nWeek    := 0
           ::nDayOfYear := 0
        Else
           ::lError := .F.
           ::nError := 0
           //          0        1         2
           //          12345678901234567890
           //     ???? yyyymmddhhmmsswyda
           // ? "|" + xRet + "|"
           ::nYear    := Val( Substr( xRet,  1, 4 ))
           ::nMonth   := Val( Substr( xRet,  5, 2 ))
           ::nDay     := Val( Substr( xRet,  7, 2 ))
           ::nHours   := Val( Substr( xRet,  9, 2 ))
           ::nMinute  := Val( Substr( xRet, 11, 2 ))
           ::nSeconds := Val( Substr( xRet, 13, 2 ))
           ::nWeek    := Val( Substr( xRet, 15, 1 ))
           ::nDayOfYear := Val( Substr( xRet, 16, 3 ))
        EndIf

RETURN  ! ::lError

//
METHOD  _Date()     CLASS   TSNTP
RETURN  StoD( PadL( ::nYear, 4, "0" )+;
              PadL( ::nMonth, 2, "0" )+;
              PadL( ::nDay, 2, "0" ))

//
METHOD  _Time()     CLASS   TSNTP
RETURN  PadL( ::nHours, 2, "0" )+":"+;
        PadL( ::nMinute, 2, "0" )+":"+;
        PadL( ::nSeconds, 2, "0" )

METHOD _DateTime()
RETURN  PadL( ::nYear, 4, "0" ) + ;
        PadL( ::nMonth, 2, "0" ) + ;
        PadL( ::nDay, 2, "0" ) + ;
        PadL( ::nHours, 2, "0" ) + ;
        PadL( ::nMinute, 2, "0" ) + ;
        PadL( ::nSeconds, 2, "0" )

METHOD _DateTime2()
RETURN  PadL( ::nMonth, 2, "0" ) + "/" + ;
        PadL( ::nDay, 2, "0" ) + "/" +;
        PadL( ::nYear, 4, "0" ) + " " + ;
        PadL( ::nHours, 2, "0" ) + ":" +;
        PadL( ::nMinute, 2, "0" ) + ":" +;
        PadL( ::nSeconds, 2, "0" )
I can not see errors for this limit and i think that probably the snpt.lib in tsntp.rar contain the GetSntp() linkable to the xharbour object but it is created with the limit, for this reason I search the source code of sntp.lib

As Stefan wrote: "maybe you can contact the author" does anyone know the author? his email address?

Thanks in advance.
Ciao, best regards,
Ugo
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Internet Date

Post by James Bott »

My apologies, Ugo. I didn't notice you were looking for a missing section of code.

James
User avatar
Ugo
Posts: 283
Joined: Sat Oct 15, 2005 6:40 am
Location: Turin, Italy

Re: Internet Date

Post by Ugo »

Hi James,

now it is certainly more clear! ;)
Ciao, best regards,
Ugo
StefanHaupt
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Internet Date

Post by StefanHaupt »

Ugo,
As Stefan wrote: "maybe you can contact the author" does anyone know the author? his email address?
maybe the author is WengSheng, as mentioned in the source, but I don´t know how to contact him.
kind regards
Stefan
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Internet Date

Post by James Bott »

I did some searching and I found a number of references to a WenSheng (not WengSheng) in Harbour and xHarbour forums. But, there were no email addresses.

James
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: Internet Date

Post by RAMESHBABU »

I did some searching and I found a number of references to a WenSheng (not WengSheng) in Harbour and xHarbour forums. But, there were no email addresses.

James
This is the email id attached to those posting in Harbour Forum Postings

wen.ssbbs@gmail.com

This ssbbs is our forum member also I think. And previously I got SMART.LIB from him.
Please look at this posting where he mentioned about his email id as:

ssbbs_at_mail_zzz_com_tw
change _at_ to @


change _zzz to .zzz ...

http://forums.fivetechsupport.com/sear ... rds=ssbbs

Just now I found a forum maintained by him:


http://www4.zzz.com.tw/phpbb2/viewtopic.php?t=29


- Ramesh Babu P
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Internet Date

Post by James Bott »

Remesh,

Yes, I found that forum too. The code posted is the same one we have here, but it doesn't not contain the source to the GetSNTP() function.

I just revisited the forum and noticed that there is an Email button at the bottom of the message.

James
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: Internet Date

Post by RAMESHBABU »

Mr.James,

Just now I wrote an email to him.
Let us wait for him to come to our support,
with the source code of his GETSNTP() function.

-Ramesh Babu
User avatar
ssbbs
Posts: 54
Joined: Mon Oct 17, 2005 3:03 am

Re: Internet Date

Post by ssbbs »

The friend about "Ugo" have contact me and my replay is like:
---8<-----------------------------------------------------------------------

about sntp.lib, you can use tlib.exe to list obj, like:
c:\>tlib sntp.lib ,sntp.txt

and you will to view:

//---------------------
Publics by module

sntp size = 1396
_HB_FUN_GETSNTP

tsntp size = 2420
_HB_FUN_TSNTP
//---------------------

you can get GETSNTP.obj use tlib.exe like:
c:\>tlib sntp.lib *sntp ,sntp.txt

and you will get sntp.obj,

the 'sntp.obj' is use Borland C++ 5.5 to compile and you can link into
your winApp not limit harbour or xharbour.

and you can get 'tsntp.prg' source code from my website!!

---8<-----------------------------------------------------------------------
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Internet Date

Post by karinha »

Señores, me gustaría ver un ejemplo completo. ¿Es posible?

Gracias.
João Santos - São Paulo - Brasil
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Internet Date

Post by karinha »

Gentlemen, I would like a complete example. Is it possible?

Thank you.
João Santos - São Paulo - Brasil
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Internet Date

Post by karinha »

UP
João Santos - São Paulo - Brasil
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Internet Date

Post by Antonio Linares »

Its a long time since I don't mess with ASM but if needed I can help :-)

Who is the author of sntp.obj ? Using http://astrobase.bajaobs.hu/astrobase/d ... jtoasm.zip we can get its ASM source code and from there is not very much difficult to figure the original C code: objtoasm.exe stnp.obj

If this violates any copyright, please say it and I will remove it, thanks:

Code: Select all

                push    EDI
                calln   htons
                mov     02B2h[ESP],AX
                push    8
                push    0
                lea     EDX,02C0h[ESP]
                push    EDX
                calln   _memset
                add     ESP,0Ch
                push    010h
                lea     ECX,02B4h[ESP]
                push    ECX
                mov     EDI,EBX
                push    EDI
                calln   bind
                inc     EAX
                jne     L146
                push    0FFFFFFFCh
                calln   _hb_retni
                pop     ECX
                jmp     L510
L146:           lea     EAX,01B0h[ESP]
                push    EAX
                calln   inet_addr
                cmp     EAX,0FFFFFFFFh
                jne     L183
                lea     EDX,01B0h[ESP]
                push    EDX
                calln   gethostbyname
                test    EAX,EAX
                jne     L17C
                push    EDI
                calln   closesocket
                push    0FFFFFFFBh
                calln   _hb_retni
                pop     ECX
                jmp     L510
L17C:           mov     ECX,0Ch[EAX]
                mov     EAX,[ECX]
                mov     EAX,[EAX]
L183:           mov     word ptr 02C0h[ESP],2
                mov     02C4h[ESP],EAX
                push    ESI
                calln   htons
                mov     02C2h[ESP],AX
                push    8
                push    0
                lea     EDX,02D0h[ESP]
                push    EDX
                calln   _memset
                add     ESP,0Ch
                push    0B000000h
                calln   htonl
                mov     02D0h[ESP],EAX
                xor     ECX,ECX
                mov     02D4h[ESP],ECX
                xor     EAX,EAX
                mov     02D8h[ESP],EAX
                xor     EDX,EDX
                mov     02DCh[ESP],EDX
                xor     ECX,ECX
                mov     dword ptr 02E0h[ESP],0
                mov     dword ptr 02E4h[ESP],0
                mov     dword ptr 02E8h[ESP],0
                mov     dword ptr 02ECh[ESP],0
                mov     dword ptr 02F0h[ESP],0
                mov     dword ptr 02F4h[ESP],0
                mov     02F8h[ESP],ECX
                xor     EAX,EAX
                mov     02FCh[ESP],EAX
                push    010h
                lea     EDX,02C4h[ESP]
                mov     ESI,EBX
                push    EDX
                push    0
                push    030h
                lea     ECX,02E0h[ESP]
                push    ECX
                push    ESI
                calln   sendto
                inc     EAX
                jne     L26A
                push    ESI
                calln   closesocket
                push    0FFFFFFFAh
                calln   _hb_retni
                pop     ECX
                jmp     L510
L26A:           mov     dword ptr 4[ESP],3
                xor     EAX,EAX
                xor     EDX,EDX
                mov     8[ESP],EAX
                mov     0330h[ESP],EDX
                xor     EAX,EAX
                lea     EDX,0334h[ESP]
                jmp short       L296
L28C:           mov     ECX,[EDX]
                cmp     ECX,EBX
                je      L29F
                inc     EAX
                add     EDX,4
L296:           cmp     EAX,0330h[ESP]
                jb      L28C
L29F:           mov     EDX,0330h[ESP]
                cmp     EAX,EDX
                jne     L2BD
                cmp     EDX,040h
                jae     L2BD
                mov     0334h[EAX*4][ESP],EBX
                inc     dword ptr 0330h[ESP]
L2BD:           lea     EAX,4[ESP]
                push    EAX
                push    0
                push    0
                lea     ECX,033Ch[ESP]
                push    ECX
                push    040h
                calln   select
                cmp     EAX,0FFFFFFFFh
                jne     L2ED
                push    EBX
                calln   closesocket
                push    0FFFFFFF9h
                calln   _hb_retni
                pop     ECX
                jmp     L510
L2ED:           test    EAX,EAX
                jne     L304
                push    EBX
                calln   closesocket
                push    0FFFFFFF8h
                calln   _hb_retni
                pop     ECX
                jmp     L510
L304:           lea     EAX,0330h[ESP]
                push    EAX
                mov     ESI,EBX
                push    ESI
                calln   __WSAFDIsSet
                test    EAX,EAX
                jne     L32B
                push    ESI
                calln   closesocket
                push    0FFFFFFF7h
                calln   _hb_retni
                pop     ECX
                jmp     L510
L32B:           mov     [ESP],010h
                push    ESP
                lea     EAX,02C4h[ESP]
                push    EAX
                push    0
                push    030h
                lea     EDX,0310h[ESP]
                push    EDX
                push    ESI
                calln   recvfrom
                inc     EAX
                jne     L375
                push    offset D0
                push    offset __streams[030h]
                calln   _fprintf
                add     ESP,8
                push    ESI
                calln   closesocket
                push    0FFFFFFF6h
                calln   _hb_retni
                pop     ECX
                jmp     L510
L375:           push    ESI
                calln   closesocket
                push    0
                calln   _time
                pop     ECX
                mov     ECX,0328h[ESP]
                push    ECX
                calln   ntohl
                sub     EAX,083AA7E80h
                mov     0Ch[ESP],EAX
                lea     EAX,0Ch[ESP]
                push    EAX
                calln   _localtime
                pop     ECX
                mov     EBX,EAX
                test    EBX,EBX
                jne     L3B7
                push    0FFFFFFF5h
                calln   _hb_retni
                pop     ECX
                jmp     L510
L3B7:           cmp     dword ptr 014h[ESP],1
                jne     L4C7
                mov     AX,014h[EBX]
                add     AX,076Ch
                mov     0434h[ESP],AX
                mov     DX,010h[EBX]
                inc     EDX
                mov     0436h[ESP],DX
                mov     CX,0Ch[EBX]
                mov     043Ah[ESP],CX
                mov     AX,8[EBX]
                mov     043Ch[ESP],AX
                mov     DX,4[EBX]
                mov     043Eh[ESP],DX
                mov     CX,[EBX]
                mov     0440h[ESP],CX
                mov     EAX,032Ch[ESP]
                push    EAX
                calln   ntohl
                mov     0458h[ESP],EAX
                xor     EDX,EDX
                mov     045Ch[ESP],EDX
                fnild   long64 ptr 0458h[ESP]
                fnstp   float ptr 010h[ESP]
                fnld    float ptr _HB_FUN_GETSNTP[051Ch]
                fnmul   float ptr 010h[ESP]
                fnstp   float ptr 010h[ESP]
                fnld    float ptr _HB_FUN_GETSNTP[0520h]
                fnmul   float ptr 010h[ESP]
                fnstp   float ptr 010h[ESP]
                fnld    float ptr 010h[ESP]
                calln   __ftol
                mov     0442h[ESP],AX
                lea     EDX,0434h[ESP]
                push    EDX
                calln   SetLocalTime
                dec     EAX
                jne     L4BD
                mov     ECX,01Ch[EBX]
                push    ECX
                mov     EAX,018h[EBX]
                push    EAX
                mov     EDX,[EBX]
                push    EDX
                mov     ECX,4[EBX]
                push    ECX
                mov     EAX,8[EBX]
                push    EAX
                mov     EDX,0Ch[EBX]
                push    EDX
                mov     ECX,010h[EBX]
                inc     ECX
                push    ECX
                mov     EAX,014h[EBX]
                add     EAX,076Ch
                push    EAX
                push    offset D01Dh
                lea     EDX,0468h[ESP]
                push    EDX
                calln   _sprintf
                add     ESP,028h
                lea     ECX,0444h[ESP]
                push    ECX
                calln   _hb_retc
                pop     ECX
                jmp short       L510
L4BD:           push    0FFFFFFF4h
                calln   _hb_retni
                pop     ECX
                jmp short       L510
L4C7:           mov     EAX,01Ch[EBX]
                push    EAX
                mov     EDX,018h[EBX]
                push    EDX
                mov     ECX,[EBX]
                push    ECX
                mov     EAX,4[EBX]
                push    EAX
                mov     EDX,8[EBX]
                push    EDX
                mov     ECX,0Ch[EBX]
                push    ECX
                mov     EAX,010h[EBX]
                inc     EAX
                push    EAX
                mov     EDX,014h[EBX]
                add     EDX,076Ch
                push    EDX
                push    offset D036h
                lea     ECX,0468h[ESP]
                push    ECX
                calln   _sprintf
                add     ESP,028h
                lea     EAX,0444h[ESP]
                push    EAX
                calln   _hb_retc
                pop     ECX
L510:           add     ESP,0460h
                pop     EDI
                pop     ESI
                pop     EBX
                ret
                add     [EAX],AL
                jmp     ESI
                pop     EBX
                das
                add     [EAX],AL
Assertion failure: 'b < vec_numbits(v)' on line 153 in file '..\tk\vec.c'

c:\temp>
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Internet Date

Post by Antonio Linares »

First lines:

Code: Select all

local_02B2h = htons( ... );

memset( local_02C0h, 0, 8 );  // 8 sizeof ???

// bind [url]http://msdn.microsoft.com/en-us/library/windows/desktop/ms737550(v=vs.85).aspx[/url]
if( ! bind(     , &local_02B4h, 16 ) )
   hb_retni( 0xFFFFFFFC );

// [url]http://msdn.microsoft.com/en-us/library/windows/desktop/ms738563(v=vs.85).aspx[/url]
if( inet_addr( &local_01B0h ) != INADDR_NONE ) // this variable holds a string with IPv4 dotted-decimal address
{
   gethostbyname( &local_01B0h );
   closesocket( ... );
   hb_retni( 0xFFFFFFFB );
}
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Internet Date

Post by Antonio Linares »

A google search for "time.windows.com" and sntp and inet_addr provide several sources codes that may help:

http://www.codeproject.com/Articles/461 ... ementation
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply