The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::CDP - Cisco Discovery Protocol (CDP) advertiser/listener

SYNOPSIS

  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;

DESCRIPTION

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.

CONSTRUCTORS

new
    $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).

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.

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.

This constructor used to take a single argument, $flags. This is now deprecated. See "UPGRADING FROM PREVIOUS VERSIONS" below.

CLASS METHODS

ports
    @ports = Net::CDP::ports()

Returns a list of network ports that can be used by this module.

OBJECT METHODS

port
    $port = $cdp->port()

Returns the network port associated with this Net::CDP object.

addresses
    @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.

recv
    $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.

By default, decoding errors will be silently ignored. If $decode_errors is set, this method will croak on a decoding error.

This method used to take a single argument, $flags. This is now deprecated. See "UPGRADING FROM PREVIOUS VERSIONS" below.

send
    $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.

UPGRADING FROM PREVIOUS VERSIONS

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.

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.

  • 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).

SEE ALSO

Net::CDP::Packet

AUTHOR

Michael Chapman, <cpan@very.puzzling.org>

COPYRIGHT AND LICENSE

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.