Subversion Repositories Kolibri OS

Rev

Rev 3545 | Details | Compare with Previous | Last modification | View Log | RSS feed

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