Use correct directory for installation.
[unet] / tests / bidi
1 #! /bin/perl
2
3 open LEFT, "+</dev/unet0" or die "open /dev/unet0: $!";
4 open RIGHT, "+</dev/unet1" or die "open /dev/unet1: $!";
5
6 $rd = 0;
7 vec($rd, fileno(LEFT), 1) = 1;
8 vec($rd, fileno(RIGHT), 1) = 1;
9
10 for (;;) {
11 select($ord = $rd, undef, undef, undef);
12 if (vec($ord, fileno(LEFT), 1)) {
13 defined sysread(LEFT, $buf, 65536) or die "read(/dev/unet0): $!";
14 print "read packet from unet0\n";
15 hexdump($buf);
16 syswrite(RIGHT, $buf, length($buf));
17 }
18 if (vec($ord, fileno(RIGHT), 1)) {
19 defined sysread(RIGHT, $buf, 65536) or die "read(/dev/unet1): $!";
20 print "read packet from unet1\n";
21 hexdump($buf);
22 syswrite(LEFT, $buf, length($buf));
23 }
24 }
25
26 sub hexdump {
27 my $buf = shift;
28 my ($off, $i);
29
30 while ($off < length($buf)) {
31 printf "%08x : ", $off;
32 for ($i = $off; $i < $off + 16; $i++) {
33 if ($i >= length($buf)) {
34 print "** ";
35 } else {
36 printf "%02x ", ord(substr($buf, $i, 1));
37 }
38 }
39 print ": ";
40 for ($i = $off; $i < $off + 16; $i++) {
41 if ($i >= length($buf)) {
42 print "*";
43 } else {
44 $ch = substr($buf, $i, 1);
45 $code = ord($ch);
46 if ($code < 32 || $code > 126) {
47 print ".";
48 } else {
49 print $ch;
50 }
51 }
52 }
53 print "\n";
54 $off += 16;
55 }
56 print "\n";
57 }