Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
3545 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
;;  netstat.asm - Network Status Tool for KolibriOS                ;;
7
;;                                                                 ;;
8
;;  Written by hidnplayr@kolibrios.org                             ;;
9
;;                                                                 ;;
10
;;          GNU GENERAL PUBLIC LICENSE                             ;;
11
;;             Version 2, June 1991                                ;;
12
;;                                                                 ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14
 
15
format binary as ""
16
 
17
use32
18
 
19
        org    0x0
20
 
3601 hidnplayr 21
        db     'MENUET01'       ; 8 byte id
22
        dd     0x01             ; header version
23
        dd     START            ; start of code
24
        dd     I_END            ; size of image
25
        dd     (I_END+0x1000)   ; memory for app
26
        dd     (I_END+0x1000)   ; esp
27
        dd     0, 0             ; I_Param , I_Path
3545 hidnplayr 28
 
29
include '..\macros.inc'
30
include '..\network.inc'
31
 
32
START:
33
        mcall   40, EVM_REDRAW + EVM_BUTTON + EVM_STACK2
34
 
35
redraw:
36
        mcall   12, 1
37
        mcall   0, 100 shl 16 + 600, 100 shl 16 + 240, 0x34bcbcbc, , name       ; draw window
38
 
39
        call    draw_interfaces
40
 
3601 hidnplayr 41
        xor     ebx, ebx
42
        mov     bh, [device]
43
        mcall   74
44
        mov     [device_type], eax
45
 
3545 hidnplayr 46
        mov     edx, 101
47
        mov     esi, 0x00aaaaff
48
        mov     edi, 0x00aaffff
49
 
50
        cmp     dl, [mode]
51
        cmove   esi, edi
3601 hidnplayr 52
        mcall   8, 5 shl 16 + 55, 5 shl 16 + 20
3545 hidnplayr 53
  .morebuttons:
54
        inc     edx
3601 hidnplayr 55
        add     ebx, 60 shl 16
3545 hidnplayr 56
        mov     esi, 0x00aaaaff
57
 
58
        cmp     dl, [mode]
59
        cmove   esi, edi
60
        mcall
61
 
62
        cmp     edx, 105
63
        jle     .morebuttons
64
 
3601 hidnplayr 65
        mcall   4, 8 shl 16 + 11, 0x80000000, modes
3545 hidnplayr 66
 
67
        cmp     [mode], 101
68
        jne     .no_eth
69
 
3601 hidnplayr 70
        mcall   4, 8 shl 16 + 35, 0x80000000, str_packets_tx
3545 hidnplayr 71
        add     ebx, 18
72
        mov     edx, str_packets_rx
73
        mcall
74
        add     ebx, 18
75
        mov     edx, str_bytes_tx
76
        mcall
77
        add     ebx, 18
78
        mov     edx, str_bytes_rx
79
        mcall
80
        add     ebx, 18
3601 hidnplayr 81
        mov     edx, str_link
3545 hidnplayr 82
        mcall
3601 hidnplayr 83
 
84
        cmp     [device_type], 1
85
        jne     end_of_draw
86
 
3545 hidnplayr 87
        add     ebx, 18
3601 hidnplayr 88
        mov     edx, str_MAC
3545 hidnplayr 89
        mcall
90
 
3601 hidnplayr 91
        mov     ebx, API_ETH
3545 hidnplayr 92
        mov     bh, [device]
93
        mcall   76
94
        push    eax
95
        push    bx
96
 
3601 hidnplayr 97
        mov     edx, 135 shl 16 + 35 + 5*18
3545 hidnplayr 98
        call    draw_mac
99
        jmp     end_of_draw
100
 
101
 .no_eth:
102
 
103
        cmp     [mode], 102
104
        jne     .no_ip
105
 
3601 hidnplayr 106
        mcall   4, 8 shl 16 + 35, 0x80000000, str_packets_tx
3545 hidnplayr 107
        add     ebx, 18
108
        mov     edx, str_packets_rx
109
        mcall
110
        add     ebx, 18
111
        mov     edx, str_ip
112
        mcall
113
        add     ebx, 18
114
        mov     edx, str_dns
115
        mcall
116
        add     ebx, 18
117
        mov     edx, str_subnet
118
        mcall
119
        add     ebx, 18
120
        mov     edx, str_gateway
121
        mcall
122
 
123
 
124
        mov     ebx, API_IPv4 + 8
125
        mov     bh, [device]
126
        mcall   76
127
        push    eax
128
 
129
        dec     bl
130
        dec     bl
131
        mcall   76
132
        push    eax
133
 
134
        dec     bl
135
        dec     bl
136
        mcall   76
137
        push    eax
138
 
139
        dec     bl
140
        dec     bl
141
        mcall   76
142
        push    eax
143
 
3601 hidnplayr 144
        mov     edx, 135 shl 16 + 35 + 2*18
3545 hidnplayr 145
        call    draw_ip
146
 
147
        add     edx, 18
148
        call    draw_ip
149
 
150
        add     edx, 18
151
        call    draw_ip
152
 
153
        add     edx, 18
154
        call    draw_ip
155
 
156
        jmp     end_of_draw
157
 
158
 .no_ip:
159
 
160
        cmp     [mode], 103
161
        jne     .no_arp
162
 
3601 hidnplayr 163
        mcall   4, 8 shl 16 + 35, 0x80000000, str_packets_tx
3545 hidnplayr 164
        add     ebx, 18
165
        mov     edx, str_packets_rx
166
        mcall
167
        add     ebx, 18
168
        mov     edx, str_arp
169
        mcall
170
        add     ebx, 18
171
        mov     edx, str_conflicts
172
        mcall
173
 
3601 hidnplayr 174
        mcall   4, 8 shl 16 + 130, 0x80000000, str_ARP_legend
175
 
3545 hidnplayr 176
        jmp     end_of_draw
177
 
178
 .no_arp:
179
 
3601 hidnplayr 180
        mcall   4, 8 shl 16 + 35, 0x80000000, str_packets_tx
3545 hidnplayr 181
 
182
        add     ebx, 18
183
        mov     edx, str_packets_rx
184
        mcall
185
 
186
        cmp     [mode], 106
187
        jne     end_of_draw
188
 
189
        add     ebx, 18
190
        mov     edx, str_missed
191
        mcall
192
 
193
        add     ebx, 18
194
        mov     edx, str_dumped
195
        mcall
196
 
197
 
198
 
199
end_of_draw:
200
        mcall   12, 2
201
 
202
draw_stats:
203
 
204
        cmp     [mode], 101
205
        jne     not_101
206
 
207
        mov     ebx, API_ETH
208
        mov     bh, [device]
3601 hidnplayr 209
        mov     bl, 6
3545 hidnplayr 210
  @@:
211
        push    ebx
3601 hidnplayr 212
        mcall   74
3545 hidnplayr 213
        pop     ebx
214
        push    eax
215
        inc     bl
3601 hidnplayr 216
        cmp     bl, 10
3545 hidnplayr 217
        jbe     @r
218
 
219
        mov     ebx, 0x000a0000
220
        pop     ecx
3601 hidnplayr 221
        mov     edx, 135 shl 16 + 35 + 4*18
3545 hidnplayr 222
        mov     esi, 0x40000000
223
        mov     edi, 0x00bcbcbc
224
        mcall   47
225
 
3601 hidnplayr 226
        sub     edx, 18
3545 hidnplayr 227
        pop     ecx
228
        mcall
229
 
230
        sub     edx, 18
231
        pop     ecx
232
        mcall
233
 
234
        sub     edx, 18
235
        pop     ecx
236
        mcall
237
 
238
        sub     edx, 18
239
        pop     ecx
240
        mcall
241
 
242
        jmp     mainloop
243
 
244
 
245
not_101:
246
 
247
        cmp     [mode], 102
248
        jne     not_102
249
 
250
        mov     ebx, API_IPv4
251
        mov     bh, [device]
252
        push    ebx
253
        mcall   76
254
        pop     ebx
255
        push    eax
256
 
257
        inc     bl
258
        push    ebx
259
        mcall   76
260
        pop     ebx
261
        push    eax
262
 
263
 
264
        mov     ebx, 0x000a0000
265
        pop     ecx
3601 hidnplayr 266
        mov     edx, 135 shl 16 + 35 + 18
3545 hidnplayr 267
        mov     esi, 0x40000000
268
        mov     edi, 0x00bcbcbc
269
        mcall   47
270
 
271
        sub     edx, 18
272
        pop     ecx
273
        mcall
274
 
275
        jmp     mainloop
276
 
277
 
278
not_102:
279
 
280
        cmp     [mode], 103
281
        jne     not_103
282
 
283
        mov     ebx, API_ARP
284
        mov     bh, [device]
285
        push    ebx
286
        mcall   76
287
        pop     ebx
288
        push    eax
289
 
290
        inc     bl
291
        push    ebx
292
        mcall   76
293
        pop     ebx
294
        push    eax
295
 
296
        inc     bl
297
        push    ebx
298
        mcall   76
299
        pop     ebx
300
        push    eax
301
 
302
        mov     bl, 7
303
        push    ebx
304
        mcall   76
305
        pop     ebx
306
        push    eax
307
 
308
        mov     ebx, 0x000a0000
309
        pop     ecx
3601 hidnplayr 310
        mov     edx, 135 shl 16 + 35 + 3*18
3545 hidnplayr 311
        mov     esi, 0x40000000
312
        mov     edi, 0x00bcbcbc
313
        mcall   47
314
 
315
        sub     edx, 18
316
        pop     ecx
317
        mcall
318
 
319
        sub     edx, 18
320
        pop     ecx
321
        mcall
322
 
323
        sub     edx, 18
324
        pop     ecx
325
        mcall
326
 
327
 
3601 hidnplayr 328
 
329
        mov     edx, 50 shl 16 + 150
330
        mov     [last], 0
331
 
332
  .arp_loop:
333
        mov     ebx, API_ARP + 3
334
        mov     bh, [device]
335
        mcall   76, , [last],,, arp_buf
336
        cmp     eax, -1
337
        je      mainloop
338
 
339
        mcall   4, 20 shl 16 + 140, 0x80000000, str_ARP_entry
340
        mov     edx, ebx
341
 
342
        mov     eax, 47
343
        mov     ebx, 0x00030000
344
        mov     esi, 0x40000000
345
        mov     edi, 0x00bcbcbc
346
        xor     ecx, ecx
347
 
348
        mov     cl, byte[arp_buf.IP+0]
349
        mcall
350
 
351
        mov     cl, byte[arp_buf.IP+1]
352
        add     edx, 24 shl 16
353
        mcall
354
 
355
        mov     cl, byte[arp_buf.IP+2]
356
        add     edx, 24 shl 16
357
        mcall
358
 
359
        mov     cl, byte[arp_buf.IP+3]
360
        add     edx, 24 shl 16
361
        mcall
362
 
363
 
364
        mov     ebx, 0x00020100
365
        mov     cl, byte[arp_buf.MAC+0]
366
        add     edx, 36 shl 16
367
        mcall
368
 
369
        mov     cl, byte[arp_buf.MAC+1]
370
        add     edx, 18 shl 16
371
        mcall
372
 
373
        mov     cl, byte[arp_buf.MAC+2]
374
        add     edx, 18 shl 16
375
        mcall
376
 
377
        mov     cl, byte[arp_buf.MAC+3]
378
        add     edx, 18 shl 16
379
        mcall
380
 
381
        mov     cl, byte[arp_buf.MAC+4]
382
        add     edx, 18 shl 16
383
        mcall
384
 
385
        mov     cl, byte[arp_buf.MAC+5]
386
        add     edx, 18 shl 16
387
        mcall
388
 
389
        mov     ebx, 0x00040000
390
        mov     cx, [arp_buf.status]
391
        add     edx, 30 shl 16
392
        mcall
393
 
394
        mov     cx, [arp_buf.TTL]
395
        add     edx, 60 shl 16
396
        mcall
397
 
398
        add     dx, 18
399
        rol     edx, 16
400
        mov     dx, 8
401
        rol     edx, 16
402
        inc     [last]
403
 
404
        jmp     .arp_loop
405
 
3545 hidnplayr 406
not_103:
407
 
408
        cmp     [mode], 104
409
        jne     not_104
410
 
411
        mov     ebx, API_ICMP
412
        mov     bh, [device]
413
        push    ebx
414
        mcall   76
415
        pop     ebx
416
        push    eax
417
 
418
        inc     bl
419
        push    ebx
420
        mcall   76
421
        pop     ebx
422
        push    eax
423
 
424
        mov     ebx, 0x000a0000
425
        pop     ecx
3601 hidnplayr 426
        mov     edx, 135 shl 16 + 35 + 18
3545 hidnplayr 427
        mov     esi, 0x40000000
428
        mov     edi, 0x00bcbcbc
429
        mcall   47
430
 
431
        sub     edx, 18
432
        pop     ecx
433
        mcall
434
 
435
        jmp     mainloop
436
 
437
not_104:
438
 
439
        cmp     [mode], 105
440
        jne     not_105
441
 
442
        mov     ebx, API_UDP
443
        mov     bh, [device]
444
        push    ebx
445
        mcall   76
446
        pop     ebx
447
        push    eax
448
 
449
        inc     bl
450
        push    ebx
451
        mcall   76
452
        pop     ebx
453
        push    eax
454
 
455
        mov     ebx, 0x000a0000
456
        pop     ecx
3601 hidnplayr 457
        mov     edx, 135 shl 16 + 35 + 18
3545 hidnplayr 458
        mov     esi, 0x40000000
459
        mov     edi, 0x00bcbcbc
460
        mcall   47
461
 
462
        sub     edx, 18
463
        pop     ecx
464
        mcall
465
 
466
        jmp     mainloop
467
 
468
not_105:
469
 
470
        cmp     [mode], 106
471
        jne     not_106
472
 
473
        mov     ebx, API_TCP
474
        mov     bh, [device]
475
        push    ebx
476
        mcall   76
477
        pop     ebx
478
        push    eax
479
 
480
        inc     bl
481
        push    ebx
482
        mcall   76
483
        pop     ebx
484
        push    eax
485
 
486
        inc     bl
487
        push    ebx
488
        mcall   76
489
        pop     ebx
490
        push    eax
491
 
492
        inc     bl
493
        push    ebx
494
        mcall   76
495
        pop     ebx
496
        push    eax
497
 
498
        mov     ebx, 0x000a0000
499
        pop     ecx
3601 hidnplayr 500
        mov     edx, 135 shl 16 + 35 + 18*3
3545 hidnplayr 501
        mov     esi, 0x40000000
502
        mov     edi, 0x00bcbcbc
503
        mcall   47
504
 
505
        sub     edx, 18
506
        pop     ecx
507
        mcall
508
 
509
        sub     edx, 18
510
        pop     ecx
511
        mcall
512
 
513
        sub     edx, 18
514
        pop     ecx
515
        mcall
516
 
517
        jmp     mainloop
518
 
519
not_106:
520
 
521
mainloop:
522
 
523
        mcall   23, 50          ; wait for event with timeout    (0,5 s)
524
 
525
        cmp     eax, 1
526
        je      redraw
527
        cmp     eax, 3
528
        je      button
529
        cmp     eax, 11
530
        je      redraw
531
 
532
        jmp     draw_stats
533
 
534
button:                         ; button
535
        mcall   17              ; get id
536
        cmp     ah, 1
537
        je      exit
538
        cmp     ah, 0
539
        je      .interface
540
        mov     [mode], ah
541
        jmp     redraw
542
 
543
  .interface:
544
        shr     eax, 16
545
        mov     [device], al
546
        jmp     redraw
547
 
548
exit:
549
        mcall   -1
550
 
551
 
552
 
553
draw_mac:
554
 
555
        mov     eax, 47
556
        mov     ebx, 0x00020100
557
        mov     esi, 0x40000000
558
        mov     edi, 0x00bcbcbc
559
 
560
        mov     cl, [esp+4]
561
        mcall
562
 
563
        mov     cl, [esp+4+1]
564
        add     edx, 15 shl 16
565
        mcall
566
 
567
        mov     cl, [esp+4+2]
568
        add     edx, 15 shl 16
569
        mcall
570
 
571
        mov     cl, [esp+4+3]
572
        add     edx, 15 shl 16
573
        mcall
574
 
575
        mov     cl, [esp+4+4]
576
        add     edx, 15 shl 16
577
        mcall
578
 
579
        mov     cl, [esp+4+5]
580
        add     edx, 15 shl 16
581
        mcall
582
 
583
        sub     edx, 5*15 shl 16
584
 
585
        ret     6
586
 
587
 
588
draw_ip:
589
 
590
        mov     eax, 47
591
        mov     ebx, 0x00030000
592
        mov     esi, 0x40000000
593
        mov     edi, 0x00bcbcbc
594
 
595
        xor     ecx, ecx
596
 
597
        mov     cl, [esp+4]
598
        mcall
599
 
600
        mov     cl, [esp+4+1]
601
        add     edx, 30 shl 16
602
        mcall
603
 
604
        mov     cl, [esp+4+2]
605
        add     edx, 30 shl 16
606
        mcall
607
 
608
        mov     cl, [esp+4+3]
609
        add     edx, 30 shl 16
610
        mcall
611
 
612
        sub     edx, 3*30 shl 16
613
        ret     4
614
 
615
 
616
draw_interfaces:
617
 
3601 hidnplayr 618
        mov     [.btnpos], 5 shl 16 + 20
619
        mov     [.txtpos], 455 shl 16 + 12
3545 hidnplayr 620
 
621
        mcall   74, -1          ; get number of active network devices
622
        mov     ecx, eax
623
 
624
        xor     ebx, ebx        ; get device type
625
  .loop:
626
        mcall   74
3601 hidnplayr 627
        cmp     eax, 1          ; loopback or ethernet?
628
        jbe     .hit
3545 hidnplayr 629
        inc     bh
630
        jb      .loop           ; tried all 256?
631
        ret
632
 
633
 
634
  .hit:
635
        push    ecx ebx
636
        movzx   edx, bh
637
        shl     edx, 8
638
        mov     esi, 0x00aaaaff
639
        cmp     bh, [device]
640
        cmove   esi, 0x00aaffff
3601 hidnplayr 641
        mcall   8, 450 shl 16 + 135, [.btnpos]
3545 hidnplayr 642
        mov     ebx, [esp]
643
        inc     bl
644
        mov     ecx, namebuf
645
        mov     edx, namebuf
3601 hidnplayr 646
        mcall   74                              ; get device name
3545 hidnplayr 647
        cmp     eax, -1
648
        jne     @f
649
        mov     edx, str_unknown
650
       @@:
3601 hidnplayr 651
        mcall   4, [.txtpos], 0x80000000        ; print the name
3545 hidnplayr 652
        pop     ebx ecx
653
 
654
        inc     bh
655
 
656
        add     [.btnpos], 25 shl 16
657
        add     [.txtpos], 25
658
 
659
        dec     ecx
660
        jnz     .loop
661
 
662
        ret
663
 
664
  .btnpos       dd ?
665
  .txtpos       dd ?
666
 
667
 
668
 
669
 
670
; DATA AREA
671
 
672
name            db 'Netstat', 0
673
mode            db 101
674
device          db 0
3601 hidnplayr 675
device_type     dd 0
676
last            dd 0
677
modes           db 'Physical    IPv4      ARP       ICMP      UDP       TCP', 0
3545 hidnplayr 678
 
679
str_packets_tx  db 'Packets sent:', 0
680
str_packets_rx  db 'Packets received:', 0
681
str_bytes_tx    db 'Bytes sent:', 0
682
str_bytes_rx    db 'Bytes received:', 0
683
str_MAC         db 'MAC address:', 0
684
str_ip          db 'IP address:', 0
685
str_dns         db 'DNS address:', 0
686
str_subnet      db 'Subnet mask:', 0
687
str_gateway     db 'Standard gateway:', 0
688
str_arp         db 'ARP entrys:', 0
689
str_conflicts   db 'ARP conflicts:', 0
690
str_unknown     db 'unknown', 0
691
str_missed      db 'Packets missed:',0
692
str_dumped      db 'Packets dumped:',0
693
str_link        db 'Link state:',0
694
 
3601 hidnplayr 695
str_ARP_legend  db 'IP-address        MAC-address         Status    TTL', 0
696
str_ARP_entry   db '   .   .   .        -  -  -  -  -                    s', 0
697
 
3545 hidnplayr 698
namebuf         rb 64
3601 hidnplayr 699
arp_buf         ARP_entry
3545 hidnplayr 700
 
701
I_END:
702