Commit 6b4399e3 authored by Alexandre Julliard's avatar Alexandre Julliard

ws2_32: Make htonl/htons/ntohl/ntohs proper functions.

parent 91e54e5f
MODULE = inetmib1.dll
IMPORTS = snmpapi
IMPORTS = snmpapi ws2_32
DELAYIMPORTS = iphlpapi
C_SRCS = \
......
MODULE = iphlpapi.dll
IMPORTLIB = iphlpapi
IMPORTS = advapi32 dnsapi nsi uuid
IMPORTS = advapi32 dnsapi nsi uuid ws2_32
C_SRCS = \
iphlpapi_main.c
......
TESTDLL = iphlpapi.dll
IMPORTS = iphlpapi
IMPORTS = iphlpapi ws2_32
C_SRCS = \
iphlpapi.c
......@@ -40,6 +40,9 @@
WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
WINE_DECLARE_DEBUG_CHANNEL(debugstr);
#define htons(x) RtlUshortByteSwap(x)
#define ntohs(x) RtlUshortByteSwap(x)
/* CRC polynomial 0xedb88320 */
static const DWORD CRC_table[256] =
{
......
......@@ -40,6 +40,11 @@
#include "utils.h"
#define htonl(x) RtlUlongByteSwap(x)
#define htons(x) RtlUshortByteSwap(x)
#define ntohl(x) RtlUlongByteSwap(x)
#define ntohs(x) RtlUshortByteSwap(x)
static DRIVER_OBJECT *driver_obj;
static DEVICE_OBJECT *device_obj;
......@@ -148,7 +153,7 @@ static void test_wsk_get_address_info(void)
ok(addr_info->ai_addrlen == sizeof(*addr), "Got unexpected ai_addrlen %I64u.\n", (UINT64)addr_info->ai_addrlen);
ok(addr->sin_family == AF_INET, "Got unexpected sin_family %u.\n", addr->sin_family);
ok(ntohs(addr->sin_port) == 12345, "Got unexpected sin_port %u.\n", ntohs(addr->sin_port));
ok(ntohl(addr->sin_addr.s_addr) == 0x7f000001, "Got unexpected sin_addr %#lx.\n",
ok(ntohl(addr->sin_addr.s_addr) == INADDR_LOOPBACK, "Got unexpected sin_addr %#lx.\n",
ntohl(addr->sin_addr.s_addr));
++count;
......@@ -308,12 +313,12 @@ static void test_wsk_listen_socket(void)
ok(local_addr.sin_family == AF_INET, "Got unexpected sin_family %u.\n", local_addr.sin_family);
ok(local_addr.sin_port == htons(SERVER_LISTEN_PORT), "Got unexpected sin_port %u.\n",
ntohs(local_addr.sin_port));
ok(local_addr.sin_addr.s_addr == htonl(0x7f000001), "Got unexpected sin_addr %#lx.\n",
ok(local_addr.sin_addr.s_addr == htonl(INADDR_LOOPBACK), "Got unexpected sin_addr %#lx.\n",
ntohl(local_addr.sin_addr.s_addr));
ok(remote_addr.sin_family == AF_INET, "Got unexpected sin_family %u.\n", remote_addr.sin_family);
ok(remote_addr.sin_port, "Got zero sin_port.\n");
ok(remote_addr.sin_addr.s_addr == htonl(0x7f000001), "Got unexpected sin_addr %#lx.\n",
ok(remote_addr.sin_addr.s_addr == htonl(INADDR_LOOPBACK), "Got unexpected sin_addr %#lx.\n",
ntohl(remote_addr.sin_addr.s_addr));
accept_socket = (WSK_SOCKET *)wsk_irp->IoStatus.Information;
......@@ -415,7 +420,7 @@ static void test_wsk_connect_socket(void)
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(CLIENT_LISTEN_PORT);
addr.sin_addr.s_addr = htonl(0x7f000001);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
IoReuseIrp(wsk_irp, STATUS_UNSUCCESSFUL);
IoSetCompletionRoutine(wsk_irp, irp_completion_routine, &irp_complete_event, TRUE, TRUE, TRUE);
......@@ -443,7 +448,7 @@ static void test_wsk_connect_socket(void)
wsk_irp->IoStatus.Information);
addr.sin_port = htons(CLIENT_LISTEN_PORT);
addr.sin_addr.s_addr = htonl(0x7f000001);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
IoReuseIrp(wsk_irp, STATUS_UNSUCCESSFUL);
IoSetCompletionRoutine(wsk_irp, irp_completion_routine, &irp_complete_event, TRUE, TRUE, TRUE);
......
......@@ -1895,18 +1895,18 @@ u_long WINAPI inet_addr( const char *str )
/***********************************************************************
* htonl (ws2_32.8)
*/
u_long WINAPI WS_htonl( u_long hostlong )
u_long WINAPI htonl( u_long hostlong )
{
return htonl( hostlong );
return RtlUlongByteSwap( hostlong );
}
/***********************************************************************
* htons (ws2_32.9)
*/
u_short WINAPI WS_htons( u_short hostshort )
u_short WINAPI htons( u_short hostshort )
{
return htons( hostshort );
return RtlUshortByteSwap( hostshort );
}
......@@ -1943,18 +1943,18 @@ int WINAPI WSAHtons( SOCKET s, u_short hostshort, u_short *netshort )
/***********************************************************************
* ntohl (ws2_32.14)
*/
u_long WINAPI WS_ntohl( u_long netlong )
u_long WINAPI ntohl( u_long netlong )
{
return ntohl( netlong );
return RtlUlongByteSwap( netlong );
}
/***********************************************************************
* ntohs (ws2_32.15)
*/
u_short WINAPI WS_ntohs( u_short netshort )
u_short WINAPI ntohs( u_short netshort )
{
return ntohs( netshort );
return RtlUshortByteSwap( netshort );
}
......
......@@ -5,14 +5,14 @@
5 stdcall getpeername(long ptr ptr)
6 stdcall getsockname(long ptr ptr)
7 stdcall getsockopt(long long long ptr ptr)
8 stdcall htonl(long) WS_htonl
9 stdcall htons(long) WS_htons
8 stdcall htonl(long)
9 stdcall htons(long)
10 stdcall ioctlsocket(long long ptr)
11 stdcall inet_addr(str)
12 stdcall inet_ntoa(ptr)
13 stdcall listen(long long)
14 stdcall ntohl(long) WS_ntohl
15 stdcall ntohs(long) WS_ntohs
14 stdcall ntohl(long)
15 stdcall ntohs(long)
16 stdcall recv(long ptr long long)
17 stdcall recvfrom(long ptr long long ptr ptr)
18 stdcall select(long ptr ptr ptr ptr)
......
......@@ -480,48 +480,6 @@ WINSOCK_API_LINKAGE int WINAPI __WSAFDIsSet(SOCKET,WS(fd_set)*);
#endif /* WS_DEFINE_SELECT */
/* we have to define hton/ntoh as macros to avoid conflicts with Unix headers */
#ifndef USE_WS_PREFIX
#undef htonl
#undef htons
#undef ntohl
#undef ntohs
#ifdef WORDS_BIGENDIAN
static inline u_short __wine_ushort_noop(u_short s)
{
return s;
}
static inline ULONG __wine_ulong_noop(ULONG l)
{
return l;
}
#define htonl __wine_ulong_noop
#define htons __wine_ushort_noop
#define ntohl __wine_ulong_noop
#define ntohs __wine_ushort_noop
#else /* WORDS_BIGENDIAN */
static inline u_short __wine_ushort_swap(u_short s)
{
return (s >> 8) | (s << 8);
}
static inline ULONG __wine_ulong_swap(ULONG l)
{
return ((ULONG)__wine_ushort_swap((u_short)l) << 16) | __wine_ushort_swap((u_short)(l >> 16));
}
#define htonl __wine_ulong_swap
#define htons __wine_ushort_swap
#define ntohl __wine_ulong_swap
#define ntohs __wine_ushort_swap
#endif /* WORDS_BIGENDIAN */
#endif /* USE_WS_PREFIX */
/*
* Internet address (old style... should be updated)
*/
......@@ -966,10 +924,14 @@ WINSOCK_API_LINKAGE struct WS(servent)* WINAPI WS(getservbyname)(const char*,con
WINSOCK_API_LINKAGE struct WS(servent)* WINAPI WS(getservbyport)(int,const char*);
WINSOCK_API_LINKAGE int WINAPI WS(getsockname)(SOCKET,struct WS(sockaddr)*,int*);
WINSOCK_API_LINKAGE int WINAPI WS(getsockopt)(SOCKET,int,int,char*,int*);
WINSOCK_API_LINKAGE ULONG WINAPI WS(htonl)(ULONG);
WINSOCK_API_LINKAGE WS(u_short) WINAPI WS(htons)(WS(u_short));
WINSOCK_API_LINKAGE ULONG WINAPI WS(inet_addr)(const char*);
WINSOCK_API_LINKAGE char* WINAPI WS(inet_ntoa)(struct WS(in_addr));
WINSOCK_API_LINKAGE int WINAPI WS(ioctlsocket)(SOCKET,LONG,ULONG*);
WINSOCK_API_LINKAGE int WINAPI WS(listen)(SOCKET,int);
WINSOCK_API_LINKAGE ULONG WINAPI WS(ntohl)(ULONG);
WINSOCK_API_LINKAGE WS(u_short) WINAPI WS(ntohs)(WS(u_short));
WINSOCK_API_LINKAGE int WINAPI WS(recv)(SOCKET,char*,int,int);
WINSOCK_API_LINKAGE int WINAPI WS(recvfrom)(SOCKET,char*,int,int,struct WS(sockaddr)*,int*);
WINSOCK_API_LINKAGE int WINAPI WS(send)(SOCKET,const char*,int,int);
......
......@@ -1001,46 +1001,6 @@ typedef struct WSAData
#endif
} WSADATA, *LPWSADATA;
#ifndef USE_WS_PREFIX
#undef htonl
#undef htons
#undef ntohl
#undef ntohs
#ifdef WORDS_BIGENDIAN
static inline u_short __wine_ushort_noop(u_short s)
{
return s;
}
static inline ULONG __wine_ulong_noop(ULONG l)
{
return l;
}
#define htonl __wine_ulong_noop
#define htons __wine_ushort_noop
#define ntohl __wine_ulong_noop
#define ntohs __wine_ushort_noop
#else /* WORDS_BIGENDIAN */
static inline u_short __wine_ushort_swap(u_short s)
{
return (s >> 8) | (s << 8);
}
static inline ULONG __wine_ulong_swap(ULONG l)
{
return ((ULONG)__wine_ushort_swap((u_short)l) << 16) | __wine_ushort_swap((u_short)(l >> 16));
}
#define htonl __wine_ulong_swap
#define htons __wine_ushort_swap
#define ntohl __wine_ulong_swap
#define ntohs __wine_ushort_swap
#endif /* WORDS_BIGENDIAN */
#endif /* USE_WS_PREFIX */
#define WSAMAKEASYNCREPLY(size, error) MAKELONG(size, error)
#define WSAMAKESELECTREPLY(flags, error) MAKELONG(flags, error)
#define WSAGETASYNCBUFLEN(x) LOWORD(x)
......@@ -1134,10 +1094,14 @@ WINSOCK_API_LINKAGE struct WS(servent) * WINAPI WS(getservbyname)(const char *,
WINSOCK_API_LINKAGE struct WS(servent) * WINAPI WS(getservbyport)(int, const char *);
WINSOCK_API_LINKAGE int WINAPI WS(getsockname)(SOCKET, struct WS(sockaddr) *, int *);
WINSOCK_API_LINKAGE int WINAPI WS(getsockopt)(SOCKET, int, int, char *, int *);
WINSOCK_API_LINKAGE ULONG WINAPI WS(htonl)(ULONG);
WINSOCK_API_LINKAGE WS(u_short) WINAPI WS(htons)(WS(u_short));
WINSOCK_API_LINKAGE ULONG WINAPI WS(inet_addr)(const char *);
WINSOCK_API_LINKAGE char * WINAPI WS(inet_ntoa)(struct WS(in_addr));
WINSOCK_API_LINKAGE int WINAPI WS(ioctlsocket)(SOCKET, LONG, WS(u_long) *);
WINSOCK_API_LINKAGE int WINAPI WS(listen)(SOCKET, int);
WINSOCK_API_LINKAGE ULONG WINAPI WS(ntohl)(ULONG);
WINSOCK_API_LINKAGE WS(u_short) WINAPI WS(ntohs)(WS(u_short));
WINSOCK_API_LINKAGE int WINAPI WS(recv)(SOCKET, char *, int, int);
WINSOCK_API_LINKAGE int WINAPI WS(recvfrom)(SOCKET, char *, int, int, struct WS(sockaddr) *, int *);
#ifdef WS_DEFINE_SELECT
......
......@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <windef.h>
#include <winerror.h>
#include <winsock.h>
#include <sspi.h>
#include <rpc.h>
#include <sasl.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment