Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Contact Us
Online Help
Domain Status
Man Pages

Virtual Servers

Topology Map

Server Agreement
Year 2038

USA Flag



Man Pages

Manual Reference Pages  -  NET::RADIUS::PACKET (3)

.ds Aq ’


Net::Radius::Packet - Object-oriented Perl interface to RADIUS packets



  use Net::Radius::Packet;
  use Net::Radius::Dictionary;

  my $d = new Net::Radius::Dictionary "/etc/radius/dictionary";

  my $p = new Net::Radius::Packet $d, $data;

  if ($p->attr(User-Name eq "lwall") {
    my $resp = new Net::Radius::Packet $d;
    $resp->set_attr(Reply-Message => "Welcome, Larry!\r\n");
    my $respdat = auth_resp($resp->pack, "mysecret");

  die "Packet is a fake response\n" if ($p->code eq Access-Accept
    and not auth_req_verify($data, $secret, $req->authenticator))

  die "Packet is a fake\n" if ($p->code eq Accounting-Request
    and not auth_acct_verify($data, $secret))


RADIUS (RFC2138) specifies a binary packet format which contains various values and attributes. Net::Radius::Packet provides an interface to turn RADIUS packets into Perl data structures and vice-versa.

Net::Radius::Packet does not provide functions for obtaining RADIUS packets from the network. A simple network RADIUS server is provided as an example at the end of this document.


<B>new Net::Radius::Packet B>$dictionary<B>, B>$data<B>B> Returns a new Net::Radius::Packet object. $dictionary is an optional reference to a Net::Radius::Dictionary object. If not supplied, you must call <B>set_dictB>.

If $data is supplied, <B>unpackB> will be called for you to initialize the object.

    Proxy-State, RFC specification

From RFC-2865:

  2. Operation
  If any Proxy-State attributes were present in the Access-Request,
  they MUST be copied unmodified and in order into the response packet.
  Other Attributes can be placed before, after, or even between the
  Proxy-State attributes.
  2.3 Proxy
  The forwarding server MUST treat any Proxy-State attributes already
  in the packet as opaque data.  Its operation MUST NOT depend on the
  content of Proxy-State attributes added by previous servers.
  If there are any Proxy-State attributes in the request received from
  the client, the forwarding server MUST include those Proxy-State
  attributes in its reply to the client.  The forwarding server MAY
  include the Proxy-State attributes in the access-request when it
  forwards the request, or MAY omit them in the forwarded request.  If
  the forwarding server omits the Proxy-State attributes in the
  forwarded access-request, it MUST attach them to the response before
  sending it to the client.

    Proxy-State, Implementation

->pack() and ->dump() now work properly with multiple atributes, in particular the Proxy-State attribute - This means that the packet will be encoded with the multiple attributes present. This change makes Net::Radius::PacketOrdered likely redundant.

->attr() method always return the last attribute inserted.

->set_attr() and ->set_vsattr() methods push either the attribute or the vendor-specific attribute, onto the Attributes stack, or overwrites it in specific circumnstances, as described in method documentation. The ->unset_attr() and ->unset_vsattr() perform the opposite function.


There are actually two families of object methods. The ones described below deal with standard RADIUS attributes. An additional set of methods handle the Vendor-Specific attributes as defined in the RADIUS protocol. Those methods behave in much the same way as the ones below with the exception that the prefix <B>vsB> must be applied before the <B>attrB> in most of the names. The vendor code must also be included as the first parameter of the call.

The <B>vsattrB> and <B>set_vsattrB> methods, used to query and set Vendor-Specific attributes return an array reference with the values of each instance of the particular attribute in the packet. This difference is required to support multiple VSAs with different parameters in the same packet.
<B>->set_dict($dictionary)B> Net::Radius::Packet needs access to a Net::Radius::Dictionary object to do packing and unpacking. set_dict must be called with an appropriate dictionary reference (see Net::Radius::Dictionary) before you can use -><B>packB> or -><B>unpackB>.
<B>->unpack($data)B> Given a raw RADIUS packet $data, unpacks its contents so that they can be retrieved with the other methods (<B>codeB>, <B>attrB>, etc.).
<B>->packB> Returns a raw RADIUS packet suitable for sending to a RADIUS client or server.
<B>->codeB> Returns the Code field as a string. As of this writing, the following codes are defined:


<B>->set_code($code)B> Sets the Code field to the string supplied.
<B>->B>identifier()<B>B> Returns the one-byte Identifier used to match requests with responses, as a character value.
<B>->set_identifier($id)B> Sets the Identifier byte to the character supplied.
<B>->B>authenticator()<B>B> Returns the 16-byte Authenticator field as a character string.
<B>->set_authenticator($authenticator)B> Sets the Authenticator field to the character string supplied.
<B>->attr($name)B> Retrieves the value of the named Attribute. Attributes will be converted automatically based on their dictionary type:

        STRING     Returned as a string.
        INTEGER    Returned as a Perl integer.
        IPADDR     Returned as a string (a.b.c.d)
        TIME       Returned as an integer

The following types are simply mapped to other types until correct encoding is implemented:
<B>ipv6addrB> Treated as a string
<B>dateB> Treated as a string
<B>ifidB> Treated as a string

When multiple attributes are inserted in the packet, the last one is returned.

<B>->set_attr($name, B>$val<B>, B>$rewrite_flag<B>)B> Sets the named Attributes to the given value. Values should be supplied as they would be returned from the <B>attrB> method. If rewrite_flag is set, and a single attribute with such name already exists on the Attributes stack, its value will be overwriten with the supplied one. In all other cases (if there are more than one attributes with such name already on the stack, there are no attributes with such name, rewrite_flag is omitted) name/pair array will be pushed onto the stack.
<B>->set_vsattr($vendor, B>$name<B>, B>$val<B>, B>$rewrite_flag<B>)B> Analogous to ->set_attr(), but operates on vendor-specific attributes for vendor $vendor.
<B>->unset_attr($name)B> Sets the named Attribute to the given value. Values should be supplied as they would be returned from the <B>attrB> method.
<B>->unset_vsattr($vendor, B>$name<B>)B> Analogous to ->unset_attr(), but operates on vendor-specific attributes for vendor $vendor.
<B>->attr_slot($integer)B> Deprecated synonym for ->attr_slot_val().
<B>->B>attr_slots()<B>B> Return the number of attribute slots in the packet.
<B>->attr_slot_name($integer)B> Retrieves the attribute name of the given slot number from the Attributes stack. Returns undef when the slot is vacant.
<B>->attr_slot_val($integer)B> Retrieves the attribute value of the given slot number from the Attributes stack. Returns undef when the slot is vacant.
<B>->B>unset_attr_slot<B>($integer)B> Removes given stack position from the Attributes stack.
<B>->password($secret, [$attr])B> The RADIUS User-Password attribute is encoded with a shared secret. Use this method to return the decoded version. By default, the password will be looked for in the User-Password attribute. You can specify an alternate RADIUS attribute, by using the second argument.
<B>->set_password($passwd, B>$secret<B>, [$attribute])B> The RADIUS User-Password attribute is encoded with a shared secret. Use this method to prepare the encoded version. The encoded password will be stored in the attribute $attribute, which defaults to ’User-Password’.

Some servers have been reported on insisting on this attribute to be ’Password’ instead. You may have to tweak this call or the dictionary accordingly.

<B>->B>dump()<B>B> Prints the content of the packet to STDOUT.
<B>->show_unknown_entries($bool)B> Controls the generation of a warn() whenever an unknown tuple is seen.


<B>auth_resp($packed_packet, B>$secret<B> [, accounting])B> Given a (packed) RADIUS packet and a shared secret, returns a new packet with the Authenticator field changed in accordace with RADIUS protocol requirements.

If the third optional parameter is true, the Authenticator is encoded for an accounting packet, using 16 0x0 octets as the placeholder for the authenticator.

<B>auth_acct_verify($packet, B>$secret<B>)B> Verifies the authenticator in an <B>Accounting-RequestB> packet as explained in RFC-2866. Returns 1 if the authenticator matches the packet and the secret, undef otherwise.

$packet is the packet data, as received. $secret is the corresponding shared secret.

<B>auth_req_verify($packet, B>$secret<B>, B>$prev_auth<B>)B> Verifies the authenticator in <B>Access-AcceptB>, <B>Access-RejectB>, and <B>Access-ChallengeB> packets as explained in RFC-2865. Returns 1 if the authenticator matches the packet and the secret, undef otherwise.

$packet is the packet data, as received. $secret is the corresponding shared secret. $prev_auth is the authenticator taken from the corresponding <B>Access-AcceptB> packet.

It’s the application’s job to keep track of the authenticators in each request.


See the examples included in the <B>examples/B> directory of the distribution. Also see Net::Radius::Server(3) for a more complete implementation of a RADIUS server.


Christopher Masto, <>. VSA support by Luis E. Munõz, <>. Fix for unpacking 3COM VSAs contributed by Ian Smith <>. Information for packing of 3Com VSAs provided by Quan Choi <>. Some functions contributed by Tony Mountifield <>. Attribute ordering provided by Toni Prug, <>, idea by Bill Hulley.


Perl, Net::Radius::Server(3), Net::Radius::Dictionary(3), RFCs 2865, 2866, 2882 and 3575.


Hey! <B>The above document had some coding errors, which are explained below:B>
Around line 1002: Non-ASCII character seen before =encoding in ’Munõz,’. Assuming UTF-8
Search for    or go to Top of page |  Section 3 |  Main Index

perl v5.20.3 RADIUS::PACKET (3) 2009-09-11

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.