示例#1
0
		boost::optional<boost::asio::const_buffer> proxy<arp_frame>::process_frame(const_helper<ethernet_frame> ethernet_helper, const_helper<arp_frame> arp_helper, boost::asio::mutable_buffer response_buffer) const
		{
			if (arp_helper.operation() == ARP_REQUEST_OPERATION)
			{
				const entry_map_type::const_iterator entry_it = m_entry_map.find(arp_helper.target_logical_address());

				ethernet_address_type eth_addr;

				bool should_answer = false;

				if (entry_it != m_entry_map.end())
				{
					eth_addr = entry_it->second;
					should_answer = true;
				}
				else
				{
					if (m_arp_request_callback)
					{
						should_answer = m_arp_request_callback(arp_helper.target_logical_address(), eth_addr);
					}
				}

				if (should_answer)
				{
					size_t payload_size;

					builder<arp_frame> arp_builder(response_buffer);

					payload_size = arp_builder.write(
					                   ARP_REPLY_OPERATION,
					                   boost::asio::buffer(eth_addr.data()),
					                   arp_helper.target_logical_address(),
					                   arp_helper.sender_hardware_address(),
					                   arp_helper.sender_logical_address()
					               );

					builder<ethernet_frame> ethernet_builder(response_buffer, payload_size);

					payload_size = ethernet_builder.write(
					                   ethernet_helper.sender(),
					                   ethernet_helper.target(),
					                   ethernet_helper.protocol()
					               );

					return boost::make_optional<boost::asio::const_buffer>(response_buffer + (boost::asio::buffer_size(response_buffer) - payload_size));
				}
			}

			return boost::optional<boost::asio::const_buffer>();
		}
示例#2
0
		void proxy<arp_frame>::do_handle_frame(const_helper<ethernet_frame> ethernet_helper, const_helper<arp_frame> arp_helper)
		{
			if (arp_helper.operation() == ARP_REQUEST_OPERATION)
			{
				entry_map_type::const_iterator entry_it = m_entry_map.find(arp_helper.target_logical_address());

				ethernet_address_type eth_addr;

				bool should_answer = false;

				if (entry_it != m_entry_map.end())
				{
					eth_addr = entry_it->second;
					should_answer = true;
				}
				else
				{
					if (m_arp_request_callback)
					{
						should_answer = m_arp_request_callback(arp_helper.target_logical_address(), eth_addr);
					}
				}

				if (should_answer)
				{
					size_t payload_size;

					builder<arp_frame> arp_builder(response_buffer());

					payload_size = arp_builder.write(
					                   ARP_REPLY_OPERATION,
					                   boost::asio::buffer(eth_addr.data()),
					                   arp_helper.target_logical_address(),
					                   arp_helper.sender_hardware_address(),
					                   arp_helper.sender_logical_address()
					               );

					builder<ethernet_frame> ethernet_builder(response_buffer(), payload_size);

					payload_size = ethernet_builder.write(
					                   ethernet_helper.sender(),
					                   ethernet_helper.target(),
					                   ethernet_helper.protocol()
					               );

					data_available(get_truncated_response_buffer(payload_size));
				}
			}
		}