Subversion Repositories Kolibri OS

Rev

Rev 3545 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3545 Rev 3618
-
 
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
2
;;                                                                 ;;
-
 
3
;; Copyright (C) KolibriOS team 2010-2013. All rights reserved.    ;;
-
 
4
;; Distributed under terms of the GNU General Public License       ;;
-
 
5
;;                                                                 ;;
-
 
6
;; nslookup.asm - name service lookup (DNS)) program for KolibriOS ;;
-
 
7
;;                                                                 ;;
-
 
8
;;  Written by hidnplayr@kolibrios.org                             ;;
-
 
9
;;                                                                 ;;
-
 
10
;;          GNU GENERAL PUBLIC LICENSE                             ;;
-
 
11
;;             Version 2, June 1991                                ;;
-
 
12
;;                                                                 ;;
-
 
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
14
 
1
format binary as ""
15
format binary as ""
2
 
16
 
3
use32
17
use32
4
; standard header
18
; standard header
5
        db      'MENUET01'      ; signature
19
        db      'MENUET01'      ; signature
6
        dd      1               ; header version
20
        dd      1               ; header version
7
        dd      start           ; entry point
21
        dd      start           ; entry point
8
        dd      i_end           ; initialized size
22
        dd      i_end           ; initialized size
9
        dd      mem             ; required memory
23
        dd      mem             ; required memory
10
        dd      mem             ; stack pointer
24
        dd      mem             ; stack pointer
11
        dd      0               ; parameters
25
        dd      0               ; parameters
12
        dd      0               ; path
26
        dd      0               ; path
13
 
27
 
14
; useful includes
28
; useful includes
15
include '../macros.inc'
29
include '../../macros.inc'
16
purge mov,add,sub
30
purge mov,add,sub
17
include '../proc32.inc'
31
include '../../proc32.inc'
18
include '../dll.inc'
32
include '../../dll.inc'
19
 
33
 
20
include '../network.inc'
34
include '../../network.inc'
21
 
35
 
22
; entry point
36
; entry point
23
start:
37
start:
24
; load libraries
38
; load libraries
25
        stdcall dll.Load, @IMPORT
39
        stdcall dll.Load, @IMPORT
26
        test    eax, eax
40
        test    eax, eax
27
        jnz     exit
41
        jnz     exit
28
; initialize console
42
; initialize console
29
        push    1
43
        push    1
30
        call    [con_start]
44
        call    [con_start]
31
        push    title
45
        push    title
32
        push    -1
46
        push    -1
33
        push    -1
47
        push    -1
34
        push    -1
48
        push    -1
35
        push    -1
49
        push    -1
36
        call    [con_init]
50
        call    [con_init]
37
; main loop
51
; main loop
38
main:
52
main:
39
; write prompt
53
; write prompt
40
        push    str1
54
        push    str1
41
        call    [con_write_asciiz]
55
        call    [con_write_asciiz]
42
; read string
56
; read string
43
        mov     esi, s
57
        mov     esi, s
44
        push    256
58
        push    256
45
        push    esi
59
        push    esi
46
        call    [con_gets]
60
        call    [con_gets]
47
; check for exit
61
; check for exit
48
        test    eax, eax
62
        test    eax, eax
49
        jz      done
63
        jz      done
50
        cmp     byte [esi], 10
64
        cmp     byte [esi], 10
51
        jz      done
65
        jz      done
52
; delete terminating '\n'
66
; delete terminating '\n'
53
        push    esi
67
        push    esi
54
@@:
68
@@:
55
        lodsb
69
        lodsb
56
        test    al, al
70
        test    al, al
57
        jnz     @b
71
        jnz     @b
58
        mov     byte [esi-2], al
72
        mov     byte [esi-2], al
59
        pop     esi
73
        pop     esi
60
; resolve name
74
; resolve name
61
        push    esp     ; reserve stack place
75
        push    esp     ; reserve stack place
62
        push    esp     ; fourth parameter
76
        push    esp     ; fourth parameter
63
        push    0       ; third parameter
77
        push    0       ; third parameter
64
        push    0       ; second parameter
78
        push    0       ; second parameter
65
        push    esi     ; first parameter
79
        push    esi     ; first parameter
66
        call    [getaddrinfo]
80
        call    [getaddrinfo]
67
        pop     esi
81
        pop     esi
68
; test for error
82
; test for error
69
        test    eax, eax
83
        test    eax, eax
70
        jnz     fail
84
        jnz     fail
71
; write results
85
; write results
72
        push    str2
86
        push    str2
73
        call    [con_write_asciiz]
87
        call    [con_write_asciiz]
74
        mov     edi, esi
88
        mov     edi, esi
75
addrloop:
89
addrloop:
76
; before all subsequent addresses print comma
90
; before all subsequent addresses print comma
77
        cmp     edi, esi
91
        cmp     edi, esi
78
        jz      @f
92
        jz      @f
79
        push    str3
93
        push    str3
80
        call    [con_write_asciiz]
94
        call    [con_write_asciiz]
81
@@:
95
@@:
82
; convert IP address to decimal notation
96
; convert IP address to decimal notation
83
        mov     eax, [edi+addrinfo.ai_addr]
97
        mov     eax, [edi+addrinfo.ai_addr]
84
        pushd   [eax+sockaddr_in.sin_addr]
98
        pushd   [eax+sockaddr_in.sin_addr]
85
        call    [inet_ntoa]
99
        call    [inet_ntoa]
86
; write result
100
; write result
87
        push    eax
101
        push    eax
88
        call    [con_write_asciiz]
102
        call    [con_write_asciiz]
89
; advance to next item
103
; advance to next item
90
        mov     edi, [edi+addrinfo.ai_next]
104
        mov     edi, [edi+addrinfo.ai_next]
91
        test    edi, edi
105
        test    edi, edi
92
        jnz     addrloop
106
        jnz     addrloop
93
; free allocated memory
107
; free allocated memory
94
        push    esi
108
        push    esi
95
        call    [freeaddrinfo]
109
        call    [freeaddrinfo]
96
; write newline and continue main loop
110
; write newline and continue main loop
97
        push    str4
111
        push    str4
98
@@:
112
@@:
99
        call    [con_write_asciiz]
113
        call    [con_write_asciiz]
100
        jmp     main
114
        jmp     main
101
fail:
115
fail:
102
        push    str5
116
        push    str5
103
        jmp     @b
117
        jmp     @b
104
done:
118
done:
105
        push    1
119
        push    1
106
        call    [con_exit]
120
        call    [con_exit]
107
exit:
121
exit:
108
        mcall   -1
122
        mcall   -1
109
 
123
 
110
; data
124
; data
111
title   db      'Names resolver',0
125
title   db      'Names resolver',0
112
str1    db      'Host name to resolve: ',0
126
str1    db      'Host name to resolve: ',0
113
str2    db      'IP address(es): ',0
127
str2    db      'IP address(es): ',0
114
str3    db      ', ',0
128
str3    db      ', ',0
115
str4    db      10,0
129
str4    db      10,0
116
str5    db      'Name resolution failed.',10,0
130
str5    db      'Name resolution failed.',10,0
117
; import
131
; import
118
align 4
132
align 4
119
@IMPORT:
133
@IMPORT:
120
 
134
 
121
library network, 'network.obj', console, 'console.obj'
135
library network, 'network.obj', console, 'console.obj'
122
import  network,        \
136
import  network,        \
123
        getaddrinfo,    'getaddrinfo',  \
137
        getaddrinfo,    'getaddrinfo',  \
124
        freeaddrinfo,   'freeaddrinfo', \
138
        freeaddrinfo,   'freeaddrinfo', \
125
        inet_ntoa,      'inet_ntoa'
139
        inet_ntoa,      'inet_ntoa'
126
import  console,        \
140
import  console,        \
127
        con_start,      'START',        \
141
        con_start,      'START',        \
128
        con_init,       'con_init',     \
142
        con_init,       'con_init',     \
129
        con_write_asciiz,       'con_write_asciiz',     \
143
        con_write_asciiz,       'con_write_asciiz',     \
130
        con_exit,       'con_exit',     \
144
        con_exit,       'con_exit',     \
131
        con_gets,       'con_gets'
145
        con_gets,       'con_gets'
132
i_end:
146
i_end:
133
s       rb      256
147
s       rb      256
134
align   4
148
align   4
135
rb      4096    ; stack
149
rb      4096    ; stack
136
mem:
150
mem: