//..............................................................................
//
// ARP (address resolution protocol) defitions
//

import "io_Ethernet.jnc"

namespace io {

//! \addtogroup proto-arp
//! @{

//..............................................................................

enum ArpHardwareType: uint16_t {
	Reserved = 0,
	Ethernet = 1,
}

// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

enum ArpOpcode: uint16_t {
	Request        = 1,
	Reply          = 2,
	RequestReverse = 3,
	ReplyReverese  = 4,
}

// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

[
	displayName = "ARP",
	formatDigestFunc = formatArpDigest
]
struct ArpHdr {
	[ displayName = "Hardware type" ]
	bigendian ArpHardwareType m_hardwareType;

	[ displayName = "Protocol type" ]
	bigendian EthernetType m_protocolType;

	[ displayName = "Hardware size" ]
	uint8_t m_hardwareLength;

	[ displayName = "Protocol size" ]
	uint8_t m_protocolLength;

	[ displayName = "Opcode" ]
	bigendian ArpOpcode m_opcode;
}

// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

string_t formatArpDigest(void const* p) {
	ArpHdr const* hdr = (ArpHdr const*)p;
	return typeof(ArpOpcode).getValueString(hdr.m_opcode);
}

//..............................................................................

//! @}

} // namespace io
