ws2_32: Build with msvcrt.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-08-04 21:20:47 -05:00 committed by Alexandre Julliard
parent d3138d711b
commit 0c81cc2782
6 changed files with 101 additions and 157 deletions

View File

@ -4,6 +4,8 @@ IMPORTLIB = ws2_32
DELAYIMPORTS = advapi32 iphlpapi user32
EXTRALIBS = $(POLL_LIBS)
EXTRADLLFLAGS = -mno-cygwin
C_SRCS = \
async.c \
protocol.c \

View File

@ -34,9 +34,6 @@
* whole stuff did not work anyway to other changes).
*/
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"

View File

@ -22,13 +22,31 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "ws2_32_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(winsock);
WINE_DECLARE_DEBUG_CHANNEL(winediag);
static inline unsigned short ntohs( unsigned short netshort )
{
return RtlUshortByteSwap( netshort );
}
static inline unsigned short htons( unsigned short hostshort )
{
return RtlUshortByteSwap( hostshort );
}
static inline unsigned int ntohl( unsigned int netlong )
{
return RtlUlongByteSwap( netlong );
}
static inline unsigned int htonl( unsigned int hostlong )
{
return RtlUlongByteSwap( hostlong );
}
static char *get_fqdn(void)
{
char *ret;
@ -135,7 +153,7 @@ int WINAPI WS_getaddrinfo( const char *node, const char *service,
{
WS_freeaddrinfo( *info );
*info = NULL;
return EAI_NONAME;
return WS_EAI_NONAME;
}
}
}
@ -293,7 +311,7 @@ static int WS_getaddrinfoW( const WCHAR *nodename, const WCHAR *servname,
const struct WS_addrinfo *hints, ADDRINFOEXW **res, OVERLAPPED *overlapped,
LPLOOKUPSERVICE_COMPLETION_ROUTINE completion_routine )
{
int ret = EAI_MEMORY, len, i;
int ret = WS_EAI_MEMORY, len, i;
char *nodenameA = NULL, *servnameA = NULL;
struct WS_addrinfo *resA;
WCHAR *local_nodenameW = (WCHAR *)nodename;
@ -323,7 +341,7 @@ static int WS_getaddrinfoW( const WCHAR *nodename, const WCHAR *servname,
if (!len)
{
ERR("Failed to convert %s to punycode\n", debugstr_w(nodename));
ret = EAI_FAIL;
ret = WS_EAI_FAIL;
goto end;
}
if (!(local_nodenameW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) goto end;
@ -455,7 +473,7 @@ int WINAPI GetAddrInfoW(const WCHAR *nodename, const WCHAR *servname, const ADDR
{
struct WS_addrinfo *hintsA = NULL;
ADDRINFOEXW *resex;
int ret = EAI_MEMORY;
int ret = WS_EAI_MEMORY;
TRACE( "nodename %s, servname %s, hints %p, result %p\n",
debugstr_w(nodename), debugstr_w(servname), hints, res );
@ -570,11 +588,11 @@ int WINAPI GetNameInfoW( const SOCKADDR *addr, WS_socklen_t addr_len, WCHAR *hos
char *hostA = NULL, *servA = NULL;
if (host && (!(hostA = HeapAlloc( GetProcessHeap(), 0, host_len ))))
return EAI_MEMORY;
return WS_EAI_MEMORY;
if (serv && (!(servA = HeapAlloc( GetProcessHeap(), 0, serv_len ))))
{
HeapFree( GetProcessHeap(), 0, hostA );
return EAI_MEMORY;
return WS_EAI_MEMORY;
}
ret = WS_getnameinfo( addr, addr_len, hostA, host_len, servA, serv_len, flags );
@ -683,12 +701,12 @@ struct WS_hostent * WINAPI WS_gethostbyaddr( const char *addr, int len, int fami
struct route
{
struct in_addr addr;
struct WS_in_addr addr;
IF_INDEX interface;
DWORD metric, default_route;
};
static int compare_routes_by_metric_asc( const void *left, const void *right )
static int __cdecl compare_routes_by_metric_asc( const void *left, const void *right )
{
const struct route *a = left, *b = right;
if (a->default_route && b->default_route)
@ -770,7 +788,7 @@ static struct WS_hostent *get_local_ips( char *hostname )
/* If no IP is found in the next step (for whatever reason)
* then fall back to the magic loopback address.
*/
memcpy( &route_addrs[numroutes].addr.s_addr, magic_loopback_addr, 4 );
memcpy( &route_addrs[numroutes].addr.WS_s_addr, magic_loopback_addr, 4 );
numroutes++;
}
if (numroutes == 0)
@ -784,20 +802,20 @@ static struct WS_hostent *get_local_ips( char *hostname )
char *ip = k->IpAddressList.IpAddress.String;
if (route_addrs[i].interface == k->Index)
route_addrs[i].addr.s_addr = inet_addr(ip);
route_addrs[i].addr.WS_s_addr = WS_inet_addr(ip);
}
}
/* Allocate a hostent and enough memory for all the IPs,
* including the NULL at the end of the list.
*/
hostlist = create_hostent( hostname, 1, 0, numroutes+1, sizeof(struct in_addr) );
hostlist = create_hostent( hostname, 1, 0, numroutes+1, sizeof(struct WS_in_addr) );
if (hostlist == NULL)
goto cleanup;
hostlist->h_addr_list[numroutes] = NULL;
hostlist->h_aliases[0] = NULL;
hostlist->h_addrtype = AF_INET;
hostlist->h_length = sizeof(struct in_addr);
hostlist->h_addrtype = WS_AF_INET;
hostlist->h_length = sizeof(struct WS_in_addr);
/* Reorder the entries before placing them in the host list. Windows expects
* the IP list in order from highest priority to lowest (the critical thing
@ -807,7 +825,7 @@ static struct WS_hostent *get_local_ips( char *hostname )
qsort( route_addrs, numroutes, sizeof(struct route), compare_routes_by_metric_asc );
for (i = 0; i < numroutes; i++)
*(struct in_addr *)hostlist->h_addr_list[i] = route_addrs[i].addr;
*(struct WS_in_addr *)hostlist->h_addr_list[i] = route_addrs[i].addr;
cleanup:
HeapFree( GetProcessHeap(), 0, route_addrs );
@ -949,26 +967,20 @@ int WINAPI GetHostNameW( WCHAR *name, int namelen )
static char *read_etc_file( const WCHAR *filename, DWORD *ret_size )
{
static const WCHAR key_pathW[] = {'S','y','s','t','e','m',
'\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t',
'\\','S','e','r','v','i','c','e','s',
'\\','t','c','p','i','p',
'\\','P','a','r','a','m','e','t','e','r','s',0};
static const WCHAR databasepathW[] = {'D','a','t','a','b','a','s','e','P','a','t','h',0};
static const WCHAR backslashW[] = {'\\',0};
WCHAR path[MAX_PATH];
DWORD size = sizeof(path);
HANDLE file;
char *data;
LONG ret;
if ((ret = RegGetValueW( HKEY_LOCAL_MACHINE, key_pathW, databasepathW, RRF_RT_REG_SZ, NULL, path, &size )))
if ((ret = RegGetValueW( HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Services\\tcpip\\Parameters",
L"DatabasePath", RRF_RT_REG_SZ, NULL, path, &size )))
{
ERR( "failed to get database path, error %u\n", ret );
return NULL;
}
lstrcatW( path, backslashW );
lstrcatW( path, filename );
wcscat( path, L"\\" );
wcscat( path, filename );
file = CreateFileW( path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
if (file == INVALID_HANDLE_VALUE)
@ -1133,7 +1145,6 @@ static struct WS_protoent *get_next_protocol( const char **cursor, const char *e
*/
struct WS_protoent * WINAPI WS_getprotobyname( const char *name )
{
static const WCHAR protocolW[] = {'p','r','o','t','o','c','o','l',0};
struct WS_protoent *proto;
const char *cursor;
char *file;
@ -1141,7 +1152,7 @@ struct WS_protoent * WINAPI WS_getprotobyname( const char *name )
TRACE( "%s\n", debugstr_a(name) );
if (!(file = read_etc_file( protocolW, &size )))
if (!(file = read_etc_file( L"protocol", &size )))
{
SetLastError( WSANO_DATA );
return NULL;
@ -1164,7 +1175,6 @@ struct WS_protoent * WINAPI WS_getprotobyname( const char *name )
*/
struct WS_protoent * WINAPI WS_getprotobynumber( int number )
{
static const WCHAR protocolW[] = {'p','r','o','t','o','c','o','l',0};
struct WS_protoent *proto;
const char *cursor;
char *file;
@ -1172,7 +1182,7 @@ struct WS_protoent * WINAPI WS_getprotobynumber( int number )
TRACE( "%d\n", number );
if (!(file = read_etc_file( protocolW, &size )))
if (!(file = read_etc_file( L"protocol", &size )))
{
SetLastError( WSANO_DATA );
return NULL;
@ -1326,7 +1336,6 @@ static struct WS_servent *get_next_service( const char **cursor, const char *end
*/
struct WS_servent * WINAPI WS_getservbyname( const char *name, const char *proto )
{
static const WCHAR servicesW[] = {'s','e','r','v','i','c','e','s',0};
struct WS_servent *serv;
const char *cursor;
char *file;
@ -1334,7 +1343,7 @@ struct WS_servent * WINAPI WS_getservbyname( const char *name, const char *proto
TRACE( "name %s, proto %s\n", debugstr_a(name), debugstr_a(proto) );
if (!(file = read_etc_file( servicesW, &size )))
if (!(file = read_etc_file( L"services", &size )))
{
SetLastError( WSANO_DATA );
return NULL;
@ -1357,7 +1366,6 @@ struct WS_servent * WINAPI WS_getservbyname( const char *name, const char *proto
*/
struct WS_servent * WINAPI WS_getservbyport( int port, const char *proto )
{
static const WCHAR servicesW[] = {'s','e','r','v','i','c','e','s',0};
struct WS_servent *serv;
const char *cursor;
char *file;
@ -1365,7 +1373,7 @@ struct WS_servent * WINAPI WS_getservbyport( int port, const char *proto )
TRACE( "port %d, proto %s\n", port, debugstr_a(proto) );
if (!(file = read_etc_file( servicesW, &size )))
if (!(file = read_etc_file( L"services", &size )))
{
SetLastError( WSANO_DATA );
return NULL;

View File

@ -26,11 +26,18 @@
* clients and servers (www.winsite.com got a lot of those).
*/
#include "config.h"
#include "wine/port.h"
#include "ws2_32_private.h"
static inline unsigned short ntohs( unsigned short netshort )
{
return RtlUshortByteSwap( netshort );
}
static inline unsigned int ntohl( unsigned int netlong )
{
return RtlUlongByteSwap( netlong );
}
#define FILE_USE_FILE_POINTER_POSITION ((LONGLONG)-2)
WINE_DEFAULT_DEBUG_CHANNEL(winsock);
@ -53,7 +60,7 @@ static const WSAPROTOCOL_INFOW supported_protocols[] =
.iMinSockAddr = sizeof(struct WS_sockaddr_in),
.iSocketType = WS_SOCK_STREAM,
.iProtocol = WS_IPPROTO_TCP,
.szProtocol = {'T','C','P','/','I','P',0},
.szProtocol = L"TCP/IP",
},
{
.dwServiceFlags1 = XP1_IFS_HANDLES | XP1_SUPPORT_BROADCAST
@ -69,7 +76,7 @@ static const WSAPROTOCOL_INFOW supported_protocols[] =
.iSocketType = WS_SOCK_DGRAM,
.iProtocol = WS_IPPROTO_UDP,
.dwMessageSize = 0xffbb,
.szProtocol = {'U','D','P','/','I','P',0},
.szProtocol = L"UDP/IP",
},
{
.dwServiceFlags1 = XP1_IFS_HANDLES | XP1_EXPEDITED_DATA | XP1_GRACEFUL_CLOSE
@ -84,7 +91,7 @@ static const WSAPROTOCOL_INFOW supported_protocols[] =
.iMinSockAddr = sizeof(struct WS_sockaddr_in6),
.iSocketType = WS_SOCK_STREAM,
.iProtocol = WS_IPPROTO_TCP,
.szProtocol = {'T','C','P','/','I','P','v','6',0},
.szProtocol = L"TCP/IPv6",
},
{
.dwServiceFlags1 = XP1_IFS_HANDLES | XP1_SUPPORT_BROADCAST
@ -100,7 +107,7 @@ static const WSAPROTOCOL_INFOW supported_protocols[] =
.iSocketType = WS_SOCK_DGRAM,
.iProtocol = WS_IPPROTO_UDP,
.dwMessageSize = 0xffbb,
.szProtocol = {'U','D','P','/','I','P','v','6',0},
.szProtocol = L"UDP/IPv6",
},
{
.dwServiceFlags1 = XP1_PARTIAL_MESSAGE | XP1_SUPPORT_BROADCAST
@ -117,7 +124,7 @@ static const WSAPROTOCOL_INFOW supported_protocols[] =
.iProtocol = WS_NSPROTO_IPX,
.iProtocolMaxOffset = 255,
.dwMessageSize = 0x240,
.szProtocol = {'I','P','X',0},
.szProtocol = L"IPX",
},
{
.dwServiceFlags1 = XP1_IFS_HANDLES | XP1_PSEUDO_STREAM | XP1_MESSAGE_ORIENTED
@ -133,7 +140,7 @@ static const WSAPROTOCOL_INFOW supported_protocols[] =
.iSocketType = WS_SOCK_SEQPACKET,
.iProtocol = WS_NSPROTO_SPX,
.dwMessageSize = UINT_MAX,
.szProtocol = {'S','P','X',0},
.szProtocol = L"SPX",
},
{
.dwServiceFlags1 = XP1_IFS_HANDLES | XP1_GRACEFUL_CLOSE | XP1_PSEUDO_STREAM
@ -149,7 +156,7 @@ static const WSAPROTOCOL_INFOW supported_protocols[] =
.iSocketType = WS_SOCK_SEQPACKET,
.iProtocol = WS_NSPROTO_SPXII,
.dwMessageSize = UINT_MAX,
.szProtocol = {'S','P','X',' ','I','I',0},
.szProtocol = L"SPX II",
},
};
@ -1388,9 +1395,9 @@ INT WINAPI WS_getsockopt(SOCKET s, INT level,
return -1;
if (infow.iAddressFamily == WS_AF_INET)
addr_size = sizeof(struct sockaddr_in);
addr_size = sizeof(struct WS_sockaddr_in);
else if (infow.iAddressFamily == WS_AF_INET6)
addr_size = sizeof(struct sockaddr_in6);
addr_size = sizeof(struct WS_sockaddr_in6);
else
{
FIXME( "family %d is unsupported for SO_BSP_STATE\n", infow.iAddressFamily );
@ -1507,7 +1514,7 @@ INT WINAPI WS_getsockopt(SOCKET s, INT level,
if (!ws_protocol_info( s, TRUE, &info, &size ))
return -1;
if (info.iSocketType == SOCK_DGRAM)
if (info.iSocketType == WS_SOCK_DGRAM)
{
SetLastError( WSAENOPROTOOPT );
return -1;
@ -2061,7 +2068,7 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
sockaddr[i].sin_family = WS_AF_INET;
sockaddr[i].sin_port = 0;
sockaddr[i].sin_addr.WS_s_addr = inet_addr(p->IpAddressList.IpAddress.String);
sockaddr[i].sin_addr.WS_s_addr = WS_inet_addr(p->IpAddressList.IpAddress.String);
i++;
}
@ -3222,7 +3229,6 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
LPWSAPROTOCOL_INFOW lpProtocolInfo,
GROUP g, DWORD flags)
{
static const WCHAR afdW[] = {'\\','D','e','v','i','c','e','\\','A','f','d',0};
struct afd_create_params create_params;
OBJECT_ATTRIBUTES attr;
UNICODE_STRING string;
@ -3302,7 +3308,7 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
}
}
RtlInitUnicodeString(&string, afdW);
RtlInitUnicodeString(&string, L"\\Device\\Afd");
InitializeObjectAttributes(&attr, &string, (flags & WSA_FLAG_NO_HANDLE_INHERIT) ? 0 : OBJ_INHERIT, NULL, NULL);
if ((status = NtOpenFile(&handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &attr,
&io, 0, (flags & WSA_FLAG_OVERLAPPED) ? 0 : FILE_SYNCHRONOUS_IO_NONALERT)))
@ -3323,7 +3329,7 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
err = RtlNtStatusToDosError( status );
if (err == WSAEACCES) /* raw socket denied */
{
if (type == SOCK_RAW)
if (type == WS_SOCK_RAW)
ERR_(winediag)("Failed to create a socket of type SOCK_RAW, this requires special permissions.\n");
else
ERR_(winediag)("Failed to create socket, this requires special permissions.\n");

View File

@ -38,6 +38,40 @@
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#ifdef HAVE_SYS_SOCKIO_H
# include <sys/sockio.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_NETINET_TCP_H
# include <netinet/tcp.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#ifdef HAVE_NET_IF_H
# define if_indextoname unix_if_indextoname
# define if_nametoindex unix_if_nametoindex
# include <net/if.h>
# undef if_indextoname
# undef if_nametoindex
#endif
#ifdef HAVE_IFADDRS_H
# include <ifaddrs.h>
#endif
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
#ifdef HAVE_SYS_POLL_H
# include <sys/poll.h>
#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#ifdef HAVE_NETIPX_IPX_H
# include <netipx/ipx.h>

View File

@ -22,109 +22,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <limits.h>
#ifdef HAVE_SYS_IPC_H
# include <sys/ipc.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_FILIO_H
# include <sys/filio.h>
#endif
#ifdef HAVE_SYS_SOCKIO_H
# include <sys/sockio.h>
#endif
#if defined(__EMX__)
# include <sys/so_ioctl.h>
#endif
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#ifdef HAVE_SYS_MSG_H
# include <sys/msg.h>
#endif
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#ifdef HAVE_SYS_UIO_H
# include <sys/uio.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_NETINET_TCP_H
# include <netinet/tcp.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#include <ctype.h>
#include <fcntl.h>
#include <errno.h>
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <stdlib.h>
#ifdef HAVE_ARPA_NAMESER_H
# include <arpa/nameser.h>
#endif
#ifdef HAVE_RESOLV_H
# include <resolv.h>
#endif
#ifdef HAVE_NET_IF_H
# define if_indextoname unix_if_indextoname
# define if_nametoindex unix_if_nametoindex
# include <net/if.h>
# undef if_indextoname
# undef if_nametoindex
#endif
#ifdef HAVE_IFADDRS_H
# include <ifaddrs.h>
#endif
#ifdef HAVE_NETIPX_IPX_H
# include <netipx/ipx.h>
#elif defined(HAVE_LINUX_IPX_H)
# ifdef HAVE_ASM_TYPES_H
# include <asm/types.h>
# endif
# ifdef HAVE_LINUX_TYPES_H
# include <linux/types.h>
# endif
# include <linux/ipx.h>
#endif
#if defined(SOL_IPX) || defined(SO_DEFAULT_HEADERS)
# define HAS_IPX
#endif
#ifdef HAVE_LINUX_IRDA_H
# ifdef HAVE_LINUX_TYPES_H
# include <linux/types.h>
# endif
# include <linux/irda.h>
# define HAS_IRDA
#endif
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
#ifdef HAVE_SYS_POLL_H
# include <sys/poll.h>
#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
@ -153,7 +51,6 @@
#include "wine/server.h"
#include "wine/debug.h"
#include "wine/exception.h"
#include "wine/unicode.h"
#include "wine/heap.h"
#define DECLARE_CRITICAL_SECTION(cs) \