Make AddMouseRegion's index unsigned
[dockapps.git] / wmjiface / src / ifacechk
blob7b81ad81c50747a0fb5db0a34214cd2973b4c5e9
1 #!/usr/bin/perl
2 ################
3 # cat /proc/net/dev
4 #Inter-| Receive | Transmit
5 # face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
6 # lo:22905347 39915 0 0 0 0 0 0 22905347 39915 0 0 0 0 0 0
7 # eth0: 923454 7885 0 0 0 0 0 347 1987558 6791 0 0 0 0 0 0
8 # ppp0: 7080806 7876 2 0 0 2 0 0 314121 5267 0 0 0 0 0 0
9 # ppp1: 331265 7810 0 0 0 0 0 0 233915 8563 0 0 0 0 0 0
10 #########################
12 $ppid=getppid();
14 $iface="/proc/net/dev";
15 $staname="$ENV{HOME}/.wmjiface.stat.$ppid";
17 @statusFiles=`ls $ENV{HOME}/.wmjiface.stat.* 2>/dev/null`;
19 foreach (@statusFiles) {
20 s/^.*[.]wmjiface[.]stat[.]//;
21 chomp;
22 system("rm $ENV{HOME}/.wmjiface.stat.$_") if not ( -d "/proc/$_" );
25 $now=time();
27 $then; # aquired during read_stat;
29 %statso; # aquired during read_stat;
30 %statsc; # aquired during read_proc;
32 &read_proc();
34 if(&read_stat()) {
35 $tdiff = $now - $then;
37 foreach (keys %statsc) {
38 if($statso{$_}) {
39 $bytesin = $statsc{$_}{bytesi} - $statso{$_}{bytesi};
40 $bytesout = $statsc{$_}{byteso} - $statso{$_}{byteso};
42 #$packetsin = $statsc{$_}{packetsi} - $statso{$_}{packetsi};
43 #$packetsout = $statsc{$_}{packetso} - $statso{$_}{packetso};
45 $bytesin_ps = $bytesin/$tdiff if $tdiff > 0;
46 $bytesout_ps = $bytesout/$tdiff if $tdiff > 0;
48 #$packetsin_ps = $packetsin/$tdiff if $tdiff > 0;
49 #$packetsout_ps = $packetsout/$tdiff if $tdiff > 0;
51 printf "%s %i %i\n", $_, $bytesin_ps, $bytesout_ps;
57 &write_stat();
58 exit;
61 ##################################################################3
63 sub write_stat() {
64 open sta, ">$staname" or die;
66 printf sta "%i\n", $now;
68 foreach (keys %statsc) {
69 printf sta "%s:%i:%i:%i:%i:%i\n",
70 $_,
71 $statsc{$_}{bytesi},
72 $statsc{$_}{byteso},
73 $statsc{$_}{packetsi},
74 $statsc{$_}{packetso};
77 close sta;
80 sub read_stat() {
81 open sta, "$staname" or return ();
83 $then = <sta>;
84 chomp $then;
86 while(<sta>) {
87 chomp;
89 ($face, $bytesi, $byteso, $packetsi, $packetso) = split ":";
91 $statso{$face} = { bytesi => $bytesi,
92 byteso => $byteso,
93 packetsi => $byteso,
94 packetso => $byteso };
97 close sta;
98 return 1;
101 sub read_proc() {
102 open dev, "$iface" or die;
104 $waste = <dev>; # title
105 $waste = <dev>; # title
106 $waste = <dev>; # lo
108 $devfilesexist = `ls /var/run/ppp*.dev 2>/dev/null`; chomp $devfilesexist;
110 while(<dev>) {
111 chomp; s/[ ]+/:/g; s/^://; s/:$//; s/[:]+/:/g;
113 s/([0-9]+)([0-9]{9})/$2/g;
115 ($face,
116 $bytesi, $packetsi, $errsi, $dropi, $fifoi, $frame, $compressedi, $multicast,
117 $byteso, $packetso, $errso, $dropo, $fifoo, $colls, $carrier, $compressedo
118 ) = split ":";
120 if($devfilesexist !~ /^$/ and $face =~ /ppp/) {
121 $tosser = `grep $face /var/run/*.dev /dev/null | head -1`;
122 chomp $tosser;
123 $tosser =~ s/^[^-]*-//;
124 $tosser =~ s/.dev:.*//;
125 if($tosser !~ /^$/) {
126 $statsc{$tosser} = { bytesi => $bytesi,
127 byteso => $byteso,
128 packetsi => $byteso,
129 packetso => $byteso };
131 } else {
132 $statsc{$face} = { bytesi => $bytesi,
133 byteso => $byteso,
134 packetsi => $byteso,
135 packetso => $byteso };
139 close dev;