make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / user-tools / header
blob45fb50ce20e23787b5fe025d41b3f231b1c81835
1 #!/usr/bin/env perl
3 =pod
5 =head1 NAME
7 header - Echo the input stream up to the first empty line (usual end-of-header marker)
9 body - Skip everything in the input stream up the the first empty line (usual end-of-header marker) and echo the rest
11 =head1 SYNOPSIS
13 header I<FILE> [I<FILE> [I<FILE> [...]]]
15 header < I<FILE>
17 body I<FILE> [I<FILE> [I<FILE> [...]]]
19 body < I<FILE>
21 =cut
23 $mode = 'header';
24 if($0 =~ /body/)
26 $mode = 'body';
29 if(not @ARGV)
31 push @ARGV, '/dev/stdin';
34 for my $idx (0..$#ARGV)
36 my $path = $ARGV[$idx];
37 open my $fh, '<', $path;
38 my $state = 'header';
39 while(<$fh>)
41 print if $mode eq 'body' and $state eq 'body';
42 $state = 'body' if /^\r?\n?$/;
43 last if $state eq 'body' and $mode eq 'header';
44 print if $mode eq 'header' and $state eq 'header';
46 if($idx < $#ARGV)
48 print "\n";