my first time server



Do you like my first time server?
If a Pc in the net send a udp message <= 4 chars
to port "37"
it should send to that address the local time...
but there is one function that i not post that is in C language
"_numero_giorni" that return the number of days
between two date

; fa il server di time UDP sulla porta 37
; int dg_timeserver(void)
; ritorna il numero di connessioni avute
; 0k, 4j, 8i, 12r, 16c, 20b, 24ra, 28P_n, 32P_argv
dg_timeServer:
push ebx
push ecx
push edx
push esi
push edi
push ebp
sub esp, 256
%define @server [esp+32]
%define @client [esp+80]
%define @quanti [esp+100]
%define @timeStru [esp+116]
jmp short .4
..1:
push _Impossibile_aprire_il_socket_di_stream$n
call _P
add esp, 4
jmp .f
..4:
push 0
push SOCK_DGRAM
push AF_INET
call socket
cmp eax, INVALID_SOCKET
je .1
mov esi, eax
mov dword @quanti, 0
lea eax, [esp+148]
mov dword[esp+164], 3
mov dword[eax], -1
mov dword[eax+4], 0
push 37
call htons ; porta di time
lea ebx, @server
mov [ebx + sin_port], ax
mov word[ebx + sin_family], AF_INET
push INADDR_ANY
call htonl
mov dword[ebx + sin_addr ], eax ; questa macchina
mov dword[ebx+sin_zero], 0
mov dword[ebx+sin_zero+4], 0
lea edi, [esp+8] ; s=0:4len(a), 8:4buffer(j), 32:16chars(b)
lea ebp, @client ; 80:16chars(k), 100:4, 116:16
; 148:8
..a:
push 16
push ebx
push esi
call bind
cmp eax, 0
je .n
push _Errore_di_bind$n
call _P
add esp, 4
..ea:
push esi
call dg_close1
cmp eax, 0
jne .e0
..ee:
mov eax, @quanti
jmp .f
..e0:
push _Errore_di_dg$close$$$n
call _P
add esp, 4
jmp short .ee
; .e1: PrintSockError();
; _P<("dg_time: errore di recvfrom\n"); #.n;
..e2:
push _dg$time$_errore_di_sendto$n
call _P
add esp, 4
jmp short .ea
..n:
mov eax, esp
mov dword[eax], 16
push eax
push ebp
push 0
push 4
push edi
push esi
call recvfrom
; a==SOCKET_ERROR#.e1; /* pronto a inviare 3 volte il tempo
cmp eax, SOCKET_ERROR
je .n ; ma alla terza volta allo stesso
; indirizzo non invia niente
; nel caso buffer insufficiente ritenta
lea edx, [esp+148]
mov eax, [ebp]
mov ecx, [ebp+4]
cmp eax, [edx]
jne .5
cmp ecx, [edx+4]
jne .5
cmp dword[esp+164], 0
jl .n
dec dword[esp+164]
jle .n
jmp short .6
..5:
mov dword[esp+164], 3
inc dword @quanti
..6:
lea eax, @timeStru
push eax
call GetSystemTime
lea eax, @timeStru
xor ecx, ecx
xor edx, edx
mov cx, [eax]
mov dx, [eax+2]
mov ax, [eax+6]
and eax, 0xFFFF
push ecx
push edx
push eax
push 1900
push 1
push 1
call _numero_giorni
add esp, 24
mov edx, 86400 ; giorni
mul edx
cmp edx, 0
jne .n
lea edx, @timeStru ; +secondi
mov ecx, eax
xor eax, eax
mov ax, [edx+12]
add ecx, eax
jc .n
xor eax, eax ; +minuti
mov ax, [edx+10]
mov edx, 60
mul edx
cmp edx, 0
jne .n
add ecx, eax
jc .n
lea edx, @timeStru
xor eax, eax ; +ore
mov ax, [edx+10]
mov edx, 3600
mul edx
cmp edx, 0
jne .n
add ecx, eax
jc .n
push ecx
call htonl ; a==16?
mov [edi], eax
mov eax, [esp]
push eax
push ebp
push 0
push 4
push edi
push esi
call sendto
cmp eax, 4
jne .e2
lea edx, [esp+148]
mov eax, [ebp]
mov ecx, [ebp+ 4]
mov [edx] , eax
mov [edx+ 4], ecx
jmp .n
..f:
%undef @server
%undef @client
%undef @quanti
%undef @timeStru
add esp, 256
pop ebp
pop edi
pop esi
pop edx
pop ecx
pop ebx
ret



/* fa il server di time UDP sulla porta 37
/* int dg_timeserver(void)
/* ritorna il numero di connessioni avute
/* 0k, 4j, 8i, 12r, 16c, 20b, 24ra, 28P_n, 32P_argv
dg_timeServer:
< b, c, r, i, j, k
s-=256
<< @server=[s+32], @client=[s+80], @quanti=[s+100]
<< @timeStru=[s+116]
#.4;
..1: _P<("Impossibile aprire il socket di stream\n");
##.f;
..4: socket(AF_INET, SOCK_DGRAM, 0 ); a==INVALID_SOCKET#.1;
i=a; D @quanti=0;
a=&[s+148]; D[s+164]=3; D[a]=-1; D[a+4]=0;
htons(37); /* porta di time
b= & @server; [b + sin_port]= ax;
W[b + sin_family]= AF_INET;
D[b + sin_addr ]= htonl(INADDR_ANY); /* questa macchina
D[b+sin_zero]= 0; D[b+sin_zero+4]=0;
j=&[s+8]; k=& @client;
/* s=0:4len(a), 8:4buffer(j), 32:16chars(b)
/* 80:16chars(k), 100:4, 116:16
/* 148:8
..a: bind(i, b, 16); a==0#.n;
_P<("Errore di bind\n");
..ea: dg_close1(i); a#.e0;
..ee: a=@quanti; ##.f;
..e0: _P<("Errore di dg_close()\n"); #.ee;
/* .e1: PrintSockError();
/* _P<("dg_time: errore di recvfrom\n"); #.n;
..e2: _P<("dg_time: errore di sendto\n"); #.ea;
..n: a=s; D*a=16; recvfrom(i, j, 4, 0, k, a);
/* a==SOCKET_ERROR#.e1; /* pronto a inviare 3 volte il tempo
a==SOCKET_ERROR#.n; /* ma alla terza volta allo stesso
/* indirizzo non invia niente.
/* Nel caso buffer [j] insufficiente
/* o errore ritenta
/* possibile loop che mangia risorse
/* al sistema?
r=&[s+148]; a=[k]; c=[k+4]; a!=[r]#.5; c!=[r+4]#.5;
D[s+164]<0?#.n; --D[s+164]; <=?#.n; #.6;
..5: D[s+164]=3; ++D @quanti;
..6: a=& @timeStru; GetSystemTime(a);
a=& @timeStru; c^=c; r^=r; cx=[a]; rx=[a+2]; ax=[a+6];
a&=0xFFFF; _numero_giorni<(1, 1, 1900, a, r, c);
r=86400; mul r; r#.n; /* giorni
r=& @timeStru; c=a; a^=a; ax=[r+12]; c+=a; jc .n; /* +secondi
a^=a; ax=[r+10]; r=60; mul r; r#.n; c+=a; jc .n; /* +minuti
r=& @timeStru;
a^=a; ax=[r+10]; r=3600; mul r; r#.n; c+=a; jc .n; /* +ore
htonl(c); *j=a; a=*s; /* a==16?
sendto(i, j, 4, 0, k, a); a!=4#.e2;
r=&[s+148]; a= [k]; c=[k+ 4];[r] =a; [r+ 4]=c;
##.n;
..f:
@server, @client, @quanti
@timeStru
s+=256;
b, c, r, i, j, k
ret



.



Relevant Pages

  • Re: Macro2D
    ... õ1, eax", 0 ... db "push striIIi", NL ... db ".2: cmp edi, ebp", NL ... db ".4: mov eax, edi", NL ...
    (alt.lang.asm)
  • One RosAsm Pre-parser
    ... cmp eax 0 | ja L0<< ... mov ecx, D ...
    (alt.lang.asm)
  • Re: Fastcode Library Design
    ... cmp ecx, SMALLMOVESIZE ... lea edx, ... fild qword ptr [eax] ... mov ecx, ...
    (borland.public.delphi.language.basm)
  • Re: Macro2D
    ... mov, eax ... cmp eax, -1 ... push STD_INPUT_HANDLE ...
    (alt.lang.asm)
  • ascii to st0
    ... push IDC_ARROW ... cmp eax, 0 ... mov ebp, esp ... cmp dword @Message, WM_CLOSE ...
    (alt.lang.asm)