remove no longer necessary lowlevel wsock implementation (superseded by enet) since the delay load hook isn't compatible with a DLL packaging of enet.

-> cstr serialization uses lib/byte_order.h instead of htons; removed
hostname/IP from system_info (Philip agrees its utility is negligible)

This was SVN commit r9572.
This commit is contained in:
janwas 2011-05-29 19:59:51 +00:00
parent acb48663d7
commit e3d87b0375
8 changed files with 10 additions and 490 deletions

View File

@ -74,7 +74,6 @@ need only be renamed (e.g. _open, _stat).
//#include "lib/posix/posix_filesystem.h"
//#include "lib/posix/posix_mman.h"
//#include "lib/posix/posix_pthread.h"
//#include "lib/posix/posix_sock.h"
//#include "lib/posix/posix_time.h"
//#include "lib/posix/posix_utsname.h"

View File

@ -1,33 +0,0 @@
/* Copyright (c) 2010 Wildfire Games
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#if OS_WIN
# include "lib/sysdep/os/win/wposix/wsock.h"
#else
# include <sys/socket.h>
# include <netdb.h>
# include <netinet/in.h>
# include <netinet/tcp.h>
# include <arpa/inet.h>
#endif
#include "lib/posix/posix_errno.h" // for user convenience

View File

@ -32,7 +32,7 @@
#endif
// Win32 socket declarations aren't portable (e.g. problems with socklen_t)
// => skip winsock.h; posix_sock.h should be used instead.
// => skip winsock.h; use curl or enet library instead.
#define _WINSOCKAPI_
#define WIN32_LEAN_AND_MEAN

View File

@ -1,155 +0,0 @@
/* Copyright (c) 2010 Wildfire Games
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* emulate Berkeley sockets on Windows.
*/
#include "precompiled.h"
#include "lib/sysdep/os/win/wposix/wsock.h"
#include "lib/sysdep/os/win/wdll_delay_load.h"
#include "lib/sysdep/os/win/wposix/wposix_internal.h"
#include "lib/sysdep/os/win/wposix/wsock_internal.h"
#include "lib/module_init.h"
#if MSC_VERSION
#pragma comment(lib, "ws2_32.lib")
#endif
WINIT_REGISTER_MAIN_INIT(wsock_Init);
WINIT_REGISTER_MAIN_SHUTDOWN(wsock_Shutdown);
// IPv6 globals
// These are included in the linux C libraries and in newer platform SDKs,
// 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
//-----------------------------------------------------------------------------
// 'optional' IPv6 routines
// we hide the function pointers behind stub functions - this avoids
// surprising users. speed is irrelevant here. manually writing these stubs
// is ugly, but delay-load error handling is hairy, so don't use that.
//
// the first call of these stubs must trigger OnLoad in case no
// other winsock function was called yet.
// adding an extra haveInitialized flag would be redundant. instead,
// enter a clever but safe hack: we call a harmless winsock function that
// triggers the delay load or does nothing if init has already happened.
typedef int (WINAPI *Pgetnameinfo)(const struct sockaddr*, socklen_t, char*, socklen_t, char*, socklen_t, unsigned int);
typedef int (WINAPI *Pgetaddrinfo)(const char*, const char*, const struct addrinfo*, struct addrinfo**);
typedef void (WINAPI *Pfreeaddrinfo)(struct addrinfo*);
static Pgetnameinfo pgetnameinfo;
static Pgetaddrinfo pgetaddrinfo;
static Pfreeaddrinfo pfreeaddrinfo;
int getnameinfo(const struct sockaddr* sa, socklen_t salen, char* host, socklen_t hostlen, char* serv, socklen_t servlen, unsigned int flags)
{
(void)htonl(0); // trigger init if not done already
if(!pgetnameinfo)
{
errno = ENOSYS;
return -1;
}
return pgetnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
}
int getaddrinfo(const char* nodename, const char* servname, const struct addrinfo* hints, struct addrinfo** res)
{
(void)htonl(0); // trigger init if not done already
if(!pgetaddrinfo)
{
errno = ENOSYS;
return -1;
}
return pgetaddrinfo(nodename, servname, hints, res);
}
void freeaddrinfo(struct addrinfo* ai)
{
// (no dummy htonl call or checking of the function pointer is needed
// since getaddrinfo must succeed to get a valid addrinfo*.)
pfreeaddrinfo(ai);
}
static void ImportOptionalFunctions()
{
// (by the time we get here, ws2_32.dll will have been loaded, so
// this isn't the only reference and can be freed immediately)
HMODULE hWs2_32Dll = LoadLibraryW(L"ws2_32.dll");
pgetnameinfo = (Pgetnameinfo)GetProcAddress(hWs2_32Dll, "getnameinfo");
pgetaddrinfo = (Pgetaddrinfo)GetProcAddress(hWs2_32Dll, "getaddrinfo");
pfreeaddrinfo = (Pfreeaddrinfo)GetProcAddress(hWs2_32Dll, "freeaddrinfo");
FreeLibrary(hWs2_32Dll);
}
//-----------------------------------------------------------------------------
static Status Init()
{
char d[1024];
int ret = WSAStartup(0x0002, d); // want 2.0
ENSURE(ret == 0);
ImportOptionalFunctions();
return INFO::OK;
}
static void Shutdown()
{
int ret = WSACleanup();
ENSURE(ret >= 0);
}
static ModuleInitState initState;
// called from delay loader the first time a wsock function is called
// (shortly before the actual wsock function is called).
static Status OnLoad()
{
return ModuleInit(&initState, Init);
}
static Status wsock_Init()
{
// trigger OnLoad when someone first calls a wsock function.
static WdllLoadNotify loadNotify = { "ws2_32", OnLoad };
wdll_add_notify(&loadNotify);
return INFO::OK;
}
static Status wsock_Shutdown()
{
ModuleShutdown(&initState, Shutdown);
return INFO::OK;
}

View File

@ -1,232 +0,0 @@
/* Copyright (c) 2010 Wildfire Games
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* emulate Berkeley sockets on Windows.
*/
#ifndef INCLUDED_WSOCK
#define INCLUDED_WSOCK
#define IMP(ret, name, param) EXTERN_C __declspec(dllimport) ret __stdcall name param;
//
// <unistd.h>
//
IMP(int, gethostname, (char*, int))
//
// <sys/socket.h>
//
typedef unsigned long socklen_t;
typedef unsigned short sa_family_t;
// Win32 values - do not change
#define SOCK_STREAM 1
#define SOCK_DGRAM 2
#define AF_INET 2
#define PF_INET AF_INET
#define AF_INET6 23
#define PF_INET6 AF_INET6
#define SOL_SOCKET 0xFFFF /* options for socket level */
#define TCP_NODELAY 0x0001
/* This is the slightly unreadable encoded form of the windows ioctl that sets
non-blocking mode for a socket */
#define FIONBIO 0x8004667E
enum {
SHUT_RD=0,
SHUT_WR=1,
SHUT_RDWR=2
};
struct sockaddr;
IMP(int, socket, (int, int, int))
IMP(int, setsockopt, (int, int, int, const void*, socklen_t))
IMP(int, getsockopt, (int, int, int, void*, socklen_t*))
IMP(int, ioctlsocket, (int, int, const void *))
IMP(int, shutdown, (int, int))
IMP(int, closesocket, (int))
//
// <netinet/in.h>
//
typedef unsigned long in_addr_t;
typedef unsigned short in_port_t;
struct in_addr
{
in_addr_t s_addr;
};
struct sockaddr_in
{
sa_family_t sin_family;
in_port_t sin_port;
struct in_addr sin_addr;
unsigned char sin_zero[8];
};
#define INET_ADDRSTRLEN 16
#define INADDR_ANY 0
#define INADDR_LOOPBACK 0x7f000001
#define INADDR_NONE ((in_addr_t)-1)
#define IPPROTO_IP 0
#define IP_ADD_MEMBERSHIP 5
#define IP_DROP_MEMBERSHIP 6
struct ip_mreq
{
struct in_addr imr_multiaddr; /* multicast group to join */
struct in_addr imr_interface; /* interface to join on */
};
// ==== IPv6 ====
#define in6addr_any PS_in6addr_any
#define in6addr_loopback PS_in6addr_loopback
extern const struct in6_addr in6addr_any; /* :: */
extern const struct in6_addr in6addr_loopback; /* ::_1 */
#define IN6ADDR_ANY_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } }
#define IN6ADDR_LOOPBACK_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } }
// struct of array => 2 braces.
struct in6_addr
{
unsigned char s6_addr[16];
};
struct sockaddr_in6 {
sa_family_t sin6_family; /* AF_INET6 */
in_port_t sin6_port; /* Transport level port number */
unsigned long sin6_flowinfo; /* IPv6 flow information */
struct in6_addr sin6_addr; /* IPv6 address */
unsigned long sin6_scope_id; /* set of interfaces for a scope */
};
//
// <netdb.h>
//
struct hostent
{
char* h_name; // Official name of the host.
char** h_aliases; // A pointer to an array of pointers to
// alternative host names, terminated by a
// null pointer.
short h_addrtype; // Address type.
short h_length; // The length, in bytes, of the address.
char** h_addr_list; // A pointer to an array of pointers to network
// addresses (in network byte order) for the host,
// terminated by a null pointer.
};
IMP(struct hostent*, gethostbyname, (const char *name))
#define h_error WSAGetLastError()
#define HOST_NOT_FOUND 11001
#define TRY_AGAIN 11002
// addrinfo struct */
struct addrinfo
{
int ai_flags; // AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST
int ai_family; // PF_xxx
int ai_socktype; // SOCK_xxx
int ai_protocol; // 0 or IPPROTO_xxx for IPv4 and IPv6
size_t ai_addrlen; // Length of ai_addr
char *ai_canonname; // Canonical name for nodename
struct sockaddr* ai_addr; // Binary address
struct addrinfo* ai_next; // Next structure in linked list
};
// Hint flags for getaddrinfo
#define AI_PASSIVE 0x1 // Socket address will be used in bind() call
// Flags for getnameinfo()
#define NI_NUMERICHOST 0x02 // Return numeric form of the host's address
#define NI_MAXHOST 1025
#define NI_MAXSERV 32
// these functions are only supported on WinXP+, and Win2k with IPv6 update.
// otherwise, they return -1 with errno = ENOSYS.
extern int getnameinfo(const struct sockaddr*, socklen_t, char*, socklen_t, char*, socklen_t, unsigned int);
extern int getaddrinfo(const char*, const char*, const struct addrinfo*, struct addrinfo**);
extern void freeaddrinfo(struct addrinfo*);
// getaddr/nameinfo error codes
#define EAI_NONAME HOST_NOT_FOUND
//
// <arpa/inet.h>
//
IMP(unsigned short, htons, (unsigned short hostlong))
IMP(unsigned short, ntohs, (unsigned short hostlong))
IMP(unsigned long, htonl, (unsigned long hostlong))
IMP(unsigned long, ntohl, (unsigned long hostlong))
IMP(in_addr_t, inet_addr, (const char*))
IMP(char*, inet_ntoa, (in_addr))
IMP(int, accept, (int, struct sockaddr*, socklen_t*))
IMP(int, bind, (int, const struct sockaddr*, socklen_t))
IMP(int, connect, (int, const struct sockaddr*, socklen_t))
IMP(int, listen, (int, int))
IMP(ssize_t, recv, (int, void*, size_t, int))
IMP(ssize_t, send, (int, const void*, size_t, int))
IMP(ssize_t, sendto, (int, const void*, size_t, int, const struct sockaddr*, socklen_t))
IMP(ssize_t, recvfrom, (int, void*, size_t, int, struct sockaddr*, socklen_t*))
// WSAAsyncSelect event bits
// (values taken from winsock2.h - do not change!)
#define FD_READ 0x01
#define FD_WRITE 0x02
#define FD_ACCEPT 0x08
#define FD_CONNECT 0x10
#define FD_CLOSE 0x20
#undef IMP
#endif // #ifndef INCLUDED_WSOCK

View File

@ -1,26 +0,0 @@
/* Copyright (c) 2010 Wildfire Games
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
EXTERN_C __declspec(dllimport) int __stdcall WSAStartup(unsigned short, void*);
EXTERN_C __declspec(dllimport) int __stdcall WSACleanup();
EXTERN_C __declspec(dllimport) int __stdcall WSAAsyncSelect(int s, HANDLE hWnd, unsigned int wMsg, long lEvent);
EXTERN_C __declspec(dllimport) int __stdcall WSAGetLastError();

View File

@ -26,9 +26,9 @@
#ifndef CStr_CPP_FIRST
#define CStr_CPP_FIRST
#include "lib/posix/posix_sock.h" // htons, ntohs
#include "lib/fnv_hash.h"
#include "lib/utf8.h"
#include "lib/byte_order.h"
#include "network/Serialization.h"
#include <cassert>
@ -446,7 +446,10 @@ u8* CStrW::Serialize(u8* buffer) const
size_t len = length();
size_t i = 0;
for (i = 0; i < len; i++)
*(u16 *)(buffer + i*2) = htons((*this)[i]); // convert to network order (big-endian)
{
const u16 bigEndian = to_be16((*this)[i]);
*(u16 *)(buffer + i*2) = bigEndian;
}
*(u16 *)(buffer + i*2) = 0;
return buffer + len*2 + 2;
}
@ -462,7 +465,10 @@ const u8* CStrW::Deserialize(const u8* buffer, const u8* bufferend)
std::wstring::iterator str = begin();
while (ptr < strend)
*(str++) = (tchar)ntohs(*(ptr++)); // convert from network order (big-endian)
{
const u16 native = to_be16(*(ptr++)); // we want from_be16, but that's the same
*(str++) = (tchar)native;
}
return (const u8 *)(strend+1);
}

View File

@ -20,7 +20,6 @@
#include "ps/Util.h"
#include "lib/posix/posix_utsname.h"
#include "lib/posix/posix_sock.h"
#include "lib/ogl.h"
#include "lib/timer.h"
#include "lib/bits.h" // round_up
@ -126,44 +125,6 @@ void WriteSystemInfo()
fprintf(f, "Sound Card : %ls\n", snd_card);
fprintf(f, "Sound Drivers : %ls\n", snd_drv_ver);
//
// network name / ips
//
// note: can't use un.nodename because it is for an
// "implementation-defined communications network".
char hostname[128] = "(unknown)";
(void)gethostname(hostname, sizeof(hostname)-1);
// -1 makes sure it's 0-terminated. if the function fails,
// we display "(unknown)" and will skip IP output below.
fprintf(f, "Network Name : %s", hostname);
{
// ignore exception here - see https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=114032
hostent* host = gethostbyname(hostname);
if(!host)
goto no_ip;
struct in_addr** ips = (struct in_addr**)host->h_addr_list;
if(!ips)
goto no_ip;
// output all IPs (> 1 if using VMware or dual ethernet)
fprintf(f, " (");
for(size_t i = 0; i < 256 && ips[i]; i++) // safety
{
// separate entries but avoid trailing comma
if(i != 0)
fprintf(f, ", ");
fprintf(f, "%s", inet_ntoa(*ips[i]));
}
fprintf(f, ")");
}
no_ip:
fprintf(f, "\n");
// OpenGL extensions (write them last, since it's a lot of text)
const char* exts = ogl_ExtensionString();
if (!exts) exts = "{unknown}";