2022-02-27 17:26:48 +00:00
|
|
|
/*
|
|
|
|
AppleWin : An Apple //e emulator for Windows
|
|
|
|
|
|
|
|
Copyright (C) 2022, Andrea Odetti
|
|
|
|
|
|
|
|
AppleWin is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
AppleWin is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with AppleWin; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
|
|
|
#include "PCapBackend.h"
|
|
|
|
#include "tfearch.h"
|
|
|
|
#include "../Common.h"
|
|
|
|
#include "../Registry.h"
|
|
|
|
|
2022-03-22 19:30:42 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <iphlpapi.h>
|
|
|
|
#endif
|
|
|
|
|
2022-05-08 15:26:01 +00:00
|
|
|
PCapBackend::PCapBackend(const std::string & interfaceName) : m_interfaceName(interfaceName)
|
2022-02-27 17:26:48 +00:00
|
|
|
{
|
2022-05-08 15:26:01 +00:00
|
|
|
m_tfePcapFP = TfePcapOpenAdapter(interfaceName);
|
2022-02-27 17:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PCapBackend::~PCapBackend()
|
|
|
|
{
|
2022-05-08 15:26:01 +00:00
|
|
|
TfePcapCloseAdapter(m_tfePcapFP);
|
|
|
|
m_tfePcapFP = NULL;
|
2022-02-27 17:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCapBackend::transmit(
|
|
|
|
const int txlength, /* Frame length */
|
|
|
|
uint8_t *txframe /* Pointer to the frame to be transmitted */
|
|
|
|
)
|
|
|
|
{
|
2022-05-08 15:26:01 +00:00
|
|
|
if (m_tfePcapFP)
|
2022-02-27 17:26:48 +00:00
|
|
|
{
|
2022-05-08 15:26:01 +00:00
|
|
|
tfe_arch_transmit(m_tfePcapFP, txlength, txframe);
|
2022-02-27 17:26:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int PCapBackend::receive(const int size, uint8_t * rxframe)
|
|
|
|
{
|
2022-05-08 15:26:01 +00:00
|
|
|
if (m_tfePcapFP)
|
2022-02-27 17:26:48 +00:00
|
|
|
{
|
2022-05-08 15:26:01 +00:00
|
|
|
return tfe_arch_receive(m_tfePcapFP, size, rxframe);
|
2022-02-27 17:26:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PCapBackend::isValid()
|
|
|
|
{
|
2022-05-08 15:26:01 +00:00
|
|
|
return m_tfePcapFP;
|
2022-02-27 17:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCapBackend::update(const ULONG /* nExecutedCycles */)
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
2022-03-22 19:30:42 +00:00
|
|
|
void PCapBackend::getMACAddress(const uint32_t address, MACAddress & mac)
|
|
|
|
{
|
|
|
|
// this is only expected to be called for IP addresses on the same network
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
const DWORD dwSourceAddress = INADDR_ANY;
|
|
|
|
ULONG len = sizeof(MACAddress::address);
|
|
|
|
SendARP(address, dwSourceAddress, mac.address, &len);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-05-08 15:26:01 +00:00
|
|
|
const std::string & PCapBackend::getInterfaceName()
|
|
|
|
{
|
|
|
|
return m_interfaceName;
|
|
|
|
}
|
|
|
|
|
2022-02-27 17:26:48 +00:00
|
|
|
int PCapBackend::tfe_enumadapter_open(void)
|
|
|
|
{
|
|
|
|
return tfe_arch_enumadapter_open();
|
|
|
|
}
|
|
|
|
|
2022-03-14 21:12:52 +00:00
|
|
|
int PCapBackend::tfe_enumadapter(std::string & name, std::string & description)
|
2022-02-27 17:26:48 +00:00
|
|
|
{
|
2022-03-14 21:12:52 +00:00
|
|
|
return tfe_arch_enumadapter(name, description);
|
2022-02-27 17:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int PCapBackend::tfe_enumadapter_close(void)
|
|
|
|
{
|
|
|
|
return tfe_arch_enumadapter_close();
|
|
|
|
}
|
|
|
|
|
2022-05-08 15:26:01 +00:00
|
|
|
const char * PCapBackend::tfe_lib_version(void)
|
|
|
|
{
|
|
|
|
return tfe_arch_lib_version();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCapBackend::SetRegistryInterface(UINT slot, const std::string& name)
|
2022-02-27 17:26:48 +00:00
|
|
|
{
|
|
|
|
std::string regSection = RegGetConfigSlotSection(slot);
|
|
|
|
RegSaveString(regSection.c_str(), REGVALUE_UTHERNET_INTERFACE, 1, name);
|
|
|
|
}
|
|
|
|
|
2022-05-08 15:26:01 +00:00
|
|
|
std::string PCapBackend::GetRegistryInterface(UINT slot)
|
|
|
|
{
|
|
|
|
char interfaceName[MAX_PATH];
|
|
|
|
std::string regSection = RegGetConfigSlotSection(slot);
|
|
|
|
RegLoadString(regSection.c_str(), REGVALUE_UTHERNET_INTERFACE, TRUE, interfaceName, sizeof(interfaceName), TEXT(""));
|
|
|
|
return interfaceName;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PCapBackend::tfe_is_npcap_loaded()
|
2022-02-27 17:26:48 +00:00
|
|
|
{
|
2022-05-08 15:26:01 +00:00
|
|
|
return tfe_arch_is_npcap_loaded();
|
2022-02-27 17:26:48 +00:00
|
|
|
}
|