Removed deprecated function GetVersion() from eth_win32.cc and niclist.c.

Since the presence of UNICODE or ANSI format only depends on the PACKET.DLL
version, no Windows version check is necessary.
This commit is contained in:
Volker Ruppert 2019-12-08 18:14:30 +00:00
parent 038ebf5815
commit 445bf01b2a
2 changed files with 17 additions and 37 deletions

View File

@ -2,7 +2,7 @@
// $Id$ // $Id$
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2001-2017 The Bochs Project // Copyright (C) 2001-2019 The Bochs Project
// //
// This library is free software; you can redistribute it and/or // This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public // modify it under the terms of the GNU Lesser General Public
@ -183,11 +183,10 @@ LPADAPTER lpAdapter = 0;
LPPACKET pkSend; LPPACKET pkSend;
LPPACKET pkRecv; LPPACKET pkRecv;
char buffer[256000]; char buffer[256000];
DWORD dwVersion, dwMajorVersion;
char AdapterList[10][1024]; char AdapterList[10][1024];
char cMacAddr[6]; char cMacAddr[6];
char NetDev[512]; char NetDev[512];
BOOL IsNT = FALSE; BOOL IsNT = TRUE;
typedef LPADAPTER (CDECL *POpenAdapter) (LPTSTR); typedef LPADAPTER (CDECL *POpenAdapter) (LPTSTR);
typedef VOID (CDECL *PCloseAdapter) (LPADAPTER); typedef VOID (CDECL *PCloseAdapter) (LPADAPTER);
@ -277,8 +276,6 @@ bx_win32_pktmover_c::bx_win32_pktmover_c(
this->netdev = dev; this->netdev = dev;
BX_INFO(("win32 network driver")); BX_INFO(("win32 network driver"));
// Open Packet Driver Here. // Open Packet Driver Here.
DWORD dwVersion;
DWORD dwWindowsMajorVersion;
this->rxh = rxh; this->rxh = rxh;
this->rxstat = rxstat; this->rxstat = rxstat;
@ -303,16 +300,8 @@ bx_win32_pktmover_c::bx_win32_pktmover_c(
} }
memset(&NetDev, 0, sizeof(NetDev)); memset(&NetDev, 0, sizeof(NetDev));
dwVersion=GetVersion(); // Expecting ANSI format for WinPCap 3.1 or newer
dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); strcpy(NetDev, netif);
if (!(dwVersion >= 0x80000000 && dwWindowsMajorVersion >= 4))
{ // Windows NT/2k
int nLen = MultiByteToWideChar(CP_ACP, 0, netif, -1, NULL, 0);
MultiByteToWideChar(CP_ACP, 0, netif, -1, (WCHAR *)NetDev, nLen);
IsNT = TRUE;
} else { // Win9x
strcpy(NetDev, netif);
}
lpAdapter = PacketOpenAdapter(NetDev); lpAdapter = PacketOpenAdapter(NetDev);
if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE)) { if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE)) {
@ -380,7 +369,7 @@ void bx_win32_pktmover_c::sendpkt(void *buf, unsigned io_len)
PacketInitPacket(pkSend, (char *)buf, io_len); PacketInitPacket(pkSend, (char *)buf, io_len);
if (!PacketSendPacket(lpAdapter, pkSend, TRUE)) { if (!PacketSendPacket(lpAdapter, pkSend, TRUE)) {
fprintf(stderr, "[ETH-WIN32] Error sending packet: %lu\n", GetLastError()); BX_ERROR(("Error sending packet: %lu\n", GetLastError()));
} }
} }

View File

@ -61,7 +61,7 @@ typedef PCHAR (CDECL *PGetVersion)();
PGetAdapterNames PacketGetAdapterNames = NULL; PGetAdapterNames PacketGetAdapterNames = NULL;
PGetVersion PacketGetVersion = NULL; PGetVersion PacketGetVersion = NULL;
void myexit (int code) void myexit(int code)
{ {
#ifndef __CYGWIN__ #ifndef __CYGWIN__
printf ("\nPress any key to continue\n"); printf ("\nPress any key to continue\n");
@ -74,7 +74,6 @@ int CDECL main(int argc, char **argv)
{ {
int i; int i;
HINSTANCE hPacket; HINSTANCE hPacket;
DWORD dwVersion, dwMajorVersion;
char AdapterInfo[NIC_BUFFER_SIZE] = { '\0','\0' }; char AdapterInfo[NIC_BUFFER_SIZE] = { '\0','\0' };
ULONG AdapterLength = NIC_BUFFER_SIZE; ULONG AdapterLength = NIC_BUFFER_SIZE;
LPWSTR wstrName; LPWSTR wstrName;
@ -86,22 +85,18 @@ int CDECL main(int argc, char **argv)
// Attemp to load the WinpCap packet library // Attemp to load the WinpCap packet library
hPacket = LoadLibrary("PACKET.DLL"); hPacket = LoadLibrary("PACKET.DLL");
if(hPacket) if (hPacket)
{ {
// Now look up the address // Now look up the address
PacketGetAdapterNames = (PGetAdapterNames)GetProcAddress(hPacket, "PacketGetAdapterNames"); PacketGetAdapterNames = (PGetAdapterNames)GetProcAddress(hPacket, "PacketGetAdapterNames");
PacketGetVersion = (PGetVersion)GetProcAddress(hPacket, "PacketGetVersion"); PacketGetVersion = (PGetVersion)GetProcAddress(hPacket, "PacketGetVersion");
} } else {
else {
printf("Could not load WinPCap driver!\n"); printf("Could not load WinPCap driver!\n");
printf ("You can download them for free from\n"); printf ("You can download them for free from\n");
printf ("http://www.winpcap.org/\n"); printf ("http://www.winpcap.org/\n");
myexit(1); myexit(1);
} }
dwVersion = GetVersion();
dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
// Get DLL Version and Tokenize // Get DLL Version and Tokenize
dllVersion = PacketGetVersion(); dllVersion = PacketGetVersion();
nDLLMajorVersion = -1; nDLLMajorVersion = -1;
@ -125,12 +120,11 @@ int CDECL main(int argc, char **argv)
} }
// Get out blob of adapter info // Get out blob of adapter info
PacketGetAdapterNames(AdapterInfo,&AdapterLength); PacketGetAdapterNames(AdapterInfo, &AdapterLength);
// If this is Windows NT ... And DLL Returns UNICODE if (nDLLMajorVersion < 3 || (nDLLMajorVersion == 3 && nDLLMinorVersion < 1))
if(!(dwVersion >= 0x80000000 && dwMajorVersion >= 4) &&
(nDLLMajorVersion < 3 || (nDLLMajorVersion == 3 && nDLLMinorVersion < 1)))
{ {
// DLL returns UNICODE
wstrName=(LPWSTR)AdapterInfo; wstrName=(LPWSTR)AdapterInfo;
// Obtain Names // Obtain Names
@ -146,7 +140,7 @@ int CDECL main(int argc, char **argv)
strDesc = (LPSTR)++wstrName; strDesc = (LPSTR)++wstrName;
// Obtain descriptions .... // Obtain descriptions ....
for(i=0;i<nAdapterCount;i++) for (i=0;i<nAdapterCount;i++)
{ {
// store pointer to description // store pointer to description
niNT[i].strDesc=strDesc; niNT[i].strDesc=strDesc;
@ -157,16 +151,14 @@ int CDECL main(int argc, char **argv)
wprintf(L" Device: %s",niNT[i].wstrName); wprintf(L" Device: %s",niNT[i].wstrName);
} }
if(i) { if (i) {
printf("\n\nExample config for bochsrc:\n"); printf("\n\nExample config for bochsrc:\n");
wprintf(L"ne2k: ioaddr=0x300, irq=3, mac=b0:c4:20:00:00:00, ethmod=win32, ethdev=%s",niNT[0].wstrName); wprintf(L"ne2k: ioaddr=0x300, irq=3, mac=b0:c4:20:00:00:00, ethmod=win32, ethdev=%s",niNT[0].wstrName);
printf("\n"); printf("\n");
} }
} } else {
else // DLL returns ANSI
{
// Windows 9x
strName=(LPSTR)AdapterInfo; strName=(LPSTR)AdapterInfo;
// Obtain Names // Obtain Names
@ -182,7 +174,7 @@ int CDECL main(int argc, char **argv)
strDesc = (LPSTR)++strName; strDesc = (LPSTR)++strName;
// Obtain descriptions .... // Obtain descriptions ....
for(i=0;i<nAdapterCount;i++) for (i=0;i<nAdapterCount;i++)
{ {
// store pointer to description // store pointer to description
ni9X[i].strDesc=strDesc; ni9X[i].strDesc=strDesc;
@ -193,8 +185,7 @@ int CDECL main(int argc, char **argv)
printf(" Device: %s",ni9X[i].strName); printf(" Device: %s",ni9X[i].strName);
} }
if(i) if (i) {
{
printf("\n\nExample config for bochsrc:\n"); printf("\n\nExample config for bochsrc:\n");
printf("ne2k: ioaddr=0x300, irq=3, mac=b0:c4:20:00:00:00, ethmod=win32, ethdev=%s",ni9X[0].strName); printf("ne2k: ioaddr=0x300, irq=3, mac=b0:c4:20:00:00:00, ethmod=win32, ethdev=%s",ni9X[0].strName);
printf("\n"); printf("\n");