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