NAME

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

SYNOPSIS

use Net::CDP qw(:caps :protos);

# Available ports (interfaces)
@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 interface. 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.

CONSTRUCTORS

new
$cdp = new Net::CDP()
$cdp = new Net::CDP($port)

Returns a new Net::CDP object.

If specified, $port must be the name of the network port (interface) that should be used to send and receive packets. If ommitted, the first interface 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.

CLASS METHODS

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

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

OBJECT METHODS

port
$port = $cdp->port()

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

addresses
@addresses = $cdp->addresses()

Returns the addresses of the network port (interface) 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 interface has more than one bound address.

recv
$packet = $cdp->recv()
$packet = $cdp->recv($flags)

Returns the next available CDP packet as a Net::CDP::Packet object. If the CDP_RECV_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.

If specified, $flags is a bitmask specifying one or more of the following constants:

CDP_RECV_NONBLOCK

Do not block if no CDP packets are immediately available.

CDP_RECV_DECODE_ERRORS

Decoding errors will result in recv croaking.

These constants can be exported from Net::CDP using the tag :recv. See Exporter.

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.

SEE ALSO

Net::CDP::Packet

AUTHOR

Michael Chapman, <mike.chapman@optusnet.com.au>

COPYRIGHT AND LICENSE

Copyright (C) 2004 by Michael Chapman

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.