Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1171 hidnplayr 1
;
2853 hidnplayr 2
; Netstat for KolibriOS v0.2
1171 hidnplayr 3
;
2853 hidnplayr 4
; 0.1 - 22 sept 2009 - initial release
5
; 0.2 - 9 july 2012 - converted to new sysfunc numbers
6
;
1171 hidnplayr 7
; hidnplayr@gmail.com
8
;
9
 
2853 hidnplayr 10
format binary as ""
11
 
1171 hidnplayr 12
use32
13
 
14
    org     0x0
15
 
2853 hidnplayr 16
    db     'MENUET01'        ; 8 byte id
17
    dd     0x01              ; header version
18
    dd     START             ; start of code
19
    dd     I_END             ; size of image
20
    dd     (I_END+0x100)     ; memory for app
21
    dd     (I_END+0x100)     ; esp
22
    dd     I_PARAM , 0x0     ; I_Param , I_Icon
1171 hidnplayr 23
 
24
__DEBUG__ equ 1
25
__DEBUG_LEVEL__ equ 1
26
 
27
include '..\macros.inc'
28
include '..\debug-fdo.inc'
2853 hidnplayr 29
include '..\network.inc'
1171 hidnplayr 30
 
2853 hidnplayr 31
START:                                 ; start of execution
1171 hidnplayr 32
    ; TODO: check Parameters
33
 
1528 hidnplayr 34
    DEBUGF  1, 'Netstat application loaded!\n'
1171 hidnplayr 35
 
36
  redraw:
37
    mcall   12, 1
38
 
1528 hidnplayr 39
    mcall   0, 100 shl 16 + 520, 100 shl 16 + 240, 0x34bcbcbc , , name
1171 hidnplayr 40
 
41
    mov     edx, 101
42
    mov     esi, 0x00aaaaff
43
    mov     edi, 0x00aaffff
44
 
45
    cmp     dl, [mode]
46
    cmove   esi, edi
47
    mcall   8, 25 shl 16 + 65, 25 shl 16 + 20
48
 
1528 hidnplayr 49
  .morebuttons:
1171 hidnplayr 50
    inc     edx
51
    add     ebx, 75 shl 16
52
    mov     esi, 0x00aaaaff
53
 
54
    cmp     dl, [mode]
55
    cmove   esi, edi
56
    mcall
57
 
58
    cmp     edx, 105
1528 hidnplayr 59
    jle     .morebuttons
1171 hidnplayr 60
 
61
    mcall   4, 28 shl 16 + 31, 0x80000000, modes
62
 
63
    cmp     [mode], 101
1528 hidnplayr 64
    jne     .no_eth
1171 hidnplayr 65
 
66
    mcall   4, 20 shl 16 + 75, 0x80000000, str_packets_tx
67
    add     ebx, 18
68
    mov     edx, str_packets_rx
69
    mcall
70
    add     ebx, 18
71
    mov     edx, str_bytes_tx
72
    mcall
73
    add     ebx, 18
74
    mov     edx, str_bytes_rx
75
    mcall
76
    add     ebx, 18
77
    mov     edx, str_MAC
78
    mcall
79
    add     ebx, 18
80
    mov     edx, str_queue_in
81
    mcall
82
    add     ebx, 18
83
    mov     edx, str_queue_out
84
    mcall
85
 
2853 hidnplayr 86
    mov     ebx, API_ETH + 4
1171 hidnplayr 87
    mov     bh, [device]
2364 hidnplayr 88
    mcall   76
1171 hidnplayr 89
    push    eax
90
    push    bx
91
 
92
    mov     edx, 135 shl 16 + 75 + 4*18
1192 hidnplayr 93
    call    draw_mac
94
    jmp     end_of_draw
1171 hidnplayr 95
 
1528 hidnplayr 96
 .no_eth:
1171 hidnplayr 97
 
98
    cmp     [mode], 102
1528 hidnplayr 99
    jne     .no_ip
1171 hidnplayr 100
 
101
    mcall   4, 20 shl 16 + 75, 0x80000000, str_packets_tx
102
    add     ebx, 18
103
    mov     edx, str_packets_rx
104
    mcall
105
    add     ebx, 18
106
    mov     edx, str_ip
107
    mcall
108
    add     ebx, 18
109
    mov     edx, str_dns
110
    mcall
111
    add     ebx, 18
112
    mov     edx, str_subnet
113
    mcall
114
    add     ebx, 18
115
    mov     edx, str_gateway
116
    mcall
117
 
118
 
2853 hidnplayr 119
    mov     ebx, API_IPv4 + 8
1171 hidnplayr 120
    mov     bh, [device]
2364 hidnplayr 121
    mcall   76
1171 hidnplayr 122
    push    eax
123
 
124
    dec     bl
125
    dec     bl
2364 hidnplayr 126
    mcall   76
1171 hidnplayr 127
    push    eax
128
 
129
    dec     bl
130
    dec     bl
2364 hidnplayr 131
    mcall   76
1171 hidnplayr 132
    push    eax
133
 
134
    dec     bl
135
    dec     bl
2364 hidnplayr 136
    mcall   76
1171 hidnplayr 137
    push    eax
138
 
139
    mov     edx, 135 shl 16 + 75 + 2*18
140
    call    draw_ip
141
 
142
    add     edx, 18
143
    call    draw_ip
144
 
145
    add     edx, 18
146
    call    draw_ip
147
 
148
    add     edx, 18
149
    call    draw_ip
150
 
151
    jmp     end_of_draw
152
 
1528 hidnplayr 153
 .no_ip:
1171 hidnplayr 154
 
155
    cmp     [mode], 103
1528 hidnplayr 156
    jne     .no_arp
1171 hidnplayr 157
 
158
    mcall   4, 20 shl 16 + 75, 0x80000000, str_packets_tx
159
    add     ebx, 18
160
    mov     edx, str_packets_rx
161
    mcall
162
    add     ebx, 18
163
    mov     edx, str_arp
164
    mcall
165
 
166
    jmp     end_of_draw
167
 
1528 hidnplayr 168
 .no_arp:
1171 hidnplayr 169
 
170
    mcall   4, 20 shl 16 + 75, 0x80000000, str_packets_tx
171
    add     ebx, 18
172
    mov     edx, str_packets_rx
173
    mcall
174
 
175
 end_of_draw:
176
 
177
    mcall   12, 2
178
 
179
    jmp     draw_stats
180
 
181
  mainloop:
182
 
2853 hidnplayr 183
    mcall   23,500                  ; wait for event with timeout    (0,5 s)
1171 hidnplayr 184
 
185
    cmp     eax, 1
2853 hidnplayr 186
    je      redraw
1171 hidnplayr 187
    cmp     eax, 2
2853 hidnplayr 188
    je      key
1171 hidnplayr 189
    cmp     eax, 3
2853 hidnplayr 190
    je      button
1171 hidnplayr 191
 
192
 
193
 
194
 
195
;-------------------------------
196
;
197
;------------------------------
198
 
199
  draw_stats:
200
 
201
    cmp     [mode], 101
202
    jne     not_101
203
 
2853 hidnplayr 204
    mov     ebx, API_ETH
1171 hidnplayr 205
    mov     bh, [device]
206
   @@:
1192 hidnplayr 207
    push    ebx
2364 hidnplayr 208
    mcall   76
1192 hidnplayr 209
    pop     ebx
1171 hidnplayr 210
    push    eax
211
    inc     bl
212
    cmp     bl, 3
213
    jle     @r
214
 
2853 hidnplayr 215
    inc     bl   ;5
216
    inc     bl   ;6
1171 hidnplayr 217
 
218
   @@:
1192 hidnplayr 219
    push    ebx
2364 hidnplayr 220
    mcall   76
1192 hidnplayr 221
    pop     ebx
1171 hidnplayr 222
    push    eax
223
    inc     bl
224
    cmp     bl, 7
225
    jle     @r
226
 
227
    mov     eax, 47
228
    mov     ebx, 0x000a0000
229
    mov     esi, 0x40000000
230
    mov     edi, 0x00bcbcbc
231
    mov     edx, 135 shl 16 + 75 + 6*18
232
    pop     ecx
233
    mcall
234
    sub     edx, 18
235
    pop     ecx
236
    mcall
237
    sub     edx, 2*18
238
    pop     ecx
239
    mcall
240
    sub     edx, 18
241
    pop     ecx
242
    mcall
243
    sub     edx, 18
244
    pop     ecx
245
    mcall
246
    sub     edx, 18
247
    pop     ecx
248
    mcall
249
 
250
    jmp     mainloop
251
 
252
 
253
 not_101:
254
 
255
    cmp     [mode], 102
256
    jne     not_102
257
 
2853 hidnplayr 258
    mov     ebx, API_IPv4
1171 hidnplayr 259
    mov     bh, [device]
1192 hidnplayr 260
    push    ebx
2364 hidnplayr 261
    mcall   76
1192 hidnplayr 262
    pop     ebx
1171 hidnplayr 263
    push    eax
264
    inc     bl
1192 hidnplayr 265
    push    ebx
2364 hidnplayr 266
    mcall   76
1192 hidnplayr 267
    pop     ebx
1171 hidnplayr 268
    push    eax
269
    inc     bl
270
 
271
    mov     eax, 47
272
    mov     ebx, 0x000a0000
273
    mov     esi, 0x40000000
274
    mov     edi, 0x00bcbcbc
275
    mov     edx, 135 shl 16 + 75 + 18
276
    pop     ecx
277
    mcall
278
    sub     edx, 18
279
    pop     ecx
280
    mcall
281
 
282
    jmp     mainloop
283
 
284
 
285
 not_102:
286
 
287
    cmp     [mode], 103
288
    jne     not_103
289
 
2853 hidnplayr 290
    mov     ebx, API_ARP
1171 hidnplayr 291
    mov     bh, [device]
1192 hidnplayr 292
    push    ebx
2364 hidnplayr 293
    mcall   76
1192 hidnplayr 294
    pop     ebx
1171 hidnplayr 295
    push    eax
296
    inc     bl
1192 hidnplayr 297
    push    ebx
2364 hidnplayr 298
    mcall   76
1192 hidnplayr 299
    pop     ebx
1171 hidnplayr 300
    push    eax
301
    inc     bl
1192 hidnplayr 302
    push    ebx
2364 hidnplayr 303
    mcall   76
1192 hidnplayr 304
    pop     ebx
1171 hidnplayr 305
    push    eax
306
    inc     bl
307
 
308
    mov     eax, 47
309
    mov     ebx, 0x000a0000
310
    mov     esi, 0x40000000
311
    mov     edi, 0x00bcbcbc
312
    mov     edx, 135 shl 16 + 75 + 2*18
313
    pop     ecx
314
    mcall
315
    sub     edx, 18
316
    pop     ecx
317
    mcall
318
    sub     edx, 18
319
    pop     ecx
320
    mcall
321
 
322
    jmp     mainloop
323
 
324
not_103:
325
 
326
    cmp     [mode], 104
327
    jne     not_104
328
 
2853 hidnplayr 329
    mov     ebx, API_ICMP
1171 hidnplayr 330
    mov     bh, [device]
1192 hidnplayr 331
    push    ebx
2364 hidnplayr 332
    mcall   76
1192 hidnplayr 333
    pop     ebx
1171 hidnplayr 334
    push    eax
335
    inc     bl
1192 hidnplayr 336
    push    ebx
2364 hidnplayr 337
    mcall   76
1192 hidnplayr 338
    pop     ebx
1171 hidnplayr 339
    push    eax
340
    inc     bl
341
 
342
    mov     eax, 47
343
    mov     ebx, 0x000a0000
344
    mov     esi, 0x40000000
345
    mov     edi, 0x00bcbcbc
346
    mov     edx, 135 shl 16 + 75 + 18
347
    pop     ecx
348
    mcall
349
    sub     edx, 18
350
    pop     ecx
351
    mcall
352
 
353
    jmp     mainloop
354
 
355
not_104:
356
 
357
    cmp     [mode], 105
358
    jne     not_105
359
 
2853 hidnplayr 360
    mov     ebx, API_UDP
1171 hidnplayr 361
    mov     bh, [device]
1192 hidnplayr 362
    push    ebx
2364 hidnplayr 363
    mcall   76
1192 hidnplayr 364
    pop     ebx
1171 hidnplayr 365
    push    eax
366
    inc     bl
1192 hidnplayr 367
    push    ebx
2364 hidnplayr 368
    mcall   76
1192 hidnplayr 369
    pop     ebx
1171 hidnplayr 370
    push    eax
371
    inc     bl
372
 
373
    mov     eax, 47
374
    mov     ebx, 0x000a0000
375
    mov     esi, 0x40000000
376
    mov     edi, 0x00bcbcbc
377
    mov     edx, 135 shl 16 + 75 + 18
378
    pop     ecx
379
    mcall
380
    sub     edx, 18
381
    pop     ecx
382
    mcall
383
 
384
    jmp     mainloop
385
 
386
not_105:
387
 
388
    cmp     [mode], 106
389
    jne     not_106
390
 
2853 hidnplayr 391
    mov     ebx, API_TCP
1171 hidnplayr 392
    mov     bh, [device]
1192 hidnplayr 393
    push    ebx
2364 hidnplayr 394
    mcall   76
1192 hidnplayr 395
    pop     ebx
1171 hidnplayr 396
    push    eax
397
    inc     bl
1192 hidnplayr 398
    push    ebx
2364 hidnplayr 399
    mcall   76
1192 hidnplayr 400
    pop     ebx
1171 hidnplayr 401
    push    eax
402
    inc     bl
403
 
404
    mov     eax, 47
405
    mov     ebx, 0x000a0000
406
    mov     esi, 0x40000000
407
    mov     edi, 0x00bcbcbc
408
    mov     edx, 135 shl 16 + 75 + 18
409
    pop     ecx
410
    mcall
411
    sub     edx, 18
412
    pop     ecx
413
    mcall
414
 
415
    jmp     mainloop
416
 
417
not_106:
418
 
419
    jmp     mainloop
420
 
421
  key:
422
    mcall   2
423
    jmp     mainloop
424
 
425
 
2853 hidnplayr 426
  button:                         ; button
427
    mcall   17                    ; get id
1171 hidnplayr 428
    cmp     ah, 1
2853 hidnplayr 429
    je      exit
1171 hidnplayr 430
    mov     [mode], ah
431
    jmp     redraw
432
 
2853 hidnplayr 433
  exit:
1171 hidnplayr 434
    mcall   -1
435
 
436
 
437
 
438
draw_mac:
439
 
2853 hidnplayr 440
        mov     eax, 47
441
        mov     ebx, 0x00020100
442
        mov     esi, 0x40000000
443
        mov     edi, 0x00bcbcbc
1171 hidnplayr 444
 
2853 hidnplayr 445
        mov     cl, [esp+4]
446
        mcall
1171 hidnplayr 447
 
2853 hidnplayr 448
        mov     cl, [esp+4+1]
449
        add     edx, 15 shl 16
450
        mcall
1171 hidnplayr 451
 
2853 hidnplayr 452
        mov     cl, [esp+4+2]
453
        add     edx, 15 shl 16
454
        mcall
1171 hidnplayr 455
 
2853 hidnplayr 456
        mov     cl, [esp+4+3]
457
        add     edx, 15 shl 16
458
        mcall
1171 hidnplayr 459
 
2853 hidnplayr 460
        mov     cl, [esp+4+4]
461
        add     edx, 15 shl 16
462
        mcall
1171 hidnplayr 463
 
2853 hidnplayr 464
        mov     cl, [esp+4+5]
465
        add     edx, 15 shl 16
466
        mcall
1171 hidnplayr 467
 
2853 hidnplayr 468
        sub     edx, 5*15 shl 16
1171 hidnplayr 469
 
2853 hidnplayr 470
        ret     6
1171 hidnplayr 471
 
472
 
473
draw_ip:
474
 
2853 hidnplayr 475
        mov     eax, 47
476
        mov     ebx, 0x00030000
477
        mov     esi, 0x40000000
478
        mov     edi, 0x00bcbcbc
1171 hidnplayr 479
 
2853 hidnplayr 480
        xor     ecx, ecx
1171 hidnplayr 481
 
2853 hidnplayr 482
        mov     cl, [esp+4]
483
        mcall
1171 hidnplayr 484
 
2853 hidnplayr 485
        mov     cl, [esp+4+1]
486
        add     edx, 30 shl 16
487
        mcall
1171 hidnplayr 488
 
2853 hidnplayr 489
        mov     cl, [esp+4+2]
490
        add     edx, 30 shl 16
491
        mcall
1171 hidnplayr 492
 
2853 hidnplayr 493
        mov     cl, [esp+4+3]
494
        add     edx, 30 shl 16
495
        mcall
1171 hidnplayr 496
 
2853 hidnplayr 497
        sub     edx, 3*30 shl 16
498
        ret     4
1171 hidnplayr 499
 
500
 
501
; DATA AREA
502
 
2853 hidnplayr 503
name    db 'Netstat', 0
504
mode    db 101
505
device  db 0
506
modes   db 'Ethernet        IPv4        ARP         ICMP         UDP         TCP', 0
1171 hidnplayr 507
 
2853 hidnplayr 508
str_packets_tx db 'Packets sent:', 0
509
str_packets_rx db 'Packets received:', 0
510
str_bytes_tx   db 'Bytes sent:', 0
511
str_bytes_rx   db 'Bytes received:', 0
512
str_MAC        db 'MAC address:', 0
513
str_queue_in   db 'IN-queue size:', 0
514
str_queue_out  db 'OUT-queue size:', 0
515
str_ip         db 'IP address:', 0
516
str_dns        db 'DNS address:', 0
517
str_subnet     db 'Subnet mask:', 0
518
str_gateway    db 'Standard gateway:', 0
519
str_arp        db 'ARP entrys:', 0
1171 hidnplayr 520
 
2853 hidnplayr 521
include_debug_strings    ; ALWAYS present in data section
1171 hidnplayr 522
 
523
I_PARAM rb 1024
524
 
1192 hidnplayr 525
I_END:
1171 hidnplayr 526