File Coverage

blib/lib/Net/SOCKS.pm
Criterion Covered Total %
statement 12 14 85.7
branch 0 2 0.0
condition n/a
subroutine 4 5 80.0
pod 0 1 0.0
total 16 22 72.7


line stmt bran cond sub pod time code
1             package Net::SOCKS;
2              
3             # Copyright (c) 1997-1998 Clinton Wong. All rights reserved.
4             # This program is free software; you can redistribute it
5             # and/or modify it under the same terms as Perl itself.
6              
7 1     1   766 use strict;
  1         2  
  1         41  
8 1     1   6 use vars qw($VERSION @ISA @EXPORT);
  1         1  
  1         87  
9 1     1   1151 use IO::Socket;
  1         32609  
  1         5  
10 1     1   612 use Carp;
  1         2  
  1         307  
11              
12             require Exporter;
13             require AutoLoader;
14              
15             @ISA = qw(Exporter AutoLoader);
16             @EXPORT = qw();
17              
18             $VERSION = '0.03';
19              
20             # Status code exporter adapted from HTTP::Status by Gisle Aas.
21             # Please note - users of this module should not use hard coded numbers
22             # in their programs. Always use the SOCKS_ version of
23             # the status code, which are the descriptions below
24             # converted to uppercase and _ replacing dash and SPACE.
25              
26             my %status_code = (
27             1 => "general SOCKS server failure", # SOCKS5
28             2 => "connection not allowed by ruleset",
29             3 => "network unreachable",
30             4 => "host unreachable",
31             5 => "connection refused",
32             6 => "TTL expired",
33             7 => "command not supported",
34             8 => "address type not supported",
35             90 => "okay", # SOCKS4
36             91 => "failed",
37             92 => "no ident",
38             93 => "user mismatch",
39             100 => "incomplete auth", # generic
40             101 => "bad auth",
41             102 => "server denies auth method",
42             202 => "missing SOCKS server net data",
43             203 => "missing peer net data",
44             204 => "SOCKS server unavailable",
45             205 => "timeout",
46             206 => "unsupported protocol version",
47             207 => "unsupported address type",
48             208 => "hostname lookup failure"
49             );
50              
51             my $mnemonic_code = '';
52             my ($code, $message);
53             while (($code, $message) = each %status_code) {
54             # create mnemonic subroutines
55             $message =~ tr/a-z \-/A-Z__/;
56             $mnemonic_code .= "sub SOCKS_$message () { $code }\t";
57             $mnemonic_code .= "push(\@EXPORT, 'SOCKS_$message');\n";
58             }
59             eval $mnemonic_code; # only one eval for speed
60             die if $@;
61              
62             sub status_message {
63 0 0   0 0   return undef unless exists $status_code{ $_[0] };
64 0           $status_code{ $_[0] };
65             }
66              
67             1;
68             __END__