Subversion Repositories Kolibri OS

Rev

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

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