Subversion Repositories Kolibri OS

Rev

Rev 551 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 551 Rev 993
Line 9... Line 9...
9
; IP address in the dnsServer string.
9
; IP address in the dnsServer string.
Line 10... Line 10...
10
 
10
 
11
 
11
 
12
; Enabling debugging puts the received response to the
12
; Enabling debugging puts the received response to the
13
; debug board
13
; debug board
14
DEBUGGING_ENABLED           equ     1
14
DEBUGGING_ENABLED	    equ     1
Line 15... Line 15...
15
DEBUGGING_DISABLED          equ     0
15
DEBUGGING_DISABLED	    equ     0
16
DEBUGGING_STATE             equ     DEBUGGING_DISABLED
16
DEBUGGING_STATE 	    equ     DEBUGGING_DISABLED
17
 
17
 
Line 25... Line 25...
25
 dd	I_END+0x10000 ; required memory
25
 dd	I_END+0x10000 ; required memory
26
 dd	I_END+0x10000 ; esp
26
 dd	I_END+0x10000 ; esp
27
 dd	0x0 , 0x0     ; I_Param , I_Path
27
 dd	0x0 , 0x0     ; I_Param , I_Path
Line 28... Line 28...
28
 
28
 
29
include 'lang.inc'
29
include 'lang.inc'
Line 30... Line 30...
30
include '..\..\..\macros.inc'
30
include 'macros.inc'
31
 
31
 
32
START:                                      ; start of execution
32
START:					    ; start of execution
33
    mov     eax,40                          ; Report events
33
    mov     eax,40			    ; Report events
Line 34... Line 34...
34
    mov     ebx,10000111b                   ; Stack 8 + defaults
34
    mov     ebx,10000111b		    ; Stack 8 + defaults
35
    int     0x40
35
    int     0x40
Line 36... Line 36...
36
 
36
 
37
    mov     dword [prompt], p1
37
    mov     dword [prompt], p1
Line 38... Line 38...
38
    mov     dword [promptlen], p1len - p1   ; 'waiting for command'
38
    mov     dword [promptlen], p1len - p1   ; 'waiting for command'
39
 
39
 
40
red:
40
red:
Line 41... Line 41...
41
    call    draw_window                     ; at first, draw the window
41
    call    draw_window 		    ; at first, draw the window
42
 
42
 
43
still:
43
still:
44
    mov     eax,10                          ; wait here for event
44
    mov     eax,10			    ; wait here for event
45
    mcall
45
    mcall
46
 
46
 
Line 47... Line 47...
47
    cmp     eax,1                           ; redraw request ?
47
    cmp     eax,1			    ; redraw request ?
48
    jz      red
48
    jz	    red
49
    cmp     eax,2                           ; key in buffer ?
49
    cmp     eax,2			    ; key in buffer ?
50
    jz      key
50
    jz	    key
51
    cmp     eax,3                           ; button in buffer ?
51
    cmp     eax,3			    ; button in buffer ?
Line 52... Line 52...
52
    jz      button
52
    jz	    button
53
 
53
 
54
    jmp     still
54
    jmp     still
Line 55... Line 55...
55
key:                            ; Keys are not valid at this part of the
55
key:				; Keys are not valid at this part of the
56
    mov     eax,2               ; loop. Just read it and ignore
56
    mov     eax,2		; loop. Just read it and ignore
Line 57... Line 57...
57
    mcall
57
    mcall
58
    jmp     still
58
    jmp     still
59
 
59
 
60
button:                         ; button
60
button: 			; button
61
    mov     eax,17              ; get id
61
    mov     eax,17		; get id
Line 62... Line 62...
62
    mcall
62
    mcall
63
 
63
 
Line 64... Line 64...
64
    cmp     ah,1                ; button id=1 ?
64
    cmp     ah,1		; button id=1 ?
65
    jnz     noclose
65
    jnz     noclose
66
 
66
 
Line 67... Line 67...
67
    ; close socket before exiting
67
    ; close socket before exiting
68
    mov     eax, 53
68
    mov     eax, 53
69
    mov     ebx, 1
69
    mov     ebx, 1
Line 70... Line 70...
70
    mov     ecx, [socketNum]
70
    mov     ecx, [socketNum]
Line 71... Line 71...
71
    mcall
71
    mcall
Line 72... Line 72...
72
 
72
 
Line 73... Line 73...
73
    mov     eax,0xffffffff      ; close this program
73
    mov     eax,0xffffffff	; close this program
74
    mcall
74
    mcall
75
 
75
 
76
noclose:
76
noclose:
77
    cmp     ah,3                ; Resolve address?
77
    cmp     ah,3		; Resolve address?
78
    jnz     noresolve
78
    jnz     noresolve
Line 79... Line 79...
79
 
79
 
80
    mov     dword [prompt], p5
80
    mov     dword [prompt], p5
Line 117... Line 117...
117
 
117
 
118
f11:
118
f11:
119
    mov     eax,10
119
    mov     eax,10
120
    mcall
120
    mcall
121
    cmp     eax,2
121
    cmp     eax,2
122
    jz      fbu
122
    jz	    fbu
Line 123... Line 123...
123
    jmp     still
123
    jmp     still
124
 
124
 
125
fbu:
125
fbu:
126
    mov     eax,2
126
    mov     eax,2
127
    mcall  ; get key
127
    mcall  ; get key
128
    shr     eax,8
128
    shr     eax,8
129
    cmp     eax,8
129
    cmp     eax,8
130
    jnz     nobs
130
    jnz     nobs
131
    cmp     edi,[addr]
131
    cmp     edi,[addr]
132
    jz      f11
132
    jz	    f11
133
    sub     edi,1
133
    sub     edi,1
134
    mov     [edi],byte ' '
134
    mov     [edi],byte ' '
Line 135... Line 135...
135
    call    print_text
135
    call    print_text
136
    jmp     f11
136
    jmp     f11
137
 
137
 
138
nobs:
138
nobs:
139
    cmp     eax,dword 31
139
    cmp     eax,dword 31
140
    jbe     f11
140
    jbe     f11
Line 141... Line 141...
141
    cmp     eax,dword 95
141
    cmp     eax,dword 95
142
    jb      keyok
142
    jb	    keyok
Line 209... Line 209...
209
    lodsb
209
    lodsb
210
    sub     al, '0'
210
    sub     al, '0'
211
    add     dl, al
211
    add     dl, al
212
    lodsb
212
    lodsb
213
    cmp     al, '.'
213
    cmp     al, '.'
214
    je      ipNext
214
    je	    ipNext
215
    cmp     al, ' '
215
    cmp     al, ' '
216
    je      ipNext
216
    je	    ipNext
217
    mov     dh, al
217
    mov     dh, al
218
    sub     dh, '0'
218
    sub     dh, '0'
219
    mov     al, 10
219
    mov     al, 10
220
    mul     dl
220
    mul     dl
221
    add     al, dh
221
    add     al, dh
222
    mov     dl, al
222
    mov     dl, al
223
    lodsb
223
    lodsb
224
    cmp     al, '.'
224
    cmp     al, '.'
225
    je      ipNext
225
    je	    ipNext
226
    cmp     al, ' '
226
    cmp     al, ' '
227
    je      ipNext
227
    je	    ipNext
228
    mov     dh, al
228
    mov     dh, al
229
    sub     dh, '0'
229
    sub     dh, '0'
230
    mov     al, 10
230
    mov     al, 10
231
    mul     dl
231
    mul     dl
232
    add     al, dh
232
    add     al, dh
Line 248... Line 248...
248
    mov     [dnsMsg+4], eax
248
    mov     [dnsMsg+4], eax
249
    mov     eax, 0x00000000
249
    mov     eax, 0x00000000
250
    mov     [dnsMsg+8], eax
250
    mov     [dnsMsg+8], eax
Line 251... Line 251...
251
 
251
 
252
    ; domain name goes in at dnsMsg+12
252
    ; domain name goes in at dnsMsg+12
253
    mov     esi, dnsMsg + 12        ; location of label length
253
    mov     esi, dnsMsg + 12	    ; location of label length
254
    mov     edi, dnsMsg + 13        ; label start
254
    mov     edi, dnsMsg + 13	    ; label start
255
    mov     edx, query
255
    mov     edx, query
Line 256... Line 256...
256
    mov     ecx, 12                  ; total string length so far
256
    mov     ecx, 12		     ; total string length so far
257
 
257
 
258
td002:
258
td002:
Line 259... Line 259...
259
    mov     [esi], byte 0
259
    mov     [esi], byte 0
260
    inc     ecx
260
    inc     ecx
261
 
261
 
262
td0021:
262
td0021:
263
    mov     al, [edx]
263
    mov     al, [edx]
264
    cmp     al, ' '
264
    cmp     al, ' '
Line 265... Line 265...
265
    je      td001                   ; we have finished the string translation
265
    je	    td001		    ; we have finished the string translation
266
    cmp     al, '.'                 ; we have finished the label
266
    cmp     al, '.'		    ; we have finished the label
267
    je      td004
267
    je	    td004
268
 
268
 
Line 307... Line 307...
307
;       works out the IP address from the response from the DNS server
307
;       works out the IP address from the response from the DNS server
308
;
308
;
309
;***************************************************************************
309
;***************************************************************************
310
resolveDomain:
310
resolveDomain:
311
    ; Get a free port number
311
    ; Get a free port number
312
 mov     ecx, 1000  ; local port starting at 1000
312
 mov	 ecx, 1000  ; local port starting at 1000
313
getlp:
313
getlp:
314
 inc     ecx
314
 inc	 ecx
315
 push ecx
315
 push ecx
316
 mov     eax, 53
316
 mov	 eax, 53
317
 mov     ebx, 9
317
 mov	 ebx, 9
318
 mcall
318
 mcall
319
 pop     ecx
319
 pop	 ecx
320
 cmp     eax, 0   ; is this local port in use?
320
 cmp	 eax, 0   ; is this local port in use?
321
 jz  getlp      ; yes - so try next
321
 jz  getlp	; yes - so try next
Line 322... Line 322...
322
 
322
 
323
    ; First, open socket
323
    ; First, open socket
324
    mov     eax, 53
324
    mov     eax, 53
325
    mov     ebx, 0
325
    mov     ebx, 0
Line 346... Line 346...
346
    ; UI redraw
346
    ; UI redraw
347
    ; UI close
347
    ; UI close
348
    ; or data from remote
348
    ; or data from remote
Line 349... Line 349...
349
 
349
 
350
ctr001:
350
ctr001:
351
    mov     eax,10                 ; wait here for event
351
    mov     eax,10		   ; wait here for event
Line 352... Line 352...
352
    mcall
352
    mcall
353
 
353
 
354
    cmp     eax,1                  ; redraw request ?
354
    cmp     eax,1		   ; redraw request ?
355
    je      ctr003
355
    je	    ctr003
356
    cmp     eax,2                  ; key in buffer ?
356
    cmp     eax,2		   ; key in buffer ?
357
    je      ctr004
357
    je	    ctr004
Line 358... Line 358...
358
    cmp     eax,3                  ; button in buffer ?
358
    cmp     eax,3		   ; button in buffer ?
359
    je      ctr005
359
    je	    ctr005
360
 
360
 
361
 
361
 
362
    ; Any data in the UDP receive buffer?
362
    ; Any data in the UDP receive buffer?
Line 363... Line 363...
363
    mov     eax, 53
363
    mov     eax, 53
364
    mov     ebx, 2
364
    mov     ebx, 2
Line 365... Line 365...
365
    mov     ecx, [socketNum]
365
    mov     ecx, [socketNum]
366
    mcall
366
    mcall
367
 
367
 
368
    cmp     eax, 0
368
    cmp     eax, 0
369
    je      ctr001
369
    je	    ctr001
370
 
370
 
Line 371... Line 371...
371
    ; we have data - this will be the response
371
    ; we have data - this will be the response
372
ctr002:
372
ctr002:
373
    mov     eax, 53
373
    mov     eax, 53
374
    mov     ebx, 3
374
    mov     ebx, 3
Line 386... Line 386...
386
end if
386
end if
Line 387... Line 387...
387
 
387
 
388
    mov     eax, 53
388
    mov     eax, 53
389
    mov     ebx, 2
389
    mov     ebx, 2
390
    mov     ecx, [socketNum]
390
    mov     ecx, [socketNum]
Line 391... Line 391...
391
    mcall                ; any more data?
391
    mcall		 ; any more data?
392
 
392
 
Line 393... Line 393...
393
    cmp     eax, 0
393
    cmp     eax, 0
394
    jne     ctr002              ; yes, so get it
394
    jne     ctr002		; yes, so get it
395
 
395
 
396
    ; close socket
396
    ; close socket
Line 429... Line 429...
429
    jne     ctr002a
429
    jne     ctr002a
Line 430... Line 430...
430
 
430
 
431
    ; Is there ( at least 1 ) answer?
431
    ; Is there ( at least 1 ) answer?
432
    mov     ax, [esi+6]
432
    mov     ax, [esi+6]
433
    cmp     ax, 0x00
433
    cmp     ax, 0x00
Line 434... Line 434...
434
    je      ctr002a
434
    je	    ctr002a
Line 435... Line 435...
435
 
435
 
Line 436... Line 436...
436
    ; Header validated. Scan through and get my answer
436
    ; Header validated. Scan through and get my answer
437
 
437
 
438
    add     esi, 12             ; Skip to the question field
438
    add     esi, 12		; Skip to the question field
Line 439... Line 439...
439
 
439
 
440
    ; Skip through the question field
440
    ; Skip through the question field
441
    call    skipName
441
    call    skipName
442
    add     esi, 4              ; skip past the questions qtype, qclass
442
    add     esi, 4		; skip past the questions qtype, qclass
443
 
443
 
444
ctr002z:
444
ctr002z:
445
    ; Now at the answer. There may be several answers,
445
    ; Now at the answer. There may be several answers,
Line 446... Line 446...
446
    ; find the right one ( TYPE = 0x0001 )
446
    ; find the right one ( TYPE = 0x0001 )
447
    call    skipName
447
    call    skipName
Line 448... Line 448...
448
    mov     ax, [esi]
448
    mov     ax, [esi]
449
    cmp     ax, 0x0100          ; Is this the IP address answer?
449
    cmp     ax, 0x0100		; Is this the IP address answer?
450
    jne     ctr002c
450
    jne     ctr002c
Line 451... Line 451...
451
 
451
 
452
    ; Yes! Point esi to the first byte of the IP address
452
    ; Yes! Point esi to the first byte of the IP address
453
    add     esi, 10
453
    add     esi, 10
454
 
454
 
455
    mov     eax, [esi]
455
    mov     eax, [esi]
456
    mov     [hostIP], eax
456
    mov     [hostIP], eax
Line 457... Line 457...
457
    jmp     ctr002a             ; And exit...
457
    jmp     ctr002a		; And exit...
458
 
458
 
459
 
459
 
460
ctr002c:                        ; Skip through the answer, move to the next
460
ctr002c:			; Skip through the answer, move to the next
461
    add     esi, 8
461
    add     esi, 8
Line 462... Line 462...
462
    movzx   eax, byte [esi+1]
462
    movzx   eax, byte [esi+1]
463
    mov     ah, [esi]
463
    mov     ah, [esi]
464
    add     esi, eax
464
    add     esi, eax
465
    add     esi, 2
465
    add     esi, 2
Line 466... Line 466...
466
 
466
 
Line 467... Line 467...
467
    ; Have we reached the end of the msg?
467
    ; Have we reached the end of the msg?
468
    ; This is an error condition, should not happen
468
    ; This is an error condition, should not happen
469
    cmp     esi, [dnsMsgLen]
469
    cmp     esi, [dnsMsgLen]
Line 470... Line 470...
470
    jl      ctr002z             ; Check next answer
470
    jl	    ctr002z		; Check next answer
471
    jmp     ctr002a             ; abort
471
    jmp     ctr002a		; abort
472
 
472
 
473
 
473
 
Line 474... Line 474...
474
ctr002a:
474
ctr002a:
475
    mov     dword [prompt], p4  ; Display IP address
475
    mov     dword [prompt], p4	; Display IP address
476
    mov     dword [promptlen], p4len - p4
476
    mov     dword [promptlen], p4len - p4
Line 477... Line 477...
477
    call    draw_window
477
    call    draw_window
478
 
478
 
479
    jmp     ctr001
479
    jmp     ctr001
Line 501... Line 501...
501
    mov     [hostIP], dword 0
501
    mov     [hostIP], dword 0
Line 502... Line 502...
502
 
502
 
503
    mov     dword [prompt], p1
503
    mov     dword [prompt], p1
Line 504... Line 504...
504
    mov     dword [promptlen], p1len - p1   ; 'waiting for command'
504
    mov     dword [promptlen], p1len - p1   ; 'waiting for command'
Line 505... Line 505...
505
 
505
 
Line 520... Line 520...
520
;
520
;
521
;***************************************************************************
521
;***************************************************************************
522
skipName:
522
skipName:
523
    mov     al, [esi]
523
    mov     al, [esi]
524
    cmp     al, 0
524
    cmp     al, 0
525
    je      sn_exit
525
    je	    sn_exit
526
    and     al, 0xc0
526
    and     al, 0xc0
527
    cmp     al, 0xc0
527
    cmp     al, 0xc0
528
    je      sn001
528
    je	    sn001
Line 529... Line 529...
529
 
529
 
530
    movzx   eax, byte [esi]
530
    movzx   eax, byte [esi]
531
    inc     eax
531
    inc     eax
532
    add     esi, eax
532
    add     esi, eax
Line 533... Line 533...
533
    jmp     skipName
533
    jmp     skipName
534
 
534
 
535
sn001:
535
sn001:
Line 536... Line 536...
536
    add     esi, 2                          ; A pointer is always at the end
536
    add     esi, 2			    ; A pointer is always at the end
537
    ret
537
    ret
538
 
538
 
Line 545... Line 545...
545
;   *******  WINDOW DEFINITIONS AND DRAW ********
545
;   *******  WINDOW DEFINITIONS AND DRAW ********
546
;   *********************************************
546
;   *********************************************
Line 547... Line 547...
547
 
547
 
548
 
548
 
549
draw_window:
549
draw_window:
550
    mov     eax,12                    ; function 12:tell os about windowdraw
550
    mov     eax,12		      ; function 12:tell os about windowdraw
551
    mov     ebx,1                     ; 1, start of draw
551
    mov     ebx,1		      ; 1, start of draw
552
    mcall
552
    mcall
553
                                      ; DRAW WINDOW
553
				      ; DRAW WINDOW
554
    mov     eax,0                     ; function 0 : define and draw window
554
    mov     eax,0		      ; function 0 : define and draw window
555
    mov     ebx,100*65536+300         ; [x start] *65536 + [x size]
555
    mov     ebx,100*65536+300	      ; [x start] *65536 + [x size]
556
    mov     ecx,100*65536+140         ; [y start] *65536 + [y size]
556
    mov     ecx,100*65536+140	      ; [y start] *65536 + [y size]
557
    mov     edx,0x14224466            ; color of work area RRGGBB
557
    mov     edx,0x14224466	      ; color of work area RRGGBB
558
    mov     edi,title                 ; WINDOW LABEL;
558
    mov     edi,title		      ; WINDOW LABEL;
559
    mcall
559
    mcall
560
                                      
560
 
561
    mov     eax,8                     ; Resolve
561
    mov     eax,8		      ; Resolve
562
    mov     ebx,20*65536+190
562
    mov     ebx,20*65536+190
563
    mov     ecx,79*65536+15
563
    mov     ecx,79*65536+15
564
    mov     edx,3
564
    mov     edx,3
Line 600... Line 600...
600
    rep     movsb
600
    rep     movsb
Line 601... Line 601...
601
 
601
 
602
    ; Re-draw the screen text
602
    ; Re-draw the screen text
603
    cld
603
    cld
604
    mov     eax,4
604
    mov     eax,4
605
    mov     ebx,25*65536+35           ; draw info text with function 4
605
    mov     ebx,25*65536+35	      ; draw info text with function 4
606
    mov     ecx,0xffffff
606
    mov     ecx,0xffffff
607
    mov     edx,text
607
    mov     edx,text
608
    mov     esi,40
608
    mov     esi,40
609
newline:
609
newline:
Line 615... Line 615...
615
 
615
 
616
 
616
 
617
    ; Write the host IP, if we have one
617
    ; Write the host IP, if we have one
618
    mov     eax, [hostIP]
618
    mov     eax, [hostIP]
Line 619... Line 619...
619
    cmp     eax, 0
619
    cmp     eax, 0
620
    je      dw001
620
    je	    dw001
621
 
621
 
622
    ; We have an IP address... display it
622
    ; We have an IP address... display it
Line 630... Line 630...
630
    movzx   ecx,byte [edi]
630
    movzx   ecx,byte [edi]
631
    mcall
631
    mcall
632
    add     edx,6*4*65536
632
    add     edx,6*4*65536
633
    inc     edi
633
    inc     edi
634
    cmp     edi,hostIP+4
634
    cmp     edi,hostIP+4
635
    jb      ipdisplay
635
    jb	    ipdisplay
Line 636... Line 636...
636
 
636
 
637
dw001:
637
dw001:
638
    mov     eax,12                    ; function 12:tell os about windowdraw
638
    mov     eax,12		      ; function 12:tell os about windowdraw
639
    mov     ebx,2                     ; 2, end of draw
639
    mov     ebx,2		      ; 2, end of draw
Line 640... Line 640...
640
    mcall
640
    mcall
Line 690... Line 690...
690
 
690
 
691
 
691
 
692
ind: dw 0
692
ind: dw 0
693
; This is used for translating hex to ASCII for display or output
693
; This is used for translating hex to ASCII for display or output
Line 694... Line 694...
694
hexchars db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
694
hexchars db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
695
IP_STR              db  'xx',0
695
IP_STR		    db	'xx',0
696
 
696
 
Line 719... Line 719...
719
end if
719
end if
Line 720... Line 720...
720
 
720
 
Line 721... Line 721...
721
 
721
 
722
; DATA AREA
722
; DATA AREA
Line 723... Line 723...
723
 
723
 
-
 
724
addr		dd  0x0
-
 
725
ya		dd  0x0
-
 
726
 
-
 
727
text:
-
 
728
 
-
 
729
    if lang eq ru
-
 
730
    db 'ˆ¬ï å®áâ   : xxxxxxxxxxxxxxx            '
-
 
731
    db 'DNS á¥à¢¥à : xxx.xxx.xxx.xxx            '
-
 
732
    db '                                        '
-
 
733
    db '       ®«ãç¨âì  ¤à¥á                   '
-
 
734
    db '                                        '
724
addr            dd  0x0
735
    db '                                        '
725
ya              dd  0x0
736
    db 'x <- END MARKER, DONT DELETE            '
726
 
737
 
727
text:
738
    else
728
    db 'Host name  : xxxxxxxxxxxxxxx            '
739
    db 'Host name  : xxxxxxxxxxxxxxx            '
729
    db 'DNS server : xxx.xxx.xxx.xxx            '
740
    db 'DNS server : xxx.xxx.xxx.xxx            '
730
    db '                                        '
741
    db '                                        '
-
 
742
    db '     RESOLVE ADDRESS                    '
Line -... Line 743...
-
 
743
    db '                                        '
-
 
744
    db '                                        '
Line -... Line 745...
-
 
745
    db 'x <- END MARKER, DONT DELETE            '
731
    db '     RESOLVE ADDRESS                    '
746
    end if
-
 
747
 
Line 732... Line 748...
732
    db '                                        '
748
if lang eq ru
733
    db '                                        '
749
title	 db   'DNS Š«¨¥­â',0
Line -... Line 750...
-
 
750
 
-
 
751
else
-
 
752
title	 db   'DNS Client',0
-
 
753
end if
-
 
754
 
-
 
755
 
734
    db 'x <- END MARKER, DONT DELETE            '
756
prompt: dd 0
735
 
757
promptlen: dd 0
-
 
758
 
Line 736... Line 759...
736
 
759
 
737
title    db   'DNS Client',0
760
if lang eq ru
Line 738... Line 761...
738
 
761
p1:		db '†¤ã ª®¬ ­¤ë                '
739
 
762
p1len:
Line 740... Line 763...
740
prompt: dd 0
763
 
741
promptlen: dd 0
764
 
Line 742... Line 765...
742
 
765
else
743
 
766
p1:		db 'Waiting for Command        '
744
p1:             db 'Waiting for Command        '
767
p1len:
745
p1len:
768
end if
746
 
769
 
747
p4:             db 'IP Address:    .   .   .   '
770
p4:		db 'IP Address:    .   .   .   '