Subversion Repositories Kolibri OS

Rev

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