Net::CDP - Cisco Discovery Protocol (CDP) advertiser/listener
use Net::CDP; # Available network ports @ports = Net::CDP::ports; # Creating a CDP advertiser/listener $cdp = new Net::CDP; # Receiving a CDP packet $packet = $cdp->recv; # Sending a CDP packet $cdp->send($packet); # Other Net::CDP methods $port = $cdp->port; @addresses = $cdp->addresses;
The Net::CDP module implements an advertiser/listener for the Cisco Discovery Protocol.
CDP is a proprietary Cisco protocol for discovering devices on a network. A typical CDP implementation sends periodic CDP packets on every network port. It might also listen for packets for advertisements sent by neighboring devices.
A Net::CDP object represents an advertiser/listener for a single network port. It can send and receive individual CDP packets, each represented by a Net::CDP::Packet object.
To manage multiple ports simultaneously, you might like to take a look at Net::CDP::Manager.
If you are upgrading code from an older version of Net::CDP, please read the "UPGRADING FROM PREVIOUS VERSIONS" section below.
$cdp = new Net::CDP($port) $cdp = new Net::CDP( [ port => $port, ] [ promiscuous => $promiscuous, ] # default = 0 [ enable_recv => $enable_recv, ] # default = 1 [ enable_send => $enable_send, ] # default = 1 );
Returns a new Net::CDP object.
If specified, $port must be the name of the network port that should be used to send and receive packets. If no port is specified, the first port on your system is used (typically, this is the first Ethernet device -- "eth0", for instance).
$port
You can use the "ports" class method to retrieve a list of valid port names.
If $promiscuous is non-zero, then promiscuous mode is enabled on the specified port. Otherwise, Net::CDP attempts to use a multicast ethernet address instead. Multicast addresses may not work with all network drivers.
$promiscuous
By default, $enable_recv and $enable_send are both 1. If either of these are set to 0 the corresponding function is disabled. This saves a small amount of memory and a file descriptor, and might be useful when you do not intend to both send and receive packets. You probably won't want to set both to 0.
$enable_recv
$enable_send
This constructor used to take a single argument, $flags. This is now deprecated. See "UPGRADING FROM PREVIOUS VERSIONS" below.
$flags
@ports = Net::CDP::ports()
Returns a list of network ports that can be used by this module.
$port = $cdp->port()
Returns the network port associated with this Net::CDP object.
@addresses = $cdp->addresses()
Returns the addresses of the network port associated with this Net::CDP object. In scalar context the number of addresses is returned.
NOTE: Currently only a single IPv4 address is returned, even if the port has more than one bound address.
$packet = $cdp->recv( [ nonblock => $nonblock, ] # default = 0 [ decode_errors => $decode_errors, ] # default = 0 )
Returns the next available CDP packet as a Net::CDP::Packet object. If the $nonblock flag is set, an undefined value returned if no packets are immediately available. Otherwise, this method blocks until a packet is received or an error occurs. If an error occurs, this method croaks.
$nonblock
By default, decoding errors will be silently ignored. If $decode_errors is set, this method will croak on a decoding error.
$decode_errors
This method used to take a single argument, $flags. This is now deprecated. See "UPGRADING FROM PREVIOUS VERSIONS" below.
$bytes = $cdp->send($packet)
Transmits the specified packet, which must be a Net::CDP::Packet object, and returns the number of bytes sent. If an error occurs, this method croaks.
Net::CDP version 0.07 introduces the use of named arguments instead of flag bitmaps for the "new" constructor and "recv" method. Furthermore, the :caps and :protos import tags now live in Net::CDP::Packet and Net::CDP::Address respectively.
:caps
:protos
A warning is generated the first time you attempt to use a deprecated feature. Actual support for the old-style flag bitmaps will be removed soon. To upgrade your code you will need to:
Do not import the :general or :recv tags; use named arguments in calls to "new" and "recv" instead.
:general
:recv
Replace use Net::CDP qw(:caps) with use Net::CDP::Packet qw(:caps), and use Net::CDP qw(:protos) with use Net::CDP::Address qw(:protos).
use Net::CDP qw(:caps)
use Net::CDP::Packet qw(:caps)
use Net::CDP qw(:protos)
use Net::CDP::Address qw(:protos)
Net::CDP::Packet
Michael Chapman, <cpan@very.puzzling.org>
Copyright (C) 2005 by Michael Chapman
libcdp is released under the terms and conditions of the GNU Library General Public License version 2. Net::CDP may be redistributed and/or modified under the same terms as Perl itself.
To install Net::CDP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::CDP
CPAN shell
perl -MCPAN -e shell install Net::CDP
For more information on module installation, please visit the detailed CPAN module installation guide.