5 # --- Read the network interface to steal ---
9 # --- Start a child if so requested ---
12 socketpair(ONE, TOTHER, PF_UNIX, SOCK_STREAM, 0)
13 or die "socketpair: $!";
15 defined $kid or die "fork: $!";
18 open STDIN, ">&TOTHER" or die "dup stdin: $!";
19 open STDOUT, ">&TOTHER" or die "dup stdout: $!";
25 open STDIN, ">&ONE" or die "dup stdin: $!";
26 open STDOUT, ">&ONE" or die "dup stdout: $!";
30 # --- Now start work on this ---
32 open NETIF, "+> $netif" or die "open($netif): $!";
36 vec($rfd, fileno(STDIN), 1) = 1;
37 vec($rfd, fileno(NETIF), 1) = 1;
38 select($rfd, undef, undef, undef) or die "select: $!";
40 if (vec($rfd, fileno(NETIF), 1)) {
41 sysread(NETIF, $pkt, 65536);
42 $pkt = pack("n", length($pkt)) . $pkt;
43 syswrite(STDOUT, $pkt, length($pkt));
45 if (vec($rfd, fileno(STDIN), 1)) {
46 sysread(STDIN, $clen, 2) or die "tunnel has vanished: $!";
47 $len = unpack("n", $clen);
48 sysread(STDIN, $pkt, $len);
49 syswrite(NETIF, $pkt, length($pkt));