Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
31 halyavin 1
;
2
;    ARP Status Monitor
3
;
4
;    Compile with FASM for Menuet
5
;
6
;  This program displays the ARP table, and it's settings
7
 
8
use32
9
 
10
                org     0x0
11
 
12
                db      'MENUET00'              ; 8 byte id
13
                dd      38                      ; required os
14
                dd      START                   ; program start
15
                dd      I_END                   ; program image size
16
                dd      0x100000                ; required amount of memory
17
                dd      0x00000000              ; reserved=no extended header
18
   include 'lang.inc'
485 heavyiron 19
   include '..\..\..\macros.inc'
625 diamond 20
   purge mov	; decrease kpack'ed size
31 halyavin 21
 
22
START:                          ; start of execution
23
    call draw_window            ; at first, draw the window
24
 
25
still:
26
    mov  eax,23                 ; wait here for event
27
    mov  ebx,200				; Time out after 2s
485 heavyiron 28
    mcall
31 halyavin 29
 
30
    cmp  eax,1                  ; redraw request ?
31
    jz   red
32
    cmp  eax,2                  ; key in buffer ?
33
    jz   key
34
    cmp  eax,3                  ; button in buffer ?
35
    jz   button
36
 
37
	; read the stack status data, and write it to the screen buffer
38
 
39
	mov		eax, 53
40
	mov		ebx, 255
41
	mov		ecx, 200
485 heavyiron 42
	mcall
31 halyavin 43
 
44
	push    eax
45
	mov		ebx, text + 24
46
	call	printhex
47
 
48
	mov		eax, 53
49
	mov		ebx, 255
50
	mov		ecx, 201
485 heavyiron 51
	mcall
31 halyavin 52
 
53
	mov		ebx, text + 64
54
	call	printhex
55
 
56
 
57
	; Fill the table with blanks
625 diamond 58
	mov		edi, text + 160
31 halyavin 59
doBlank:
60
	mov		esi, blank
61
	mov		ecx, 40
62
	rep		movsb
63
 
625 diamond 64
	cmp		edi, text + 560
31 halyavin 65
	jne		doBlank
66
 
67
	pop		ecx					; The number of entries
68
 
69
	mov		ebx, text+ 160	+1	; the position for the first IP address line
70
 
71
	xor		edx, edx			; edx is index into the ARP table
72
 
73
	cmp		ecx, 10
74
	jle		show_entries
75
	mov		ecx, 10
76
 
77
 
78
; The following code is not very efficient; Sorry about that.
79
; ARPSTAT is a debugging tool, so I didn't want to put much effort in
80
show_entries:
81
	; Ecx now holds the number of entries to populate.
82
	; Ebx holds the place to put the data
83
	; edx is a counter
84
	cmp		ecx, 0
85
	je		red
86
 
87
	push	ecx
88
	push	edx
89
	push	ebx
90
 
91
 
92
	; select the arp table entry (in edx)
93
	mov		eax, 53
94
	mov		ebx, 255
95
	mov		ecx, 202
485 heavyiron 96
	mcall
31 halyavin 97
 
98
	; Read the IP address
99
	mov		eax, 53
100
	mov		ebx, 255
101
	mov		ecx, 203
485 heavyiron 102
	mcall
31 halyavin 103
 
104
	; IP in eax. Get the address to put it back
105
	pop		ebx
106
	push		ebx
107
 
108
	call		writeDecimal			; Extract 1 byte from eax, store it in string
109
	add		ebx, 4
110
	shr		eax, 8
111
	call		writeDecimal			; Extract 1 byte from eax, store it in string
112
	add		ebx, 4
113
	shr		eax, 8
114
	call		writeDecimal			; Extract 1 byte from eax, store it in string
115
	add		ebx, 4
116
	shr		eax, 8
117
	call		writeDecimal			; Extract 1 byte from eax, store it in string
118
 
119
	add		ebx, 4
120
 
121
	; Now display the 6 byte MAC
122
	push		ebx
123
	mov		eax, 53
124
	mov		ebx, 255
125
	mov		ecx, 204
485 heavyiron 126
	mcall
31 halyavin 127
	pop		ebx
128
 
129
	mov		ecx, eax
130
 
131
	shr		eax, 4
132
	and		eax, 0x0f
133
	mov		al, [eax + hextable]
134
	mov		[ebx], al
135
	inc		ebx
136
	mov		eax, ecx
137
	and		eax, 0x0f
138
	mov		al, [eax + hextable]
139
	mov		[ebx], al
140
	inc		ebx
141
	mov		eax, ecx
142
	shr		eax, 12
143
	and		eax, 0x0f
144
	mov		al, [eax + hextable]
145
	mov		[ebx], al
146
	inc		ebx
147
	mov		eax, ecx
148
	shr		eax, 8
149
	and		eax, 0x0f
150
	mov		al, [eax + hextable]
151
	mov		[ebx], al
152
	inc		ebx
153
	mov		eax, ecx
154
	shr		eax, 20
155
	and		eax, 0x0f
156
	mov		al, [eax + hextable]
157
	mov		[ebx], al
158
	inc		ebx
159
	mov		eax, ecx
160
	shr		eax, 16
161
	and		eax, 0x0f
162
	mov		al, [eax + hextable]
163
	mov		[ebx], al
164
	inc		ebx
165
	mov		eax, ecx
166
	shr		eax, 28
167
	mov		al, [eax + hextable]
168
	mov		[ebx], al
169
	inc		ebx
170
	mov		eax, ecx
171
	shr		eax, 24
172
	and		eax, 0x0f
173
	mov		al, [eax + hextable]
174
	mov		[ebx], al
175
	inc		ebx
176
 
177
	push		ebx
178
	mov		eax, 53
179
	mov		ebx, 255
180
	mov		ecx, 205
485 heavyiron 181
	mcall
31 halyavin 182
	pop		ebx
183
 
184
	mov		ecx, eax
185
 
186
	shr		eax, 4
187
	and		eax, 0x0f
188
	mov		al, [eax + hextable]
189
	mov		[ebx], al
190
	inc		ebx
191
	mov		eax, ecx
192
	and		eax, 0x0f
193
	mov		al, [eax + hextable]
194
	mov		[ebx], al
195
	inc		ebx
196
	mov		eax, ecx
197
	shr		eax, 12
198
	and		eax, 0x0f
199
	mov		al, [eax + hextable]
200
	mov		[ebx], al
201
	inc		ebx
202
	mov		eax, ecx
203
	shr		eax, 8
204
	and		eax, 0x0f
205
	mov		al, [eax + hextable]
206
	mov		[ebx], al
207
 
208
	; Now display the stat field
209
	inc		ebx
210
	inc		ebx
211
	push		ebx
212
	mov		eax, 53
213
	mov		ebx, 255
214
	mov		ecx, 206
485 heavyiron 215
	mcall
31 halyavin 216
	pop		ebx
217
 
218
	mov		ecx, eax
219
 
220
	shr		eax, 4
221
	and		eax, 0x0f
222
	mov		al, [eax + hextable]
223
	mov		[ebx], al
224
	inc		ebx
225
	mov		eax, ecx
226
	and		eax, 0x0f
227
	mov		al, [eax + hextable]
228
	mov		[ebx], al
229
	inc		ebx
230
	mov		eax, ecx
231
	shr		eax, 12
232
	and		eax, 0x0f
233
	mov		al, [eax + hextable]
234
	mov		[ebx], al
235
	inc		ebx
236
	mov		eax, ecx
237
	shr		eax, 8
238
	and		eax, 0x0f
239
	mov		al, [eax + hextable]
240
	mov		[ebx], al
241
 
242
	; Now display the TTL field (this is intel word format)
243
	inc		ebx
244
	inc		ebx
245
	push		ebx
246
	mov		eax, 53
247
	mov		ebx, 255
248
	mov		ecx, 207
485 heavyiron 249
	mcall
31 halyavin 250
	pop		ebx
251
 
252
	mov		ecx, eax
253
 
254
	shr		eax, 12
255
	and		eax, 0x0f
256
	mov		al, [eax + hextable]
257
	mov		[ebx], al
258
	inc		ebx
259
	mov		eax, ecx
260
	shr		eax, 8
261
	and		eax, 0x0f
262
	mov		al, [eax + hextable]
263
	mov		[ebx], al
264
	inc		ebx
265
	mov		eax, ecx
266
	shr		eax, 4
267
	and		eax, 0x0f
268
	mov		al, [eax + hextable]
269
	mov		[ebx], al
270
	inc		ebx
271
	mov		eax, ecx
272
	and		eax, 0x0f
273
	mov		al, [eax + hextable]
274
	mov		[ebx], al
275
 
276
 
277
	pop		ebx
278
	add		ebx, 40
279
	pop		edx
280
	inc		edx
281
	pop		ecx
282
	dec		ecx
283
	jmp		show_entries
284
 
285
red:                          	; redraw
286
    call draw_window
287
    jmp  still
288
 
289
key:                          	; Keys are not valid at this part of the
290
    mov  eax,2                  ; loop. Just read it and ignore
485 heavyiron 291
    mcall
31 halyavin 292
    jmp  still
293
 
294
button:                       	; button
295
    mov  eax,17                 ; get id
485 heavyiron 296
    mcall
31 halyavin 297
 
298
    cmp  ah,1                   ; button id=1 ?
299
    jnz  still
300
 
301
    mov  eax,0xffffffff         ; close this program
485 heavyiron 302
    mcall
31 halyavin 303
 
304
 
305
writeDecimal:
306
	pusha
307
	and	eax, 0xff
308
	mov	dl, 100
309
	div	dl
625 diamond 310
	movzx	ecx, ah
31 halyavin 311
	add	al, '0'
312
	mov	[ebx], al
313
	inc	ebx
314
	mov	eax, ecx
315
	mov	dl, 10
316
	div	dl
625 diamond 317
	add	ax, '00'
318
	mov	[ebx], ax
31 halyavin 319
	popa
320
	ret
321
 
322
 
323
;   *********************************************
324
;   *******  WINDOW DEFINITIONS AND DRAW ********
325
;   *********************************************
326
 
327
 
328
draw_window:
329
 
330
    mov  eax,12                    ; function 12:tell os about windowdraw
331
    mov  ebx,1                     ; 1, start of draw
485 heavyiron 332
    mcall
31 halyavin 333
 
334
                                   ; DRAW WINDOW
335
    mov  eax,0                     ; function 0 : define and draw window
336
    mov  ebx,100*65536+280         ; [x start] *65536 + [x size]
337
    mov  ecx,100*65536+270         ; [y start] *65536 + [y size]
551 spraid 338
    mov  edx,0x14224466            ; color of work area RRGGBB
485 heavyiron 339
    mov  edi,title                 ; WINDOW LABEL
340
    mcall
31 halyavin 341
 
485 heavyiron 342
 
31 halyavin 343
   	; Re-draw the screen text
344
    cld
485 heavyiron 345
    mov  eax,4
31 halyavin 346
    mov  ebx,25*65536+35           ; draw info text with function 4
347
    mov  ecx,0xffffff
348
    mov  edx,text
349
    mov  esi,40
350
  newline:
485 heavyiron 351
    mcall
31 halyavin 352
    add  ebx,16
625 diamond 353
    add  edx,esi
31 halyavin 354
    cmp  [edx],byte 'x'
355
    jnz  newline
356
 
357
 
358
    mov  eax,12                    ; function 12:tell os about windowdraw
359
    mov  ebx,2                     ; 2, end of draw
485 heavyiron 360
    mcall
31 halyavin 361
 
362
    ret
363
 
364
; Taken from PS.ASM
365
printhex:
366
; number in eax
367
; print to ebx
368
; xlat from hextable
369
 pusha
370
 mov esi, ebx
371
 add esi, 8
372
 mov ebx, hextable
373
 mov ecx, 8
374
phex_loop:
375
 mov edx, eax
376
 and eax, 15
377
 xlatb
378
 mov [esi], al
379
 mov eax, edx
380
 shr eax, 4
381
 dec esi
382
 loop phex_loop
383
 popa
384
 ret
385
 
386
 
387
; DATA AREA
388
 
389
text:
390
    db ' Number of ARP entries: xxxxxxxx        '
391
    db ' Maximum # of entries : xxxxxxxx        '
392
    db '                                        '
393
    db ' IP Address      MAC          Stat TTL  '
394
    db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
395
    db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
396
    db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
397
    db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
398
    db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
399
    db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
400
    db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
401
    db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
402
    db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
403
    db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
625 diamond 404
    db 'x' ; <- END MARKER, DONT DELETE
31 halyavin 405
 
406
 
407
blank:
408
 	  db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
409
 
410
 
485 heavyiron 411
title    db   'ARP Table ( First 10 Entries )',0
31 halyavin 412
 
413
hextable db '0123456789ABCDEF'
414
 
415
 
416
I_END: