Kea: Pkt4 Class Reference

| Kea 3.2.0-git

Pkt4 Class Reference

Represents DHCPv4 packet. More...

`#include <pkt4.h>`

Inheritance diagram for Pkt4:
[legend]

## Public Member Functions
| Pkt4 (const uint8_t *data, size_t len)
| Constructor, used in message reception.
| Pkt4 (uint8_t msg_type, uint32_t transid)
| Constructor, used in replying to a message.
virtual void | addOption (const OptionPtr &opt)
| Add an option.
const isc::asiolink::IOAddress & | getCiaddr () const
| Returns ciaddr field.
std::list< uint16_t > & | getDeferredOptions ()
| Returns a reference to option codes which unpacking will be deferred.
const OptionBuffer | getFile () const
| Returns file field.
uint16_t | getFlags () const
| Returns flags field.
const isc::asiolink::IOAddress & | getGiaddr () const
| Returns giaddr field.
uint8_t | getHlen () const
| Returns hlen field.
uint8_t | getHops () const
| Returns hops field.
uint8_t | getHtype () const
| Returns htype field.
HWAddrPtr | getHWAddr () const
| returns hardware address information
std::string | getHWAddrLabel () const
| Returns text representation of the hardware address.
std::string | getLabel () const
| Returns text representation of the primary packet identifiers.
HWAddrPtr | getLocalHWAddr () const
| Returns local HW address.
const char * | getName () const
| Returns name of the DHCP message.
uint8_t | getOp () const
| Returns op field.
uint16_t | getSecs () const
| Returns secs field.
const isc::asiolink::IOAddress & | getSiaddr () const
| Returns siaddr field.
const OptionBuffer | getSname () const
| Returns sname field.
uint8_t | getType () const
| Returns DHCP message type (e.g.
const isc::asiolink::IOAddress & | getYiaddr () const
| Returns yiaddr field.
virtual bool | isDhcp4o6 () const
| Checks if a DHCPv4 message has been transported over DHCPv6.
bool | isRelayed () const
| Checks if a DHCPv4 message has been relayed.
size_t | len ()
| Returns the size of the required buffer to build the packet.
virtual void | pack ()
| Prepares on-wire format of DHCPv4 packet.
void | setCiaddr (const isc::asiolink::IOAddress &ciaddr)
| Sets ciaddr field.
void | setFile (const uint8_t *file, size_t file_len)
| Sets file field.
void | setFlags (uint16_t flags)
| Sets flags field.
void | setGiaddr (const isc::asiolink::IOAddress &giaddr)
| Sets giaddr field.
void | setHops (uint8_t hops)
| Sets hops field.
void | setHWAddr (const HWAddrPtr &addr)
| Sets hardware address.
void | setHWAddr (uint8_t htype, uint8_t hlen, const std::vector< uint8_t > &mac_addr)
| Sets hardware address.
void | setLocalHWAddr (const HWAddrPtr &addr)
| Sets local HW address.
void | setLocalHWAddr (const uint8_t htype, const uint8_t hlen, const std::vector< uint8_t > &mac_addr)
| Sets local HW address.
void | setSecs (uint16_t secs)
| Sets secs field.
void | setSiaddr (const isc::asiolink::IOAddress &siaddr)
| Sets siaddr field.
void | setSname (const uint8_t *sname, size_t sname_len)
| Sets sname field.
void | setType (uint8_t type)
| Sets DHCP message type (e.g.
void | setYiaddr (const isc::asiolink::IOAddress &yiaddr)
| Sets yiaddr field.
std::string | toText (bool verbose=false) const
| Returns text representation of the packet.
virtual void | unpack ()
| Parses on-wire form of DHCPv4 packet.
Public Member Functions inherited from isc::dhcp::Pkt
virtual | ~Pkt ()
| Virtual destructor.
void | addAdditionalClass (const isc::dhcp::ClientClass &client_class)
| Adds a specified class to the packet's additional class list.
void | addClass (const isc::dhcp::ClientClass &client_class)
| Adds a specified class to the packet.
void | addPktEvent (const std::string &label, const boost::posix_time::ptime &timestamp=PktEvent::now())
| Adds an event to the end of the event stack.
void | addPktEvent (const std::string &label, const struct timeval &timestamp)
| Adds an event to the end of the event stack with the timestamp specified as a struct timeval.
void | addSubClass (const isc::dhcp::ClientClass &class_def, const isc::dhcp::ClientClass &subclass)
| Adds a specified subclass to the packet.
void | clearPktEvents ()
| Discards contents of the packet event stack.
OptionCollection | cloneOptions ()
| Clones all options so that they can be safely modified.
bool | delOption (uint16_t type)
| Attempts to delete first suboption of requested type.
std::string | dumpPktEvents (bool verbose=false) const
| Creates a dump of the stack contents to a string for logging.
const ClientClasses & | getAdditionalClasses () const
| Returns the additional class list.
isc::util::OutputBuffer & | getBuffer ()
| Returns reference to output buffer.
const ClientClasses & | getClasses () const
| Returns the class set.
std::string | getIface () const
| Returns interface name.
int | getIndex () const
| Returns interface index.
const isc::asiolink::IOAddress & | getLocalAddr () const
| Returns local IP address.
uint16_t | getLocalPort () const
| Returns local UDP (and soon TCP) port.
HWAddrPtr | getMAC (uint32_t hw_addr_src)
| Returns MAC address.
OptionPtr | getOption (const uint16_t type)
| Returns the first option of specified type.
isc::dhcp::OptionCollection | getOptions (const uint16_t type)
| Returns all instances of specified type.
const std::list< PktEvent > & | getPktEvents ()
| Fetches the current event stack contents.
boost::posix_time::ptime | getPktEventTime (const std::string &label) const
| Fetches the timestamp for a given event in the stack.
const isc::asiolink::IOAddress & | getRemoteAddr () const
| Returns remote IP address.
HWAddrPtr | getRemoteHWAddr () const
| Returns the remote HW address obtained from raw sockets.
uint16_t | getRemotePort () const
| Returns remote port.
const SubClassRelationContainer & | getSubClassesRelations () const
| Returns the class set including template classes associated with subclasses.
const boost::posix_time::ptime & | getTimestamp () const
| Returns packet timestamp.
uint32_t | getTransid () const
| Returns value of transaction-id field.
bool | inClass (const isc::dhcp::ClientClass &client_class)
| Checks whether a client belongs to a given class.
bool | indexSet () const
| Checks if interface index has been set.
bool | isCopyRetrievedOptions () const
| Returns whether the copying of retrieved options is enabled.
void | repack ()
| Copies content of input buffer to output buffer.
void | resetIndex ()
| Resets interface index to negative value.
virtual void | setCopyRetrievedOptions (const bool copy)
| Controls whether the option retrieved by the Pkt::getOption should be copied before being returned.
void | setIface (const std::string &iface)
| Sets interface name.
void | setIndex (const unsigned int ifindex)
| Sets interface index.
void | setLocalAddr (const isc::asiolink::IOAddress &local)
| Sets local IP address.
void | setLocalPort (uint16_t local)
| Sets local UDP (and soon TCP) port.
void | setPktEvent (const std::string &label, const boost::posix_time::ptime &timestamp=PktEvent::now())
| Updates (or adds) an event in the event stack.
void | setRemoteAddr (const isc::asiolink::IOAddress &remote)
| Sets remote IP address.
void | setRemoteHWAddr (const HWAddrPtr &hw_addr)
| Sets remote hardware address.
void | setRemoteHWAddr (const uint8_t htype, const uint8_t hlen, const std::vector< uint8_t > &hw_addr)
| Sets remote hardware address.
void | setRemotePort (uint16_t remote)
| Sets remote UDP (and soon TCP) port.
void | setTimestamp (boost::posix_time::ptime &timestamp)
| Set socket receive timestamp.
void | setTransid (uint32_t transid)
| Sets transaction-id value.
void | updateTimestamp ()
| Update packet timestamp.
Public Member Functions inherited from isc::hooks::CalloutHandleAssociate
| CalloutHandleAssociate ()
| Constructor.
CalloutHandlePtr | getCalloutHandle ()
| Returns callout handle.
void | resetCalloutHandle ()
| Reset callout handle.

## Static Public Member Functions
static const char * | getName (const uint8_t type)
| Returns name of the DHCP message for a given type number.
static std::string | makeLabel (const HWAddrPtr &hwaddr, const ClientIdPtr &client_id)
| Returns text representation of the given packet identifiers.
static std::string | makeLabel (const HWAddrPtr &hwaddr, const ClientIdPtr &client_id, const uint32_t transid)
| Returns text representation of the given packet identifiers.

## Static Public Attributes
static const size_t | DHCPV4_PKT_HDR_LEN = 236
| specifies DHCPv4 packet header length (fixed part)
static const uint16_t | FLAG_BROADCAST_MASK = 0x8000
| Mask for the value of flags field in the DHCPv4 message to check whether client requested broadcast response.
static const size_t | MAX_CHADDR_LEN = 16
| length of the CHADDR field in DHCPv4 message
static const size_t | MAX_FILE_LEN = 128
| length of the FILE field in DHCPv4 message
static const size_t | MAX_SNAME_LEN = 64
| length of the SNAME field in DHCPv4 message

## Protected Member Functions
uint8_t | DHCPTypeToBootpType (uint8_t dhcpType)
| converts DHCP message type to BOOTP op type
virtual HWAddrPtr | getMACFromDocsisCMTS ()
| No-op.
virtual HWAddrPtr | getMACFromDocsisModem ()
| No-op.
virtual HWAddrPtr | getMACFromDUID ()
| No-op.
virtual HWAddrPtr | getMACFromIPv6RelayOpt ()
| No-op.
virtual HWAddrPtr | getMACFromRemoteIdRelayOption ()
| No-op.
virtual HWAddrPtr | getMACFromSrcLinkLocalAddr ()
| No-op.
Protected Member Functions inherited from isc::dhcp::Pkt
| Pkt (const uint8_t *buf, uint32_t len, const isc::asiolink::IOAddress &local_addr, const isc::asiolink::IOAddress &remote_addr, uint16_t local_port, uint16_t remote_port)
| Constructor.
| Pkt (uint32_t transid, const isc::asiolink::IOAddress &local_addr, const isc::asiolink::IOAddress &remote_addr, uint16_t local_port, uint16_t remote_port)
| Constructor.
HWAddrPtr | getMACFromIPv6 (const isc::asiolink::IOAddress &addr)
| Attempts to convert IPv6 address into MAC.
OptionPtr | getNonCopiedOption (const uint16_t type) const
| Returns the first option of specified type without copying.
OptionCollection | getNonCopiedOptions (const uint16_t opt_type) const
| Returns all option instances of specified type without copying.

## Protected Attributes
isc::asiolink::IOAddress | ciaddr_
| ciaddr field (32 bits): Client's IP address
std::list< uint16_t > | deferred_options_
| List of deferred option codes.
uint8_t | file_ [MAX_FILE_LEN]
| file field (128 bytes)
uint16_t | flags_
| flags
isc::asiolink::IOAddress | giaddr_
| giaddr field (32 bits): Gateway IP address
uint8_t | hops_
| Number of relay agents traversed.
HWAddrPtr | hwaddr_
| link-layer address and hardware information represents 3 fields: htype (hardware type, 1 byte), hlen (length of the hardware address, up to 16) and chaddr (hardware address field, 16 bytes)
HWAddrPtr | local_hwaddr_
| local HW address (dst if receiving packet, src if sending packet)
uint8_t | op_
| message operation code
uint16_t | secs_
| elapsed (number of seconds since beginning of transmission)
isc::asiolink::IOAddress | siaddr_
| siaddr field (32 bits): next server IP address in boot process(e.g.TFTP)
uint8_t | sname_ [MAX_SNAME_LEN]
| sname field (64 bytes)
isc::asiolink::IOAddress | yiaddr_
| yiaddr field (32 bits): Client's IP address ("your"), set by server
Protected Attributes inherited from isc::dhcp::Pkt
isc::util::OutputBuffer | buffer_out_
| Output buffer (used during message transmission).
bool | copy_retrieved_options_
| Indicates if a copy of the retrieved option should be returned when Pkt::getOption is called.
std::string | iface_
| Name of the network interface the packet was received/to be sent over.
unsigned int | ifindex_
| Interface index.
isc::asiolink::IOAddress | local_addr_
| Local IP (v4 or v6) address.
uint16_t | local_port_
| local TDP or UDP port
isc::asiolink::IOAddress | remote_addr_
| Remote IP address.
HWAddrPtr | remote_hwaddr_
uint16_t | remote_port_
| remote TCP or UDP port
boost::posix_time::ptime | timestamp_
| packet timestamp
uint32_t | transid_
| Transaction-id (32 bits for v4, 24 bits for v6).
Protected Attributes inherited from isc::hooks::CalloutHandleAssociate
CalloutHandlePtr | callout_handle_
| Callout handle stored.

## Additional Inherited Members
Public Attributes inherited from isc::dhcp::Pkt
ClientClasses | additional_classes_
| Classes to be evaluated during additional class evaluation.
ClientClasses | classes_
| Classes this packet belongs to.
OptionBuffer | data_
| Unparsed data (in received packets).
isc::dhcp::OptionCollection | options_
| Collection of options present in this message.
SubClassRelationContainer | subclasses_
| SubClasses this packet belongs to.

## Detailed Description

Represents DHCPv4 packet.

This class represents a single DHCPv4 packet. It handles both incoming and transmitted packets, parsing incoming options, options handling (add, get, remove), on-wire assembly, sanity checks and other operations. This specific class has several DHCPv4-specific methods, but it uses a lot of common operations from its base `Pkt` class that is shared with Pkt6.

Definition at line 37 of file pkt4.h.

## Constructor & Destructor Documentation

## ◆ Pkt4() [1/2]

isc::dhcp::Pkt4::Pkt4 | ( | uint8_t | msg_type,
|  | uint32_t | transid )

Constructor, used in replying to a message.

Parameters

  msg_type | type of message (e.g. DHCPDISCOVER=1)
  transid | transaction-id

Definition at line 34 of file pkt4.cc.

## ◆ Pkt4() [2/2]

isc::dhcp::Pkt4::Pkt4 | ( | const uint8_t * | data,
|  | size_t | len )

Constructor, used in message reception.

Creates new message. Pkt4 will copy data to bufferIn_ buffer on creation.

Parameters

  data | pointer to received data
  len | size of buffer to be allocated for this packet.

Definition at line 45 of file pkt4.cc.

## Member Function Documentation

## ◆ addOption()

void isc::dhcp::Pkt4::addOption | ( | const OptionPtr & | opt | ) |
| virtual

Add an option.

Note
  : to avoid throwing when adding multiple options with the same type use isc::dhcp::Pkt::addOption.

Exceptions

  BadValue | if option with that type is already present.

Parameters

  opt | option to be added

Reimplemented from isc::dhcp::Pkt.

Definition at line 621 of file pkt4.cc.

## ◆ DHCPTypeToBootpType()

uint8_t isc::dhcp::Pkt4::DHCPTypeToBootpType | ( | uint8_t | dhcpType | ) |
| protected

converts DHCP message type to BOOTP op type

Parameters

  dhcpType | DHCP message type (e.g. DHCPDISCOVER)

Returns
  BOOTP type (BOOTREQUEST or BOOTREPLY)

Definition at line 577 of file pkt4.cc.

## ◆ getCiaddr()

const isc::asiolink::IOAddress & isc::dhcp::Pkt4::getCiaddr | ( |  | ) | const
| inline

Returns ciaddr field.

Returns
  ciaddr field

Definition at line 183 of file pkt4.h.

## ◆ getDeferredOptions()

std::list< uint16_t > & isc::dhcp::Pkt4::getDeferredOptions | ( |  | ) |
| inline

Returns a reference to option codes which unpacking will be deferred.

Only options 43 and 224-254 are subject of deferred unpacking: when the packet unpacking is performed, each time such an option is found, it is unpacked as an unknown option and the code added in this list.

Returns
  List of codes of options which unpacking is deferred.

Definition at line 386 of file pkt4.h.

## ◆ getFile()

const OptionBuffer isc::dhcp::Pkt4::getFile | ( |  | ) | const
| inline

Returns file field.

Note: This is 128 bytes long field. It doesn't have to be null-terminated. Do not use strlen() or similar on it.

Returns
  pointer to file field

Definition at line 281 of file pkt4.h.

## ◆ getFlags()

uint16_t isc::dhcp::Pkt4::getFlags | ( |  | ) | const
| inline

Returns flags field.

Returns
  flags field

Definition at line 177 of file pkt4.h.

## ◆ getGiaddr()

const isc::asiolink::IOAddress & isc::dhcp::Pkt4::getGiaddr | ( |  | ) | const
| inline

Returns giaddr field.

Returns
  giaddr field

Definition at line 219 of file pkt4.h.

## ◆ getHlen()

uint8_t isc::dhcp::Pkt4::getHlen | ( |  | ) | const

Returns hlen field.

Returns
  hardware address length

Definition at line 612 of file pkt4.cc.

## ◆ getHops()

uint8_t isc::dhcp::Pkt4::getHops | ( |  | ) | const
| inline

Returns hops field.

Returns
  hops field

Definition at line 149 of file pkt4.h.

## ◆ getHtype()

uint8_t isc::dhcp::Pkt4::getHtype | ( |  | ) | const

Returns htype field.

Returns
  hardware type

Definition at line 604 of file pkt4.cc.

## ◆ getHWAddr()

HWAddrPtr isc::dhcp::Pkt4::getHWAddr | ( |  | ) | const
| inline

returns hardware address information

Returns
  hardware address structure

Definition at line 325 of file pkt4.h.

## ◆ getHWAddrLabel()

std::string isc::dhcp::Pkt4::getHWAddrLabel | ( |  | ) | const

Returns text representation of the hardware address.

Returns text representation of the hardware address (e.g. hwaddr=00:01:02:03:04:05). If there is no defined hardware address, it returns `hwaddr=`(undefined).

Returns
  string with text representation

Definition at line 637 of file pkt4.cc.

## ◆ getLabel()

std::string isc::dhcp::Pkt4::getLabel | ( |  | ) | const
| virtual

Returns text representation of the primary packet identifiers.

This method is intended to be used to provide a consistent way to identify packets within log statements. It is an instance-level wrapper around static makeLabel(). See this method for string content.

This method is exception safe.

Returns
  string with text representation

Todo
  If and when client id is extracted into Pkt4, this method should use the instance member rather than fetch it every time.

Reimplemented from isc::dhcp::Pkt.

Definition at line 367 of file pkt4.cc.

## ◆ getLocalHWAddr()

HWAddrPtr isc::dhcp::Pkt4::getLocalHWAddr | ( |  | ) | const
| inline

Returns local HW address.

Returns
  local HW addr.

Definition at line 373 of file pkt4.h.

## ◆ getMACFromDocsisCMTS()

virtual HWAddrPtr isc::dhcp::Pkt4::getMACFromDocsisCMTS | ( |  | ) |
| inlineprotectedvirtual

No-op.

This is a DHCPv4 version of the function that attempts to extract MAC address from the options inserted by a CMTS. It is currently not implemented for v4.

Returns
  always NULL

Implements isc::dhcp::Pkt.

Definition at line 490 of file pkt4.h.

## ◆ getMACFromDocsisModem()

virtual HWAddrPtr isc::dhcp::Pkt4::getMACFromDocsisModem | ( |  | ) |
| inlineprotectedvirtual

No-op.

This is a DHCPv4 version of the function that attempts to extract MAC address from the options inserted by a cable modem. It is currently not implemented for v4.

Returns
  always NULL

Implements isc::dhcp::Pkt.

Definition at line 468 of file pkt4.h.

## ◆ getMACFromDUID()

virtual HWAddrPtr isc::dhcp::Pkt4::getMACFromDUID | ( |  | ) |
| inlineprotectedvirtual

No-op.

This method returns hardware address extracted from DUID. Currently it is a no-op, even though there's RFC that defines how to use DUID in DHCPv4 (see RFC4361). We may implement it one day.

Returns
  always NULL

Implements isc::dhcp::Pkt.

Definition at line 479 of file pkt4.h.

## ◆ getMACFromIPv6RelayOpt()

virtual HWAddrPtr isc::dhcp::Pkt4::getMACFromIPv6RelayOpt | ( |  | ) |
| inlineprotectedvirtual

No-op.

This method returns hardware address extracted from an IPv6 relay agent. option. As there is no IPv4-equivalent, it always returns NULL. We need this stub implementation here, to keep all the get hardware address logic in the base class.

Returns
  always NULL

Implements isc::dhcp::Pkt.

Definition at line 457 of file pkt4.h.

## ◆ getMACFromRemoteIdRelayOption()

virtual HWAddrPtr isc::dhcp::Pkt4::getMACFromRemoteIdRelayOption | ( |  | ) |
| inlineprotectedvirtual

No-op.

This method returns hardware address extracted from remote-id relay option. Currently it is a no-op, it always returns NULL.

Returns
  always NULL

Implements isc::dhcp::Pkt.

Definition at line 500 of file pkt4.h.

## ◆ getMACFromSrcLinkLocalAddr()

virtual HWAddrPtr isc::dhcp::Pkt4::getMACFromSrcLinkLocalAddr | ( |  | ) |
| inlineprotectedvirtual

No-op.

This method returns hardware address generated from the IPv6 link-local address. As there is no IPv4-equivalent, it always returns NULL. We need this stub implementation here, to keep all the get hardware address logic in the base class.

Returns
  always NULL

Implements isc::dhcp::Pkt.

Definition at line 445 of file pkt4.h.

## ◆ getName() [1/2]

const char * isc::dhcp::Pkt4::getName | ( |  | ) | const
| virtual

Returns name of the DHCP message.

Returns
  Pointer to the "const" string containing DHCP message name. If the message type is unsupported the "UNKNOWN" is returned. The caller must not release the returned pointer.

Implements isc::dhcp::Pkt.

Definition at line 359 of file pkt4.cc.

## ◆ getName() [2/2]

const char * isc::dhcp::Pkt4::getName | ( | const uint8_t | type | ) |
| static

Returns name of the DHCP message for a given type number.

This method is exception safe. For messages without DHCP Message Type options, it returns UNKNOWN.

Parameters

  type | DHCPv4 message type which name should be returned.

Returns
  Pointer to the "const" string containing DHCP message name. If the message type is unsupported the "UNKNOWN" is returned. The caller must not release the returned pointer.

Definition at line 284 of file pkt4.cc.

## ◆ getOp()

uint8_t isc::dhcp::Pkt4::getOp | ( |  | ) | const
| inline

Returns op field.

Returns
  op field

Definition at line 157 of file pkt4.h.

## ◆ getSecs()

uint16_t isc::dhcp::Pkt4::getSecs | ( |  | ) | const
| inline

Returns secs field.

Returns
  secs field

Definition at line 167 of file pkt4.h.

## ◆ getSiaddr()

const isc::asiolink::IOAddress & isc::dhcp::Pkt4::getSiaddr | ( |  | ) | const
| inline

Returns siaddr field.

Returns
  siaddr field

Definition at line 195 of file pkt4.h.

## ◆ getSname()

const OptionBuffer isc::dhcp::Pkt4::getSname | ( |  | ) | const
| inline

Returns sname field.

Note: This is 64 bytes long field. It doesn't have to be null-terminated. Do not use strlen() or similar on it.

Returns
  sname field

Definition at line 266 of file pkt4.h.

## ◆ getType()

uint8_t isc::dhcp::Pkt4::getType | ( |  | ) | const
| virtual

Returns DHCP message type (e.g.

1 = DHCPDISCOVER).

This method is exception safe. For packets without DHCP Message Type option, it returns DHCP_NOTYPE (0).

Returns
  message type

Implements isc::dhcp::Pkt.

Definition at line 236 of file pkt4.cc.

## ◆ getYiaddr()

const isc::asiolink::IOAddress & isc::dhcp::Pkt4::getYiaddr | ( |  | ) | const
| inline

Returns yiaddr field.

Returns
  yiaddr field

Definition at line 207 of file pkt4.h.

## ◆ isDhcp4o6()

virtual bool isc::dhcp::Pkt4::isDhcp4o6 | ( |  | ) | const
| inlinevirtual

Checks if a DHCPv4 message has been transported over DHCPv6.

Returns
  Boolean value which indicates whether the message is transported over DHCPv6 (true) or native DHCPv4 (false)

Definition at line 406 of file pkt4.h.

## ◆ isRelayed()

bool isc::dhcp::Pkt4::isRelayed | ( |  | ) | const

Checks if a DHCPv4 message has been relayed.

This function returns a boolean value which indicates whether a DHCPv4 message has been relayed (if true is returned) or not (if false).

The message is considered relayed if the giaddr field is non-zero and non-broadcast.

Returns
  Boolean value which indicates whether the message is relayed (true) or non-relayed (false).

Definition at line 632 of file pkt4.cc.

## ◆ len()

size_t isc::dhcp::Pkt4::len | ( |  | ) |
| virtual

Returns the size of the required buffer to build the packet.

Returns the size of the required buffer to build the packet with the current set of packet options.

Returns
  number of bytes required to build this packet

Implements isc::dhcp::Pkt.

Definition at line 61 of file pkt4.cc.

## ◆ makeLabel() [1/2]

std::string isc::dhcp::Pkt4::makeLabel | ( | const HWAddrPtr & | hwaddr,
|  | const ClientIdPtr & | client_id )
| static

Returns text representation of the given packet identifiers.

This variant of the method does not include transaction id.

Parameters

  hwaddr | hardware address to include in the string, it may be NULL.
  client_id | client id to include in the string, it may be NULL.

Definition at line 412 of file pkt4.cc.

## ◆ makeLabel() [2/2]

std::string isc::dhcp::Pkt4::makeLabel | ( | const HWAddrPtr & | hwaddr,
|  | const ClientIdPtr & | client_id,
|  | const uint32_t | transid )
| static

Returns text representation of the given packet identifiers.

Parameters

  hwaddr | - hardware address to include in the string, it may be NULL.
  client_id | - client id to include in the string, it may be NULL. to include in the string
  transid | - numeric transaction id to include in the string

Returns
  string with text representation

Definition at line 399 of file pkt4.cc.

## ◆ pack()

void isc::dhcp::Pkt4::pack | ( |  | ) |
| virtual

Prepares on-wire format of DHCPv4 packet.

Prepares on-wire format of message and all its options. Options must be stored in options_ field. Output buffer will be stored in buffer_out_. The buffer_out_ is cleared before writing to the buffer.

Exceptions

  InvalidOperation | if packing fails

Create a ManagedScopedOptionsCopyContainer to handle storing and restoration of copied options.

Implements isc::dhcp::Pkt.

Definition at line 73 of file pkt4.cc.

## ◆ setCiaddr()

void isc::dhcp::Pkt4::setCiaddr | ( | const isc::asiolink::IOAddress & | ciaddr | ) |
| inline

Sets ciaddr field.

Parameters

  ciaddr | value to be set

Definition at line 189 of file pkt4.h.

## ◆ setFile()

void isc::dhcp::Pkt4::setFile | ( | const uint8_t * | file,
|  | size_t | file_len )

Sets file field.

Parameters

  file | value to be set
  file_len | length of the file buffer (up to MAX_FILE_LEN)

Definition at line 558 of file pkt4.cc.

## ◆ setFlags()

void isc::dhcp::Pkt4::setFlags | ( | uint16_t | flags | ) |
| inline

Sets flags field.

Parameters

  flags | value to be set

Definition at line 172 of file pkt4.h.

## ◆ setGiaddr()

void isc::dhcp::Pkt4::setGiaddr | ( | const isc::asiolink::IOAddress & | giaddr | ) |
| inline

Sets giaddr field.

Parameters

  giaddr | value to be set

Definition at line 225 of file pkt4.h.

## ◆ setHops()

void isc::dhcp::Pkt4::setHops | ( | uint8_t | hops | ) |
| inline

Sets hops field.

Parameters

  hops | value to be set

Definition at line 144 of file pkt4.h.

## ◆ setHWAddr() [1/2]

void isc::dhcp::Pkt4::setHWAddr | ( | const HWAddrPtr & | addr | ) |

Sets hardware address.

Sets hardware address, based on existing HWAddr structure

Parameters

  addr | already filled in HWAddr structure

Exceptions

  BadValue | if addr is null

Definition at line 496 of file pkt4.cc.

## ◆ setHWAddr() [2/2]

void isc::dhcp::Pkt4::setHWAddr | ( | uint8_t | htype,
|  | uint8_t | hlen,
|  | const std::vector< uint8_t > & | mac_addr )

Sets hardware address.

Sets parameters of hardware address. hlen specifies length of mac_addr buffer. Content of mac_addr buffer will be copied to appropriate field.

Note: mac_addr must be a buffer of at least hlen bytes.

Parameters

  htype | hardware type (will be sent in htype field)
  hlen | hardware length (will be sent in hlen field)
  mac_addr | pointer to hardware address

Definition at line 490 of file pkt4.cc.

## ◆ setLocalHWAddr() [1/2]

void isc::dhcp::Pkt4::setLocalHWAddr | ( | const HWAddrPtr & | addr | ) |

Sets local HW address.

Sets hardware address from an existing HWAddr structure. The local address is a source address for outgoing packet and destination address for incoming packet.

Parameters

  addr | structure representing HW address.

Exceptions

  BadValue | if addr is null

Definition at line 531 of file pkt4.cc.

## ◆ setLocalHWAddr() [2/2]

void isc::dhcp::Pkt4::setLocalHWAddr | ( | const uint8_t | htype,
|  | const uint8_t | hlen,
|  | const std::vector< uint8_t > & | mac_addr )

Sets local HW address.

Sets the source HW address for the outgoing packet or destination HW address for the incoming packet.

Note
  mac_addr must be a buffer of at least hlen bytes.

Parameters

  htype | hardware type (will be sent in htype field)
  hlen | hardware length (will be sent in hlen field)
  mac_addr | pointer to hardware address

Definition at line 525 of file pkt4.cc.

## ◆ setSecs()

void isc::dhcp::Pkt4::setSecs | ( | uint16_t | secs | ) |
| inline

Sets secs field.

Parameters

  secs | value to be set

Definition at line 162 of file pkt4.h.

## ◆ setSiaddr()

void isc::dhcp::Pkt4::setSiaddr | ( | const isc::asiolink::IOAddress & | siaddr | ) |
| inline

Sets siaddr field.

Parameters

  siaddr | value to be set

Definition at line 201 of file pkt4.h.

## ◆ setSname()

void isc::dhcp::Pkt4::setSname | ( | const uint8_t * | sname,
|  | size_t | sname_len )

Sets sname field.

Parameters

  sname | value to be set
  sname_len | length of the sname buffer (up to MAX_SNAME_LEN)

Definition at line 540 of file pkt4.cc.

## ◆ setType()

void isc::dhcp::Pkt4::setType | ( | uint8_t | type | ) |
| virtual

Sets DHCP message type (e.g.

1 = DHCPDISCOVER).

Parameters

  type | message type to be set

Implements isc::dhcp::Pkt.

Definition at line 253 of file pkt4.cc.

## ◆ setYiaddr()

void isc::dhcp::Pkt4::setYiaddr | ( | const isc::asiolink::IOAddress & | yiaddr | ) |
| inline

Sets yiaddr field.

Parameters

  yiaddr | value to be set

Definition at line 213 of file pkt4.h.

## ◆ toText()

std::string isc::dhcp::Pkt4::toText | ( | bool | verbose = false | ) | const
| virtual

Returns text representation of the packet.

This function is useful mainly for debugging.

Parameters

  verbose | output includes secs, flags and if they are populated: ciaddr, yiaddr, siaddr, giaddr, sname, and file

Returns
  string with text representation

Implements isc::dhcp::Pkt.

Definition at line 422 of file pkt4.cc.

## ◆ unpack()

void isc::dhcp::Pkt4::unpack | ( |  | ) |
| virtual

Parses on-wire form of DHCPv4 packet.

Parses received packet, stored in on-wire format in bufferIn_.

Will create a collection of option objects that will be stored in options_ container.

Method with throw exception if packet parsing fails.

Implements isc::dhcp::Pkt.

Definition at line 153 of file pkt4.cc.

## Member Data Documentation

## ◆ ciaddr_

isc::asiolink::IOAddress isc::dhcp::Pkt4::ciaddr_
| protected

ciaddr field (32 bits): Client's IP address

Definition at line 535 of file pkt4.h.

## ◆ deferred_options_

std::list<uint16_t> isc::dhcp::Pkt4::deferred_options_
| protected

List of deferred option codes.

Definition at line 508 of file pkt4.h.

## ◆ DHCPV4_PKT_HDR_LEN

const size_t isc::dhcp::Pkt4::DHCPV4_PKT_HDR_LEN = 236
| static

specifies DHCPv4 packet header length (fixed part)

Definition at line 50 of file pkt4.h.

## ◆ file_

uint8_t isc::dhcp::Pkt4::file_[MAX_FILE_LEN]
| protected

file field (128 bytes)

Definition at line 550 of file pkt4.h.

## ◆ FLAG_BROADCAST_MASK

const uint16_t isc::dhcp::Pkt4::FLAG_BROADCAST_MASK = 0x8000
| static

Mask for the value of flags field in the DHCPv4 message to check whether client requested broadcast response.

Definition at line 54 of file pkt4.h.

## ◆ flags_

uint16_t isc::dhcp::Pkt4::flags_
| protected

flags

Definition at line 532 of file pkt4.h.

## ◆ giaddr_

isc::asiolink::IOAddress isc::dhcp::Pkt4::giaddr_
| protected

giaddr field (32 bits): Gateway IP address

Definition at line 544 of file pkt4.h.

## ◆ hops_

uint8_t isc::dhcp::Pkt4::hops_
| protected

Number of relay agents traversed.

Definition at line 526 of file pkt4.h.

## ◆ hwaddr_

HWAddrPtr isc::dhcp::Pkt4::hwaddr_
| protected

link-layer address and hardware information represents 3 fields: htype (hardware type, 1 byte), hlen (length of the hardware address, up to 16) and chaddr (hardware address field, 16 bytes)

Definition at line 523 of file pkt4.h.

## ◆ local_hwaddr_

HWAddrPtr isc::dhcp::Pkt4::local_hwaddr_
| protected

local HW address (dst if receiving packet, src if sending packet)

Definition at line 505 of file pkt4.h.

## ◆ MAX_CHADDR_LEN

const size_t isc::dhcp::Pkt4::MAX_CHADDR_LEN = 16
| static

length of the CHADDR field in DHCPv4 message

Definition at line 41 of file pkt4.h.

## ◆ MAX_FILE_LEN

const size_t isc::dhcp::Pkt4::MAX_FILE_LEN = 128
| static

length of the FILE field in DHCPv4 message

Definition at line 47 of file pkt4.h.

## ◆ MAX_SNAME_LEN

const size_t isc::dhcp::Pkt4::MAX_SNAME_LEN = 64
| static

length of the SNAME field in DHCPv4 message

Definition at line 44 of file pkt4.h.

## ◆ op_

uint8_t isc::dhcp::Pkt4::op_
| protected

message operation code

Note: This is legacy BOOTP field. There's no need to manipulate it directly. Its value is set based on DHCP message type. Note that DHCPv4 protocol reuses BOOTP message format, so this field is kept due to BOOTP format. This is NOT DHCPv4 type (DHCPv4 message type is kept in message type option).

Definition at line 517 of file pkt4.h.

## ◆ secs_

uint16_t isc::dhcp::Pkt4::secs_
| protected

elapsed (number of seconds since beginning of transmission)

Definition at line 529 of file pkt4.h.

## ◆ siaddr_

isc::asiolink::IOAddress isc::dhcp::Pkt4::siaddr_
| protected

siaddr field (32 bits): next server IP address in boot process(e.g.TFTP)

Definition at line 541 of file pkt4.h.

## ◆ sname_

uint8_t isc::dhcp::Pkt4::sname_[MAX_SNAME_LEN]
| protected

sname field (64 bytes)

Definition at line 547 of file pkt4.h.

## ◆ yiaddr_

isc::asiolink::IOAddress isc::dhcp::Pkt4::yiaddr_
| protected

yiaddr field (32 bits): Client's IP address ("your"), set by server

Definition at line 538 of file pkt4.h.

The documentation for this class was generated from the following files:

- pkt4.h
- pkt4.cc