2004-06-03 20:36:48 +02:00
|
|
|
// Berkeley sockets emulation for Win32
|
|
|
|
// Copyright (c) 2004 Jan Wassenberg
|
|
|
|
//
|
|
|
|
// This program 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.
|
|
|
|
//
|
|
|
|
// This program 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.
|
|
|
|
//
|
|
|
|
// Contact info:
|
|
|
|
// Jan.Wassenberg@stud.uni-karlsruhe.de
|
|
|
|
// http://www.stud.uni-karlsruhe.de/~urkt/
|
|
|
|
|
2004-05-27 19:30:06 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
#include "win_internal.h"
|
|
|
|
#include "lib.h"
|
|
|
|
#include "wsock.h"
|
|
|
|
|
2004-06-04 14:41:53 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
2004-05-27 19:30:06 +02:00
|
|
|
#pragma comment(lib, "ws2_32.lib")
|
2004-06-04 14:41:53 +02:00
|
|
|
#endif
|
2004-05-27 19:30:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
fp_getnameinfo_t getnameinfo;
|
|
|
|
fp_getaddrinfo_t getaddrinfo;
|
|
|
|
fp_freeaddrinfo_t freeaddrinfo;
|
|
|
|
|
|
|
|
|
|
|
|
/* IPv6 globals
|
|
|
|
These are included in the linux C libraries, and in newer platform SDK's, so
|
|
|
|
should only be needed in VC++6 or earlier.
|
|
|
|
*/
|
|
|
|
const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; /* :: */
|
|
|
|
const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT; /* ::1 */
|
|
|
|
|
|
|
|
|
|
|
|
WIN_REGISTER_MODULE(wsock);
|
|
|
|
|
|
|
|
static int wsock_init()
|
|
|
|
{
|
|
|
|
char d[1024];
|
|
|
|
CHECK_ERR(WSAStartup(0x0002, d)); // want 2.0
|
|
|
|
|
|
|
|
const HMODULE hWs2_32Dll = LoadLibrary("ws2_32.dll");
|
|
|
|
*(void**)&getaddrinfo = GetProcAddress(hWs2_32Dll, "getaddrinfo");
|
|
|
|
*(void**)&getnameinfo = GetProcAddress(hWs2_32Dll, "getnameinfo");
|
|
|
|
*(void**)&freeaddrinfo = GetProcAddress(hWs2_32Dll, "freeaddrinfo");
|
|
|
|
FreeLibrary(hWs2_32Dll);
|
|
|
|
// make sure the reference is released so BoundsChecker
|
|
|
|
// doesn't complain. it won't actually be unloaded anyway -
|
|
|
|
// there is at least one other reference.
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int wsock_shutdown()
|
|
|
|
{
|
|
|
|
return WSACleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-01 19:34:12 +02:00
|
|
|
uint16_t htons(uint16_t s)
|
2004-05-27 19:30:06 +02:00
|
|
|
{
|
|
|
|
return (s >> 8) | ((s & 0xff) << 8);
|
|
|
|
}
|
2004-06-08 22:37:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma comment(lib, "delayimp.lib")
|
|
|
|
|
|
|
|
#include <delayimp.h>
|
|
|
|
|
|
|
|
FARPROC WINAPI MSJCheezyDelayLoadHook(unsigned dliNotify, PDelayLoadInfo pdli )
|
|
|
|
{
|
|
|
|
// Display which type of notification it is
|
|
|
|
switch( dliNotify )
|
|
|
|
{
|
|
|
|
case dliStartProcessing:
|
|
|
|
printf( "dliStartProcessing " );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dliNotePreLoadLibrary:
|
|
|
|
printf( "dliNotePreLoadLibrary " );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dliNotePreGetProcAddress:
|
|
|
|
printf( "dliNotePreGetProcAddress" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dliNoteEndProcessing:
|
|
|
|
printf( "dliNoteEndProcessing " );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display the DLL name and the HMODULE
|
|
|
|
printf( " %s(%08P) -> ", pdli->szDll, pdli->hmodCur );
|
|
|
|
|
|
|
|
// Display the API ordinal or API name, as appropriate
|
|
|
|
if ( pdli->dlp.fImportByName )
|
|
|
|
printf( " %s", pdli->dlp.szProcName );
|
|
|
|
else
|
|
|
|
printf( " ordinal:%u", pdli->dlp.dwOrdinal );
|
|
|
|
|
|
|
|
printf( "\n" );
|
|
|
|
|
|
|
|
return 0; // Make sure __delayLoadHelper doesn't think we did something!
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Override the standard definition of __pfnDliNotifyHook that's part of
|
|
|
|
// DELAYHLP.LIB
|
|
|
|
//
|
|
|
|
PfnDliHook __pfnDliNotifyHook = MSJCheezyDelayLoadHook;
|