Subversion Repositories Kolibri OS

Rev

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