mirror of
https://github.com/nmap/nmap.git
synced 2026-01-06 06:29:03 +00:00
removed winip lib
This commit is contained in:
@@ -103,11 +103,188 @@
|
||||
#include <winclude.h>
|
||||
#include <sys/timeb.h>
|
||||
|
||||
#include "nmap_error.h"
|
||||
|
||||
#include "..\nmap.h"
|
||||
#include "..\tcpip.h"
|
||||
#include "winfix.h"
|
||||
#include "..\NmapOps.h"
|
||||
#include "..\nmap_error.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include <delayimp.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define DLI_ERROR VcppException(ERROR_SEVERITY_ERROR, ERROR_MOD_NOT_FOUND)
|
||||
#endif
|
||||
|
||||
/* delay-load hooks only for troubleshooting */
|
||||
#ifdef _MSC_VER
|
||||
static int dli_done = 0;
|
||||
static FARPROC WINAPI winip_dli_fail_hook(unsigned code, PDelayLoadInfo info);
|
||||
#endif
|
||||
|
||||
extern NmapOps o;
|
||||
|
||||
int pcap_avail = 0;
|
||||
|
||||
/* internal functions */
|
||||
static void win_cleanup(void);
|
||||
static char pcaplist[4096];
|
||||
|
||||
void win_barf(const char *msg)
|
||||
{
|
||||
if(msg) printf("%s\n\n", msg);
|
||||
printf("\nYour system doesn't have iphlpapi.dll\n\nIf you have Win95, "
|
||||
"maybe you could grab it from a Win98 system\n"
|
||||
"If you have NT4, you need service pack 4 or higher\n"
|
||||
"If you have NT3.51, try grabbing it from an NT4 system\n"
|
||||
"Otherwise, your system has problems ;-)\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void win_init()
|
||||
{
|
||||
// variables
|
||||
DWORD cb = 0;
|
||||
DWORD nRes;
|
||||
OSVERSIONINFOEX ver;
|
||||
PMIB_IPADDRTABLE pIp = 0;
|
||||
int i;
|
||||
int numipsleft;
|
||||
WORD werd;
|
||||
WSADATA data;
|
||||
|
||||
werd = MAKEWORD( 2, 2 );
|
||||
if( (WSAStartup(werd, &data)) !=0 )
|
||||
fatal("failed to start winsock.\n");
|
||||
|
||||
ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
||||
if(!GetVersionEx((LPOSVERSIONINFO)&ver))
|
||||
{
|
||||
ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
if(!GetVersionEx((LPOSVERSIONINFO)&ver))
|
||||
fatal("GetVersionEx failed\n");
|
||||
|
||||
ver.wServicePackMajor = 0;
|
||||
ver.wServicePackMinor = 0;
|
||||
}
|
||||
|
||||
|
||||
// Try to initialize winpcap
|
||||
#ifdef _MSC_VER
|
||||
__try
|
||||
#endif
|
||||
{
|
||||
ULONG len = sizeof(pcaplist);
|
||||
|
||||
pcap_avail = 1;
|
||||
if(o.debugging > 2) printf("***WinIP*** trying to initialize winpcap 2.1\n");
|
||||
PacketGetAdapterNames(pcaplist, &len);
|
||||
if(o.debugging)
|
||||
printf("***WinIP*** winpcap present, dynamic linked to: %s\n", pcap_lib_version());
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
__except(GetExceptionCode() == DLI_ERROR)
|
||||
{
|
||||
pcap_avail = 0;
|
||||
printf("WARNING: Failed to locate Winpcap. Nmap may not function properly until this is installed! WinPcap is freely available from http://winpcap.polito.it.\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Check for a wpcap.dll (so we don't crash on old winpcap
|
||||
// But only with VC++.NET, since old versions do not
|
||||
// provide this functionality :(
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1300
|
||||
if(pcap_avail)
|
||||
{
|
||||
if(FAILED(__HrLoadAllImportsForDll("wpcap.dll")))
|
||||
{
|
||||
error("WARNING: your winpcap is too old to use. Nmap may not function.\n");
|
||||
pcap_avail = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
o.isr00t = pcap_avail;
|
||||
atexit(win_cleanup);
|
||||
|
||||
// Mark load as complete so that dli errors are handled
|
||||
#ifdef _MSC_VER
|
||||
dli_done = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void win_cleanup(void)
|
||||
{
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
typedef DWORD (__stdcall *PGBI)(IPAddr, PDWORD);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
static FARPROC WINAPI winip_dli_fail_hook(unsigned code, PDelayLoadInfo info)
|
||||
{
|
||||
if(o.debugging)
|
||||
{
|
||||
printf("***WinIP*** delay load error:\n");
|
||||
switch(code)
|
||||
{
|
||||
case dliFailLoadLib:
|
||||
printf(" failed to load dll: %s\n", info->szDll);
|
||||
break;
|
||||
|
||||
case dliFailGetProc:
|
||||
printf(" failed to load ");
|
||||
if(info->dlp.fImportByName)
|
||||
printf("function %s", info->dlp.szProcName + 2);
|
||||
else printf("ordinal %d", info->dlp.dwOrdinal);
|
||||
printf(" in dll %s\n", info->szDll);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf(" unknown error\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(dli_done)
|
||||
{
|
||||
printf("******* Unexpected delay-load failure *******\n");
|
||||
|
||||
switch(code)
|
||||
{
|
||||
case dliFailLoadLib:
|
||||
printf(" failed to load dll: %s\n", info->szDll);
|
||||
if(!stricmp(info->szDll, "wpcap.dll"))
|
||||
printf(" this is most likely because you have"
|
||||
" winpcap 2.0 (2.1 or later is required)\n"
|
||||
"Get it from http://netgroup-serv.polito.it/winpcap\n");
|
||||
break;
|
||||
|
||||
case dliFailGetProc:
|
||||
printf(" failed to load ");
|
||||
if(info->dlp.fImportByName)
|
||||
printf("function %s", info->dlp.szProcName + 2);
|
||||
else printf("ordinal %d", info->dlp.dwOrdinal);
|
||||
printf(" in dll %s\n", info->szDll);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf(" unknown error\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif // _MSC_VER
|
||||
|
||||
|
||||
|
||||
int my_close(int sd)
|
||||
{
|
||||
if(sd == 501) return 0;
|
||||
return closesocket(sd);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user