Subversion Repositories Kolibri OS

Rev

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

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