Subversion Repositories Kolibri OS

Rev

Rev 1514 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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