use Net::ParseRouteTable;
my $table = new Net::ParseRouteTable \%options;
$table->next_row(); $table->eot(); $table->eof();
undef $table; # Destroys RouteTable object
$table = new Net::ParseRouteTable \%options;
Creates a new routing table object, opening the supplied raw data file and seeking to the beginning of the first table of the appropriate type in the file. The parameter must be a hash, and the filename containing the raw data must be stored under the key `filename' in that hash.
The user can optimize performance by disabling parts of the parser that would spend time extracting undesired fields from the raw table. To disable specific field, include a hash under the key `parse' in the options passed to new, e.g.
%{$options{"parse"}} = ( "prefix" => 1, "masklen" => 1, "nexthop" => 1, "aspath" => 1, "status_code" => 1, "origin_code" => 1, "med" => 1, "locprf" => 1, "weight" => 1, );
The keys in this hash correspond to columns in the input data. Set the value under each key to 0 to disable parsing of that field. Note that the parser will sometimes return the values of unrequested fields if extracting those values did not require any extra work.
$table->next_row();
Retrieves the next row from the table, returning a pointer to a hash of the values parsed from that table row. This function returns a pointer to a hash, and each of the parsed values is stored under the column name. For example
$data = $table->next_row(); $nexthop = ${$data}{"nexthop"};
stores the next hop router's address in $nexthop.
$table->eot();
Predicate for determining if the parser has reached the end of the route table. Returns 0 for false and 1 for true.
$table->eof();
Predicate for determining if the parser has reached the end of the input
file. Returns 0 for false and 1 for true. Note that for a normal data file,
eot()
will be true when eof()
is true. Otherwise,
the data file is likely to be incomplete.
%options = ( "handle" => $filehandle, ); $table = new Net::ParseRouteTable \%options;
while ( ! $table->eof() ) { my $data = $table->next_row() || last;
## Do some work on $data
} if ( ! $table->eot() ) { warn "Table did not end with a router prompt. Possible truncated file\n "; }
The MED, local preference, and weight fields are particularly difficult to parse. If you require these fields, be sure to inspect the output of the parser carefully.
This software was produced with support from Packet Clearing House, a nonprofit research institute supporting investigation and operations in the area of Internet traffic exchange and global IP routing economics. The latest release of this package may be downloaded from <http://www.pch.net/software/route_table/Net-ParseRouteTable-Current.tgz>
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.