Subversion Repositories Kolibri OS

Rev

Rev 3618 | Rev 4737 | 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
 
3618 hidnplayr 29
include '../../macros.inc'
30
include '../../network.inc'
3545 hidnplayr 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
3641 hidnplayr 286
        mcall   76      ; tx
3545 hidnplayr 287
        pop     ebx
288
        push    eax
289
 
290
        inc     bl
291
        push    ebx
3641 hidnplayr 292
        mcall   76      ; rx
3545 hidnplayr 293
        pop     ebx
294
        push    eax
295
 
296
        inc     bl
297
        push    ebx
3641 hidnplayr 298
        mcall   76      ; entries
3545 hidnplayr 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
 
3618 hidnplayr 327
;        mov     edx, 50 shl 16 + 150
3601 hidnplayr 328
        mov     [last], 0
329
 
330
  .arp_loop:
3641 hidnplayr 331
        mov     ebx, API_ARP + 3                ; read ARP entry
3601 hidnplayr 332
        mov     bh, [device]
3641 hidnplayr 333
        mcall   76, ,[last], , , arp_buf
3601 hidnplayr 334
        cmp     eax, -1
335
        je      mainloop
336
 
3641 hidnplayr 337
        mov     ebx, [last]
338
        imul    ebx, 16
339
        add     ebx, 8 shl 16 + 140
340
        mcall   4, , 0x80000000, str_ARP_entry
3601 hidnplayr 341
        mov     edx, ebx
342
 
343
        mov     eax, 47
344
        mov     ebx, 0x00030000
345
        mov     esi, 0x40000000
346
        mov     edi, 0x00bcbcbc
347
        xor     ecx, ecx
348
 
349
        mov     cl, byte[arp_buf.IP+0]
350
        mcall
351
 
352
        mov     cl, byte[arp_buf.IP+1]
353
        add     edx, 24 shl 16
354
        mcall
355
 
356
        mov     cl, byte[arp_buf.IP+2]
357
        add     edx, 24 shl 16
358
        mcall
359
 
360
        mov     cl, byte[arp_buf.IP+3]
361
        add     edx, 24 shl 16
362
        mcall
363
 
364
 
365
        mov     ebx, 0x00020100
366
        mov     cl, byte[arp_buf.MAC+0]
367
        add     edx, 36 shl 16
368
        mcall
369
 
370
        mov     cl, byte[arp_buf.MAC+1]
371
        add     edx, 18 shl 16
372
        mcall
373
 
374
        mov     cl, byte[arp_buf.MAC+2]
375
        add     edx, 18 shl 16
376
        mcall
377
 
378
        mov     cl, byte[arp_buf.MAC+3]
379
        add     edx, 18 shl 16
380
        mcall
381
 
382
        mov     cl, byte[arp_buf.MAC+4]
383
        add     edx, 18 shl 16
384
        mcall
385
 
386
        mov     cl, byte[arp_buf.MAC+5]
387
        add     edx, 18 shl 16
388
        mcall
389
 
390
        mov     ebx, 0x00040000
391
        mov     cx, [arp_buf.status]
392
        add     edx, 30 shl 16
393
        mcall
394
 
395
        mov     cx, [arp_buf.TTL]
396
        add     edx, 60 shl 16
397
        mcall
398
 
399
        add     dx, 18
400
        rol     edx, 16
401
        mov     dx, 8
402
        rol     edx, 16
403
        inc     [last]
404
 
405
        jmp     .arp_loop
406
 
3545 hidnplayr 407
not_103:
408
 
409
        cmp     [mode], 104
410
        jne     not_104
411
 
412
        mov     ebx, API_ICMP
413
        mov     bh, [device]
414
        push    ebx
415
        mcall   76
416
        pop     ebx
417
        push    eax
418
 
419
        inc     bl
420
        push    ebx
421
        mcall   76
422
        pop     ebx
423
        push    eax
424
 
425
        mov     ebx, 0x000a0000
426
        pop     ecx
3601 hidnplayr 427
        mov     edx, 135 shl 16 + 35 + 18
3545 hidnplayr 428
        mov     esi, 0x40000000
429
        mov     edi, 0x00bcbcbc
430
        mcall   47
431
 
432
        sub     edx, 18
433
        pop     ecx
434
        mcall
435
 
436
        jmp     mainloop
437
 
438
not_104:
439
 
440
        cmp     [mode], 105
441
        jne     not_105
442
 
443
        mov     ebx, API_UDP
444
        mov     bh, [device]
445
        push    ebx
446
        mcall   76
447
        pop     ebx
448
        push    eax
449
 
450
        inc     bl
451
        push    ebx
452
        mcall   76
453
        pop     ebx
454
        push    eax
455
 
456
        mov     ebx, 0x000a0000
457
        pop     ecx
3601 hidnplayr 458
        mov     edx, 135 shl 16 + 35 + 18
3545 hidnplayr 459
        mov     esi, 0x40000000
460
        mov     edi, 0x00bcbcbc
461
        mcall   47
462
 
463
        sub     edx, 18
464
        pop     ecx
465
        mcall
466
 
467
        jmp     mainloop
468
 
469
not_105:
470
 
471
        cmp     [mode], 106
472
        jne     not_106
473
 
474
        mov     ebx, API_TCP
475
        mov     bh, [device]
476
        push    ebx
477
        mcall   76
478
        pop     ebx
479
        push    eax
480
 
481
        inc     bl
482
        push    ebx
483
        mcall   76
484
        pop     ebx
485
        push    eax
486
 
487
        inc     bl
488
        push    ebx
489
        mcall   76
490
        pop     ebx
491
        push    eax
492
 
493
        inc     bl
494
        push    ebx
495
        mcall   76
496
        pop     ebx
497
        push    eax
498
 
499
        mov     ebx, 0x000a0000
500
        pop     ecx
3601 hidnplayr 501
        mov     edx, 135 shl 16 + 35 + 18*3
3545 hidnplayr 502
        mov     esi, 0x40000000
503
        mov     edi, 0x00bcbcbc
504
        mcall   47
505
 
506
        sub     edx, 18
507
        pop     ecx
508
        mcall
509
 
510
        sub     edx, 18
511
        pop     ecx
512
        mcall
513
 
514
        sub     edx, 18
515
        pop     ecx
516
        mcall
517
 
518
        jmp     mainloop
519
 
520
not_106:
521
 
522
mainloop:
523
 
524
        mcall   23, 50          ; wait for event with timeout    (0,5 s)
525
 
526
        cmp     eax, 1
527
        je      redraw
528
        cmp     eax, 3
529
        je      button
530
        cmp     eax, 11
531
        je      redraw
532
 
533
        jmp     draw_stats
534
 
535
button:                         ; button
536
        mcall   17              ; get id
537
        cmp     ah, 1
538
        je      exit
539
        cmp     ah, 0
540
        je      .interface
541
        mov     [mode], ah
542
        jmp     redraw
543
 
544
  .interface:
545
        shr     eax, 16
546
        mov     [device], al
547
        jmp     redraw
548
 
549
exit:
550
        mcall   -1
551
 
552
 
553
 
554
draw_mac:
555
 
556
        mov     eax, 47
557
        mov     ebx, 0x00020100
558
        mov     esi, 0x40000000
559
        mov     edi, 0x00bcbcbc
560
 
561
        mov     cl, [esp+4]
562
        mcall
563
 
564
        mov     cl, [esp+4+1]
565
        add     edx, 15 shl 16
566
        mcall
567
 
568
        mov     cl, [esp+4+2]
569
        add     edx, 15 shl 16
570
        mcall
571
 
572
        mov     cl, [esp+4+3]
573
        add     edx, 15 shl 16
574
        mcall
575
 
576
        mov     cl, [esp+4+4]
577
        add     edx, 15 shl 16
578
        mcall
579
 
580
        mov     cl, [esp+4+5]
581
        add     edx, 15 shl 16
582
        mcall
583
 
584
        sub     edx, 5*15 shl 16
585
 
586
        ret     6
587
 
588
 
589
draw_ip:
590
 
591
        mov     eax, 47
592
        mov     ebx, 0x00030000
593
        mov     esi, 0x40000000
594
        mov     edi, 0x00bcbcbc
595
 
596
        xor     ecx, ecx
597
 
598
        mov     cl, [esp+4]
599
        mcall
600
 
601
        mov     cl, [esp+4+1]
602
        add     edx, 30 shl 16
603
        mcall
604
 
605
        mov     cl, [esp+4+2]
606
        add     edx, 30 shl 16
607
        mcall
608
 
609
        mov     cl, [esp+4+3]
610
        add     edx, 30 shl 16
611
        mcall
612
 
613
        sub     edx, 3*30 shl 16
614
        ret     4
615
 
616
 
617
draw_interfaces:
618
 
3601 hidnplayr 619
        mov     [.btnpos], 5 shl 16 + 20
620
        mov     [.txtpos], 455 shl 16 + 12
3545 hidnplayr 621
 
622
        mcall   74, -1          ; get number of active network devices
623
        mov     ecx, eax
624
 
625
        xor     ebx, ebx        ; get device type
626
  .loop:
627
        mcall   74
3601 hidnplayr 628
        cmp     eax, 1          ; loopback or ethernet?
629
        jbe     .hit
3545 hidnplayr 630
        inc     bh
631
        jb      .loop           ; tried all 256?
632
        ret
633
 
634
 
635
  .hit:
636
        push    ecx ebx
637
        movzx   edx, bh
638
        shl     edx, 8
639
        mov     esi, 0x00aaaaff
640
        cmp     bh, [device]
641
        cmove   esi, 0x00aaffff
3601 hidnplayr 642
        mcall   8, 450 shl 16 + 135, [.btnpos]
3545 hidnplayr 643
        mov     ebx, [esp]
644
        inc     bl
645
        mov     ecx, namebuf
646
        mov     edx, namebuf
3601 hidnplayr 647
        mcall   74                              ; get device name
3545 hidnplayr 648
        cmp     eax, -1
649
        jne     @f
650
        mov     edx, str_unknown
651
       @@:
3601 hidnplayr 652
        mcall   4, [.txtpos], 0x80000000        ; print the name
3545 hidnplayr 653
        pop     ebx ecx
654
 
655
        inc     bh
656
 
657
        add     [.btnpos], 25 shl 16
658
        add     [.txtpos], 25
659
 
660
        dec     ecx
661
        jnz     .loop
662
 
663
        ret
664
 
665
  .btnpos       dd ?
666
  .txtpos       dd ?
667
 
668
 
669
 
670
 
671
; DATA AREA
672
 
673
name            db 'Netstat', 0
674
mode            db 101
675
device          db 0
3601 hidnplayr 676
device_type     dd 0
677
last            dd 0
678
modes           db 'Physical    IPv4      ARP       ICMP      UDP       TCP', 0
3545 hidnplayr 679
 
680
str_packets_tx  db 'Packets sent:', 0
681
str_packets_rx  db 'Packets received:', 0
682
str_bytes_tx    db 'Bytes sent:', 0
683
str_bytes_rx    db 'Bytes received:', 0
684
str_MAC         db 'MAC address:', 0
685
str_ip          db 'IP address:', 0
686
str_dns         db 'DNS address:', 0
687
str_subnet      db 'Subnet mask:', 0
688
str_gateway     db 'Standard gateway:', 0
689
str_arp         db 'ARP entrys:', 0
690
str_conflicts   db 'ARP conflicts:', 0
691
str_unknown     db 'unknown', 0
692
str_missed      db 'Packets missed:',0
693
str_dumped      db 'Packets dumped:',0
694
str_link        db 'Link state:',0
695
 
3601 hidnplayr 696
str_ARP_legend  db 'IP-address        MAC-address         Status    TTL', 0
697
str_ARP_entry   db '   .   .   .        -  -  -  -  -                    s', 0
698
 
3545 hidnplayr 699
namebuf         rb 64
3601 hidnplayr 700
arp_buf         ARP_entry
3545 hidnplayr 701
 
702
I_END:
703