mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 17:12:58 +00:00
[IPHLPAPI] icmp.c: Restore sync after Wine Staging 1.7.55
Mark all our (new) differences.
This commit is contained in:
parent
bda22774a7
commit
9f5f7a97f8
1 changed files with 97 additions and 9 deletions
|
@ -32,7 +32,57 @@
|
||||||
* - Using the winsock functions has not been tested.
|
* - Using the winsock functions has not been tested.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef __REACTOS__
|
||||||
#include "iphlpapi_private.h"
|
#include "iphlpapi_private.h"
|
||||||
|
#else // ! __REACTOS__
|
||||||
|
#include "config.h"
|
||||||
|
#include "wine/port.h"
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#ifdef HAVE_SYS_SOCKET_H
|
||||||
|
# include <sys/socket.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_NETDB_H
|
||||||
|
# include <netdb.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_NETINET_IN_SYSTM_H
|
||||||
|
# include <netinet/in_systm.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_NETINET_IN_H
|
||||||
|
# include <netinet/in.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
# include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
# include <unistd.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_ARPA_INET_H
|
||||||
|
# include <arpa/inet.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_POLL_H
|
||||||
|
# include <sys/poll.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_WAIT_H
|
||||||
|
# include <sys/wait.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define USE_WS_PREFIX
|
||||||
|
|
||||||
|
#include "windef.h"
|
||||||
|
#include "winbase.h"
|
||||||
|
#include "winerror.h"
|
||||||
|
#include "winternl.h"
|
||||||
|
#include "ipexport.h"
|
||||||
|
#include "icmpapi.h"
|
||||||
|
#include "wine/debug.h"
|
||||||
|
#endif // ! __REACTOS__
|
||||||
|
|
||||||
/* Set up endianness macros for the ip and ip_icmp BSD headers */
|
/* Set up endianness macros for the ip and ip_icmp BSD headers */
|
||||||
#ifndef BIG_ENDIAN
|
#ifndef BIG_ENDIAN
|
||||||
|
@ -114,8 +164,8 @@ static int in_cksum(u_short *addr, int len)
|
||||||
HANDLE WINAPI Icmp6CreateFile(VOID)
|
HANDLE WINAPI Icmp6CreateFile(VOID)
|
||||||
{
|
{
|
||||||
icmp_t* icp;
|
icmp_t* icp;
|
||||||
int sid;
|
|
||||||
#ifdef __REACTOS__
|
#ifdef __REACTOS__
|
||||||
|
int sid;
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
|
|
||||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != ERROR_SUCCESS)
|
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != ERROR_SUCCESS)
|
||||||
|
@ -123,10 +173,11 @@ HANDLE WINAPI Icmp6CreateFile(VOID)
|
||||||
ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n");
|
ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n");
|
||||||
return INVALID_HANDLE_VALUE;
|
return INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
sid=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6);
|
sid=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6);
|
||||||
#ifndef __REACTOS__
|
#else
|
||||||
|
|
||||||
|
int sid=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6);
|
||||||
if (sid < 0)
|
if (sid < 0)
|
||||||
{
|
{
|
||||||
/* Mac OS X supports non-privileged ICMP via SOCK_DGRAM type. */
|
/* Mac OS X supports non-privileged ICMP via SOCK_DGRAM type. */
|
||||||
|
@ -191,8 +242,8 @@ HANDLE WINAPI IcmpCreateFile(VOID)
|
||||||
static int once;
|
static int once;
|
||||||
#endif
|
#endif
|
||||||
icmp_t* icp;
|
icmp_t* icp;
|
||||||
int sid;
|
|
||||||
#ifdef __REACTOS__
|
#ifdef __REACTOS__
|
||||||
|
int sid;
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
|
|
||||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != ERROR_SUCCESS)
|
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != ERROR_SUCCESS)
|
||||||
|
@ -200,15 +251,15 @@ HANDLE WINAPI IcmpCreateFile(VOID)
|
||||||
ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n");
|
ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n");
|
||||||
return INVALID_HANDLE_VALUE;
|
return INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
sid=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP);
|
sid=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP);
|
||||||
#ifdef __REACTOS__
|
|
||||||
if (sid < 0) {
|
if (sid < 0) {
|
||||||
ERR_(winediag)("Failed to use ICMP (network ping), this requires special permissions.\n");
|
ERR_(winediag)("Failed to use ICMP (network ping), this requires special permissions.\n");
|
||||||
SetLastError(ERROR_ACCESS_DENIED);
|
SetLastError(ERROR_ACCESS_DENIED);
|
||||||
return INVALID_HANDLE_VALUE;
|
return INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
int sid=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP);
|
||||||
if (sid < 0)
|
if (sid < 0)
|
||||||
{
|
{
|
||||||
/* Mac OS X supports non-privileged ICMP via SOCK_DGRAM type. */
|
/* Mac OS X supports non-privileged ICMP via SOCK_DGRAM type. */
|
||||||
|
@ -243,8 +294,12 @@ HANDLE WINAPI IcmpCreateFile(VOID)
|
||||||
BOOL WINAPI IcmpCloseHandle(HANDLE IcmpHandle)
|
BOOL WINAPI IcmpCloseHandle(HANDLE IcmpHandle)
|
||||||
{
|
{
|
||||||
icmp_t* icp=(icmp_t*)IcmpHandle;
|
icmp_t* icp=(icmp_t*)IcmpHandle;
|
||||||
|
#ifdef __REACTOS__
|
||||||
// REACTOS: Added a check for NULL handle, CORE-10707
|
// REACTOS: Added a check for NULL handle, CORE-10707
|
||||||
if (IcmpHandle==INVALID_HANDLE_VALUE || IcmpHandle==NULL) {
|
if (IcmpHandle==INVALID_HANDLE_VALUE || IcmpHandle==NULL) {
|
||||||
|
#else
|
||||||
|
if (IcmpHandle==INVALID_HANDLE_VALUE) {
|
||||||
|
#endif
|
||||||
/* FIXME: in fact win98 seems to ignore the handle value !!! */
|
/* FIXME: in fact win98 seems to ignore the handle value !!! */
|
||||||
SetLastError(ERROR_INVALID_HANDLE);
|
SetLastError(ERROR_INVALID_HANDLE);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -494,8 +549,7 @@ static DWORD system_icmp(
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#else // __REACTOS__
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
GetIPv4ByIndex(
|
GetIPv4ByIndex(
|
||||||
_In_ DWORD Index,
|
_In_ DWORD Index,
|
||||||
|
@ -529,6 +583,7 @@ GetIPv4ByIndex(
|
||||||
HeapFree(GetProcessHeap(), 0, pIpAddrTable);
|
HeapFree(GetProcessHeap(), 0, pIpAddrTable);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#endif // __REACTOS__
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* IcmpSendEcho (IPHLPAPI.@)
|
* IcmpSendEcho (IPHLPAPI.@)
|
||||||
|
@ -572,6 +627,7 @@ DWORD WINAPI IcmpSendEcho(
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __REACTOS__
|
||||||
if (ReplySize<sizeof(ICMP_ECHO_REPLY)) {
|
if (ReplySize<sizeof(ICMP_ECHO_REPLY)) {
|
||||||
SetLastError(ERROR_INVALID_PARAMETER);
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -589,6 +645,10 @@ DWORD WINAPI IcmpSendEcho(
|
||||||
|
|
||||||
if (Timeout == 0 || Timeout == -1) {
|
if (Timeout == 0 || Timeout == -1) {
|
||||||
SetLastError(ERROR_INVALID_PARAMETER);
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
|
#else
|
||||||
|
if (ReplySize<sizeof(ICMP_ECHO_REPLY)+ICMP_MINLEN) {
|
||||||
|
SetLastError(IP_BUF_TOO_SMALL);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* check the request size against SO_MAX_MSG_SIZE using getsockopt */
|
/* check the request size against SO_MAX_MSG_SIZE using getsockopt */
|
||||||
|
@ -614,9 +674,13 @@ DWORD WINAPI IcmpSendEcho(
|
||||||
#endif
|
#endif
|
||||||
seq=InterlockedIncrement(&icmp_sequence) & 0xFFFF;
|
seq=InterlockedIncrement(&icmp_sequence) & 0xFFFF;
|
||||||
|
|
||||||
|
#ifdef __REACTOS__
|
||||||
reqsize=ICMP_MINLEN;
|
reqsize=ICMP_MINLEN;
|
||||||
if (RequestData && RequestSize > 0)
|
if (RequestData && RequestSize > 0)
|
||||||
reqsize += RequestSize;
|
reqsize += RequestSize;
|
||||||
|
#else
|
||||||
|
reqsize=ICMP_MINLEN+RequestSize;
|
||||||
|
#endif
|
||||||
reqbuf=HeapAlloc(GetProcessHeap(), 0, reqsize);
|
reqbuf=HeapAlloc(GetProcessHeap(), 0, reqsize);
|
||||||
if (reqbuf==NULL) {
|
if (reqbuf==NULL) {
|
||||||
SetLastError(ERROR_OUTOFMEMORY);
|
SetLastError(ERROR_OUTOFMEMORY);
|
||||||
|
@ -629,8 +693,12 @@ DWORD WINAPI IcmpSendEcho(
|
||||||
icmp_header->icmp_cksum=0;
|
icmp_header->icmp_cksum=0;
|
||||||
icmp_header->icmp_id=id;
|
icmp_header->icmp_id=id;
|
||||||
icmp_header->icmp_seq=seq;
|
icmp_header->icmp_seq=seq;
|
||||||
|
#ifdef __REACTOS__
|
||||||
if (RequestData && RequestSize > 0)
|
if (RequestData && RequestSize > 0)
|
||||||
memcpy(reqbuf+ICMP_MINLEN, RequestData, RequestSize);
|
memcpy(reqbuf+ICMP_MINLEN, RequestData, RequestSize);
|
||||||
|
#else
|
||||||
|
memcpy(reqbuf+ICMP_MINLEN, RequestData, RequestSize);
|
||||||
|
#endif
|
||||||
icmp_header->icmp_cksum=cksum=in_cksum((u_short*)reqbuf,reqsize);
|
icmp_header->icmp_cksum=cksum=in_cksum((u_short*)reqbuf,reqsize);
|
||||||
|
|
||||||
addr.sin_family=AF_INET;
|
addr.sin_family=AF_INET;
|
||||||
|
@ -686,8 +754,14 @@ DWORD WINAPI IcmpSendEcho(
|
||||||
#endif
|
#endif
|
||||||
addrlen=sizeof(addr);
|
addrlen=sizeof(addr);
|
||||||
ier=ReplyBuffer;
|
ier=ReplyBuffer;
|
||||||
|
#ifdef __REACTOS__
|
||||||
endbuf=((char *) ReplyBuffer)+ReplySize;
|
endbuf=((char *) ReplyBuffer)+ReplySize;
|
||||||
maxlen=sizeof(struct ip)+ICMP_MINLEN+RequestSize;
|
maxlen=sizeof(struct ip)+ICMP_MINLEN+RequestSize;
|
||||||
|
#else
|
||||||
|
ip_header=(struct ip *) ((char *) ReplyBuffer+sizeof(ICMP_ECHO_REPLY));
|
||||||
|
endbuf=(char *) ReplyBuffer+ReplySize;
|
||||||
|
maxlen=ReplySize-sizeof(ICMP_ECHO_REPLY);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Send the packet */
|
/* Send the packet */
|
||||||
TRACE("Sending %d bytes (RequestSize=%d) to %s\n", reqsize, RequestSize, inet_ntoa(addr.sin_addr));
|
TRACE("Sending %d bytes (RequestSize=%d) to %s\n", reqsize, RequestSize, inet_ntoa(addr.sin_addr));
|
||||||
|
@ -710,6 +784,7 @@ DWORD WINAPI IcmpSendEcho(
|
||||||
#endif
|
#endif
|
||||||
HeapFree(GetProcessHeap (), 0, reqbuf);
|
HeapFree(GetProcessHeap (), 0, reqbuf);
|
||||||
if (res<0) {
|
if (res<0) {
|
||||||
|
#ifdef __REACTOS__
|
||||||
DWORD dwBestIfIndex;
|
DWORD dwBestIfIndex;
|
||||||
IPAddr IP4Addr;
|
IPAddr IP4Addr;
|
||||||
|
|
||||||
|
@ -721,7 +796,6 @@ DWORD WINAPI IcmpSendEcho(
|
||||||
memcpy(&ier->Address, &IP4Addr, sizeof(IP4Addr));
|
memcpy(&ier->Address, &IP4Addr, sizeof(IP4Addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __REACTOS__
|
|
||||||
if (WSAGetLastError()==WSAEMSGSIZE)
|
if (WSAGetLastError()==WSAEMSGSIZE)
|
||||||
ier->Status = IP_PACKET_TOO_BIG;
|
ier->Status = IP_PACKET_TOO_BIG;
|
||||||
else {
|
else {
|
||||||
|
@ -760,7 +834,9 @@ DWORD WINAPI IcmpSendEcho(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the reply */
|
/* Get the reply */
|
||||||
|
#ifdef __REACTOS__
|
||||||
ip_header=HeapAlloc(GetProcessHeap(), 0, maxlen);
|
ip_header=HeapAlloc(GetProcessHeap(), 0, maxlen);
|
||||||
|
#endif
|
||||||
ip_header_len=0; /* because gcc was complaining */
|
ip_header_len=0; /* because gcc was complaining */
|
||||||
#ifdef __REACTOS__
|
#ifdef __REACTOS__
|
||||||
while ((res=select(icp->sid+1,&fdr,NULL,NULL,&timeout))>0) {
|
while ((res=select(icp->sid+1,&fdr,NULL,NULL,&timeout))>0) {
|
||||||
|
@ -775,8 +851,10 @@ DWORD WINAPI IcmpSendEcho(
|
||||||
#endif
|
#endif
|
||||||
TRACE("received %d bytes from %s\n",res, inet_ntoa(addr.sin_addr));
|
TRACE("received %d bytes from %s\n",res, inet_ntoa(addr.sin_addr));
|
||||||
ier->Status=IP_REQ_TIMED_OUT;
|
ier->Status=IP_REQ_TIMED_OUT;
|
||||||
|
#ifdef __REACTOS__
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Check whether we should ignore this packet */
|
/* Check whether we should ignore this packet */
|
||||||
if ((ip_header->ip_p==IPPROTO_ICMP) && (res>=sizeof(struct ip)+ICMP_MINLEN)) {
|
if ((ip_header->ip_p==IPPROTO_ICMP) && (res>=sizeof(struct ip)+ICMP_MINLEN)) {
|
||||||
|
@ -905,6 +983,10 @@ DWORD WINAPI IcmpSendEcho(
|
||||||
|
|
||||||
/* Prepare for the next packet */
|
/* Prepare for the next packet */
|
||||||
ier++;
|
ier++;
|
||||||
|
#ifndef __REACTOS__
|
||||||
|
ip_header=(struct ip*)(((char*)ip_header)+sizeof(ICMP_ECHO_REPLY));
|
||||||
|
maxlen=endbuf-(char*)ip_header;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Check out whether there is more but don't wait this time */
|
/* Check out whether there is more but don't wait this time */
|
||||||
#ifdef __REACTOS__
|
#ifdef __REACTOS__
|
||||||
|
@ -919,13 +1001,19 @@ DWORD WINAPI IcmpSendEcho(
|
||||||
FD_SET(icp->sid,&fdr);
|
FD_SET(icp->sid,&fdr);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#ifdef __REACTOS__
|
||||||
HeapFree(GetProcessHeap(), 0, ip_header);
|
HeapFree(GetProcessHeap(), 0, ip_header);
|
||||||
|
#endif
|
||||||
res=ier-(ICMP_ECHO_REPLY*)ReplyBuffer;
|
res=ier-(ICMP_ECHO_REPLY*)ReplyBuffer;
|
||||||
if (res==0)
|
if (res==0)
|
||||||
|
#ifdef __REACTOS__
|
||||||
{
|
{
|
||||||
ier->Status = IP_REQ_TIMED_OUT;
|
ier->Status = IP_REQ_TIMED_OUT;
|
||||||
|
#endif
|
||||||
SetLastError(IP_REQ_TIMED_OUT);
|
SetLastError(IP_REQ_TIMED_OUT);
|
||||||
|
#ifdef __REACTOS__
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
TRACE("received %d replies\n",res);
|
TRACE("received %d replies\n",res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue