File README changed (mode: 100644) (index 1f6c287..6cd29f3) |
... |
... |
ifdata |
17 |
17 |
get network interface info without parsing ifconfig output |
get network interface info without parsing ifconfig output |
18 |
18 |
pee |
pee |
19 |
19 |
tee standard input to pipes |
tee standard input to pipes |
20 |
|
|
|
|
20 |
|
zrun |
|
21 |
|
automatically uncompress arguments to command |
21 |
22 |
|
|
22 |
23 |
Your suggestions of additional tools to add to this collection are |
Your suggestions of additional tools to add to this collection are |
23 |
24 |
apprecitated. Here are some that are under consideration but have not yet |
apprecitated. Here are some that are under consideration but have not yet |
|
... |
... |
mime |
29 |
30 |
(More useful than file(1) in many cases but would add a lot of |
(More useful than file(1) in many cases but would add a lot of |
30 |
31 |
gnome libraries to the package's dependency chain.) |
gnome libraries to the package's dependency chain.) |
31 |
32 |
|
|
32 |
|
z |
|
33 |
|
makes another program understand compressed files |
|
34 |
|
ex: z zxgv file.bmp.gz |
|
35 |
|
|
|
36 |
|
(Dare I take the "z" name?) |
|
37 |
|
|
|
38 |
33 |
tmp |
tmp |
39 |
34 |
puts stdin into a temp file and passes it to the specified program |
puts stdin into a temp file and passes it to the specified program |
40 |
35 |
ex: zcat file.bmp.gz | tmp zxgv |
ex: zcat file.bmp.gz | tmp zxgv |
File ifdata.c changed (mode: 100644) (index c9a4622..b81424c) |
12 |
12 |
#include <string.h> |
#include <string.h> |
13 |
13 |
#include <unistd.h> |
#include <unistd.h> |
14 |
14 |
#include <ctype.h> |
#include <ctype.h> |
15 |
|
//#include <linux/socket.h> |
|
16 |
15 |
|
|
17 |
|
#define DO_EXISTS 1 |
|
18 |
|
#define DO_PEXISTS 2 |
|
19 |
|
#define DO_PADDRESS 3 |
|
20 |
|
#define DO_PMASK 4 |
|
21 |
|
#define DO_PMTU 5 |
|
22 |
|
#define DO_PCAST 6 |
|
23 |
|
#define DO_PALL 7 |
|
24 |
|
#define DO_PFLAGS 8 |
|
25 |
|
#define DO_SINPACKETS 9 |
|
26 |
|
#define DO_SINBYTES 10 |
|
27 |
|
#define DO_SINERRORS 11 |
|
28 |
|
#define DO_SINDROPS 12 |
|
29 |
|
#define DO_SINALL 13 |
|
30 |
|
#define DO_SINFIFO 14 |
|
31 |
|
#define DO_SINFRAME 15 |
|
32 |
|
#define DO_SINCOMPRESSES 16 |
|
33 |
|
#define DO_SINMULTICAST 17 |
|
34 |
|
#define DO_SOUTALL 18 |
|
35 |
|
#define DO_SOUTBYTES 19 |
|
36 |
|
#define DO_SOUTPACKETS 20 |
|
37 |
|
#define DO_SOUTERRORS 21 |
|
38 |
|
#define DO_SOUTDROPS 22 |
|
39 |
|
#define DO_SOUTFIFO 23 |
|
40 |
|
#define DO_SOUTCOLLS 24 |
|
41 |
|
#define DO_SOUTCARRIER 25 |
|
42 |
|
#define DO_SOUTMULTICAST 26 |
|
43 |
|
#define DO_PNETWORK 27 |
|
44 |
|
#define DO_PHWADDRESS 28 |
|
|
16 |
|
enum { |
|
17 |
|
DO_EXISTS = 1, |
|
18 |
|
DO_PEXISTS, |
|
19 |
|
DO_PADDRESS, |
|
20 |
|
DO_PMASK, |
|
21 |
|
DO_PMTU, |
|
22 |
|
DO_PCAST, |
|
23 |
|
DO_PALL, |
|
24 |
|
DO_PFLAGS, |
|
25 |
|
DO_SINPACKETS, |
|
26 |
|
DO_SINBYTES, |
|
27 |
|
DO_SINERRORS, |
|
28 |
|
DO_SINDROPS, |
|
29 |
|
DO_SINALL, |
|
30 |
|
DO_SINFIFO, |
|
31 |
|
DO_SINFRAME, |
|
32 |
|
DO_SINCOMPRESSES, |
|
33 |
|
DO_SINMULTICAST, |
|
34 |
|
DO_SOUTALL, |
|
35 |
|
DO_SOUTBYTES, |
|
36 |
|
DO_SOUTPACKETS, |
|
37 |
|
DO_SOUTERRORS, |
|
38 |
|
DO_SOUTDROPS, |
|
39 |
|
DO_SOUTFIFO, |
|
40 |
|
DO_SOUTCOLLS, |
|
41 |
|
DO_SOUTCARRIER, |
|
42 |
|
DO_SOUTMULTICAST, |
|
43 |
|
DO_PNETWORK, |
|
44 |
|
DO_PHWADDRESS, |
|
45 |
|
}; |
45 |
46 |
|
|
46 |
47 |
struct if_stat { |
struct if_stat { |
47 |
48 |
unsigned long long int in_packets; |
unsigned long long int in_packets; |
|
... |
... |
void if_hwaddr(char *iface) { |
152 |
153 |
|
|
153 |
154 |
PREPARE_SOCK(iface); |
PREPARE_SOCK(iface); |
154 |
155 |
CALL_IOCTL(SIOCGIFHWADDR); |
CALL_IOCTL(SIOCGIFHWADDR); |
155 |
|
if (res < 0) { |
|
156 |
|
CALL_ERROR(); |
|
157 |
|
} |
|
|
156 |
|
CALL_ERROR(return); |
158 |
157 |
hwaddr = (unsigned char *)req.ifr_hwaddr.sa_data; |
hwaddr = (unsigned char *)req.ifr_hwaddr.sa_data; |
159 |
158 |
printf("%02X:%02X:%02X:%02X:%02X:%02X", |
printf("%02X:%02X:%02X:%02X:%02X:%02X", |
160 |
159 |
hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]); |
hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]); |
|
... |
... |
int if_mtu(char *iface) { |
211 |
210 |
return req.ifr_mtu; |
return req.ifr_mtu; |
212 |
211 |
} |
} |
213 |
212 |
|
|
214 |
|
#define START 1 |
|
215 |
|
#define SKIP_LINE 2 |
|
216 |
|
#define START_LINE 3 |
|
217 |
|
#define START_IFNAME 4 |
|
218 |
|
#define IFACE_FOUND 5 |
|
219 |
|
#define RX_BYTES 6 |
|
220 |
|
#define WAIT_RX_PACKETS 7 |
|
221 |
|
#define RX_PACKETS 8 |
|
222 |
|
#define WAIT_RX_ERRORS 9 |
|
223 |
|
#define RX_ERRORS 10 |
|
224 |
|
#define WAIT_RX_DROPS 11 |
|
225 |
|
#define RX_DROPS 12 |
|
226 |
|
#define WAIT_RX_FIFO 13 |
|
227 |
|
#define RX_FIFO 14 |
|
228 |
|
#define WAIT_RX_FRAME 15 |
|
229 |
|
#define RX_FRAME 16 |
|
230 |
|
#define WAIT_RX_COMPRESS 17 |
|
231 |
|
#define RX_COMPRESS 18 |
|
232 |
|
#define WAIT_RX_MULTICAST 19 |
|
233 |
|
#define RX_MULTICAST 20 |
|
234 |
|
#define WAIT_TX_BYTES 21 |
|
235 |
|
#define TX_BYTES 22 |
|
236 |
|
#define WAIT_TX_PACKETS 23 |
|
237 |
|
#define TX_PACKETS 24 |
|
238 |
|
#define WAIT_TX_ERRORS 25 |
|
239 |
|
#define TX_ERRORS 26 |
|
240 |
|
#define WAIT_TX_DROPS 27 |
|
241 |
|
#define TX_DROPS 28 |
|
242 |
|
#define WAIT_TX_FIFO 29 |
|
243 |
|
#define TX_FIFO 30 |
|
244 |
|
#define WAIT_TX_COLLS 31 |
|
245 |
|
#define TX_COLLS 32 |
|
246 |
|
#define WAIT_TX_CARRIER 33 |
|
247 |
|
#define TX_CARRIER 34 |
|
248 |
|
#define WAIT_TX_MULTICAST 35 |
|
249 |
|
#define TX_MULTICAST 36 |
|
|
213 |
|
enum { |
|
214 |
|
START = 1, |
|
215 |
|
SKIP_LINE, |
|
216 |
|
START_LINE, |
|
217 |
|
START_IFNAME, |
|
218 |
|
IFACE_FOUND, |
|
219 |
|
RX_BYTES, |
|
220 |
|
WAIT_RX_PACKETS, RX_PACKETS, |
|
221 |
|
WAIT_RX_ERRORS, RX_ERRORS, |
|
222 |
|
WAIT_RX_DROPS, RX_DROPS, |
|
223 |
|
WAIT_RX_FIFO, RX_FIFO, |
|
224 |
|
WAIT_RX_FRAME, RX_FRAME, |
|
225 |
|
WAIT_RX_COMPRESS, RX_COMPRESS, |
|
226 |
|
WAIT_RX_MULTICAST, RX_MULTICAST, |
|
227 |
|
WAIT_TX_BYTES, TX_BYTES, |
|
228 |
|
WAIT_TX_PACKETS, TX_PACKETS, |
|
229 |
|
WAIT_TX_ERRORS, TX_ERRORS, |
|
230 |
|
WAIT_TX_DROPS, TX_DROPS, |
|
231 |
|
WAIT_TX_FIFO, TX_FIFO, |
|
232 |
|
WAIT_TX_COLLS, TX_COLLS, |
|
233 |
|
WAIT_TX_CARRIER, TX_CARRIER, |
|
234 |
|
WAIT_TX_MULTICAST, TX_MULTICAST, |
|
235 |
|
}; |
250 |
236 |
|
|
251 |
237 |
#define FIRST_DIGIT(val,digit) do {val=digit-'0'; } while(0) |
#define FIRST_DIGIT(val,digit) do {val=digit-'0'; } while(0) |
252 |
238 |
#define NEXT_DIGIT(val,digit) do {val*=10; val+=digit-'0'; } while(0) |
#define NEXT_DIGIT(val,digit) do {val*=10; val+=digit-'0'; } while(0) |
|
... |
... |
struct if_stat *get_stats(char *iface) { |
340 |
326 |
READ_INT(TX_CARRIER,res->out_carrier,WAIT_TX_MULTICAST); |
READ_INT(TX_CARRIER,res->out_carrier,WAIT_TX_MULTICAST); |
341 |
327 |
READ_INT(TX_MULTICAST,res->out_carrier,SKIP_LINE); |
READ_INT(TX_MULTICAST,res->out_carrier,SKIP_LINE); |
342 |
328 |
default: |
default: |
343 |
|
fprintf(stderr,"Mon totomate est po bon!\n"); |
|
|
329 |
|
fprintf(stderr,"Internal state machine error!\n"); |
344 |
330 |
break; |
break; |
345 |
331 |
} |
} |
346 |
332 |
} |
} |
|
... |
... |
void please_do(int ndo, int *todo, char *ifname) { |
392 |
378 |
struct sockaddr *sadr; |
struct sockaddr *sadr; |
393 |
379 |
struct if_stat *stats=NULL; |
struct if_stat *stats=NULL; |
394 |
380 |
if (!ndo) return; |
if (!ndo) return; |
395 |
|
// printf("J'ai %d actions a r�aliser\n",ndo); |
|
|
381 |
|
// printf("I have %d items in my queue.\n",ndo); |
396 |
382 |
for (i=0; i<ndo; i++) { |
for (i=0; i<ndo; i++) { |
397 |
383 |
switch (todo[i]) { |
switch (todo[i]) { |
398 |
384 |
case DO_EXISTS: |
case DO_EXISTS: |
|
... |
... |
void please_do(int ndo, int *todo, char *ifname) { |
553 |
539 |
stats->out_multicast); |
stats->out_multicast); |
554 |
540 |
break; |
break; |
555 |
541 |
default: |
default: |
556 |
|
printf("Je comprends pas ce que je dois faire: %d\n",todo[i]); |
|
|
542 |
|
printf("Unknown command: %d\n",todo[i]); |
557 |
543 |
break; |
break; |
558 |
544 |
} |
} |
559 |
545 |
printf("\n"); |
printf("\n"); |
|
... |
... |
int main(int argc, char *argv[]) { |
649 |
635 |
usage(me); |
usage(me); |
650 |
636 |
return 1; |
return 1; |
651 |
637 |
} |
} |
652 |
|
// printf("Je travaille sur l'interface %s\n",ifname); |
|
|
638 |
|
// printf("Interface %s\n",ifname); |
653 |
639 |
please_do(ndo,todo,ifname); |
please_do(ndo,todo,ifname); |
654 |
640 |
return 0; |
return 0; |
655 |
641 |
} |
} |
File zrun added (mode: 100755) (index 0000000..8e6d159) |
|
1 |
|
#!/usr/bin/perl |
|
2 |
|
|
|
3 |
|
=head1 NAME |
|
4 |
|
|
|
5 |
|
zrun - automatically uncompress arguments to command |
|
6 |
|
|
|
7 |
|
=head1 SYNOPSIS |
|
8 |
|
|
|
9 |
|
zrun command file.gz [...] |
|
10 |
|
|
|
11 |
|
=head1 DESCRIPTION |
|
12 |
|
|
|
13 |
|
Prefixing a shell command with "zrun" causes any compressed files that are |
|
14 |
|
arguments of the command to be transparently uncompressed to temp files |
|
15 |
|
(not pipes) and the uncompressed files fed to the command. |
|
16 |
|
|
|
17 |
|
This is a quick way to run a command that does not itself support |
|
18 |
|
compressed files, without manually uncompressing the files. |
|
19 |
|
|
|
20 |
|
=head1 BUGS |
|
21 |
|
|
|
22 |
|
Modifications to the uncompressed temporary file are not fed back into the |
|
23 |
|
input file, so using this as a quick way to make an editor support |
|
24 |
|
compressed files won't work. |
|
25 |
|
|
|
26 |
|
=head1 AUTHOR |
|
27 |
|
|
|
28 |
|
Copyright 2006 by Chung-chieh Shan <ccshan@post.harvard.edu> |
|
29 |
|
|
|
30 |
|
=cut |
|
31 |
|
|
|
32 |
|
use warnings; |
|
33 |
|
use strict; |
|
34 |
|
use IO::Handle; |
|
35 |
|
use File::Temp qw{tempfile}; |
|
36 |
|
|
|
37 |
|
my $program = shift; |
|
38 |
|
|
|
39 |
|
my @argument; |
|
40 |
|
my %child; |
|
41 |
|
foreach my $argument (@ARGV) { |
|
42 |
|
if ($argument =~ m{^(.*/)?([^/]*)\.(gz|Z|bz2)$}s) { |
|
43 |
|
my $suffix = "-$2"; |
|
44 |
|
my @preprocess = $3 eq "bz2" ? qw(bzip2 -d -c) : qw(gzip -d -c); |
|
45 |
|
|
|
46 |
|
my ($fh, $tmpname) = tempfile(SUFFIX => $suffix, UNLINK => 1) |
|
47 |
|
or die "zrun: cannot create temporary file: $!\n"; |
|
48 |
|
|
|
49 |
|
if (my $child = fork) { |
|
50 |
|
$child{$child} = $argument; |
|
51 |
|
$argument = $tmpname; |
|
52 |
|
} |
|
53 |
|
elsif (defined $child) { |
|
54 |
|
STDOUT->fdopen($fh, "w"); |
|
55 |
|
exec @preprocess, $argument; |
|
56 |
|
} |
|
57 |
|
else { |
|
58 |
|
die "zrun: cannot fork to handle $argument: $!\n"; |
|
59 |
|
} |
|
60 |
|
} |
|
61 |
|
push @argument, $argument; |
|
62 |
|
} |
|
63 |
|
|
|
64 |
|
while (%child and (my $pid = wait) != -1) { |
|
65 |
|
if (defined(my $argument = delete $child{$pid})) { |
|
66 |
|
if ($? & 255) { |
|
67 |
|
die "zrun: preprocessing for $argument terminated abnormally: $?\n"; |
|
68 |
|
} |
|
69 |
|
elsif (my $code = $? >> 8) { |
|
70 |
|
die "zrun: preprocessing for $argument terminated with code $code\n"; |
|
71 |
|
} |
|
72 |
|
} |
|
73 |
|
} |
|
74 |
|
|
|
75 |
|
my $status = system $program ($program, @argument); |
|
76 |
|
if ($status & 255) { |
|
77 |
|
die "zrun: $program terminated abnormally: $?\n"; |
|
78 |
|
} |
|
79 |
|
else { |
|
80 |
|
my $code = $? >> 8; |
|
81 |
|
exit $code; |
|
82 |
|
} |